Skip to content

Commit

Permalink
Introducing proctoring mode; refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MerliX committed Apr 7, 2017
1 parent d6da41c commit e87f4fe
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 61 deletions.
12 changes: 11 additions & 1 deletion classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ class condition extends \core_availability\condition
{

protected $duration = 60;
protected $mode = 'normal';
public function __construct($structure)
{
if (!empty($structure->duration)) {
$this->duration = $structure->duration;
}
if (!empty($structure->mode)) {
$this->mode = $structure->mode;
}
}

private static function delete_empty_entry($userid, $courseid, $cmid)
Expand All @@ -37,6 +41,12 @@ public static function get_examus_duration($cm) {
return (int) $econds[0]->duration;
}

public static function get_examus_mode($cm) {
$econds = self::get_examus_conditions($cm);
// TODO: restrict examus condition to be only one
return (string) $econds[0]->mode;
}

private static function get_examus_conditions($cm) {
$info = new info_module($cm);
try {
Expand All @@ -49,7 +59,7 @@ private static function get_examus_conditions($cm) {

public function save()
{
return (object) ['duration' => (int) $this->duration];
return (object) ['duration' => (int) $this->duration, 'mode' => (string) $this->mode];
}

public function is_available($not,
Expand Down
2 changes: 1 addition & 1 deletion classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class frontend extends \core_availability\frontend {

protected function get_javascript_strings() {
return ['title', 'error_setduration', 'duration', 'link'];
return ['title', 'error_setduration', 'duration', 'link', 'mode', 'normal_mode', 'olympics_mode', 'identification_mode'];
}

protected function get_javascript_init_params($course, \cm_info $cm = null,
Expand Down
61 changes: 29 additions & 32 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static function user_proctored_modules($useremail)

$user = $DB->get_record('user', array('email' => $useremail));
$courses = enrol_get_users_courses($user->id, true);

$answer = array();
foreach ($courses as $course) {
$course = get_course($course->id);

Expand All @@ -40,8 +42,33 @@ public static function user_proctored_modules($useremail)
foreach ($instances_by_types as $instances) {
foreach ($instances as $cm) {
if (\availability_examus\condition::has_examus_condition($cm) and $cm->uservisible) {
\availability_examus\condition::create_entry_for_cm($user->id, $cm);
$entry = \availability_examus\condition::create_entry_for_cm($user->id, $cm);
// TODO build answer array here
$url = new moodle_url(
'/availability/condition/examus/entry.php',
array('accesscode' => $entry->accesscode));
$module_answer = 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' => $entry->duration,
'mode' => \availability_examus\condition::get_examus_mode($cm),
'accesscode' => $entry->accesscode,
);

if ($cm->modname == "quiz") {
$quiz = $DB->get_record('quiz', array('id' => $cm->instance));
$module_answer['start'] = $quiz->timeopen;
$module_answer['end'] = $quiz->timeclose;
}

array_push($answer, $module_answer);


} else {
\availability_examus\condition::delete_empty_entry_for_cm($user->id, $cm);
}
Expand All @@ -51,37 +78,6 @@ public static function user_proctored_modules($useremail)

}

$entries = $DB->get_records('availability_examus', array('userid' => $user->id, 'status' => 'Not inited'));

$answer = array();
foreach ($entries as $entry) {
$course = get_course($entry->courseid);
$modinfo = get_fast_modinfo($course);
$cm = $modinfo->get_cm($entry->cmid);
$url = new moodle_url(
'/availability/condition/examus/entry.php',
array('accesscode' => $entry->accesscode));
$module_answer = 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' => $entry->duration,
'accesscode' => $entry->accesscode,
);

if ($cm->modname == "quiz") {
$quiz = $DB->get_record('quiz', array('id' => $cm->instance));
$module_answer['start'] = $quiz->timeopen;
$module_answer['end'] = $quiz->timeclose;
}

array_push($answer, $module_answer);
}

return array('modules' => $answer);
}

Expand All @@ -102,6 +98,7 @@ public static function user_proctored_modules_returns()
// 'cm_id' => new external_value(PARAM_TEXT, 'module id'),
'course_name' => new external_value(PARAM_TEXT, 'module course name', VALUE_OPTIONAL),
'time_limit_mins' => new external_value(PARAM_INT, 'module duration', VALUE_OPTIONAL),
'mode' => new external_value(PARAM_TEXT, 'module proctoring mode', VALUE_OPTIONAL),
'is_proctored' => new external_value(PARAM_BOOL, 'module proctored'),
'accesscode' => new external_value(PARAM_TEXT, 'module code'),
'start' => new external_value(PARAM_INT, 'module start', VALUE_OPTIONAL),
Expand Down
5 changes: 5 additions & 0 deletions lang/en/availability_examus.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
$string['new_entry_created'] = 'New entry created';
$string['entry_exist'] = 'New entry already exist';
$string['date_modified'] = 'Date of last change';

$string['mode'] = 'Proctoring mode';
$string['normal_mode'] = 'Normal (Full human proctoring)';
$string['olympics_mode'] = 'Olympics (Automatic)';
$string['identification_mode'] = 'Identification (Human identification, automatic proctoring)';
5 changes: 5 additions & 0 deletions lang/ru/availability_examus.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
$string['new_entry_created'] = 'Новая запись успешно создана';
$string['entry_exist'] = 'Новая запись уже существует';
$string['date_modified'] = 'Дата последнего изменения';

$string['mode'] = 'Режим прокторинга';
$string['normal_mode'] = 'Нормальный (Ручной прокторинг)';
$string['olympics_mode'] = 'Олимпиадный (Полностью автоматический)';
$string['identification_mode'] = 'Идентификация (Ручная идентификация, автоматический прокторинг)';
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'availability_examus';
$plugin->version = 2016122900;
$plugin->version = 2017040700;
$plugin->release = 'v3.1-r1';
$plugin->requires = 2016052300;
$plugin->maturity = MATURITY_STABLE;
Loading

0 comments on commit e87f4fe

Please sign in to comment.