diff --git a/block_iagora.php b/block_iagora.php index e9e3d75..71bc03c 100644 --- a/block_iagora.php +++ b/block_iagora.php @@ -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; } /** @@ -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); } diff --git a/templates/chat.mustache b/templates/chat.mustache index 2197f4b..eb5fdcc 100644 --- a/templates/chat.mustache +++ b/templates/chat.mustache @@ -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({ @@ -80,7 +80,10 @@ localTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone, locale, name: 'startConversation', - type: 'event' + type: 'event', + value: { + completedActivities: completedActivities + } }) .subscribe(); subscription.unsubscribe();