From d328ccb1f0a43618616b85fc3f81ff09861482ac Mon Sep 17 00:00:00 2001 From: Max Pomazuev Date: Fri, 10 Nov 2017 12:00:53 +0500 Subject: [PATCH] No event for attempts; check on poll --- classes/condition.php | 10 ++-- db/events.php | 6 --- externallib.php | 108 +++++++++++++++++++++++------------------- locallib.php | 47 ------------------ version.php | 2 +- 5 files changed, 65 insertions(+), 108 deletions(-) delete mode 100644 locallib.php diff --git a/classes/condition.php b/classes/condition.php index 0c8fb1b..f981b39 100644 --- a/classes/condition.php +++ b/classes/condition.php @@ -80,7 +80,7 @@ private static function delete_empty_entry($userid, $courseid, $cmid) { /** * has examus condition * - * @param int $cm Cm + * @param \cm_info $cm Cm * @return bool */ public static function has_examus_condition($cm) { @@ -91,7 +91,7 @@ public static function has_examus_condition($cm) { /** * get examus duration * - * @param int $cm Cm + * @param \cm_info $cm Cm * @return int */ public static function get_examus_duration($cm) { @@ -103,7 +103,7 @@ public static function get_examus_duration($cm) { /** * get examus mode * - * @param int $cm Cm + * @param \cm_info $cm Cm * @return string */ public static function get_examus_mode($cm) { @@ -115,7 +115,7 @@ public static function get_examus_mode($cm) { /** * get examus mode * - * @param int $cm Cm + * @param \cm_info $cm Cm * @return array */ public static function get_examus_rules($cm) { @@ -126,7 +126,7 @@ public static function get_examus_rules($cm) { /** * get examus conditions * - * @param int $cm Cm + * @param \cm_info $cm Cm * @return array */ private static function get_examus_conditions($cm) { diff --git a/db/events.php b/db/events.php index f7a3f70..8a5b8d6 100644 --- a/db/events.php +++ b/db/events.php @@ -33,10 +33,4 @@ 'eventname' => '\core\event\user_enrolment_deleted', 'callback' => '\availability_examus\condition::user_enrolment_deleted' ], - [ - 'eventname' => '\mod_quiz\event\attempt_submitted', - 'callback' => 'examus_attempt_submitted_handler', - 'includefile' => '/availability/condition/examus/locallib.php', - 'internal' => false - ] ]; diff --git a/externallib.php b/externallib.php index 4bb8eb4..deffbab 100644 --- a/externallib.php +++ b/externallib.php @@ -47,6 +47,63 @@ public static function user_proctored_modules_parameters() { ); } + + static function moduleanswer($entry) { + global $DB; + $course = get_course($entry->courseid); + $modinfo = get_fast_modinfo($course); + $cm = $modinfo->get_cm($entry->cmid); + $user = $DB->get_record('user', array('id' => $entry->userid)); + + $url = new moodle_url( + '/availability/condition/examus/entry.php', + array('accesscode' => $entry->accesscode)); + + $moduleanswer = array( + 'id' => $entry->id, + 'name' => $cm->get_formatted_name(), + 'url' => $url->out(), + 'course_name' => $course->fullname, + 'course_id' => $course->id, + 'cm_id' => $entry->cmid, + 'is_proctored' => true, + 'time_limit_mins' => \availability_examus\condition::get_examus_duration($cm), + 'mode' => \availability_examus\condition::get_examus_mode($cm), + 'accesscode' => $entry->accesscode, + ); + $rules = \availability_examus\condition::get_examus_rules($cm); + if ($rules) { + $moduleanswer['rules'] = $rules; + } + + if ($cm->modname == "quiz") { + $quiz = $DB->get_record('quiz', array('id' => $cm->instance)); + $moduleanswer['start'] = $quiz->timeopen; + $moduleanswer['end'] = $quiz->timeclose; + + if ($entry->status == "Started") { + $attempts = quiz_get_user_attempts($quiz->id, $user->id, 'unfinished'); + if (count($attempts) > 0) { + $entry->status = "Started Attempt"; + $DB->update_record('availability_examus', $entry); + } + } + + if ($entry->status == "Started Attempt") { + $attempts = quiz_get_user_attempts($quiz->id, $user->id, 'unfinished'); + if (count($attempts) == 0) { + $entry->status = "Finished"; + $DB->update_record('availability_examus', $entry); + } + } + } + + $moduleanswer['status'] = $entry->status; + + + + return $moduleanswer; + } /** * Returns welcome message * @@ -70,29 +127,8 @@ public static function user_proctored_modules($useremail, $accesscode) { } foreach ($entries as $entry) { - $course = get_course($entry->courseid); - $modinfo = get_fast_modinfo($course); - $cm = $modinfo->get_cm($entry->cmid); - - $moduleanswer = array( - 'id' => $entry->id, - 'name' => $cm->get_formatted_name(), - 'url' => $entry->url, - 'course_name' => $course->fullname, - 'course_id' => $course->id, - 'cm_id' => $entry->cmid, - 'status' => $entry->status, - 'is_proctored' => true, - 'time_limit_mins' => \availability_examus\condition::get_examus_duration($cm), - 'mode' => \availability_examus\condition::get_examus_mode($cm), - 'accesscode' => $entry->accesscode, - ); - $rules = \availability_examus\condition::get_examus_rules($cm); - if ($rules) { - $moduleanswer['rules'] = $rules; - } return array('modules' => array( - $moduleanswer + self::moduleanswer($entry) )); } @@ -118,34 +154,8 @@ public static function user_proctored_modules($useremail, $accesscode) { if ($entry == null) { continue; } - $url = new moodle_url( - '/availability/condition/examus/entry.php', - array('accesscode' => $entry->accesscode)); - $moduleanswer = array( - 'id' => $entry->id, - 'name' => $cm->get_formatted_name(), - 'url' => $url->out(), - 'course_name' => $course->fullname, - 'course_id' => $course->id, - 'cm_id' => $entry->cmid, - 'status' => $entry->status, - 'is_proctored' => true, - 'time_limit_mins' => \availability_examus\condition::get_examus_duration($cm), - 'mode' => \availability_examus\condition::get_examus_mode($cm), - 'accesscode' => $entry->accesscode, - ); - $rules = \availability_examus\condition::get_examus_rules($cm); - if ($rules) { - $moduleanswer['rules'] = $rules; - } - - if ($cm->modname == "quiz") { - $quiz = $DB->get_record('quiz', array('id' => $cm->instance)); - $moduleanswer['start'] = $quiz->timeopen; - $moduleanswer['end'] = $quiz->timeclose; - } - array_push($answer, $moduleanswer); + array_push($answer, self::moduleanswer($entry)); } else { \availability_examus\condition::delete_empty_entry_for_cm($user->id, $cm); diff --git a/locallib.php b/locallib.php deleted file mode 100644 index aa93b74..0000000 --- a/locallib.php +++ /dev/null @@ -1,47 +0,0 @@ -. - -/** - * Availability plugin for integration with Examus proctoring system. - * - * @package availability_examus - * @copyright 2017 Max Pomazuev - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Finish attempt on attempt finish event. - * - * @param stdClass $event Event - */ -function examus_attempt_submitted_handler($event) { - global $DB; - - $course = $DB->get_record('course', array('id' => $event->courseid)); - $attempt = $event->get_record_snapshot('quiz_attempts', $event->objectid); - $quiz = $event->get_record_snapshot('quiz', $attempt->quiz); - $cm = get_coursemodule_from_id('quiz', $event->get_context()->instanceid, $event->courseid); - - $userid = $event->userid; - $entries = $DB->get_records('availability_examus', - array('userid' => $userid, 'courseid' => $event->courseid, 'cmid' => $cm->id, 'status' => "Started"), '-id'); - foreach ($entries as $entry) { - $entry->status = "Finished"; - $DB->update_record('availability_examus', $entry); - } -} \ No newline at end of file diff --git a/version.php b/version.php index 2a082fe..ee5b0ca 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'availability_examus'; -$plugin->version = 2017110803; +$plugin->version = 2017111000; $plugin->release = 'v3.1-r1'; $plugin->requires = 2016052300; $plugin->maturity = MATURITY_STABLE;