Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-8687: Remove deprecated elements and cleanup #90

Merged
merged 1 commit into from
Jan 25, 2024
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
13 changes: 6 additions & 7 deletions backup/moodle2/backup_learningmap_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/mod/learningmap/backup/moodle2/backup_learningmap_stepslib.php');
require_once($CFG->dirroot . '/mod/learningmap/backup/moodle2/backup_learningmap_stepslib.php');

/**
* Backup class for mod_learningmap
Expand All @@ -27,17 +27,16 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_learningmap_activity_task extends backup_activity_task {

/**
* No specific settings for this activity
*/
protected function define_my_settings() : void {
protected function define_my_settings(): void {
}

/**
* Defines a backup step to store the instance data in the learningmap.xml file
*/
protected function define_my_steps() : void {
protected function define_my_steps(): void {
$this->add_step(new backup_learningmap_activity_structure_step('learningmap_structure', 'learningmap.xml'));
}

Expand All @@ -47,12 +46,12 @@ protected function define_my_steps() : void {
* @param string $content
* @return string
*/
public static function encode_content_links($content) : string {
public static function encode_content_links($content): string {
global $CFG;

$base = preg_quote($CFG->wwwroot.'/mod/learningmap', '#');
$base = preg_quote($CFG->wwwroot . '/mod/learningmap', '#');

$pattern = "#(".$base."\/view.php\?id\=)([0-9]+)#";
$pattern = "#(" . $base . "\/view.php\?id\=)([0-9]+)#";
$content = preg_replace($pattern, '$@LEARNINGMAPVIEWBYID*$2@$', $content);
return $content;
}
Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/backup_learningmap_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class backup_learningmap_activity_structure_step extends backup_activity_structu
*
* @return backup_nested_element
*/
protected function define_structure() : backup_nested_element {
protected function define_structure(): backup_nested_element {
$learningmap = new backup_nested_element(
'learningmap',
['id'],
Expand Down
13 changes: 6 additions & 7 deletions backup/moodle2/restore_learningmap_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/mod/learningmap/backup/moodle2/restore_learningmap_stepslib.php');
require_once($CFG->dirroot . '/mod/learningmap/backup/moodle2/restore_learningmap_stepslib.php');

/**
* Restore class for mod_learningmap
Expand All @@ -27,21 +27,20 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_learningmap_activity_task extends restore_activity_task {

/**
* No specific settings for this activity
*
* @return void
*/
protected function define_my_settings() : void {
protected function define_my_settings(): void {
}

/**
* Defines the restore step for learningmap
*
* @return void
*/
protected function define_my_steps() : void {
protected function define_my_steps(): void {
$this->add_step(new restore_learningmap_activity_structure_step('learningmap_structure', 'learningmap.xml'));
}

Expand All @@ -52,7 +51,7 @@ protected function define_my_steps() : void {
*
* @return array
*/
public static function define_decode_contents() : array {
public static function define_decode_contents(): array {
$contents = [];
$contents[] = new restore_decode_content('learningmap', ['intro'], 'learningmap');
return $contents;
Expand All @@ -63,7 +62,7 @@ public static function define_decode_contents() : array {
*
* @return array
*/
public static function define_decode_rules() : array {
public static function define_decode_rules(): array {
$rules = [];
$rules[] = new restore_decode_rule('LEARNINGMAPVIEWBYID', '/mod/learningmap/view.php?id=$1', 'course_module');
return $rules;
Expand All @@ -73,7 +72,7 @@ public static function define_decode_rules() : array {
* Update placestore to new module ids after restore is complete
* @throws dml_exception
*/
public function after_restore() : void {
public function after_restore(): void {
global $DB;
$courseid = $this->get_courseid();
$modinfo = get_fast_modinfo($courseid);
Expand Down
7 changes: 3 additions & 4 deletions backup/moodle2/restore_learningmap_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_learningmap_activity_structure_step extends restore_activity_structure_step {

/**
* List of elements that can be restored
* @return array
* @throws base_step_exception
*/
protected function define_structure() : array {
protected function define_structure(): array {
$paths = [];
$paths[] = new restore_path_element('learningmap', '/activity/learningmap');
return $this->prepare_activity_structure($paths);
Expand All @@ -42,7 +41,7 @@ protected function define_structure() : array {
* @throws dml_exception
* @throws restore_step_exception
*/
protected function process_learningmap($data) : void {
protected function process_learningmap($data): void {
global $DB;

$data = (object) $data;
Expand All @@ -57,7 +56,7 @@ protected function process_learningmap($data) : void {
/**
* Extra actions to take once restore is complete.
*/
protected function after_execute() : void {
protected function after_execute(): void {
$this->add_related_files('mod_learningmap', 'intro', null);
}
}
16 changes: 10 additions & 6 deletions classes/activitymanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ public function __construct(stdClass $course, stdClass $user, int $group = 0) {
*/
public function is_completed(cm_info $cm): bool {
foreach ($this->members as $member) {
if ($this->completion->get_data($cm, true, $member->id)->completionstate == COMPLETION_COMPLETE ||
$this->completion->get_data($cm, true, $member->id)->completionstate == COMPLETION_COMPLETE_PASS) {
if (
$this->completion->get_data($cm, true, $member->id)->completionstate == COMPLETION_COMPLETE ||
$this->completion->get_data($cm, true, $member->id)->completionstate == COMPLETION_COMPLETE_PASS
) {
return true;
}
}
Expand All @@ -100,8 +102,8 @@ public function is_completed(cm_info $cm): bool {
public function get_completion_order(array $cms): array {
if (count($cms) > 0 && intval(current($cms)) > 0) {
$intcms = $cms;
$cms = array_map(function($value) {
$obj = new stdClass;
$cms = array_map(function ($value) {
$obj = new stdClass();
$obj->id = $value;
$obj->course = $this->course;
return $obj;
Expand All @@ -110,8 +112,10 @@ public function get_completion_order(array $cms): array {
$completiontime = [];
foreach ($cms as $cm) {
foreach ($this->members as $member) {
if ($this->completion->get_data($cm, true, $member->id)->completionstate == COMPLETION_COMPLETE ||
$this->completion->get_data($cm, true, $member->id)->completionstate == COMPLETION_COMPLETE_PASS) {
if (
$this->completion->get_data($cm, true, $member->id)->completionstate == COMPLETION_COMPLETE ||
$this->completion->get_data($cm, true, $member->id)->completionstate == COMPLETION_COMPLETE_PASS
) {
$completed = $this->completion->get_data($cm, true, $member->id)->timemodified;
if (!isset($completiontime[$cm->id]) || $completed < $completiontime[$cm->id]) {
$completiontime[$cm->id] = $completed;
Expand Down
8 changes: 4 additions & 4 deletions classes/autoupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class autoupdate {
* @param \core\event\base $event
* @return void
*/
public static function update_from_event(\core\event\base $event) : void {
public static function update_from_event(\core\event\base $event): void {
$data = $event->get_data();
if (isset($data['courseid']) && $data['courseid'] > 0) {
$modinfo = get_fast_modinfo($data['courseid']);
Expand All @@ -51,7 +51,7 @@ public static function update_from_event(\core\event\base $event) : void {
$members = groups_get_members($group);
}
if (empty($members)) {
$user = new \stdClass;
$user = new \stdClass();
$user->id = $data['userid'];
$members = [$user];
}
Expand All @@ -71,7 +71,7 @@ public static function update_from_event(\core\event\base $event) : void {
* @param \core\event\base $event
* @return void
*/
public static function update_from_delete_event(\core\event\base $event) : void {
public static function update_from_delete_event(\core\event\base $event): void {
global $DB;
$data = $event->get_data();
if (isset($data['courseid']) && $data['courseid'] > 0) {
Expand Down Expand Up @@ -103,7 +103,7 @@ public static function update_from_delete_event(\core\event\base $event) : void
* @param \core\event\base $event
* @return void
*/
public static function reset_backlink_cache(\core\event\base $event) : void {
public static function reset_backlink_cache(\core\event\base $event): void {
if (isset($data['courseid']) && $data['courseid'] > 0) {
$course = $data['courseid'];
$cache = \cache::make('mod_learningmap', 'backlinks');
Expand Down
3 changes: 1 addition & 2 deletions classes/external/get_dependingmodules.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_dependingmodules extends external_api {

/**
* Returns description of method parameters for the get_dependingmodules webservice function.
*
Expand Down Expand Up @@ -90,7 +89,7 @@ public static function execute_returns(): external_single_structure {
public static function execute(int $cmid): array {
$params = self::validate_parameters(self::execute_parameters(), ['cmId' => $cmid]);
$cmid = $params['cmId'];
list($course, $cminfo) = get_course_and_cm_from_cmid($cmid);
[$course, $cminfo] = get_course_and_cm_from_cmid($cmid);
$context = context_module::instance($cmid);
self::validate_context($context);
require_capability('mod/learningmap:view', $context);
Expand Down
3 changes: 1 addition & 2 deletions classes/external/get_learningmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_learningmap extends external_api {

/**
* Returns description of method parameters for the get_learningmap webservice function.
*
Expand Down Expand Up @@ -88,7 +87,7 @@ public static function execute_returns(): external_single_structure {
public static function execute(int $cmid): array {
$params = self::validate_parameters(self::execute_parameters(), ['cmId' => $cmid]);
$cmid = $params['cmId'];
list($course, $cminfo) = get_course_and_cm_from_cmid($cmid);
[$course, $cminfo] = get_course_and_cm_from_cmid($cmid);
$context = context_module::instance($cmid);
self::validate_context($context);
require_capability('mod/learningmap:view', $context);
Expand Down
38 changes: 21 additions & 17 deletions classes/mapworker.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,37 @@ class mapworker {
* Object to process the SVG
* @var svgmap;
*/
protected $svgmap;
protected svgmap $svgmap;
/**
* Array containing the placestore
* @var array
*/
protected $placestore;
protected array $placestore;
/**
* Course module object belonging to the map - only needed for completion
* @var cm_info
*/
protected $cm;
protected \cm_info $cm;
/**
* Whether to prepare the code for edit mode
* @var boolean
* @var bool
*/
protected $edit;
protected bool $edit;
/**
* Stores the group id when using group mode. 0 if no group is used.
* @var int
*/
protected $group;
protected int $group;
/**
* Activity worker to handle completion
* @var activitymanager
*/
protected $activitymanager;
protected activitymanager $activitymanager;
/**
* Active places
* @var array
*/
protected $active;
protected array $active;

/**
* Creates mapworker from SVG code
Expand All @@ -73,13 +73,17 @@ class mapworker {
* @param int $group Group id to use (default 0 means no group)
*/
public function __construct(string $svgcode, array $placestore, \cm_info $cm = null, bool $edit = false, int $group = 0) {
global $CFG, $USER;
$svgcode = preg_replace('/<text(.*)>(?!(<\!\[CDATA\[))(.*)<\/text>/',
global $USER;
$svgcode = preg_replace(
'/<text(.*)>(?!(<\!\[CDATA\[))(.*)<\/text>/',
'<text$1><![CDATA[$3]]></text>',
$svgcode);
$svgcode = preg_replace('/<title(.*)>(?!(<\!\[CDATA\[))(.*)<\/title>/',
$svgcode
);
$svgcode = preg_replace(
'/<title(.*)>(?!(<\!\[CDATA\[))(.*)<\/title>/',
'<title$1><![CDATA[$3]]></title>',
$svgcode);
$svgcode
);
$this->edit = $edit;
$placestore['editmode'] = $this->edit;
$this->placestore = $placestore;
Expand All @@ -98,7 +102,7 @@ public function __construct(string $svgcode, array $placestore, \cm_info $cm = n
* @param array $placestoreoverride array of overrides for placestore
* @return void
*/
public function replace_stylesheet(array $placestoreoverride = []) : void {
public function replace_stylesheet(array $placestoreoverride = []): void {
$this->svgmap->replace_stylesheet($placestoreoverride);
}

Expand All @@ -107,7 +111,7 @@ public function replace_stylesheet(array $placestoreoverride = []) : void {
*
* @return void
*/
public function replace_defs() : void {
public function replace_defs(): void {
$this->svgmap->replace_defs();
}

Expand All @@ -116,15 +120,15 @@ public function replace_defs() : void {
*
* @return void
*/
public function remove_tags_before_svg() : void {
public function remove_tags_before_svg(): void {
$this->svgmap->remove_tags_before_svg();
}

/**
* Process the map to show / hide paths and places
* @return void
*/
public function process_map_objects() : void {
public function process_map_objects(): void {
global $CFG, $USER;
$this->active = [];
$completedplaces = [];
Expand Down
3 changes: 1 addition & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
Loading
Loading