Skip to content

Commit

Permalink
#13: Added toggleable course homepage link
Browse files Browse the repository at this point in the history
  • Loading branch information
Vidalia committed May 15, 2024
1 parent 5ebf713 commit fd3e8e6
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 7 deletions.
75 changes: 75 additions & 0 deletions classes/output/courseformat/content/sectionnavigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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/>.

/**
* Renders course section navigation
*
* @package format_cards
* @copyright 2024 University of Essex
* @author John Maydew <jdmayd@essex.ac.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace format_cards\output\courseformat\content;

use core_courseformat\output\local\content\sectionnavigation as sectionnavigation_base;
use renderer_base;
use stdClass;

/**
* Renders course section navigation
*
* @package format_cards
* @copyright 2024 University of Essex
* @author John Maydew <jdmayd@essex.ac.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sectionnavigation extends sectionnavigation_base {

/**
* Get the template path
*
* @param renderer_base $renderer
* @return string
*/
public function get_template_name(renderer_base $renderer): string {
return 'format_cards/local/content/sectionnavigation';
}

/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a mustache template
*/
public function export_for_template(renderer_base $output): stdClass {

$data = parent::export_for_template($output);

// Inject courseurl into the template data if we don't already have it.
if (!object_property_exists($data, 'courseurl')) {
$format = $this->format;
$course = $format->get_course();

$displayoption = $this->format->get_format_option('sectionnavigationhome');
$data->showcoursehome = $displayoption == FORMAT_CARDS_SECTIONNAVIGATIONHOME_SHOW;

$data->courseurl = course_get_url($course, null, [ 'navigation' => true ])->out();
}

return $data;
}
}
4 changes: 4 additions & 0 deletions lang/en/format_cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
$string['form:course:sectionnavigation:top'] = 'Top only';
$string['form:course:sectionnavigation:bottom'] = 'Bottom only';
$string['form:course:sectionnavigation:both'] = 'Both';
$string['form:course:sectionnavigationhome'] = 'Home link';
$string['form:course:sectionnavigationhome_help'] = 'Show a course homepage link in the section navigation. No effect unless the top section navigation is visible';
$string['form:course:sectionnavigationhome:show'] = 'Shown';
$string['form:course:sectionnavigationhome:hide'] = 'Hidden';
$string['form:course:cardorientation'] = 'Card orientation';
$string['form:course:cardorientation:vertical'] = 'Vertical';
$string['form:course:cardorientation:horizontal'] = 'Horizontal';
Expand Down
14 changes: 14 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
define('FORMAT_CARDS_SECTIONNAVIGATION_TOP', 2);
define('FORMAT_CARDS_SECTIONNAVIGATION_BOTTOM', 3);
define('FORMAT_CARDS_SECTIONNAVIGATION_BOTH', 4);
define('FORMAT_CARDS_SECTIONNAVIGATIONHOME_HIDE', '1');
define('FORMAT_CARDS_SECTIONNAVIGATIONHOME_SHOW', '2');

/**
* Course format main class
Expand Down Expand Up @@ -148,6 +150,18 @@ public function course_format_options($foreditform = false) {

$options['sectionnavigation'] = $createselect('sectionnavigation', $sectionnavigationoptions, $defaults->sectionnavigation);

$sectionnavigationhomeoptions = [
FORMAT_CARDS_SECTIONNAVIGATIONHOME_HIDE =>
new lang_string('form:course:sectionnavigationhome:hide', 'format_cards'),
FORMAT_CARDS_SECTIONNAVIGATIONHOME_SHOW =>
new lang_string('form:course:sectionnavigationhome:show', 'format_cards'),
];
$options['sectionnavigationhome'] = $createselect(
'sectionnavigationhome',
$sectionnavigationhomeoptions,
$defaults->sectionnavigationhome
);

$orientationoptions = [
FORMAT_CARDS_ORIENTATION_VERTICAL => new lang_string('form:course:cardorientation:vertical', 'format_cards'),
FORMAT_CARDS_ORIENTATION_HORIZONTAL => new lang_string('form:course:cardorientation:horizontal', 'format_cards'),
Expand Down
10 changes: 10 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
]
));

$settings->add(new admin_setting_configselect('format_cards/sectionnavigationhome',
get_string('form:course:sectionnavigationhome', 'format_cards'),
get_string('form:course:sectionnavigationhome_help', 'format_cards'),
FORMAT_CARDS_SECTIONNAVIGATIONHOME_HIDE,
[
FORMAT_CARDS_SECTIONNAVIGATIONHOME_HIDE => get_string('form:course:sectionnavigationhome:hide', 'format_cards'),
FORMAT_CARDS_SECTIONNAVIGATIONHOME_SHOW => get_string('form:course:sectionnavigationhome:show', 'format_cards'),
]
));

$settings->add(new admin_setting_configselect('format_cards/cardorientation',
get_string('form:course:cardorientation', 'format_cards'),
'',
Expand Down
6 changes: 3 additions & 3 deletions templates/local/content.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@
{{#hasnavigation}}
<div class="single-section">
{{#sectionnavigation}}
{{$ core_courseformat/local/content/sectionnavigation }}
{{> core_courseformat/local/content/sectionnavigation }}
{{/ core_courseformat/local/content/sectionnavigation }}
{{$ format_cards/local/content/sectionnavigation }}
{{> format_cards/local/content/sectionnavigation }}
{{/ format_cards/local/content/sectionnavigation }}
{{/sectionnavigation}}
<ul class="{{format}}">
{{#singlesection}}
Expand Down
54 changes: 54 additions & 0 deletions templates/local/content/sectionnavigation.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{!
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/>.
}}
{{!
@template core_courseformat/local/content/sectionnavigation
Displays the course section navigation.
Example context (json):
{
"hasprevious": true,
"previousurl": "#",
"larrow": "&#x25C4;",
"previousname": "Section 3",
"hasnext": true,
"rarrow": "&#x25BA;",
"nexturl": "#",
"nextname": "Section 5"
}
}}
<div class="section-navigation navigationtitle d-flex justify-content-between">
<div class="prevsection">
{{#hasprevious}}
<a href="{{{previousurl}}}" class="{{#previoushidden}} dimmed_text {{/previoushidden}} mr-2">
<span class="larrow">{{{larrow}}}</span>{{{previousname}}}
</a>
{{/hasprevious}}
{{#showcoursehome}}
<a href="{{{courseurl}}}">
{{#pix}} i/home, core, {{#str}} course {{/str}} {{/pix}}{{#str}} course {{/str}}
</a>
{{/showcoursehome}}
</div>
<div class="nextsection">
{{#hasnext}}
<a href="{{{nexturl}}}" class="{{#nexthidden}} dimmed_text {{/nexthidden}}">
<span class="rarrow">{{{rarrow}}}</span>{{{nextname}}}
</a>
{{/hasnext}}
</div>
</div>
8 changes: 4 additions & 4 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

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

$plugin->version = 2023090601; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2022041200; // Requires this Moodle version.
$plugin->version = 2023090603; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2022112800; // Requires this Moodle version.
$plugin->component = 'format_cards'; // Full name of the plugin (used for diagnostics).
$plugin->release = "v1.3.3";
$plugin->release = "v1.4.0";
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = [
"format_topics" => 2022041900
"format_topics" => 2022112800,
];

0 comments on commit fd3e8e6

Please sign in to comment.