Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ class condition extends \core_availability\condition {
* @throws \coding_exception If invalid data structure.
*/
public function __construct($structure) {
// Get courseid.
if (isset($structure->cm) && is_number($structure->cm)) {
$this->courseid = (int)$structure->cm;
// Get courseid. Accept 'course' (post-69e5c26) and 'cm' (pre-69e5c26) for backwards compatibility.
if (isset($structure->course) && is_number($structure->course)) {
$this->courseid = (int)$structure->course;
} else if (isset($structure->cm) && is_number($structure->cm)) {
$this->courseid = (int)$structure->cm; // Backwards compat for pre-69e5c26 data.
} else {
throw new \coding_exception('Missing or invalid ->cm for completion condition');
throw new \coding_exception('Missing or invalid ->course for completion condition');
}

// Get expected completion.
Expand Down
11 changes: 5 additions & 6 deletions tests/condition_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->cm', $e->getMessage());
$this->assertContains('Missing or invalid ->course', $e->getMessage());
}

// Invalid $cm.
Expand All @@ -105,7 +105,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->cm', $e->getMessage());
$this->assertContains('Missing or invalid ->course', $e->getMessage());
}

// Missing $e.
Expand Down Expand Up @@ -136,9 +136,8 @@ public function test_constructor() {
* Tests the save() function.
*/
public function test_save() {
$structure = (object)array('cm' => 42, 'e' => COMPLETION_COMPLETE);
$cond = new condition($structure);
$structure->type = 'othercompleted';
$structure = (object)array('type' => 'othercompleted', 'course' => 42, 'e' => COMPLETION_COMPLETE);
$cond = new condition((object)array('course' => 42, 'e' => COMPLETION_COMPLETE));
$this->assertEquals($structure, $cond->save());
}

Expand Down Expand Up @@ -257,6 +256,6 @@ public function test_update_dependency_id() {
$this->assertFalse($cond->update_dependency_id('course_modules', 12, 34));
$this->assertTrue($cond->update_dependency_id('course_modules', 123, 456));
$after = $cond->save();
$this->assertEquals(456, $after->cm);
$this->assertEquals(456, $after->course);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ YUI.add('moodle-availability_othercompleted-form', function (Y, NAME) {
var node = Y.Node.create('<span class="form-inline">' + html + '</span>');

// Set initial values.
if (json.cm !== undefined &&
node.one('select[name=cm] > option[value=' + json.cm + ']')) {
node.one('select[name=cm]').set('value', '' + json.cm);
if (json.course !== undefined &&
node.one('select[name=cm] > option[value=' + json.course + ']')) {
node.one('select[name=cm]').set('value', '' + json.course);
}
if (json.e !== undefined) {
node.one('select[name=e]').set('value', '' + json.e);
Expand All @@ -66,7 +66,7 @@ YUI.add('moodle-availability_othercompleted-form', function (Y, NAME) {
};

M.availability_othercompleted.form.fillValue = function(value, node) {
value.cm = parseInt(node.one('select[name=cm]').get('value'), 10);
value.course = parseInt(node.one('select[name=cm]').get('value'), 10);
value.e = parseInt(node.one('select[name=e]').get('value'), 10);
};

Expand Down

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 @@ -43,9 +43,9 @@ M.availability_othercompleted.form.getNode = function(json) {
var node = Y.Node.create('<span class="form-inline">' + html + '</span>');

// Set initial values.
if (json.cm !== undefined &&
node.one('select[name=cm] > option[value=' + json.cm + ']')) {
node.one('select[name=cm]').set('value', '' + json.cm);
if (json.course !== undefined &&
node.one('select[name=cm] > option[value=' + json.course + ']')) {
node.one('select[name=cm]').set('value', '' + json.course);
}
if (json.e !== undefined) {
node.one('select[name=e]').set('value', '' + json.e);
Expand All @@ -65,7 +65,7 @@ M.availability_othercompleted.form.getNode = function(json) {
};

M.availability_othercompleted.form.fillValue = function(value, node) {
value.cm = parseInt(node.one('select[name=cm]').get('value'), 10);
value.course = parseInt(node.one('select[name=cm]').get('value'), 10);
value.e = parseInt(node.one('select[name=e]').get('value'), 10);
};

Expand Down
8 changes: 4 additions & 4 deletions yui/src/form/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ M.availability_othercompleted.form.getNode = function(json) {
var node = Y.Node.create('<span class="form-inline">' + html + '</span>');

// Set initial values.
if (json.cm !== undefined &&
node.one('select[name=cm] > option[value=' + json.cm + ']')) {
node.one('select[name=cm]').set('value', '' + json.cm);
if (json.course !== undefined &&
node.one('select[name=cm] > option[value=' + json.course + ']')) {
node.one('select[name=cm]').set('value', '' + json.course);
}
if (json.e !== undefined) {
node.one('select[name=e]').set('value', '' + json.e);
Expand All @@ -65,7 +65,7 @@ M.availability_othercompleted.form.getNode = function(json) {
};

M.availability_othercompleted.form.fillValue = function(value, node) {
value.cm = parseInt(node.one('select[name=cm]').get('value'), 10);
value.course = parseInt(node.one('select[name=cm]').get('value'), 10);
value.e = parseInt(node.one('select[name=e]').get('value'), 10);
};

Expand Down