Skip to content

Commit

Permalink
MBS-9793: Changes for format_learningmap (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg authored Feb 13, 2025
1 parent aa11ead commit 235c6d2
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 10 deletions.
42 changes: 42 additions & 0 deletions classes/helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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;

/**
* Class helper
*
* @package mod_learningmap
* @copyright 2024 ISB Bayern
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class helper {
/**
* Returns whether the map should be shown on the course page.
*
* If course format format_learningmap is being used the module setting will be ignored.
*
* @param cm_info $cm the coursemodule info object
* @return bool the "showoncoursemap" setting of the coursemodule, or false if current course format is format_learningmap
*/
public static function show_map_on_course_page($cm): bool {
global $DB;
$showmaponcoursepage = $DB->get_field('learningmap', 'showmaponcoursepage', ['id' => $cm->instance]);
[$course, ] = get_course_and_cm_from_cmid($cm->id);
$courseformat = $course->format;
return !empty($showmaponcoursepage) && $courseformat !== 'learningmap';
}
}
43 changes: 43 additions & 0 deletions classes/output/courseformat/activitybadge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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 {
/**
* Updates the content of the activity badge.
*/
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';
}
}
}
}
}
7 changes: 3 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

use mod_learningmap\cachemanager;
use mod_learningmap\helper;

/**
* Array with all features the plugin supports for advanced settings. Might be moved
Expand Down Expand Up @@ -213,10 +214,8 @@ function learningmap_get_coursemodule_info($cm): cached_cm_info {
* @return void
*/
function learningmap_cm_info_dynamic(cm_info $cm): void {
global $DB;
$showmaponcoursepage = $DB->get_field('learningmap', 'showmaponcoursepage', ['id' => $cm->instance]);
// Decides whether to display the link.
if (!empty($showmaponcoursepage)) {
if (helper::show_map_on_course_page($cm)) {
$cm->set_no_view_link(true);
}
}
Expand All @@ -241,7 +240,7 @@ function learningmap_cm_info_view(cm_info $cm): void {
}

// Only show map on course page if showmaponcoursepage is set.
if (!empty($learningmap->showmaponcoursepage)) {
if (helper::show_map_on_course_page($cm)) {
if (!empty($cm->groupmode)) {
$groupdropdown = groups_print_activity_menu(
$cm,
Expand Down
15 changes: 12 additions & 3 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,25 @@ public function definition(): void {
)
);

$mform->addElement('advcheckbox', 'showmaponcoursepage', get_string('showmaponcoursepage', 'learningmap'));
$learningmapformat = $this->_course->format === 'learningmap';

// If using learningmap course format, the map is never shown on the course page.
if ($learningmapformat) {
$mform->addElement('hidden', 'showmaponcoursepage', 0);
} else {
$mform->addElement('advcheckbox', 'showmaponcoursepage', get_string('showmaponcoursepage', 'learningmap'));
$mform->addHelpButton('showmaponcoursepage', 'showmaponcoursepage', 'learningmap');
}

$mform->setType('showmaponcoursepage', PARAM_INT);
$mform->addHelpButton('showmaponcoursepage', 'showmaponcoursepage', 'learningmap');

$backlinkallowed = get_config('mod_learningmap', 'backlinkallowed');

if ($backlinkallowed) {
$mform->addElement('advcheckbox', 'backlink', get_string('showbacklink', 'learningmap'));
$mform->setType('backlink', PARAM_INT);
$mform->addHelpButton('backlink', 'showbacklink', 'learningmap');
$mform->setDefault('backlink', $learningmapformat);
} else {
$mform->addElement('hidden', 'backlink', 0);
}
Expand Down Expand Up @@ -146,7 +155,7 @@ public function definition(): void {

$this->standard_coursemodule_elements();

$this->add_action_buttons(true, false, null);
$this->add_action_buttons(true, null, null);

$mform->addHelpButton('groupmode', 'groupmode', 'learningmap');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class mod_learningmap_generator extends testing_module_generator {
* @param array|null $options
* @return stdClass learningmap instance
*/
public function create_instance($record = null, array $options = null): stdClass {
public function create_instance($record = null, ?array $options = null): stdClass {
global $CFG;

$record = (array)$record + [
Expand Down
9 changes: 7 additions & 2 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@
$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);

$completion = new completion_info($course);
$completion->set_module_viewed($cm);

// This is is a workaround to redirect to the course page if editing mode is turned on.
if ($course->format === 'learningmap') {
$PAGE->set_url(new moodle_url('/course/view.php', ['id' => $course->id]));
}

echo $OUTPUT->header();

if (!empty($cm->groupmode)) {
Expand Down

0 comments on commit 235c6d2

Please sign in to comment.