mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-67707 mod_h5pactivity: plugin skeleton
AMOS BEGIN CPY [h5poptions,atto_h5p],[h5pdisplay,mod_h5pactivity] CPY [downloadbutton,atto_h5p],[displayexport,mod_h5pactivity] CPY [embedbutton,atto_h5p],[displayembed,mod_h5pactivity] CPY [copyrightbutton,atto_h5p],[displaycopyright,mod_h5pactivity] AMOS END
- Loading branch information
1 parent
40cef8a
commit b7a4168
Showing
22 changed files
with
2,238 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
mod/h5pactivity/backup/moodle2/backup_h5pactivity_activity_task.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* The task that provides all the steps to perform a complete backup is defined here. | ||
* | ||
* @package mod_h5pactivity | ||
* @category backup | ||
* @copyright 2020 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot.'/mod/h5pactivity/backup/moodle2/backup_h5pactivity_stepslib.php'); | ||
|
||
/** | ||
* The class provides all the settings and steps to perform one complete backup of mod_h5pactivity. | ||
*/ | ||
class backup_h5pactivity_activity_task extends backup_activity_task { | ||
|
||
/** | ||
* Defines particular settings for the plugin. | ||
*/ | ||
protected function define_my_settings() { | ||
return; | ||
} | ||
|
||
/** | ||
* Defines particular steps for the backup process. | ||
*/ | ||
protected function define_my_steps() { | ||
$this->add_step(new backup_h5pactivity_activity_structure_step('h5pactivity_structure', 'h5pactivity.xml')); | ||
} | ||
|
||
/** | ||
* Codes the transformations to perform in the activity in order to get transportable (encoded) links. | ||
* | ||
* @param string $content content to encode. | ||
* @return string encoded string | ||
*/ | ||
static public function encode_content_links($content) { | ||
global $CFG; | ||
|
||
$base = preg_quote($CFG->wwwroot, "/"); | ||
|
||
// Link to the list of choices. | ||
$search = "/(".$base."\/mod\/h5pactivity\/index.php\?id\=)([0-9]+)/"; | ||
$content = preg_replace($search, '$@H5PACTIVITYINDEX*$2@$', $content); | ||
|
||
// Link to choice view by moduleid. | ||
$search = "/(".$base."\/mod\/h5pactivity\/view.php\?id\=)([0-9]+)/"; | ||
$content = preg_replace($search, '$@H5PACTIVITYVIEWBYID*$2@$', $content); | ||
|
||
return $content; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
mod/h5pactivity/backup/moodle2/backup_h5pactivity_stepslib.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Backup steps for mod_h5pactivity are defined here. | ||
* | ||
* @package mod_h5pactivity | ||
* @category backup | ||
* @copyright 2020 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Define the complete structure for backup, with file and id annotations. | ||
*/ | ||
class backup_h5pactivity_activity_structure_step extends backup_activity_structure_step { | ||
|
||
/** | ||
* Defines the structure of the resulting xml file. | ||
* | ||
* @return backup_nested_element The structure wrapped by the common 'activity' element. | ||
*/ | ||
protected function define_structure() { | ||
$userinfo = $this->get_setting_value('userinfo'); | ||
|
||
// Replace with the attributes and final elements that the element will handle. | ||
$attributes = ['id']; | ||
$finalelements = ['name', 'timecreated', 'timemodified', 'intro', | ||
'introformat', 'grade', 'displayoptions']; | ||
$root = new backup_nested_element('h5pactivity', $attributes, $finalelements); | ||
|
||
// Define the source tables for the elements. | ||
$root->set_source_table('h5pactivity', ['id' => backup::VAR_ACTIVITYID]); | ||
|
||
// Define id annotations. | ||
|
||
// Define file annotations. | ||
$root->annotate_files('mod_h5pactivity', 'intro', null); // This file area hasn't itemid. | ||
$root->annotate_files('mod_h5pactivity', 'package', null); // This file area hasn't itemid. | ||
|
||
return $this->prepare_activity_structure($root); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
mod/h5pactivity/backup/moodle2/restore_h5pactivity_activity_task.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* The task that provides a complete restore of mod_h5pactivity is defined here. | ||
* | ||
* @package mod_h5pactivity | ||
* @copyright 2020 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot.'/mod/h5pactivity/backup/moodle2/restore_h5pactivity_stepslib.php'); | ||
|
||
/** | ||
* Restore task for mod_h5pactivity. | ||
*/ | ||
class restore_h5pactivity_activity_task extends restore_activity_task { | ||
|
||
/** | ||
* Defines particular settings that this activity can have. | ||
*/ | ||
protected function define_my_settings(): void { | ||
return; | ||
} | ||
|
||
/** | ||
* Defines particular steps that this activity can have. | ||
* | ||
* @return base_step. | ||
*/ | ||
protected function define_my_steps(): void { | ||
$this->add_step(new restore_h5pactivity_activity_structure_step('h5pactivity_structure', 'h5pactivity.xml')); | ||
} | ||
|
||
/** | ||
* Defines the contents in the activity that must be processed by the link decoder. | ||
* | ||
* @return array. | ||
*/ | ||
static public function define_decode_contents(): array { | ||
$contents = []; | ||
|
||
// Define the contents. | ||
$contents[] = new restore_decode_content('h5pactivity', ['intro'], 'h5pactivity'); | ||
|
||
return $contents; | ||
} | ||
|
||
/** | ||
* Defines the decoding rules for links belonging to the activity to be executed by the link decoder. | ||
* | ||
* @return restore_decode_rule[]. | ||
*/ | ||
static public function define_decode_rules(): array { | ||
$rules = []; | ||
|
||
$rules[] = new restore_decode_rule('H5PACTIVITYVIEWBYID', '/mod/h5pactivity/view.php?id=$1', 'course_module'); | ||
$rules[] = new restore_decode_rule('H5PACTIVITYINDEX', '/mod/h5pactivity/index.php?id=$1', 'course'); | ||
|
||
return $rules; | ||
} | ||
|
||
/** | ||
* Defines the restore log rules that will be applied by the | ||
* {@link restore_logs_processor} when restoring mod_h5pactivity logs. It | ||
* must return one array of {@link restore_log_rule} objects. | ||
* | ||
* @return restore_log_rule[]. | ||
*/ | ||
static public function define_restore_log_rules(): array { | ||
$rules = []; | ||
|
||
// Define the rules. | ||
$rules[] = new restore_log_rule('h5pactivity', 'view all', 'index.php?id={course}', null); | ||
|
||
return $rules; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
mod/h5pactivity/backup/moodle2/restore_h5pactivity_stepslib.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* All the steps to restore mod_h5pactivity are defined here. | ||
* | ||
* @package mod_h5pactivity | ||
* @copyright 2020 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Defines the structure step to restore one mod_h5pactivity activity. | ||
*/ | ||
class restore_h5pactivity_activity_structure_step extends restore_activity_structure_step { | ||
|
||
/** | ||
* Defines the structure to be restored. | ||
* | ||
* @return restore_path_element[]. | ||
*/ | ||
protected function define_structure(): array { | ||
$paths = []; | ||
$userinfo = $this->get_setting_value('userinfo'); | ||
$paths[] = new restore_path_element('h5pactivity', '/activity/h5pactivity'); | ||
return $this->prepare_activity_structure($paths); | ||
} | ||
|
||
/** | ||
* Processes the elt restore data. | ||
* | ||
* @param array $data Parsed element data. | ||
*/ | ||
protected function process_h5pactivity(array $data): void { | ||
global $DB; | ||
$data = (object) $data; | ||
$data->course = $this->get_courseid(); | ||
// Insert the record. | ||
$newitemid = $DB->insert_record('h5pactivity', $data); | ||
// Immediately after inserting "activity" record, call this. | ||
$this->apply_activity_instance($newitemid); | ||
} | ||
|
||
/** | ||
* Defines post-execution actions. | ||
*/ | ||
protected function after_execute(): void { | ||
// Add related files, no need to match by itemname (just internally handled context). | ||
$this->add_related_files('mod_h5pactivity', 'intro', null); | ||
$this->add_related_files('mod_h5pactivity', 'package', null); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
mod/h5pactivity/classes/event/course_module_instance_list_viewed.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Plugin event classes are defined here. | ||
* | ||
* @package mod_h5pactivity | ||
* @copyright 2020 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_h5pactivity\event; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* The course_module_instance_list_viewed event class. | ||
* | ||
* @package mod_h5pactivity | ||
* @copyright 2020 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Plugin event classes are defined here. | ||
* | ||
* @package mod_h5pactivity | ||
* @copyright 2020 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_h5pactivity\event; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* The course_module_viewed event class. | ||
* | ||
* @package mod_h5pactivity | ||
* @copyright 2020 Ferran Recio <ferran@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class course_module_viewed extends \core\event\course_module_viewed { | ||
|
||
/** | ||
* Init method. | ||
* | ||
* @return void | ||
*/ | ||
protected function init(): void { | ||
$this->data['objecttable'] = 'h5pactivity'; | ||
$this->data['crud'] = 'r'; | ||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING; | ||
} | ||
|
||
/** | ||
* This is used when restoring course logs where it is required that we | ||
* map the objectid to it's new value in the new course. | ||
* | ||
* @return array | ||
*/ | ||
public static function get_objectid_mapping() { | ||
return ['db' => 'h5pactivity', 'restore' => 'h5pactivity']; | ||
} | ||
|
||
} |
Oops, something went wrong.