Skip to content

Commit

Permalink
proctoring duration
Browse files Browse the repository at this point in the history
  • Loading branch information
MerliX committed Nov 10, 2016
1 parent 13c02e6 commit c89970d
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 40 deletions.
32 changes: 29 additions & 3 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
namespace availability_examus;

defined('MOODLE_INTERNAL') || die();
use core_availability\info_module;
use stdClass;

class condition extends \core_availability\condition
{

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

private static function delete_empty_entry($userid, $courseid, $cmid)
Expand All @@ -25,8 +30,25 @@ private static function examus_enabled_for($cm)
return strpos($cm->availability, '"c":[{"type":"examus"}]') !== false;
}

public static function has_examus_condition(cm_info $cm) {
$econds = self::get_examus_conditions($cm);
return (bool)$econds;
}

public static function get_examus_duration(cm_info $cm) {
$econds = self::get_examus_conditions($cm);
return $econds[0]->duration;
}

private static function get_examus_conditions(cm_info $cm) {
$info = new info_module($cm);
$tree = $info->get_availability_tree();
return $tree->get_all_children('\\availability_examus\\condition');
}

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

public function is_available($not,
Expand Down Expand Up @@ -64,9 +86,13 @@ public static function course_module_deleted(\core\event\course_module_deleted $
private static function create_entry_if_not_exist($userid, $courseid, $cmid)
{
global $DB;
$entry = $DB->get_record('availability_examus', array(
'userid' => $userid, 'courseid' => $courseid, 'cmid' => $cmid));
if (!$entry) {
$entries = $DB->get_records(
'availability_examus',
array('userid' => $userid, 'courseid' => $courseid, 'cmid' => $cmid),
$sort='id');


if (count($entries) !== 0) {
$timenow = time();
$entry = new stdClass();
$entry->userid = $userid;
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 array();
return ['title', 'error_setduration', 'duration'];
}

protected function get_javascript_init_params($course, \cm_info $cm = null,
Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<FIELD NAME="review_link" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Review link"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this record was created"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this record was modified."/>
<!--<FIELD NAME="duration" SEQUENCE="false" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Duration of proctoring session in minutes"/>-->
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
2 changes: 1 addition & 1 deletion externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function user_proctored_modules($useremail)

$user = $DB->get_record('user', array('email' => $useremail));

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

$answer = array();
foreach ($entries as $entry) {
Expand Down
3 changes: 2 additions & 1 deletion lang/en/availability_examus.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
$string['review'] = 'Review';
$string['module'] = 'Module';
$string['new_entry'] = 'New entry';

$string['error_setduration'] = 'Duration in minutes';
$string['duration'] = 'Duration in minutes';

$string[''] = '';
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 = 2016103105;
$plugin->version = 2016103107;
$plugin->release = 'v3.1-r1';
$plugin->requires = 2016052300;
$plugin->maturity = MATURITY_STABLE;

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

Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,50 @@ M.availability_examus = M.availability_examus || {};

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

// M.availability_examus.form.initInner = function(param) {
// // The 'param' variable is the parameter passed through from PHP (you
// // can have more than one if required).
//
// // Using the PHP code above it'll show 'The param was: frog'.
// console.log('The param was: ' + param);
// };
M.availability_examus.form.initInner = function() {
// Nothing
};

M.availability_examus.form.instId = 1;

M.availability_examus.form.getNode = function(json) {
var strings = M.str.availability_examus;
var html = '<label> ' + strings.title + ' </label>';
var node = Y.Node.create('<span> ' + html + ' </span>');
var html, node, root, id, strings;
strings = M.str.availability_examus;

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

html = '<label> ' + strings.title + ' </label><br>';
html += '<label for"' + id + '">' + strings.duration + '</label>';
html += '<input type="text" name="duration" id="' + id + '">';
node = Y.Node.create('<span> ' + html + ' </span>');
if (json.duration !== undefined) {
node.one('input[name=duration]').set('value', json.duration);
}

if (!M.availability_examus.form.addedEvents) {
M.availability_examus.form.addedEvents = true;
root = Y.one('#fitem_id_availabilityconditionsjson');
root.delegate('valuechange', function () {
// Trigger the updating of the hidden availability data whenever the password field changes.
M.core_availability.form.update();
}, '.availability_examus input[name=duration]');
}

return node;
};

M.availability_examus.form.fillValue = function(value, node) {
value.duration = node.one('input[name=duration').get('value').trim();
};

M.availability_examus.form.fillErrors = function(errors, node) {
var value = {};
this.fillValue(value, node);

if (value.duration === undefined || !/^\d+$/.test(value.duration)) {
errors.push('availability_examus:error_setduration');
}
};

}, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]});
Loading

0 comments on commit c89970d

Please sign in to comment.