From 5e5f731f74338dbf66e8da2678869da57faf2bff Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 30 Nov 2021 09:42:55 +0100 Subject: [PATCH 1/8] Bring up to speed --- lang/en/expcontent.php | 6 +++--- lib.php | 10 +++++++++- mod_form.php | 4 +++- view.php | 6 +++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lang/en/expcontent.php b/lang/en/expcontent.php index 1532ba6..2b42fd4 100644 --- a/lang/en/expcontent.php +++ b/lang/en/expcontent.php @@ -2,8 +2,8 @@ defined('MOODLE_INTERNAL') || die(); -$string['modulename'] = 'EXP360 Content'; -$string['modulename'] = 'EXP360 Contents'; +$string['modulename'] = '360° Content'; +$string['modulename'] = '360° Content'; $string['settings'] = 'Settings'; @@ -11,4 +11,4 @@ $string['baseurl'] = 'Base URL'; $string['baseurl_help'] = 'Base URL of the EXP360 Content Server'; $string['name'] = 'Name'; -$string['contentid'] = 'Content ID'; \ No newline at end of file +$string['contentid'] = 'Content ID'; diff --git a/lib.php b/lib.php index 6182a55..c078e8b 100644 --- a/lib.php +++ b/lib.php @@ -36,4 +36,12 @@ function expcontent_delete_instance($id) { $DB->delete_records('expcontent', array('id' => $id)); return true; -} \ No newline at end of file +} + +function expcontent_supports($feature) { + switch($feature) { + case FEATURE_COMPLETION_TRACKS_VIEWS: return true; + case FEATRUE_SHOW_COMPLETION: return true; + default: return null; + } +} diff --git a/mod_form.php b/mod_form.php index d2b0574..4e7c420 100644 --- a/mod_form.php +++ b/mod_form.php @@ -19,10 +19,12 @@ class mod_expcontent_mod_form extends moodleform_mod { $mform->addElement('text', 'contentid', get_string('contentid', 'expcontent'), array('size'=>'64')); $mform->setType('contentid', PARAM_TEXT); $mform->addRule('contentid', null, 'required', null, 'client'); + + $this->standard_intro_elements(); $this->standard_coursemodule_elements(); $this->add_action_buttons(); } -} \ No newline at end of file +} diff --git a/view.php b/view.php index b5b271e..b8d6e6b 100644 --- a/view.php +++ b/view.php @@ -1,7 +1,8 @@ dirroot.'/mod/expcontent/lib.php'); +require_once($CFG->libdir.'/completionlib.php'); $id = required_param('id', PARAM_INT); list ($course, $cm) = get_course_and_cm_from_cmid($id, 'expcontent'); @@ -10,6 +11,9 @@ $expcontent = $DB->get_record('expcontent', array('id'=> $cm->instance), '*', MU $expconfig = get_config('mod_expcontent'); $baseurl = $expconfig->baseurl; +$completion = new completion_info($course); +$completion->set_module_viewed($cm); + if ($baseurl[-1] != "/") $baseurl += "/"; ?> From 7a1c1754419661c0331b18a6747e150fa0385c49 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 30 Nov 2021 09:43:31 +0100 Subject: [PATCH 2/8] Bump version --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index 44a491e..65831a8 100644 --- a/version.php +++ b/version.php @@ -2,8 +2,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = "2021081900"; +$plugin->version = "2021113000"; $plugin->component = 'mod_expcontent'; $plugin->maturity = MATURITY_ALPHA; $plugin->release = 'v0.0.1'; -$plugin->requires = '2019111800'; \ No newline at end of file +$plugin->requires = '2019111800'; From 91a7a7884b1c1e7c6a67dc33f018857be0591659 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 30 Nov 2021 11:20:49 +0100 Subject: [PATCH 3/8] Backups --- .../backup_expcontent_activity_task.class.php | 70 ++++++++++++ backup/moodle2/backup_expcontent_stepslib.php | 53 +++++++++ ...restore_expcontent_activity_task.class.php | 101 ++++++++++++++++++ .../moodle2/restore_expcontent_stepslib.php | 73 +++++++++++++ lib.php | 1 + version.php | 2 +- 6 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 backup/moodle2/backup_expcontent_activity_task.class.php create mode 100644 backup/moodle2/backup_expcontent_stepslib.php create mode 100644 backup/moodle2/restore_expcontent_activity_task.class.php create mode 100644 backup/moodle2/restore_expcontent_stepslib.php diff --git a/backup/moodle2/backup_expcontent_activity_task.class.php b/backup/moodle2/backup_expcontent_activity_task.class.php new file mode 100644 index 0000000..10732b3 --- /dev/null +++ b/backup/moodle2/backup_expcontent_activity_task.class.php @@ -0,0 +1,70 @@ +. + +/** + * This file contains the backup tasks that provides all the settings and steps to perform a backup of the activity. + * + * @package mod_expcontent + * @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +require_once($CFG->dirroot . '/mod/expcontent/backup/moodle2/backup_expcontent_stepslib.php'); + +/** + * Handles creating tasks to peform in order to create the backup. + * + * @package mod_expcontent + * @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class backup_expcontent_activity_task extends backup_activity_task { + + /** + * Define particular settings this activity can have. + */ + protected function define_my_settings() { + // No particular settings for this activity. + } + + /** + * Define particular steps this activity can have. + */ + protected function define_my_steps() { + // The expcontent only has one structure step. + $this->add_step(new backup_expcontent_activity_structure_step('expcontent_structure', 'expcontent.xml')); + } + + /** + * Code the transformations to perform in the activity in order to get transportable (encoded) links. + * + * @param string $content + * @return mixed|string + */ + public static function encode_content_links($content) { + global $CFG; + + $base = preg_quote($CFG->wwwroot, "/"); + + // Link to expcontent view by moduleid. + $search = "/(".$base."\/mod\/expcontent\/view.php\?id\=)([0-9]+)/"; + $content = preg_replace($search, '$@EXPCONTENTVIEWBYID*$2@$', $content); + + return $content; + } +} diff --git a/backup/moodle2/backup_expcontent_stepslib.php b/backup/moodle2/backup_expcontent_stepslib.php new file mode 100644 index 0000000..af55474 --- /dev/null +++ b/backup/moodle2/backup_expcontent_stepslib.php @@ -0,0 +1,53 @@ +. + +/** + * Define all the backup steps that will be used by the backup_expcontent_activity_task. + * + * @package mod_expcontent + * @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +/** + * Define the complete expcontent structure for backup, with file and id annotations. + * + * @package mod_expcontent + * @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class backup_expcontent_activity_structure_step extends backup_activity_structure_step { + + /** + * Define the structure of the backup file. + * + * @return backup_nested_element + */ + protected function define_structure() { + + // The instance. + $expcontent = new backup_nested_element('expcontent', array('id'), array( + 'name', 'contentid', 'intro', 'introformat')); + + // Define sources. + $expcontent->set_source_table('expcontent', array('id' => backup::VAR_ACTIVITYID)); + + // Return the root element (expcontent), wrapped into standard activity structure. + return $this->prepare_activity_structure($expcontent); + } +} diff --git a/backup/moodle2/restore_expcontent_activity_task.class.php b/backup/moodle2/restore_expcontent_activity_task.class.php new file mode 100644 index 0000000..a866cdc --- /dev/null +++ b/backup/moodle2/restore_expcontent_activity_task.class.php @@ -0,0 +1,101 @@ +. + +/** + * Define all the restore steps that will be used by the restore_expcontent_activity_task. + * + * @package mod_expcontent + * @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +require_once($CFG->dirroot . '/mod/expcontent/backup/moodle2/restore_expcontent_stepslib.php'); + +/** + * The class definition for assigning tasks that provide the settings and steps to perform a restore of the activity. + * + * @package mod_expcontent + * @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class restore_expcontent_activity_task extends restore_activity_task { + + /** + * Define particular settings this activity can have. + */ + protected function define_my_settings() { + // No particular settings for this activity. + } + + /** + * Define particular steps this activity can have. + */ + protected function define_my_steps() { + // The expcontent only has one structure step. + $this->add_step(new restore_expcontent_activity_structure_step('expcontent_structure', 'expcontent.xml')); + } + + /** + * Define the contents in the activity that must be processed by the link decoder. + */ + public static function define_decode_contents() { + $contents = array(); + + $contents[] = new restore_decode_content('expcontent', array('intro'), 'expcontent'); + + return $contents; + } + + /** + * Define the decoding rules for links belonging to the activity to be executed by the link decoder. + */ + public static function define_decode_rules() { + $rules = array(); + + $rules[] = new restore_decode_rule('EXPCONTENTVIEWBYID', '/mod/expcontent/view.php?id=$1', 'course_module'); + + return $rules; + + } + + /** + * Define the restore log rules that will be applied by the {@see restore_logs_processor} when restoring + * expcontent logs. It must return one array of {@see restore_log_rule} objects. + * + * @return array the restore log rules + */ + public static function define_restore_log_rules() { + $rules = array(); + + $rules[] = new restore_log_rule('expcontent', 'add', 'view.php?id={course_module}', '{expcontent}'); + $rules[] = new restore_log_rule('expcontent', 'update', 'view.php?id={course_module}', '{expcontent}'); + $rules[] = new restore_log_rule('expcontent', 'view', 'view.php?id={course_module}', '{expcontent}'); + $rules[] = new restore_log_rule('expcontent', 'view report', 'view.php?id={course_module}', '{expcontent}'); + + return $rules; + } + + /** + * This function is called after all the activities in the backup have been restored. This allows us to get + * the new course module ids, as they may have been restored after the expcontent module, meaning no id + * was available at the time. + */ + public function after_restore() { + global $DB; + } +} diff --git a/backup/moodle2/restore_expcontent_stepslib.php b/backup/moodle2/restore_expcontent_stepslib.php new file mode 100644 index 0000000..7c844cd --- /dev/null +++ b/backup/moodle2/restore_expcontent_stepslib.php @@ -0,0 +1,73 @@ +. + +/** + * Define all the restore steps that will be used by the restore_expcontent_activity_task. + * + * @package mod_expcontent + * @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); + +/** + * Define the complete expcontent structure for restore, with file and id annotations. + * + * @package mod_expcontent + * @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class restore_expcontent_activity_structure_step extends restore_activity_structure_step { + + /** + * Define the different items to restore. + * + * @return array the restore paths + */ + protected function define_structure() { + // The array used to store the path to the items we want to restore. + $paths = array(); + + // The htmlcert instance. + $paths[] = new restore_path_element('expcontent', '/activity/expcontent'); + + // Return the paths wrapped into standard activity structure. + return $this->prepare_activity_structure($paths); + } + + /** + * Handles restoring the htmlcert activity. + * + * @param stdClass $data the htmlcert data + */ + protected function process_expcontent($data) { + global $DB; + + $data = (object) $data; + $data->course = $this->get_courseid(); + $data->timecreated = $this->apply_date_offset($data->timecreated); + $data->timemodified = $this->apply_date_offset($data->timemodified); + $data->usermodified = $USER->id; + + // Insert the htmlcert record. + $newitemid = $DB->insert_record('expcontent', $data); + + // Immediately after inserting record call this. + $this->apply_activity_instance($newitemid); + } + +} diff --git a/lib.php b/lib.php index c078e8b..2ca2ba4 100644 --- a/lib.php +++ b/lib.php @@ -42,6 +42,7 @@ function expcontent_supports($feature) { switch($feature) { case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATRUE_SHOW_COMPLETION: return true; + case FEATURE_BACKUP_MOODLE2: return true; default: return null; } } diff --git a/version.php b/version.php index 65831a8..446baab 100644 --- a/version.php +++ b/version.php @@ -2,7 +2,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = "2021113000"; +$plugin->version = "2021113001"; $plugin->component = 'mod_expcontent'; $plugin->maturity = MATURITY_ALPHA; $plugin->release = 'v0.0.1'; From af47f28d4c91a2c70bc5b48a03a15b911fff1d40 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 30 Nov 2021 11:42:37 +0100 Subject: [PATCH 4/8] Add missing language string --- lang/en/expcontent.php | 3 ++- version.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lang/en/expcontent.php b/lang/en/expcontent.php index 2b42fd4..b61487d 100644 --- a/lang/en/expcontent.php +++ b/lang/en/expcontent.php @@ -3,7 +3,8 @@ defined('MOODLE_INTERNAL') || die(); $string['modulename'] = '360° Content'; -$string['modulename'] = '360° Content'; +$string['modulename'] = $string['modulename']; +$string['pluginname'] = $string['modulename']; $string['settings'] = 'Settings'; diff --git a/version.php b/version.php index 446baab..2494537 100644 --- a/version.php +++ b/version.php @@ -2,7 +2,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = "2021113001"; +$plugin->version = "2021113002"; $plugin->component = 'mod_expcontent'; $plugin->maturity = MATURITY_ALPHA; $plugin->release = 'v0.0.1'; From 34ac04d92bc4a4e98068c877063493a1dc033a2e Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 30 Nov 2021 11:58:04 +0100 Subject: [PATCH 5/8] Fix typo --- lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.php b/lib.php index 2ca2ba4..6dbc960 100644 --- a/lib.php +++ b/lib.php @@ -41,7 +41,7 @@ function expcontent_delete_instance($id) { function expcontent_supports($feature) { switch($feature) { case FEATURE_COMPLETION_TRACKS_VIEWS: return true; - case FEATRUE_SHOW_COMPLETION: return true; + case FEATURE_SHOW_COMPLETION: return true; case FEATURE_BACKUP_MOODLE2: return true; default: return null; } From 63d2ff658d07919671362c5d40506eb37c28ee2b Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 30 Nov 2021 12:00:44 +0100 Subject: [PATCH 6/8] Fix module name, export a bit more data --- backup/moodle2/backup_expcontent_stepslib.php | 2 +- backup/moodle2/restore_expcontent_stepslib.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backup/moodle2/backup_expcontent_stepslib.php b/backup/moodle2/backup_expcontent_stepslib.php index af55474..4a6ca2e 100644 --- a/backup/moodle2/backup_expcontent_stepslib.php +++ b/backup/moodle2/backup_expcontent_stepslib.php @@ -42,7 +42,7 @@ class backup_expcontent_activity_structure_step extends backup_activity_structur // The instance. $expcontent = new backup_nested_element('expcontent', array('id'), array( - 'name', 'contentid', 'intro', 'introformat')); + 'name', 'contentid', 'intro', 'introformat', 'timecreated', 'timemodified')); // Define sources. $expcontent->set_source_table('expcontent', array('id' => backup::VAR_ACTIVITYID)); diff --git a/backup/moodle2/restore_expcontent_stepslib.php b/backup/moodle2/restore_expcontent_stepslib.php index 7c844cd..5fe6dbc 100644 --- a/backup/moodle2/restore_expcontent_stepslib.php +++ b/backup/moodle2/restore_expcontent_stepslib.php @@ -42,7 +42,7 @@ class restore_expcontent_activity_structure_step extends restore_activity_struct // The array used to store the path to the items we want to restore. $paths = array(); - // The htmlcert instance. + // The expcontent instance. $paths[] = new restore_path_element('expcontent', '/activity/expcontent'); // Return the paths wrapped into standard activity structure. @@ -50,9 +50,9 @@ class restore_expcontent_activity_structure_step extends restore_activity_struct } /** - * Handles restoring the htmlcert activity. + * Handles restoring the expcontent activity. * - * @param stdClass $data the htmlcert data + * @param stdClass $data the expcontent data */ protected function process_expcontent($data) { global $DB; @@ -63,7 +63,7 @@ class restore_expcontent_activity_structure_step extends restore_activity_struct $data->timemodified = $this->apply_date_offset($data->timemodified); $data->usermodified = $USER->id; - // Insert the htmlcert record. + // Insert the expcontent record. $newitemid = $DB->insert_record('expcontent', $data); // Immediately after inserting record call this. From a53097f4226b4539e5213849dd6f6ea29a55a44b Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 30 Nov 2021 12:09:04 +0100 Subject: [PATCH 7/8] Fix string name --- lang/en/expcontent.php | 2 +- version.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/en/expcontent.php b/lang/en/expcontent.php index b61487d..ed5e862 100644 --- a/lang/en/expcontent.php +++ b/lang/en/expcontent.php @@ -3,7 +3,7 @@ defined('MOODLE_INTERNAL') || die(); $string['modulename'] = '360° Content'; -$string['modulename'] = $string['modulename']; +$string['modulenameplural'] = $string['modulename']; $string['pluginname'] = $string['modulename']; $string['settings'] = 'Settings'; diff --git a/version.php b/version.php index 2494537..76961e2 100644 --- a/version.php +++ b/version.php @@ -2,7 +2,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = "2021113002"; +$plugin->version = "2021113003"; $plugin->component = 'mod_expcontent'; $plugin->maturity = MATURITY_ALPHA; $plugin->release = 'v0.0.1'; From 4de71b44df770712ba3a4813187bcaed050f35c1 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 30 Nov 2021 12:32:05 +0100 Subject: [PATCH 8/8] Add missing global declaration --- backup/moodle2/restore_expcontent_stepslib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup/moodle2/restore_expcontent_stepslib.php b/backup/moodle2/restore_expcontent_stepslib.php index 5fe6dbc..3bf3b6f 100644 --- a/backup/moodle2/restore_expcontent_stepslib.php +++ b/backup/moodle2/restore_expcontent_stepslib.php @@ -55,7 +55,7 @@ class restore_expcontent_activity_structure_step extends restore_activity_struct * @param stdClass $data the expcontent data */ protected function process_expcontent($data) { - global $DB; + global $DB, $USER; $data = (object) $data; $data->course = $this->get_courseid();