From f095cfee04ef4be2c599d7ced26617b7433cfb69 Mon Sep 17 00:00:00 2001 From: Adis Date: Thu, 25 Jan 2024 18:15:18 +0100 Subject: [PATCH] 2024012500 release code --- .../backup_panoptosubmission_stepslib.php | 4 +- db/install.xml | 4 +- db/upgrade.php | 31 +++ grade_submissions.php | 46 ++-- lang/en/panoptosubmission.php | 41 +++- lib.php | 5 +- locallib.php | 198 ++++++++++++------ mod_form.php | 21 +- single_submission.php | 28 ++- single_submission_form.php | 5 + submission.php | 9 +- version.php | 6 +- 12 files changed, 293 insertions(+), 105 deletions(-) diff --git a/backup/moodle2/backup_panoptosubmission_stepslib.php b/backup/moodle2/backup_panoptosubmission_stepslib.php index 8de69c3..e8e3247 100644 --- a/backup/moodle2/backup_panoptosubmission_stepslib.php +++ b/backup/moodle2/backup_panoptosubmission_stepslib.php @@ -50,7 +50,9 @@ protected function define_structure() { 'cutofftime', 'preventlate', 'resubmit', - 'emailteachers', + 'sendnotifications', + 'sendlatenotifications', + 'sendstudentnotifications', 'grade', 'timecreated', 'timemodified' diff --git a/db/install.xml b/db/install.xml index ba0c27a..5766bd4 100644 --- a/db/install.xml +++ b/db/install.xml @@ -12,7 +12,9 @@ xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"> - + + + diff --git a/db/upgrade.php b/db/upgrade.php index 1b991cf..90fb045 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -63,5 +63,36 @@ function xmldb_panoptosubmission_upgrade($oldversion) { // Panopto savepoint reached. upgrade_mod_savepoint(true, 2023012400, 'panoptosubmission'); } + + if ($oldversion < 2023120100) { + $table = new xmldb_table('panoptosubmission'); + + // Update 'emailteachers' to 'sendnotifications'. + $field = new xmldb_field('emailteachers', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', null); + + // Check if field exists. + if ($dbman->field_exists($table, $field)) { + // Rename field emailteachers to sendnotifications. + $dbman->rename_field($table, $field, 'sendnotifications'); + } + + // Add sendlatenotifications field. + $field = new xmldb_field('sendlatenotifications', XMLDB_TYPE_INTEGER, + '2', null, XMLDB_NOTNULL, null, '0', 'sendnotifications'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Add sendstudentnotifications field. + $field = new xmldb_field('sendstudentnotifications', XMLDB_TYPE_INTEGER, + '2', null, XMLDB_NOTNULL, null, '0', 'sendlatenotifications'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Update the savepoint. + upgrade_mod_savepoint(true, 2023120100, 'panoptosubmission'); + } + return true; } diff --git a/grade_submissions.php b/grade_submissions.php index 40f6dc9..cd3ff1d 100644 --- a/grade_submissions.php +++ b/grade_submissions.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * main grading page for the Panopto Student Submission module + * Main grading page for the Panopto Student Submission module. * * @package mod_panoptosubmission * @copyright Panopto 2021 @@ -28,7 +28,8 @@ require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/grade_preferences_form.php'); -$id = required_param('cmid', PARAM_INT); // Course Module ID. +// Course Module ID. +$id = required_param('cmid', PARAM_INT); $mode = optional_param('mode', 0, PARAM_TEXT); $tifirst = optional_param('tifirst', '', PARAM_TEXT); $tilast = optional_param('tilast', '', PARAM_TEXT); @@ -78,10 +79,8 @@ if ($data = $prefform->get_data()) { set_user_preference('panoptosubmission_group_filter', $data->group_filter); - set_user_preference('panoptosubmission_filter', $data->filter); - // Make sure advanced grading is disabled before we enable quick grading. $gradingmanager = get_grading_manager($context, 'mod_panoptosubmission', 'submissions'); $controller = $gradingmanager->get_active_controller(); @@ -120,6 +119,7 @@ foreach ($gradedata->users as $userid => $val) { + $userto = $DB->get_record('user', ['id' => $userid]); $param = array('panactivityid' => $pansubmissionactivity->id, 'userid' => $userid); $usersubmissions = $DB->get_record('panoptosubmission_submission', $param); @@ -127,7 +127,6 @@ if ($usersubmissions) { if (array_key_exists($userid, $gradedata->menu)) { - // Update grade. if (($gradedata->menu[$userid] != $usersubmissions->grade)) { @@ -139,14 +138,10 @@ } } - if (array_key_exists($userid, $gradedata->submissioncomment)) { - - if (0 != strcmp($usersubmissions->submissioncomment, $gradedata->submissioncomment[$userid])) { - $usersubmissions->submissioncomment = $gradedata->submissioncomment[$userid]; - - $updated = true; - - } + if ( array_key_exists($userid, $gradedata->submissioncomment) + && 0 != strcmp($usersubmissions->submissioncomment, $gradedata->submissioncomment[$userid])) { + $usersubmissions->submissioncomment = $gradedata->submissioncomment[$userid]; + $updated = true; } // Trigger grade event. @@ -158,6 +153,18 @@ panoptosubmission_grade_item_update($pansubmissionactivity, $grade); + // Send notification to student. + if ($pansubmissionactivity->sendstudentnotifications) { + panoptosubmission_send_notification($cm, + $course, + $pansubmissionactivity->name, + $submission, + $USER, + $userto, + 'feedbackavailable' + ); + } + // Add to log only if updating. $event = \mod_panoptosubmission\event\grades_updated::create(array( 'context' => $context, @@ -207,6 +214,18 @@ panoptosubmission_grade_item_update($pansubmissionactivity, $grade); + // Send notification to student. + if ($pansubmissionactivity->sendstudentnotifications) { + panoptosubmission_send_notification($cm, + $course, + $pansubmissionactivity->name, + $submission, + $USER, + $userto, + 'feedbackavailable' + ); + } + // Add to log only if updating. $event = \mod_panoptosubmission\event\grades_updated::create(array( 'context' => $context, @@ -216,7 +235,6 @@ )); $event->trigger(); } - } $updated = false; diff --git a/lang/en/panoptosubmission.php b/lang/en/panoptosubmission.php index 58c7c40..52b36f5 100644 --- a/lang/en/panoptosubmission.php +++ b/lang/en/panoptosubmission.php @@ -39,7 +39,6 @@ $string['preventlate_help'] = 'If enabled, this will prevent students from submitting the assignment after the due date.'; $string['allowdeleting'] = 'Allow resubmitting'; $string['allowdeleting_help'] = 'If enabled, students may replace submitted videos. Whether it is possible to submit after the due date is controlled by the \'Prevent late submissions\' setting'; -$string['emailteachers'] = 'Email alerts to teachers'; $string['emailteachers_help'] = 'If enabled, teachers receive email notification whenever students add or update an assignment submission. Only teachers who are able to grade the particular assignment are notified. So, for example, if the course uses separate groups, teachers restricted to particular groups won\'t receive notification about students in other groups.'; $string['invalidid'] = 'Invalid ID'; $string['invalid_launch_parameters'] = 'Invalid launch parameters'; @@ -93,6 +92,16 @@ $string['submissions'] = 'Submissions'; $string['gradeitem:submissions'] = 'Submissions'; $string['feedback'] = 'Feedback'; +$string['feedbackavailabletext'] = '{$a->username} has posted some feedback on your +assignment submission for \'{$a->assignment}\' + +You can see it appended to your assignment submission: + + {$a->url}'; +$string['feedbackavailablehtml'] = '{$a->username} has posted some feedback on your +assignment submission for \'{$a->assignment}\'

+You can see it appended to your assignment submission.'; +$string['feedbackavailablesmall'] = '{$a->username} has given feedback for assignment {$a->assignment}'; $string['singlesubmissionheader'] = 'Grade submission'; $string['singlegrade'] = 'Add help text'; $string['singlegrade_help'] = 'Add help text'; @@ -102,20 +111,27 @@ $string['save'] = 'Save Changes'; $string['cancel'] = 'Close'; $string['pluginname'] = 'Panopto Student Submission'; -$string['emailteachermail'] = '{$a->username} has updated their assignment submission +$string['gradersubmissionupdatedtext'] = '{$a->username} has updated their assignment submission for \'{$a->assignment}\' at {$a->timeupdated} View the submission here: {$a->url}'; -$string['emailteachermailhtml'] = '{$a->username} has updated their assignment submission +$string['gradersubmissionupdatedhtml'] = '{$a->username} has updated their assignment submission for \'{$a->assignment}\' at {$a->timeupdated}

It is available on the web site.'; +$string['gradersubmissionupdatedsmall'] = '{$a->username} has updated their submission for assignment {$a->assignment}.'; +$string['submissionreceipttext'] = 'You have submitted an +assignment submission for \'{$a->assignment}\' + +You can see the status of your assignment submission: + + {$a->url}'; +$string['submissionreceipthtml'] = '

You have submitted an assignment submission for \'{$a->assignment}\'.

+

You can see the status of your assignment submission.

'; +$string['submissionreceiptsmall'] = 'You have submitted your assignment submission for {$a->assignment}'; $string['messageprovider:panoptosubmission_updates'] = 'Panopto Student Submission notifications'; $string['video_preview_header'] = 'Submission preview'; -$string['panoptosubmission:gradesubmission'] = 'Grade video submissions'; -$string['panoptosubmission:addinstance'] = 'Add a Panopto Student Submission activity'; -$string['panoptosubmission:submit'] = 'Submit'; $string['noenrolledstudents'] = 'No students are enrolled in the course'; $string['group_filter'] = 'Group Filter'; $string['noassignments'] = 'No Panopto Student Submission activities found in the course'; @@ -144,6 +160,15 @@ $string['quickgrade_help'] = 'If enabled, multiple assignments can be graded at the same time. Update grades and feedback and then click "Save all feedback".'; $string['no_existing_lti_tools'] = 'A preconfigured Panopto LTI tool with the custom parameter "panopto_student_submission_tool" must exist to be able to use the Panopto Student Submission activity. Please see setup documentation for more information.'; $string['no_automatic_operation_target_server'] = 'Please set Automatic Operation Target Server in the settings, so course can be provisioned.'; +$string['notifications'] = 'Notifications'; +$string['sendstudentnotificationsdefault'] = 'Default for \'Notify student\''; +$string['sendstudentnotificationsdefault_help'] = 'When grading each student, should \'Notify student\' be ticked by default?'; +$string['sendstudentnotifications'] = 'Notify student'; +$string['sendstudentnotifications_help'] = 'Tick this box to send a notification about the updated grade or feedback. If the assignment uses a marking workflow, or the grades are hidden in the grader report, then the notification will not be sent until the grade is released.'; +$string['sendnotifications'] = 'Notify graders about submissions'; +$string['sendnotifications_help'] = 'If enabled, graders (usually teachers) receive a message whenever a student submits an assignment, early, on time and late.'; +$string['sendlatenotifications'] = 'Notify graders about late submissions'; +$string['sendlatenotifications_help'] = 'If enabled, graders (usually teachers) receive a message whenever a student submits an assignment late.'; $string['privacy:metadata:emailteachersexplanation'] = 'Messages are sent to teachers through the messaging system.'; $string['privacy:metadata:panoptosubmission_submission'] = 'Panopto Student Submission submissions'; $string['privacy:metadata:panoptosubmission_submission:email'] = 'Your email is sent to Panopto to allow use of Panopto\'s email features.'; @@ -163,3 +188,7 @@ $string['privacy:metadata:panoptosubmissionquickgrade'] = 'Quick grading preference for Panopto Submission.'; $string['privacy:markedsubmissionspath'] = 'markedsubmissions'; $string['privacy:submissionpath'] = 'submission'; +$string['panoptosubmission:gradesubmission'] = 'Grade video submissions'; +$string['panoptosubmission:addinstance'] = 'Add a Panopto Student Submission activity'; +$string['panoptosubmission:submit'] = 'Submit'; +$string['panoptosubmission:receivegradernotifications'] = 'Receive grader submission notifications'; diff --git a/lib.php b/lib.php index ab094a9..91adeac 100644 --- a/lib.php +++ b/lib.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * main lib.php file for the Panopto Student Submission mod + * Main lib.php file for the Panopto Student Submission mod. * * @package mod_panoptosubmission * @copyright Panopto 2021 @@ -178,7 +178,6 @@ function panoptosubmission_user_outline($course, $user, $mod, $data) { return $return; } - /** * Print a detailed representation of what a user has done with * a given particular instance of this module, for user activity reports. @@ -208,7 +207,6 @@ function panoptosubmission_print_recent_activity($course, $viewfullnames, $times return false; } - /** * Must return an array of users who are participants an instance of the * Panopto Student Submission activity @@ -220,7 +218,6 @@ function panoptosubmission_get_participants($targetactivity) { return false; } - /** * This function returns if a scale is being used by one panoptosubmission * if it has support for grading and scales. Commented code should be diff --git a/locallib.php b/locallib.php index 9a2a457..744cad7 100644 --- a/locallib.php +++ b/locallib.php @@ -213,59 +213,62 @@ function panoptosubmission_display_lateness($timesubmitted, $timedue) { } /** - * Alerts teachers by email of new or changed assignments that need grading + * Alerts users by email of new or changed assignments. * - * Sends an email to ALL teachers in the course (or in the group if using separate groups). * * @param object $cm Panopto Student Submission activity course module object. + * @param object $course The course object. * @param string $name Name of the Panopto activity instance. * @param object $submission The submission that has changed. - * @param object $context The context object. + * @param stdClass $userfrom User that is sending notification. + * @param stdClass $userto User that is receiving notification. + * @param string $messagetype Message type. */ -function panoptosubmission_email_teachers($cm, $name, $submission, $context) { - global $CFG, $DB, $COURSE; - - $user = $DB->get_record('user', array('id' => $submission->userid)); - - if ($teachers = panoptosubmission_get_graders($cm, $user, $context)) { - - $strassignments = get_string('modulenameplural', 'panoptosubmission'); - $strassignment = get_string('modulename', 'panoptosubmission'); - $strsubmitted = get_string('submitted', 'panoptosubmission'); - - foreach ($teachers as $teacher) { - $info = new stdClass(); - $info->username = fullname($user, true); - $info->assignment = format_string($name, true); - $info->url = $CFG->wwwroot . '/mod/panoptosubmission/grade_submissions.php?cmid=' . $cm->id; - $info->timeupdated = strftime('%c', $submission->timemodified); - $info->courseid = $cm->course; - $info->cmid = $cm->id; - - $postsubject = $strsubmitted . ': ' . $user->username . ' -> ' . $name; - $posttext = panoptosubmission_email_teachers_text($info); - $posthtml = ($teacher->mailformat == 1) ? panoptosubmission_email_teachers_html($info) : ''; - - $eventdata = new \core\message\message(); - $eventdata->courseid = $COURSE->id; - $eventdata->modulename = 'panoptosubmission'; - $eventdata->userfrom = $user; - $eventdata->userto = $teacher; - $eventdata->subject = $postsubject; - $eventdata->fullmessage = $posttext; - $eventdata->fullmessageformat = FORMAT_PLAIN; - $eventdata->fullmessagehtml = $posthtml; - $eventdata->smallmessage = $postsubject; - - $eventdata->name = 'panoptosubmission_updates'; - $eventdata->component = 'mod_panoptosubmission'; - $eventdata->notification = 1; - $eventdata->contexturl = $info->url; - $eventdata->contexturlname = $info->assignment; - - message_send($eventdata); - } - } +function panoptosubmission_send_notification($cm, + $course, + $name, + $submission, + $userfrom, + $userto, + $messagetype) { + global $CFG; + + $modulename = get_string('modulename', 'panoptosubmission'); + $strsubmitted = get_string('submitted', 'panoptosubmission'); + $courseid = $cm->course ?? $course->id; + + $info = new stdClass(); + $info->username = fullname($userfrom, true); + $info->assignment = format_string($name, true); + $info->url = $CFG->wwwroot . '/mod/panoptosubmission/grade_submissions.php?cmid=' . $cm->id; + $info->timeupdated = strftime('%c', $submission->timemodified); + $info->courseid = $courseid; + $info->cmid = $cm->id; + + $postsubject = $strsubmitted . ': ' . $userfrom->username . ' -> ' . $name; + $posttext = panoptosubmission_format_notification_message_text($messagetype, $course, $info, $modulename); + $posthtml = ($userto->mailformat == 1) + ? panoptosubmission_format_notification_message_html($messagetype, $course, $info) + : ''; + + $eventdata = new \core\message\message(); + $eventdata->courseid = $courseid; + $eventdata->modulename = 'panoptosubmission'; + $eventdata->userfrom = $userfrom; + $eventdata->userto = $userto; + $eventdata->subject = $postsubject; + $eventdata->fullmessage = $posttext; + $eventdata->fullmessageformat = FORMAT_PLAIN; + $eventdata->fullmessagehtml = $posthtml; + $eventdata->smallmessage = $postsubject; + + $eventdata->name = 'panoptosubmission_updates'; + $eventdata->component = 'mod_panoptosubmission'; + $eventdata->notification = 1; + $eventdata->contexturl = $info->url; + $eventdata->contexturlname = $info->assignment; + + message_send($eventdata); } /** @@ -278,7 +281,8 @@ function panoptosubmission_email_teachers($cm, $name, $submission, $context) { */ function panoptosubmission_get_graders($cm, $user, $context) { // Potential graders. - $potgraders = get_enrolled_users($context, 'mod/panoptosubmission:gradesubmission', 0, 'u.*', null, 0, 0, true); + $potgraders = get_enrolled_users($context, 'mod/panoptosubmission:gradesubmission', + 0, 'u.*', null, 0, 0, true); $graders = array(); // Separate groups are being used. @@ -322,24 +326,76 @@ function panoptosubmission_get_graders($cm, $user, $context) { } /** - * Creates the text content for emails to teachers + * Send notifications to graders upon student submissions. + * + * @param object $pansubmissionactivity The submission object or NULL in which case it will be loaded + * @param object $submission The submission that has changed. + * @param object $cm Panopto Student Submission activity course module object. + * @param object $context The context object. + * @param object $course The course object. + * @return void + */ +function panoptosubmission_notify_graders($pansubmissionactivity, + $submission, + $cm, + $context, + $course) { + global $DB, $USER; + + $late = $pansubmissionactivity->timedue && ($pansubmissionactivity->timedue < time()); + + if (!$pansubmissionactivity->sendnotifications && !($late && $pansubmissionactivity->sendlatenotifications)) { + // No need to do anything. + return; + } + + if ($submission->userid) { + $user = $DB->get_record('user', ['id' => $submission->userid]); + } else { + $user = $USER; + } + + if ($teachers = panoptosubmission_get_graders($cm, $user, $context)) { + foreach ($teachers as $teacher) { + panoptosubmission_send_notification($cm, + $course, + $pansubmissionactivity->name, + $submission, + $user, + $teacher, + 'gradersubmissionupdated' + ); + } + } +} + +/** + * Creates the text content for emails. * - * @param object $info The info used by the 'emailteachermail' language string + * @param string $messagetype Message type. + * @param object $course Course object. + * @param object $info The info used by the messagetype language strings. + * @param string $modulename Module name. * @return string */ -function panoptosubmission_email_teachers_text($info) { +function panoptosubmission_format_notification_message_text($messagetype, $course, $info, $modulename) { global $DB; - $param = array('id' => $info->courseid); - $course = $DB->get_record('course', $param); + if (empty($course)) { + $param = array('id' => $info->courseid); + $course = $DB->get_record('course', $param); + } + $posttext = ''; if (!empty($course)) { - $posttext = format_string($course->shortname, true, $course->id) . ' -> ' . - get_string('modulenameplural', 'panoptosubmission') . ' -> '; - $posttext .= format_string($info->assignment, true, $course->id) . "\n"; + $posttext = format_string($course->shortname, true, $course->id) . + ' -> ' . + $modulename . + ' -> ' . + format_string($info->assignment, true, $course->id) . "\n"; $posttext .= '---------------------------------------------------------------------' . "\n"; - $posttext .= get_string('emailteachermail', 'panoptosubmission', $info) . "\n"; + $posttext .= get_string($messagetype . 'text', 'panoptosubmission', $info) . "\n"; $posttext .= "\n---------------------------------------------------------------------\n"; } @@ -347,16 +403,21 @@ function panoptosubmission_email_teachers_text($info) { } /** - * Creates the html content for emails to teachers + * Creates the html content for emails. * - * @param object $info The info used by the 'emailteachermailhtml' language string + * @param string $messagetype Message type. + * @param object $course Course object. + * @param object $info The info used by the messagetype language strings. * @return string */ -function panoptosubmission_email_teachers_html($info) { - global $CFG, $DB; +function panoptosubmission_format_notification_message_html($messagetype, $course, $info) { + global $DB; + + if (empty($course)) { + $param = array('id' => $info->courseid); + $course = $DB->get_record('course', $param); + } - $param = array('id' => $info->courseid); - $course = $DB->get_record('course', $param); $posthtml = ''; if (!empty($course)) { @@ -368,7 +429,7 @@ function panoptosubmission_email_teachers_html($info) { $posthtml .= html_writer::tag('a', format_string($info->assignment, true, $course->id), $attr); $posthtml .= html_writer::end_tag('p'); $posthtml .= html_writer::start_tag('hr'); - $posthtml .= html_writer::tag('p', get_string('emailteachermailhtml', 'panoptosubmission', $info)); + $posthtml .= html_writer::tag('p', get_string($messagetype . 'html', 'panoptosubmission', $info)); $posthtml .= html_writer::end_tag('hr'); } return $posthtml; @@ -397,7 +458,7 @@ function panoptosubmission_get_assignment_students($cm) { * @return array An array of grading userids */ function panoptosubmission_get_grading_instance($cminstance, $context, $submission, $gradingdisabled) { - global $CFG, $USER; + global $USER; $grademenu = make_grades_menu($cminstance->grade); $allowgradedecimals = $cminstance->grade > 0; @@ -443,7 +504,12 @@ function panoptosubmission_get_grading_instance($cminstance, $context, $submissi * @return panoptosubmission_submissions_feedback_status renderable object */ function panoptosubmission_get_feedback_status_renderable($cm, - $pansubmissionactivity, $submission, $context, $userid, $grade, $teacher) { + $pansubmissionactivity, + $submission, + $context, + $userid, + $grade, + $teacher) { global $DB, $PAGE; $gradinginfo = grade_get_grades($pansubmissionactivity->course, diff --git a/mod_form.php b/mod_form.php index 28f7749..5207377 100644 --- a/mod_form.php +++ b/mod_form.php @@ -82,9 +82,22 @@ public function definition() { $mform->addHelpButton('resubmit', 'allowdeleting', 'panoptosubmission'); $mform->setDefault('resubmit', 0); - $mform->addElement('select', 'emailteachers', get_string('emailteachers', 'panoptosubmission'), $ynoptions); - $mform->addHelpButton('emailteachers', 'emailteachers', 'panoptosubmission'); - $mform->setDefault('emailteachers', 0); + // Notifications. + $mform->addElement('header', 'notifications', get_string('notifications', 'panoptosubmission')); + + $name = get_string('sendnotifications', 'panoptosubmission'); + $mform->addElement('selectyesno', 'sendnotifications', $name); + $mform->addHelpButton('sendnotifications', 'sendnotifications', 'panoptosubmission'); + + $name = get_string('sendlatenotifications', 'panoptosubmission'); + $mform->addElement('selectyesno', 'sendlatenotifications', $name); + $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'panoptosubmission'); + $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1); + + $name = get_string('sendstudentnotificationsdefault', 'panoptosubmission'); + $mform->addElement('selectyesno', 'sendstudentnotifications', $name); + $mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'panoptosubmission'); + $mform->setDefault('sendstudentnotificationsdefault', 0); $this->standard_grading_coursemodule_elements(); @@ -93,8 +106,6 @@ public function definition() { $this->add_action_buttons(); } - - /** * Perform minimal validation on the settings form * @param array $data diff --git a/single_submission.php b/single_submission.php index a5b4e62..aa40708 100644 --- a/single_submission.php +++ b/single_submission.php @@ -168,13 +168,16 @@ $currentgrade = $submitteddata->xgrade; } + $notifystudentchanged = $pansubmissionactivity->sendstudentnotifications != $submitteddata->sendstudentnotifications; if (!$blanksubmission) { $submissionchanged = strcmp( $submission->submissioncomment ?? '', $submitteddata->submissioncomment_editor['text'] ?? '' ); - if ($submission->grade == $currentgrade && !$submissionchanged) { + if ( $submission->grade == $currentgrade + && !$notifystudentchanged + && !$submissionchanged) { $updategrade = false; } if ($submissionchanged || $updategrade) { @@ -199,11 +202,32 @@ if ($updategrade) { $pansubmissionactivity->cmidnumber = $cm->idnumber; - $gradeobj = panoptosubmission_get_submission_grade_object($pansubmissionactivity->id, $userid); panoptosubmission_grade_item_update($pansubmissionactivity, $gradeobj); + if (empty($teacher)) { + $teacher = $USER; + } + + // Update notify student flag if there was a change. + if ($notifystudentchanged) { + $pansubmissionactivity->sendstudentnotifications = $submitteddata->sendstudentnotifications; + $DB->update_record('panoptosubmission', $pansubmissionactivity); + } + + // Send notification to student. + if ($pansubmissionactivity->sendstudentnotifications) { + panoptosubmission_send_notification($cm, + $course, + $pansubmissionactivity->name, + $submission, + $teacher, + $user, + 'feedbackavailable' + ); + } + // Add to log. $event = \mod_panoptosubmission\event\grades_updated::create(array( 'context' => $context, diff --git a/single_submission_form.php b/single_submission_form.php index 68dc811..94ee7a4 100644 --- a/single_submission_form.php +++ b/single_submission_form.php @@ -204,6 +204,11 @@ public function definition() { } + // Notify student checkbox. + $mform->addElement('selectyesno', 'sendstudentnotifications', get_string('sendstudentnotifications', 'panoptosubmission')); + $mform->setDefault('sendstudentnotifications', $this->_customdata->cminstance->sendstudentnotifications ?? 0); + $mform->setType('sendstudentnotifications', PARAM_BOOL); + $this->add_action_buttons(); } diff --git a/submission.php b/submission.php index 5f4362e..2f72318 100644 --- a/submission.php +++ b/submission.php @@ -149,8 +149,11 @@ $context = $PAGE->context; // Email an alert to the teacher. -if ($pansubmissionactivity->emailteachers) { - panoptosubmission_email_teachers($cm, $pansubmissionactivity->name, $submission, $context); -} +panoptosubmission_notify_graders($pansubmissionactivity, + $submission, + $cm, + $context, + $course); + echo $OUTPUT->footer(); diff --git a/version.php b/version.php index 9a9aa3c..c0825d2 100644 --- a/version.php +++ b/version.php @@ -25,10 +25,10 @@ defined('MOODLE_INTERNAL') || die(); // The current plugin version (Date: YYYYMMDDXX). -$plugin->version = 2023083100; +$plugin->version = 2024012500; -// Requires this Moodle version - 2.7. -$plugin->requires = 2014051202; +// Requires this Moodle version - 4.1.0 +$plugin->requires = 2022112800; // Never run cron for this plugin. $plugin->cron = 0;