Skip to content

Commit

Permalink
MBS-7744: Add backlink option
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg committed Dec 11, 2023
1 parent c3d3f45 commit 10fa950
Show file tree
Hide file tree
Showing 22 changed files with 289 additions and 36 deletions.
2 changes: 1 addition & 1 deletion amd/build/placestore.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/placestore.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions amd/src/placestore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let placestore = {
version: 2023080101,
version: 2023080201,
id: 0,
places: [],
paths: [],
Expand Down Expand Up @@ -36,7 +36,7 @@ let placestore = {
// eslint-disable-next-line no-empty
} catch { }
// Update version (only relevant if learning map is saved)
this.version = 2023080101;
this.version = 2023080201;
},
/**
* Returns placestore as a JSON string ()
Expand Down
4 changes: 2 additions & 2 deletions backup/moodle2/restore_learningmap_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public function after_restore() : void {
$item->intro = str_replace('learningmap-svgmap-' . $oldmapid, 'learningmap-svgmap-' . $newmapid, $item->intro);
$placestore->mapid = $newmapid;

if (!isset($placestore->version) || $placestore->version < 2023080101) {
$placestore->version = 2023080101;
if (!isset($placestore->version) || $placestore->version < 2023080201) {
$placestore->version = 2023080201;
// Needs 1 as default value (otherwise all place strokes would be hidden).
if (!isset($placestore->strokeopacity)) {
$placestore->strokeopacity = 1;
Expand Down
18 changes: 18 additions & 0 deletions classes/autoupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,23 @@ public static function update_from_delete_event(\core\event\base $event) : void
}
}
}
self::reset_backlink_cache($event);
}

/**
* Resets backlink cache of the whole course if a learningmap was created / updated / deleted.
* @param \core\event\base $event
* @return 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');
$modinfo = get_fast_modinfo($course);
$cms = $modinfo->get_cms();
foreach ($cms as $cm) {
$cache->delete($cm->id);
}
}
}
}
32 changes: 32 additions & 0 deletions db/caches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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/>.

/**
* Cache definitions for mod_learningmap
*
* @package mod_learningmap
* @copyright 2021-2023, ISB Bayern
* @author Stefan Hanauska <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

$definitions = [
'backlinks' => [
'mode' => cache_store::MODE_APPLICATION,
]
];
8 changes: 8 additions & 0 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@
'eventname' => '\core\event\course_module_deleted',
'callback' => '\mod_learningmap\autoupdate::update_from_delete_event',
],
[
'eventname' => '\core\event\course_module_created',
'callback' => '\mod_learningmap\autoupdate::reset_backlink_cache',
],
[
'eventname' => '\core\event\course_module_updated',
'callback' => '\mod_learningmap\autoupdate::reset_backlink_cache',
],
];
4 changes: 3 additions & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/learningmap/db" VERSION="20211201" COMMENT="XMLDB file for Moodle mod/learningmap"
<XMLDB PATH="mod/learningmap/db" VERSION="20230619" COMMENT="XMLDB file for Moodle mod/learningmap"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -14,12 +14,14 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="placestore" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="completiontype" TYPE="int" LENGTH="5" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="0 = no completion 1 = reaching one target place is necessary for completion 2 = reaching all target places is necessary for completion 3 = reaching all places is necessary for completion"/>
<FIELD NAME="backlink" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
<INDEX NAME="backlink" UNIQUE="false" FIELDS="backlink"/>
</INDEXES>
</TABLE>
</TABLES>
Expand Down
22 changes: 19 additions & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
*/
function xmldb_learningmap_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();

if ($oldversion < 2023080101) {
if ($oldversion < 2023080201) {
$entries = $DB->get_records('learningmap', []);
if ($entries) {
foreach ($entries as $entry) {
$placestore = json_decode($entry->placestore, true);
$placestore['version'] = 2023080101;
$placestore['version'] = 2023080201;
// Needs 1 as default value (otherwise all place strokes would be hidden).
if (!isset($placestore['strokeopacity'])) {
$placestore['strokeopacity'] = 1;
Expand All @@ -49,7 +50,22 @@ function xmldb_learningmap_upgrade($oldversion) {
$DB->update_record('learningmap', $entry);
}
}
upgrade_mod_savepoint(true, 2023080101, 'learningmap');

$table = new xmldb_table('learningmap');
$field = new xmldb_field('backlink', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'completiontype');

if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$index = new xmldb_index('backlink', XMLDB_INDEX_NOTUNIQUE, ['backlink']);

if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

upgrade_mod_savepoint(true, 2023080201, 'learningmap');
}

return true;
}
Binary file added fonts/learningmap.eot
Binary file not shown.
Loading

0 comments on commit 10fa950

Please sign in to comment.