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
1 change: 1 addition & 0 deletions classes/external/get_cm.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use core_external\external_single_structure;
use core_external\external_function_parameters;
use mod_learningmap\helper;

/**
* Class get_cm
*
Expand Down
22 changes: 0 additions & 22 deletions classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class helper {
/**
* Get the current default activity header description without rendering the full header.
*
* Calling activity_header::export_for_template() here would add completion actions as a side effect.
*
* @return string
*/
public static function get_activity_header_description(): string {
global $PAGE;

$layoutoptions = $PAGE->layout_options['activityheader'] ?? [];
if (
empty($layoutoptions['nodescription'])
&& !empty($PAGE->activityrecord->intro)
&& trim($PAGE->activityrecord->intro)
) {
return format_module_intro($PAGE->activityname, $PAGE->activityrecord, $PAGE->cm->id);
}

return '';
}

/**
* Render the activity header for learningmap modals.
*
Expand Down
4 changes: 1 addition & 3 deletions classes/local/hook_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use core\hook\output\before_http_headers;
use Exception;
use mod_learningmap\cachemanager;
use mod_learningmap\helper;

/**
* Hook callbacks for mod_learningmap.
Expand Down Expand Up @@ -100,8 +99,7 @@ public static function inject_backlinks_into_activity_header(before_http_headers
}

if ($backlinktext) {
$description = helper::get_activity_header_description();
$PAGE->activityheader->set_description($description . $backlinktext);
$PAGE->add_header_action($backlinktext);
}
} catch (Exception $e) {
debugging($e->getMessage());
Expand Down
1 change: 1 addition & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @author Philipp Memmel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

$callbacks = [
Expand Down
3 changes: 1 addition & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ function learningmap_before_http_headers() {
}

if ($backlinktext) {
$description = helper::get_activity_header_description();
$PAGE->activityheader->set_description($description . $backlinktext);
$PAGE->add_header_action($backlinktext);
}
} catch (Exception $e) {
debugging($e->getMessage());
Expand Down
5 changes: 1 addition & 4 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@
.learningmap-icon:before {
content: 'A';
padding-right: 0.5rem;
}

.learningmap-backlink {
padding-top: 1rem;
vertical-align: middle;
}

.learningmap-container {
Expand Down
4 changes: 2 additions & 2 deletions templates/backtomap.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{!
@template mod_learningmap/backtomap

Template for displaying the "back to learning map" button in activity descriptions.
Template for displaying the "back to learning map" button in the page header actions of activities.

Classes required for JS:
* none
Expand All @@ -35,5 +35,5 @@
}
}}
<div class="learningmap-backlink">
<a href="{{{url}}}" class="learningmap-icon">{{#str}} backlink, learningmap, { "name": {{#quote}}{{name}}{{/quote}} } {{/str}}</a>
<a href="{{{url}}}" class="btn btn-secondary btn-sm learningmap-icon">{{#str}} backlink, learningmap, { "name": {{#quote}}{{name}}{{/quote}} } {{/str}}</a>
</div>
30 changes: 14 additions & 16 deletions tests/mod_learningmap_backlink_cache_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,47 +182,45 @@ public function test_backlink_generation(): void {
// Test an activity that is part of the first learning map (with backlink enabled).
$PAGE->set_cm($modinfo->get_cm($this->activities[0][0]->cmid));
$PAGE->set_activity_record($this->activities[0][0]);
// Simulate an activity setting its own header description (e.g. mod_assign with intro attachments).
$PAGE->activityheader->set_description('Custom activity description');

$descriptionbefore = $PAGE->activityheader->export_for_template($OUTPUT)['description'];
$this->assertEmpty($PAGE->get_header_actions());
learningmap_before_http_headers();

$descriptionafter = $PAGE->activityheader->export_for_template($OUTPUT)['description'];
$this->assertNotEquals($descriptionbefore, $descriptionafter);
$this->assertTrue(str_contains($descriptionafter, $this->learningmaps[0]->cmid));
$headeractions = $PAGE->get_header_actions();
$this->assertCount(1, $headeractions);
$this->assertTrue(str_contains($headeractions[0], $this->learningmaps[0]->cmid));
// The description set by the activity must not be touched.
$this->assertEquals(
'Custom activity description',
$PAGE->activityheader->export_for_template($OUTPUT)['description']
);

// Test an activity that is part of the second learning map (with backlink disabled).
$PAGE = new \moodle_page();
$PAGE->set_cm($modinfo->get_cm($this->activities[1][1]->cmid));
$PAGE->set_activity_record($this->activities[1][1]);

$descriptionbefore = $PAGE->activityheader->export_for_template($OUTPUT)['description'];
learningmap_before_http_headers();

$descriptionafter = $PAGE->activityheader->export_for_template($OUTPUT)['description'];
$this->assertEquals($descriptionbefore, $descriptionafter);
$this->assertEmpty($PAGE->get_header_actions());

// Test an activity that is part of the second course (without any learning maps).
$PAGE = new \moodle_page();
$modinfo = get_fast_modinfo($this->courses[1]);
$PAGE->set_cm($modinfo->get_cm($this->activities[3][0]->cmid));
$PAGE->set_activity_record($this->activities[3][0]);

$descriptionbefore = $PAGE->activityheader->export_for_template($OUTPUT)['description'];
learningmap_before_http_headers();

$descriptionafter = $PAGE->activityheader->export_for_template($OUTPUT)['description'];
$this->assertEquals($descriptionbefore, $descriptionafter);
$this->assertEmpty($PAGE->get_header_actions());

// Learningmap is invisible for the user. Backlink should not be generated.
$PAGE = new \moodle_page();
$modinfo = get_fast_modinfo($this->courses[0]);
$PAGE->set_cm($modinfo->get_cm($this->activities[2][1]->cmid));
$PAGE->set_activity_record($this->activities[2][1]);

$descriptionbefore = $PAGE->activityheader->export_for_template($OUTPUT)['description'];
learningmap_before_http_headers();

$descriptionafter = $PAGE->activityheader->export_for_template($OUTPUT)['description'];
$this->assertEquals($descriptionbefore, $descriptionafter);
$this->assertEmpty($PAGE->get_header_actions());
}
}
1 change: 1 addition & 0 deletions tests/mod_learningmap_completion_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace mod_learningmap;

use mod_learningmap\completion\custom_completion;

defined('MOODLE_INTERNAL') || die();
Expand Down
1 change: 1 addition & 0 deletions tests/mod_learningmap_mapworker_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace mod_learningmap;

use mod_learningmap\completion\custom_completion;

/**
Expand Down
1 change: 1 addition & 0 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @author Stefan Hanauska <stefan.hanauska@csg-in.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

$plugin->component = 'mod_learningmap';
Expand Down
Loading