Skip to content

Commit

Permalink
✨(projet) get user completion recover the student's progress
Browse files Browse the repository at this point in the history
use moodle's completion tracker to track student progress
  • Loading branch information
Arame22 committed Sep 25, 2024
1 parent e7cf614 commit 9e3f576
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
38 changes: 36 additions & 2 deletions block_iagora.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,41 @@ public function get_content() {
} else {
$this->content->text = $this->generate_chat_content($copilotendpointurl);
}
return $this->content;


return $this->content;

}
/**
* Get the student's progress.
*
* @param int $courseid
* @param int $userid
* @return array
*/
function get_student_progress() {
global $COURSE, $USER;

$completedActivities = array();
$completion = new completion_info($COURSE);
$modinfo = get_fast_modinfo($COURSE, $USER->id);
$cms = $modinfo->get_cms();

foreach ($cms as $cm) {
if ($cm->completion == COMPLETION_TRACKING_NONE) {
continue;
}
if (!$cm->uservisible) {
continue;
}
$completiondata = $completion->get_data($cm, true, $USER->id);
if ($completiondata->completionstate == COMPLETION_COMPLETE ||
$completiondata->completionstate == COMPLETION_COMPLETE_PASS) {
$completedActivities[] = $cm->name;
}
}
// Return the array of completed activities
return $completedActivities;
}

/**
Expand All @@ -66,12 +99,13 @@ public function get_content() {
* @return string The generated HTML content for the chat.
*/
private function generate_chat_content($copilotendpointurl) {
global $OUTPUT;
global $OUTPUT, $USER, $COURSE;
// Generate a unique identifier for the chat container.
$chatid = uniqid('iagora_chat_');
$context = [
'chatId' => $chatid,
'tokenEndpointURL' => $copilotendpointurl,
'completedActivities' => json_encode($this->get_student_progress()),
];
return $OUTPUT->render_from_template('block_iagora/chat', $context);
}
Expand Down
7 changes: 5 additions & 2 deletions templates/chat.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
})
.then(({token}) => token)
]);

const completedActivities = {{{completedActivities}}};
const directLine = WebChat.createDirectLine({domain: new URL('v3/directline', directLineURL), token});

const subscription = directLine.connectionStatus$.subscribe({
Expand All @@ -80,7 +80,10 @@
localTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
locale,
name: 'startConversation',
type: 'event'
type: 'event',
value: {
completedActivities: completedActivities
}
})
.subscribe();
subscription.unsubscribe();
Expand Down

0 comments on commit 9e3f576

Please sign in to comment.