Skip to content

Commit

Permalink
Merge pull request #5 from examus/rules
Browse files Browse the repository at this point in the history
Rules
  • Loading branch information
MerliX authored Nov 9, 2017
2 parents 48b55a3 + 973fd2c commit 1682375
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 44 deletions.
21 changes: 19 additions & 2 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class condition extends \core_availability\condition {
/** @var string Default exam mode */
protected $mode = 'normal';

/** @var array Default exam rules */
protected $rules = Array();

/**
* Construct
*
Expand All @@ -56,6 +59,9 @@ public function __construct($structure) {
if (!empty($structure->mode)) {
$this->mode = $structure->mode;
}
if (!empty($structure->rules)) {
$this->rules = $structure->rules;
}
}

/**
Expand Down Expand Up @@ -106,6 +112,17 @@ public static function get_examus_mode($cm) {
return (string) $econds[0]->mode;
}

/**
* get examus mode
*
* @param int $cm Cm
* @return array
*/
public static function get_examus_rules($cm) {
$econds = self::get_examus_conditions($cm);
return (array) $econds[0]->rules;
}

/**
* get examus conditions
*
Expand All @@ -128,7 +145,7 @@ private static function get_examus_conditions($cm) {
* @return object
*/
public function save() {
return (object) ['duration' => (int) $this->duration, 'mode' => (string) $this->mode];
return (object) ['duration' => (int) $this->duration, 'mode' => (string) $this->mode, 'rules' => (array) $this->rules];
}

/**
Expand Down Expand Up @@ -208,7 +225,7 @@ public static function course_module_deleted(\core\event\course_module_deleted $
*
* @param int $userid User id
* @param stdClass $cm Cm
* @return bool
* @return stdClass
*/
public static function create_entry_for_cm($userid, $cm) {
$course = $cm->get_course();
Expand Down
20 changes: 17 additions & 3 deletions classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class frontend extends \core_availability\frontend {
* @return array
*/
protected function get_javascript_strings() {
return ['title', 'error_setduration', 'duration', 'link', 'mode', 'normal_mode', 'olympics_mode', 'identification_mode'];
return ['title', 'error_setduration', 'duration', 'link', 'mode', 'normal_mode',
'rules', 'olympics_mode', 'identification_mode', 'allow_to_use_websites',
'allow_to_use_books', 'allow_to_use_paper', 'allow_to_use_messengers',
'allow_to_use_calculator', 'allow_to_use_excel', 'allow_to_use_human_assistant',
'allow_absence_in_frame', 'allow_voices', 'allow_wrong_gaze_direction'];
}

/**
Expand All @@ -52,7 +56,17 @@ protected function get_javascript_strings() {
*/
protected function get_javascript_init_params($course, \cm_info $cm = null,
\section_info $section = null) {
return array();
$rules['allow_to_use_websites'] = false;
$rules['allow_to_use_books'] = false;
$rules['allow_to_use_paper'] = true;
$rules['allow_to_use_messengers'] = false;
$rules['allow_to_use_calculator'] = true;
$rules['allow_to_use_excel'] = false;
$rules['allow_to_use_human_assistant'] = false;
$rules['allow_absence_in_frame'] = false;
$rules['allow_voices'] = false;
$rules['allow_wrong_gaze_direction'] = false;
return array($rules);
}

/**
Expand All @@ -61,7 +75,7 @@ protected function get_javascript_init_params($course, \cm_info $cm = null,
* @param int $course Course id
* @param \cm_info $cm Cm
* @param \section_info $section Section
* @return array
* @return bool
*/
protected function allow_add($course, \cm_info $cm = null,
\section_info $section = null) {
Expand Down
48 changes: 35 additions & 13 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,25 @@ public static function user_proctored_modules($useremail, $accesscode) {
$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(
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,
)
$moduleanswer
));
}

Expand Down Expand Up @@ -129,6 +134,10 @@ public static function user_proctored_modules($useremail, $accesscode) {
'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));
Expand Down Expand Up @@ -167,6 +176,19 @@ public static function user_proctored_modules_returns() {
'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),
'rules' => new external_single_structure(
array(
'allow_to_use_websites' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_to_use_books' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_to_use_paper' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_to_use_messengers' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_to_use_calculator' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_to_use_excel' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_to_use_human_assistant' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_absence_in_frame' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_voices' => new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
'allow_wrong_gaze_direction'=> new external_value(PARAM_BOOL, 'proctoring rule', VALUE_OPTIONAL),
), 'rules set', 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
15 changes: 14 additions & 1 deletion lang/en/availability_examus.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@
$string['olympics_mode'] = 'Olympics (Automatic)';
$string['identification_mode'] = 'Identification (Human identification, automatic proctoring)';

$string['time_scheduled'] = 'Scheduled';
$string['rules'] = "Rules";

$string['time_scheduled'] = 'Scheduled';

$string['allow_to_use_websites'] = 'Allow to use websites';
$string['allow_to_use_books'] = 'Allow to use books';
$string['allow_to_use_paper'] = 'Allow to use paper';
$string['allow_to_use_messengers'] = 'Allow to use messengers';
$string['allow_to_use_calculator'] = 'Allow to use calculator';
$string['allow_to_use_excel'] = 'Allow to use excel';
$string['allow_to_use_human_assistant'] = 'Allow to use human assistant';
$string['allow_absence_in_frame'] = 'Allow absence in frame';
$string['allow_voices'] = 'Allow voices';
$string['allow_wrong_gaze_direction'] = 'Allow wrong gaze direction';
15 changes: 14 additions & 1 deletion lang/ru/availability_examus.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@
$string['olympics_mode'] = 'Олимпиадный (Полностью автоматический)';
$string['identification_mode'] = 'Идентификация (Ручная идентификация, автоматический прокторинг)';

$string['time_scheduled'] = 'Время записи в календаре';
$string['rules'] = 'Правила';

$string['time_scheduled'] = 'Время записи в календаре';

$string['allow_to_use_websites'] = 'Разрешить использование веб-сайтов';
$string['allow_to_use_books'] = 'Разрешить использование книг';
$string['allow_to_use_paper'] = 'Разрешить использование черновиков';
$string['allow_to_use_messengers'] = 'Разрешить использование мессенджеров';
$string['allow_to_use_calculator'] = 'Разрешить использование калькулятора';
$string['allow_to_use_excel'] = 'Разрешить использование Excel';
$string['allow_to_use_human_assistant'] = 'Разрешить использование помощи людей';
$string['allow_absence_in_frame'] = 'Разрешить выход из комнаты';
$string['allow_voices'] = 'Разрешить голоса';
$string['allow_wrong_gaze_direction'] = 'Разрешить взгляд в сторону';
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 = 2017061615;
$plugin->version = 2017110803;
$plugin->release = 'v3.1-r1';
$plugin->requires = 2016052300;
$plugin->maturity = MATURITY_STABLE;

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,53 @@ YUI.add('moodle-availability_examus-form', function (Y, NAME) {
*
* @module moodle-availability_examus-form
*/
/** @suppress checkVars */
M.availability_examus = M.availability_examus || {};

M.availability_examus.form = Y.Object(M.core_availability.plugin);

M.availability_examus.form.initInner = function() {
// Nothing.
M.availability_examus.form.rules = null;

M.availability_examus.form.initInner = function(rules)
{
this.rules = rules;
};

M.availability_examus.form.instId = 1;

M.availability_examus.form.getNode = function(json) {
var html, node, root, id, modeId;

function get_string(identifier) {
/** Returns string from translations. */
function getString(identifier) {
return M.util.get_string(identifier, 'availability_examus');
}

id = 'examus' + M.availability_examus.form.instId;
M.availability_examus.form.instId += 1;

html = '<label> ' + get_string('title') + ' </label><br>';
html = '<label> ' + getString('title') + ' </label><br>';

html += '<label for"' + id + '">' + get_string('duration') + '</label> ';
html += '<label for"' + id + '">' + getString('duration') + '</label> ';
html += '<input type="text" name="duration" id="' + id + '">';

modeId = 'examus' + M.availability_examus.form.instId;
html += '<br><label for"' + modeId + '">' + get_string('mode') + '</label> ';
html += '<br><label for"' + modeId + '">' + getString('mode') + '</label> ';
html += '<select name="mode" id="' + modeId + '">';
html += ' <option value="normal">' + get_string('normal_mode') + '</option>';
html += ' <option value="identification">' + get_string('identification_mode') + '</option>';
html += ' <option value="olympics">' + get_string('olympics_mode') + '</option>';
html += ' <option value="normal">' + getString('normal_mode') + '</option>';
html += ' <option value="identification">' + getString('identification_mode') + '</option>';
html += ' <option value="olympics">' + getString('olympics_mode') + '</option>';
html += '</select>';

html += '<div class="rules">';
html += '<label>' + getString('rules') + '</label> ';
for (var key in this.rules) {
html += ' <br><input type="checkbox" name="' + key + '" id="' + key + '" value="' + key + '" >';
html += ' <label for="' + key + '">' + getString(key) + '</label>';
}
html += '</div>';


node = Y.Node.create('<span> ' + html + ' </span>');
if (json.duration !== undefined) {
node.one('input[name=duration]').set('value', json.duration);
Expand All @@ -48,6 +62,16 @@ M.availability_examus.form.getNode = function(json) {
node.one('select[name=mode] option[value=' + json.mode + ']').set('selected', 'selected');
}

if (json.rules === undefined) {
json.rules = this.rules
}

for (key in json.rules) {
if (json.rules[key]) {
node.one('.rules input[name=' + key + ']').set('checked', 'checked');
}
}

if (!M.availability_examus.form.addedEvents) {
M.availability_examus.form.addedEvents = true;
root = Y.one(".availability-field");
Expand All @@ -57,14 +81,29 @@ M.availability_examus.form.getNode = function(json) {
root.delegate('valuechange', function() {
M.core_availability.form.update();
}, '.availability_examus select[name=mode]');
root.delegate('click', function() {
M.core_availability.form.update();
}, '.availability_examus .rules input');
}

return node;
};

M.availability_examus.form.fillValue = function(value, node) {
var rulesInputs, key;
value.duration = node.one('input[name=duration]').get('value').trim();
value.mode = node.one('select[name=mode]').get('value').trim();
value.rules = {};
rulesInputs = node.all('.rules input');
Y.each(rulesInputs, function (ruleInput) {
key = ruleInput.get('value');
if (ruleInput.get('checked') === true) {
value.rules[key] = true;
} else {
value.rules[key] = false;
}

});
};

M.availability_examus.form.fillErrors = function(errors, node) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1682375

Please sign in to comment.