diff --git a/block_iagora.php b/block_iagora.php index e9e3d75..221ca6f 100644 --- a/block_iagora.php +++ b/block_iagora.php @@ -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. @@ -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); } diff --git a/templates/chat.mustache b/templates/chat.mustache index 2197f4b..7d37786 100644 --- a/templates/chat.mustache +++ b/templates/chat.mustache @@ -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'); @@ -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({ @@ -80,7 +93,10 @@ localTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone, locale, name: 'startConversation', - type: 'event' + type: 'event', + value: { + completedactivities: completedactivities + } }) .subscribe(); subscription.unsubscribe(); @@ -88,6 +104,6 @@ } }); - WebChat.renderWebChat({directLine, locale, styleOptions}, document.getElementById('{{chatId}}')); + WebChat.renderWebChat({directLine, locale, styleOptions, styleSet}, document.getElementById('{{chatId}}')); })(); {{/js}}