Skip to content

Commit

Permalink
fix(errortypetemplates): Ensured compatibility with Moodle 4.3. Chang…
Browse files Browse the repository at this point in the history
…ed default error type template colors for new installations to improve contrast.
  • Loading branch information
Daniel Nolte committed Oct 22, 2023
1 parent 935f63a commit e6840db
Show file tree
Hide file tree
Showing 37 changed files with 371 additions and 458 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog ##

- [1.3.1]:
- Ensured compatibility with Moodle 4.3.
- Changed code to comply with new moodle coding standards.
- [Bugfix]: Changed default error type template colors for new installations to improve contrast.

- [1.3.0]:
- [Bugfix]: Fixed a bug that prevented the order of Margic error types (that were subsequently added to an instance from an error type template) from being changed under certain conditions.
- [Bugfix]: Deleting error types now triggers a confirm prompt.
Expand Down
2 changes: 1 addition & 1 deletion annotation_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ public function definition() {
* @return array Array with errors
*/
public function validation($data, $files) {
return array();
return [];
}
}
43 changes: 16 additions & 27 deletions annotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@
throw new moodle_exception(get_string('incorrectmodule', 'margic'));
}

if (! $coursesections = $DB->get_record("course_sections", array(
"id" => $cm->section
))) {
if (! $coursesections = $DB->get_record("course_sections", ["id" => $cm->section])) {
throw new moodle_exception(get_string('incorrectmodule', 'margic'));
}

Expand All @@ -74,7 +72,7 @@
if ($annotations) {
echo json_encode($annotations);
} else {
echo json_encode(array());
echo json_encode([]);
}

die;
Expand All @@ -83,10 +81,10 @@
require_capability('mod/margic:makeannotations', $context);

// Header.
$PAGE->set_url('/mod/margic/annotations.php', array('id' => $id));
$PAGE->set_url('/mod/margic/annotations.php', ['id' => $id]);
$PAGE->set_title(format_string($moduleinstance->name));

$urlparams = array('id' => $id, 'annotationmode' => 1);
$urlparams = ['id' => $id, 'annotationmode' => 1];

$redirecturl = new moodle_url('/mod/margic/view.php', $urlparams);

Expand All @@ -96,16 +94,13 @@

global $USER;

$a = $DB->get_record('margic_annotations', array('id' => $deleteannotation, 'margic' => $moduleinstance->id));
$a = $DB->get_record('margic_annotations', ['id' => $deleteannotation, 'margic' => $moduleinstance->id]);
if (isset($a) && ($moduleinstance->overwriteannotations || $a->userid == $USER->id)) {

$DB->delete_records('margic_annotations', array('id' => $deleteannotation, 'margic' => $moduleinstance->id));
$DB->delete_records('margic_annotations', ['id' => $deleteannotation, 'margic' => $moduleinstance->id]);

// Trigger module annotation deleted event.
$event = \mod_margic\event\annotation_deleted::create(array(
'objectid' => $deleteannotation,
'context' => $context
));
$event = \mod_margic\event\annotation_deleted::create(['objectid' => $deleteannotation, 'context' => $context]);

$event->trigger();

Expand All @@ -119,14 +114,14 @@
require_once($CFG->dirroot . '/mod/margic/annotation_form.php');

// Instantiate form.
$mform = new mod_margic_annotation_form(null, array('types' => $margic->get_errortypes_for_form()));
$mform = new mod_margic_annotation_form(null, ['types' => $margic->get_errortypes_for_form()]);

if ($fromform = $mform->get_data()) {

// In this case you process validated data. $mform->get_data() returns data posted in form.
if ((isset($fromform->annotationid) && $fromform->annotationid !== 0) && isset($fromform->text)) { // Update annotation.
$annotation = $DB->get_record('margic_annotations', array('margic' => $cm->instance, 'entry' => $fromform->entry,
'id' => $fromform->annotationid));
$annotation = $DB->get_record('margic_annotations', ['margic' => $cm->instance, 'entry' => $fromform->entry,
'id' => $fromform->annotationid, ]);

// Prevent changes by user in hidden form fields.
if (!$annotation) {
Expand All @@ -140,7 +135,7 @@
}

$annotation->timemodified = time();
$annotation->text = format_text($fromform->text, 2, array('para' => false));
$annotation->text = format_text($fromform->text, 2, ['para' => false]);
$annotation->type = $fromform->type;

if ($moduleinstance->overwriteannotations) {
Expand All @@ -150,14 +145,11 @@
$DB->update_record('margic_annotations', $annotation);

// Trigger module annotation updated event.
$event = \mod_margic\event\annotation_updated::create(array(
'objectid' => $fromform->annotationid,
'context' => $context
));
$event = \mod_margic\event\annotation_updated::create(['objectid' => $fromform->annotationid, 'context' => $context]);

$event->trigger();

$urlparams = array('id' => $id, 'annotationmode' => 1, 'focusannotation' => $fromform->annotationid);
$urlparams = ['id' => $id, 'annotationmode' => 1, 'focusannotation' => $fromform->annotationid];
$redirecturl = new moodle_url('/mod/margic/view.php', $urlparams);

redirect($redirecturl, get_string('annotationedited', 'mod_margic'), null, notification::NOTIFY_SUCCESS);
Expand All @@ -176,7 +168,7 @@
redirect($redirecturl, get_string('annotationinvalid', 'mod_margic'), null, notification::NOTIFY_ERROR);
}

if (!$DB->record_exists('margic_entries', array('margic' => $cm->instance, 'id' => $fromform->entry))) {
if (!$DB->record_exists('margic_entries', ['margic' => $cm->instance, 'id' => $fromform->entry])) {
redirect($redirecturl, get_string('annotationinvalid', 'mod_margic'), null, notification::NOTIFY_ERROR);
}

Expand All @@ -200,13 +192,10 @@

$newid = $DB->insert_record('margic_annotations', $annotation);
// Trigger module annotation created event.
$event = \mod_margic\event\annotation_created::create(array(
'objectid' => $newid,
'context' => $context
));
$event = \mod_margic\event\annotation_created::create(['objectid' => $newid, 'context' => $context]);
$event->trigger();

$urlparams = array('id' => $id, 'annotationmode' => 1, 'focusannotation' => $newid);
$urlparams = ['id' => $id, 'annotationmode' => 1, 'focusannotation' => $newid];
$redirecturl = new moodle_url('/mod/margic/view.php', $urlparams);

redirect($redirecturl, get_string('annotationadded', 'mod_margic'), null, notification::NOTIFY_SUCCESS);
Expand Down
32 changes: 16 additions & 16 deletions backup/moodle2/backup_margic_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Replace with the attributes and final elements that the element will handle.
$margic = new backup_nested_element('margic', array('id'), array(
$margic = new backup_nested_element('margic', ['id'], [
'name', 'intro', 'introformat', 'timecreated', 'timemodified',
'scale', 'assessed', 'assesstimestart', 'assesstimefinish',
'timeopen', 'timeclose', 'editentries', 'editentrydates', 'annotationareawidth'));
'timeopen', 'timeclose', 'editentries', 'editentrydates', 'annotationareawidth', ]);

$errortypes = new backup_nested_element('errortypes');
$errortype = new backup_nested_element('errortype', array('id'), array(
'timecreated', 'timemodified', 'name', 'color', 'priority'));
$errortype = new backup_nested_element('errortype', ['id'], [
'timecreated', 'timemodified', 'name', 'color', 'priority', ]);

$entries = new backup_nested_element('entries');
$entry = new backup_nested_element('entry', array('id'), array(
$entry = new backup_nested_element('entry', ['id'], [
'userid', 'timecreated', 'timemodified', 'text', 'format',
'rating', 'feedback', 'formatfeedback', 'teacher',
'timemarked', 'baseentry'));
'timemarked', 'baseentry', ]);

$annotations = new backup_nested_element('annotations');
$annotation = new backup_nested_element('annotation', array('id'), array(
$annotation = new backup_nested_element('annotation', ['id'], [
'userid', 'timecreated', 'timemodified', 'type', 'startcontainer', 'endcontainer',
'startoffset', 'endoffset', 'annotationstart', 'annotationend', 'exact', 'prefix', 'suffix', 'text'));
'startoffset', 'endoffset', 'annotationstart', 'annotationend', 'exact', 'prefix', 'suffix', 'text', ]);

$ratings = new backup_nested_element('ratings');
$rating = new backup_nested_element('rating', array('id'), array(
$rating = new backup_nested_element('rating', ['id'], [
'component', 'ratingarea', 'scaleid', 'value', 'userid',
'timecreated', 'timemodified'));
'timecreated', 'timemodified', ]);

// Build the tree with these elements with $margic as the root of the backup tree.
$margic->add_child($errortypes);
Expand All @@ -77,24 +77,24 @@ protected function define_structure() {

// Define the source tables for the elements.

$margic->set_source_table('margic', array('id' => backup::VAR_ACTIVITYID));
$margic->set_source_table('margic', ['id' => backup::VAR_ACTIVITYID]);

// Errortypes.
$errortype->set_source_table('margic_errortypes', array('margic' => backup::VAR_PARENTID));
$errortype->set_source_table('margic_errortypes', ['margic' => backup::VAR_PARENTID]);

if ($userinfo) {

// Entries.
$entry->set_source_table('margic_entries', array('margic' => backup::VAR_PARENTID));
$entry->set_source_table('margic_entries', ['margic' => backup::VAR_PARENTID]);

// Annotations.
$annotation->set_source_table('margic_annotations', array('entry' => backup::VAR_PARENTID));
$annotation->set_source_table('margic_annotations', ['entry' => backup::VAR_PARENTID]);

// Ratings (core).
$rating->set_source_table('rating', array('contextid' => backup::VAR_CONTEXTID,
$rating->set_source_table('rating', ['contextid' => backup::VAR_CONTEXTID,
'itemid' => backup::VAR_PARENTID,
'component' => backup_helper::is_sqlparam('mod_margic'),
'ratingarea' => backup_helper::is_sqlparam('entry')));
'ratingarea' => backup_helper::is_sqlparam('entry'), ]);

$rating->set_source_alias('rating', 'value');
}
Expand Down
20 changes: 10 additions & 10 deletions backup/moodle2/restore_margic_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected function define_my_steps() {
* @return array.
*/
public static function define_decode_contents() {
$contents = array();
$contents = [];

// Define the contents (files).
// tablename, array(field1, field 2), $mapping.
$contents[] = new restore_decode_content('margic', array('intro'), 'margic');
$contents[] = new restore_decode_content('margic_entries', array('text', 'feedback'), 'margic_entry');
// tablename, [field1, field 2], $mapping.
$contents[] = new restore_decode_content('margic', ['intro'], 'margic');
$contents[] = new restore_decode_content('margic_entries', ['text', 'feedback'], 'margic_entry');

return $contents;
}
Expand All @@ -69,16 +69,16 @@ public static function define_decode_contents() {
* @return array.
*/
public static function define_decode_rules() {
$rules = array();
$rules = [];

// Define the rules.

$rules[] = new restore_decode_rule('MARGICINDEX', '/mod/margic/index.php?id=$1', 'course');
$rules[] = new restore_decode_rule('MARGICVIEWBYID', '/mod/margic/view.php?id=$1&userid=$2',
array('course_module', 'userid'));
$rules[] = new restore_decode_rule('MARGICEDITVIEW', '/mod/margic/edit.php?id=$1', array('course_module'));
['course_module', 'userid']);
$rules[] = new restore_decode_rule('MARGICEDITVIEW', '/mod/margic/edit.php?id=$1', ['course_module']);
$rules[] = new restore_decode_rule('MARGICANNOTATIONSUMMARY', '/mod/margic/error_summary.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('MARGICERRORTYPES', '/mod/margic/errortypes.php?id=$1', array('course_module'));
$rules[] = new restore_decode_rule('MARGICERRORTYPES', '/mod/margic/errortypes.php?id=$1', ['course_module']);

return $rules;
}
Expand All @@ -91,7 +91,7 @@ public static function define_decode_rules() {
* @return array.
*/
public static function define_restore_log_rules() {
$rules = array();
$rules = [];

// Define the rules.
$rules[] = new restore_log_rule('margic', 'view', 'view.php?id={course_module}', '{margic}');
Expand All @@ -117,7 +117,7 @@ public static function define_restore_log_rules() {
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules = [];

$rules[] = new restore_log_rule('margic', 'view all', 'index.php?id={course}', null);

Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/restore_margic_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class restore_margic_activity_structure_step extends restore_activity_structure_
* @return restore_path_element[].
*/
protected function define_structure() {
$paths = array();
$paths = [];

$userinfo = $this->get_setting_value('userinfo');

Expand Down
6 changes: 2 additions & 4 deletions classes/event/annotation_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ public function get_description() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/margic/view.php', array(
'id' => $this->contextinstanceid
));
return new \moodle_url('/mod/margic/view.php', ['id' => $this->contextinstanceid]);
}

/**
* Get objectid mapping for restore.
*/
public static function get_objectid_mapping() {
return array('db' => 'margic_annotations', 'restore' => 'margic_annotation');
return ['db' => 'margic_annotations', 'restore' => 'margic_annotation'];
}
}
6 changes: 2 additions & 4 deletions classes/event/annotation_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ public function get_description() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/margic/view.php', array(
'id' => $this->contextinstanceid
));
return new \moodle_url('/mod/margic/view.php', ['id' => $this->contextinstanceid]);
}

/**
* Get objectid mapping for restore.
*/
public static function get_objectid_mapping() {
return array('db' => 'margic_annotations', 'restore' => 'margic_annotation');
return ['db' => 'margic_annotations', 'restore' => 'margic_annotation'];
}
}
6 changes: 2 additions & 4 deletions classes/event/annotation_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ public function get_description() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/margic/view.php', array(
'id' => $this->contextinstanceid
));
return new \moodle_url('/mod/margic/view.php', ['id' => $this->contextinstanceid]);
}

/**
* Get objectid mapping for restore.
*/
public static function get_objectid_mapping() {
return array('db' => 'margic_annotations', 'restore' => 'margic_annotation');
return ['db' => 'margic_annotations', 'restore' => 'margic_annotation'];
}
}
2 changes: 1 addition & 1 deletion classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ protected function init() {
* Get objectid mapping for restore.
*/
public static function get_objectid_mapping() {
return array('db' => 'margic', 'restore' => 'margic');
return ['db' => 'margic', 'restore' => 'margic'];
}
}
4 changes: 1 addition & 3 deletions classes/event/download_margic_entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public function get_description() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/margic/view.php', array(
'id' => $this->contextinstanceid
));
return new \moodle_url('/mod/margic/view.php', ['id' => $this->contextinstanceid]);
}
}
6 changes: 2 additions & 4 deletions classes/event/entry_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ public function get_description() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/margic/edit.php', array(
'id' => $this->contextinstanceid
));
return new \moodle_url('/mod/margic/edit.php', ['id' => $this->contextinstanceid]);
}

/**
* Get objectid mapping for restore.
*/
public static function get_objectid_mapping() {
return array('db' => 'margic_entries', 'restore' => 'margic_entry');
return ['db' => 'margic_entries', 'restore' => 'margic_entry'];
}
}
6 changes: 2 additions & 4 deletions classes/event/entry_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ public function get_description() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/margic/edit.php', array(
'id' => $this->contextinstanceid
));
return new \moodle_url('/mod/margic/edit.php', ['id' => $this->contextinstanceid]);
}

/**
* Get objectid mapping for restore.
*/
public static function get_objectid_mapping() {
return array('db' => 'margic_entries', 'restore' => 'margic_entry');
return ['db' => 'margic_entries', 'restore' => 'margic_entry'];
}
}
Loading

0 comments on commit e6840db

Please sign in to comment.