Skip to content

Commit

Permalink
✨(projet) get user completion ecover 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 Oct 8, 2024
1 parent e7cf614 commit 6b5b399
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
38 changes: 37 additions & 1 deletion block_iagora.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,44 @@ public function get_content() {
} else {
$this->content->text = $this->generate_chat_content($copilotendpointurl);
}

return $this->content;

}

/**
* Retrieves the progress of a student in the current course.
*
* This function returns an array containing the names of activities the student has completed
* based on their activity completion status within the course.
*
* @return array An array of completed activities.
*/
private function get_student_progress() {
global $COURSE, $USER;

$completedactivities = [];
$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;
}

/**
* Generate the HTML content for the chat block.
Expand All @@ -66,12 +101,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
24 changes: 20 additions & 4 deletions templates/chat.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,21 @@
/* eslint-disable promise/no-native */
(async function() {
const styleOptions = {
hideUploadButton: true
hideUploadButton: true,
botAvatarImage: "/image/iagora.jpg",
botAvatarInitials: 'BF',
userAvatarImage: 'https://github.com/compulim.png?size=64',
userAvatarInitials: 'WC'
};
const styleSet = window.WebChat.createStyleSet({
bubbleBackground: 'rgba(0, 0, 255, .1)',
bubbleFromUserBackground: 'rgba(0, 255, 0, .1)'
});

styleSet.textContent = Object.assign({}, styleSet.textContent, {
fontFamily: "'Comic Sans MS', 'Arial', sans-serif",
fontWeight: 'bold'
});
const tokenEndpointURL = new URL('{{tokenEndpointURL}}');
const locale = document.documentElement.lang || 'en';
const apiVersion = tokenEndpointURL.searchParams.get('api-version');
Expand All @@ -69,7 +82,7 @@
})
.then(({token}) => token)
]);

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

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

WebChat.renderWebChat({directLine, locale, styleOptions}, document.getElementById('{{chatId}}'));
WebChat.renderWebChat({directLine, locale, styleOptions, styleSet}, document.getElementById('{{chatId}}'));
})();
{{/js}}

0 comments on commit 6b5b399

Please sign in to comment.