From 9e3f57601ae3e7e750319abb690f8a5560945e6e Mon Sep 17 00:00:00 2001 From: Arame22 <151528881+Arame22@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:41:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(projet)=20get=20user=20completion=20r?= =?UTF-8?q?ecover=20the=20student's=20progress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit use moodle's completion tracker to track student progress --- block_iagora.php | 38 ++++++++++++++++++++++++++++++++++++-- templates/chat.mustache | 7 +++++-- 2 files changed, 41 insertions(+), 4 deletions(-) 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();