Skip to content
Merged
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
74 changes: 74 additions & 0 deletions backup/moodle2/backup_edflex_activity_task.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* Backup task for mod_edflex.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/mod/edflex/backup/moodle2/backup_edflex_stepslib.php');

/**
* Provides the steps to perform one complete backup of the edflex instance.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_edflex_activity_task extends backup_activity_task {
/**
* Defines particular settings for this activity task. None required.
*
* @return void
*/
protected function define_my_settings() {
}

/**
* Defines particular steps for this activity backup.
*
* @return void
*/
protected function define_my_steps() {
$this->add_step(new backup_edflex_activity_structure_step('edflex_structure', 'edflex.xml'));
}

/**
* Encodes URLs to the view and index scripts so they can be decoded on restore.
*
* @param string $content The content to encode.
*
* @return string The content with encoded links.
*/
public static function encode_content_links($content) {
global $CFG;

$base = preg_quote($CFG->wwwroot, '/');

$search = '/(' . $base . '\/mod\/edflex\/view\.php\?id\=)([0-9]+)/';
$content = preg_replace($search, '$@EDFLEXVIEWBYID*$2@$', $content);

$search = '/(' . $base . '\/mod\/edflex\/index\.php\?id\=)([0-9]+)/';
$content = preg_replace($search, '$@EDFLEXINDEX*$2@$', $content);

return $content;
}
}
49 changes: 49 additions & 0 deletions backup/moodle2/backup_edflex_stepslib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* Backup steps for mod_edflex.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Defines the complete edflex structure for backup, with file annotations.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_edflex_activity_structure_step extends backup_activity_structure_step {
/**
* Defines the backup structure of the edflex activity.
*
* @return backup_nested_element The prepared activity structure to back up.
*/
protected function define_structure() {
$edflex = new backup_nested_element('edflex', ['id'], [
'name', 'intro', 'introformat', 'timemodified',
]);

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

$edflex->annotate_files('mod_edflex', 'intro', null);

return $this->prepare_activity_structure($edflex);
}
}
90 changes: 90 additions & 0 deletions backup/moodle2/restore_edflex_activity_task.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* Restore task for mod_edflex.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/mod/edflex/backup/moodle2/restore_edflex_stepslib.php');

/**
* Restore task for the edflex activity module.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_edflex_activity_task extends restore_activity_task {
/**
* Defines particular settings for this activity task. None required.
*
* @return void
*/
protected function define_my_settings() {
}

/**
* Defines particular steps for this activity restore.
*
* @return void
*/
protected function define_my_steps() {
$this->add_step(new restore_edflex_activity_structure_step('edflex_structure', 'edflex.xml'));
}

/**
* Defines the contents in the activity that must be processed by the link decoder.
*
* @return array The decode contents.
*/
public static function define_decode_contents() {
$contents = [];
$contents[] = new restore_decode_content('edflex', ['intro'], 'edflex');

return $contents;
}

/**
* Defines the decoding rules for links belonging to the activity to be executed by the link decoder.
*
* @return array The decode rules.
*/
public static function define_decode_rules() {
$rules = [];
$rules[] = new restore_decode_rule('EDFLEXVIEWBYID', '/mod/edflex/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('EDFLEXINDEX', '/mod/edflex/index.php?id=$1', 'course');

return $rules;
}

/**
* Defines the restore log rules that will be applied for the activity logs.
*
* @return array The restore log rules.
*/
public static function define_restore_log_rules() {
$rules = [];
$rules[] = new restore_log_rule('edflex', 'view', 'view.php?id={course_module}', '{edflex}');

return $rules;
}
}
71 changes: 71 additions & 0 deletions backup/moodle2/restore_edflex_stepslib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* Restore steps for mod_edflex.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Defines the structure step to restore one edflex activity.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_edflex_activity_structure_step extends restore_activity_structure_step {
/**
* Defines the structure to be restored for the edflex activity.
*
* @return mixed The prepared activity structure.
*/
protected function define_structure() {
$paths = [];
$paths[] = new restore_path_element('edflex', '/activity/edflex');

return $this->prepare_activity_structure($paths);
}

/**
* Restores one edflex instance from the backup data.
*
* @param array $data The edflex record to restore.
*
* @return void
*/
protected function process_edflex($data) {
global $DB;

$data = (object) $data;
$data->course = $this->get_courseid();
$data->timemodified = $this->apply_date_offset($data->timemodified);

$newitemid = $DB->insert_record('edflex', $data);
$this->apply_activity_instance($newitemid);
}

/**
* Re-adds the files belonging to the restored instance once execution completes.
*
* @return void
*/
protected function after_execute() {
$this->add_related_files('mod_edflex', 'intro', null);
}
}
54 changes: 54 additions & 0 deletions classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* The mod_edflex course module viewed event.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_edflex\event;

/**
* The mod_edflex course module viewed event class.
*
* @package mod_edflex
* @copyright 2025 Edflex <support@edflex.com>
* @license https://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() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'edflex';
}

/**
* Returns the mapping used by restore to remap the objectid.
*
* @return array The objectid mapping.
*/
public static function get_objectid_mapping() {
return ['db' => 'edflex', 'restore' => 'edflex'];
}
}
11 changes: 11 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@
'contextlevel' => CONTEXT_COURSE,
'archetypes' => ['editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW],
],
'mod/edflex:view' => [
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => [
'guest' => CAP_ALLOW,
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
],
],
];
1 change: 1 addition & 0 deletions lang/en/edflex.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
$string['downloadscormzipmissing'] = 'Scorm download URL is missing';
$string['duration'] = 'Duration';
$string['edflex:addinstance'] = 'Add a new Edflex activity';
$string['edflex:view'] = 'View Edflex activity';
$string['edflexbrowserloading'] = 'Loading...';
$string['edflexbrowsertitle'] = 'Browse Edflex Contents';
$string['edflexcontentidinvalid'] = 'Edflex content ID invalid';
Expand Down
11 changes: 10 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@
* @return mixed True if module supports feature, null if doesn't know
*/
function edflex_supports($feature) {
return null;
switch ($feature) {
case FEATURE_MOD_INTRO:
case FEATURE_SHOW_DESCRIPTION:
case FEATURE_BACKUP_MOODLE2:
return true;
default:
return null;
}
}

/**
Expand All @@ -48,6 +55,8 @@ function edflex_supports($feature) {
* @return bool
*/
function edflex_add_instance($moduleinstance, $mform = null) {
// The mod_edflex form is a launcher: it spawns SCORM modules via the
// Edflex browser, so no standalone edflex instance is ever persisted.
return false;
}

Expand Down
Loading
Loading