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..4a6ca2e --- /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', 'timecreated', 'timemodified')); + + // 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..3bf3b6f --- /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 expcontent 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 expcontent activity. + * + * @param stdClass $data the expcontent data + */ + protected function process_expcontent($data) { + global $DB, $USER; + + $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 expcontent record. + $newitemid = $DB->insert_record('expcontent', $data); + + // Immediately after inserting record call this. + $this->apply_activity_instance($newitemid); + } + +} diff --git a/lang/en/expcontent.php b/lang/en/expcontent.php index 20cf8c4..ed5e862 100644 --- a/lang/en/expcontent.php +++ b/lang/en/expcontent.php @@ -2,8 +2,9 @@ defined('MOODLE_INTERNAL') || die(); -$string['modulename'] = 'EXP360 Content'; -$string['modulenameplural'] = 'EXP360 Contents'; +$string['modulename'] = '360° Content'; +$string['modulenameplural'] = $string['modulename']; +$string['pluginname'] = $string['modulename']; $string['settings'] = 'Settings'; @@ -11,4 +12,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 87aec35..6dbc960 100644 --- a/lib.php +++ b/lib.php @@ -18,7 +18,6 @@ function expcontent_update_instance($expcontent) { $expcontent->timemodified = time(); $expcontent->id = $expcontent->instance; - $expcontent->introformat = FORMAT_MOODLE; if (! $DB->update_record('expcontent', $expcontent)) { return false; @@ -41,8 +40,9 @@ function expcontent_delete_instance($id) { function expcontent_supports($feature) { switch($feature) { - case FEATURE_COMPLETION_TRACKS_VIEWS: return true; - case FEATURE_SHOW_DESCRIPTION: return true; - default: return null; + case FEATURE_COMPLETION_TRACKS_VIEWS: return true; + case FEATURE_SHOW_COMPLETION: return true; + case FEATURE_BACKUP_MOODLE2: return true; + default: return null; } -} \ No newline at end of file +} diff --git a/mod_form.php b/mod_form.php index ed45616..a2c6547 100644 --- a/mod_form.php +++ b/mod_form.php @@ -19,6 +19,8 @@ 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_intro_elements(); @@ -27,4 +29,4 @@ class mod_expcontent_mod_form extends moodleform_mod { $this->add_action_buttons(); } -} \ No newline at end of file +} diff --git a/version.php b/version.php index ed6f334..76961e2 100644 --- a/version.php +++ b/version.php @@ -2,8 +2,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = "2021111500"; +$plugin->version = "2021113003"; $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';