Skip to content

Commit

Permalink
Changes for format_learningmap
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg committed Oct 28, 2024
1 parent 4f513d9 commit 621829e
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 2 deletions.
11 changes: 11 additions & 0 deletions amd/build/initmainlearningmap.min.js

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

1 change: 1 addition & 0 deletions amd/build/initmainlearningmap.min.js.map

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

12 changes: 12 additions & 0 deletions amd/build/mainlearningmap.min.js

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

1 change: 1 addition & 0 deletions amd/build/mainlearningmap.min.js.map

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

34 changes: 34 additions & 0 deletions amd/src/initmainlearningmap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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/>.

/**
* Load module for highlighting the main learningmap.
*
* @module mod_learningmap/initmainlearningmap
* @copyright 2024 ISB Bayern
* @author Stefan Hanauska <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import MainLearningmap from 'mod_learningmap/mainlearningmap';
import {getCurrentCourseEditor} from 'core_courseformat/courseeditor';

export const init = (cmid, isfirstlearningmap = false) => {
return new MainLearningmap({
element: document.querySelector('.activity[data-id="' + cmid + '"]'),
reactive: getCurrentCourseEditor(),
cmid: cmid,
isfirstlearningmap: isfirstlearningmap,
});
};
98 changes: 98 additions & 0 deletions amd/src/mainlearningmap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// 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/>.

/**
* Highlight main learningmap for format_learningmap.
*
* @module mod_learningmap/mainlearningmap
* @copyright 2024 ISB Bayern
* @author Stefan Hanauska <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import {BaseComponent} from 'core/reactive';
import {refreshModule} from 'core_course/actions';
import {render as renderTemplate} from 'core/templates';

/**
* The live updater component.
*/
export default class extends BaseComponent {
create(descriptor) {
this.element = descriptor.element;
this.reactive = descriptor.reactive;
this.cmid = descriptor.cmid;
this.isfirstlearningmap = descriptor.isfirstlearningmap;
}

getWatchers() {
const watchers = [
{watch: `cm:deleted`, handler: this._updateLearningmap},
{watch: `section:updated`, handler: this._updateLearningmap},
{watch: `cm:added`, handler: this._updateLearningmap},
{watch: `cm[${this.cmid}]:deleted`, handler: this.destroy},
];
return watchers;
}

async destroy() {
if (this._getFirstLearningmap() === undefined) {
await renderTemplate('format_learningmap/notification', {}).then((html) => {
document.querySelector('.format_learningmap-notification').innerHTML = html;
return true;
});
}
}

async _updateLearningmap() {
if (this._isFirstLearningmap() && !this.isfirstlearningmap) {
this.isfirstlearningmap = true;
this.getElement().classList.add('format_learningmap-firstlearningmap');
refreshModule(this.element, this.cmid);
document.querySelector('.format_learningmap-notification').innerHTML = '';
} else {
if (this.isfirstlearningmap) {
this.isfirstlearningmap = false;
this.getElement().classList.remove('format_learningmap-firstlearningmap');
refreshModule(this.element, this.cmid);
}
}
}

_isFirstLearningmap() {
let firstLearningmap = this._getFirstLearningmap();
return firstLearningmap == this.cmid;
}

_getFirstLearningmap() {
let state = this.reactive.stateManager.state;
let cmlist = this._getCmlist();
return cmlist.find((cmid) => {
let cm = state.cm.get(cmid);
return (cm.module == 'learningmap');
});
}

_getCmlist() {
let state = this.reactive.stateManager.state;
let cmlist = [];
state.course.sectionlist.forEach((sectionid) => {
let section = state.section.get(sectionid);
section.cmlist.forEach((cmid) => {
cmlist.push(cmid);
});
});
return cmlist;
}
}
41 changes: 41 additions & 0 deletions classes/output/courseformat/activitybadge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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/>.

namespace mod_learningmap\output\courseformat;

/**
* Class activitybadge
*
* @package mod_learningmap
* @copyright 2024 ISB Bayern
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activitybadge extends \core_courseformat\output\activitybadge {

protected function update_content(): void {
$course = $this->cminfo->get_course();
if ($course->format == 'learningmap') {
$courseformat = course_get_format($course);
if($courseformat->main_learningmap_exists()) {
$mainlearningmap = $courseformat->get_main_learningmap();
if ($this->cminfo->id == $mainlearningmap->id) {
$this->content = get_string('mainlearningmap', 'format_learningmap');
$this->style = 'badge-primary';
}
}
}
}
}
4 changes: 2 additions & 2 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
$id = required_param('id', PARAM_INT);
[$course, $cm] = get_course_and_cm_from_cmid($id, 'learningmap');

$PAGE->set_url(new moodle_url('/mod/learningmap/view.php', ['id' => $id]));

require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/learningmap:view', $context);

$map = $DB->get_record('learningmap', ['id' => $cm->instance], '*', MUST_EXIST);

$PAGE->set_url(new moodle_url('/mod/learningmap/view.php', ['id' => $id]));
$PAGE->set_title(get_string('pluginname', 'mod_learningmap') . ' ' . $map->name);
$PAGE->set_heading($map->name);

Expand Down

0 comments on commit 621829e

Please sign in to comment.