Skip to content

Commit

Permalink
Merge pull request #6 from examus/attempt-poll
Browse files Browse the repository at this point in the history
No event for attempts; check on poll
  • Loading branch information
MerliX authored Nov 10, 2017
2 parents 1682375 + d328ccb commit 8e45aec
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 108 deletions.
10 changes: 5 additions & 5 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
];
108 changes: 59 additions & 49 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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)
));
}

Expand All @@ -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);
Expand Down
47 changes: 0 additions & 47 deletions locallib.php

This file was deleted.

2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 8e45aec

Please sign in to comment.