From 40875cc7b2f130685102a868edf35c40c67f3eb1 Mon Sep 17 00:00:00 2001 From: Mathias Chouet Date: Mon, 1 Aug 2016 16:30:04 +0200 Subject: [PATCH 1/3] Added an option to manage cross section navigation --- db/install.xml | 8 ++++---- db/upgrade.php | 15 +++++++++++++++ definitions.php | 6 +++++- edit.php | 10 ++++++++++ footer.php | 35 +++++++++++++++++++++++++++++------ lang/en/block_navbuttons.php | 6 ++++++ lang/fr/block_navbuttons.php | 6 ++++++ version.php | 4 ++-- 8 files changed, 77 insertions(+), 13 deletions(-) diff --git a/db/install.xml b/db/install.xml index b4cac77..1cf567f 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -11,9 +11,9 @@ - - - + + + diff --git a/db/upgrade.php b/db/upgrade.php index 3af5cb1..f1715df 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -74,5 +74,20 @@ function xmldb_block_navbuttons_upgrade($oldversion) { upgrade_block_savepoint(true, 2014070601, 'navbuttons'); } + if ($oldversion < 2016080116) { + + // Define field crosssectionmode to be added to navbuttons. + $table = new xmldb_table('navbuttons'); + $field = new xmldb_field('crosssectionmode', XMLDB_TYPE_CHAR, '4', null, XMLDB_NOTNULL, null, 'show', 'enabled'); + + // Conditionally launch add field buttonstype. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Navbuttons savepoint reached. + upgrade_block_savepoint(true, 2016080116, 'navbuttons'); + } + return true; } diff --git a/definitions.php b/definitions.php index 32e8565..77202bd 100644 --- a/definitions.php +++ b/definitions.php @@ -37,4 +37,8 @@ define("BLOCK_NAVBUTTONS_EXTRA2ICON", 6); define("BLOCK_NAVBUTTONS_TYPE_ICON", 'icon'); -define("BLOCK_NAVBUTTONS_TYPE_TEXT", 'text'); \ No newline at end of file +define("BLOCK_NAVBUTTONS_TYPE_TEXT", 'text'); + +define("BLOCK_NAVBUTTONS_XSEC_SHOW", 'show'); +define("BLOCK_NAVBUTTONS_XSEC_HIDE", 'hide'); +define("BLOCK_NAVBUTTONS_XSEC_SECPAGE", 'sect'); \ No newline at end of file diff --git a/edit.php b/edit.php index b91455e..c986822 100644 --- a/edit.php +++ b/edit.php @@ -52,6 +52,14 @@ function definition() { $mform->addElement('selectyesno', 'customusebackground', get_string('customusebackground', 'block_navbuttons')); $mform->disabledIf('customusebackground', 'buttonstype', 'neq', BLOCK_NAVBUTTONS_TYPE_ICON); + $crosssectionopts = array( + BLOCK_NAVBUTTONS_XSEC_SHOW => get_string('xsecshowbutton', 'block_navbuttons'), + BLOCK_NAVBUTTONS_XSEC_SECPAGE => get_string('xsecshowsectionpage', 'block_navbuttons'), + BLOCK_NAVBUTTONS_XSEC_HIDE => get_string('xsechidebutton', 'block_navbuttons'), + ); + $mform->addElement('select', 'crosssectionmode', get_string('crosssectionmode', 'block_navbuttons'), $crosssectionopts); + $mform->setDefault('crosssectionmode', BLOCK_NAVBUTTONS_XSEC_SHOW); + $hometypes = array( BLOCK_NAVBUTTONS_HOME_FRONTPAGE => get_string('frontpage', 'block_navbuttons'), BLOCK_NAVBUTTONS_HOME_COURSE => get_string('coursepage', 'block_navbuttons') @@ -156,6 +164,7 @@ function definition() { $defaults->buttonstype = $settings->buttonstype; $defaults->backgroundcolour = $settings->backgroundcolour; $defaults->customusebackground = $settings->customusebackground; +$defaults->crosssectionmode = $settings->crosssectionmode; $defaults->homebuttonshow = $settings->homebuttonshow; $defaults->homebuttontype = $settings->homebuttontype; $defaults->firstbuttonshow = $settings->firstbuttonshow; @@ -223,6 +232,7 @@ function definition() { $update->buttonstype = $data->buttonstype; $update->backgroundcolour = $data->backgroundcolour; $update->customusebackground = $data->customusebackground; + $update->crosssectionmode = $data->crosssectionmode; $update->homebuttonshow = $data->homebuttonshow; $update->homebuttontype = $data->homebuttontype; $update->firstbuttonshow = $data->firstbuttonshow; diff --git a/footer.php b/footer.php index 98b4b98..a19a784 100644 --- a/footer.php +++ b/footer.php @@ -53,6 +53,8 @@ function draw_navbuttons() { } $cmid = $PAGE->cm->id; + $csnum = $PAGE->cm->sectionnum; + $xsecmode = $settings->crosssectionmode; $modinfo = get_fast_modinfo($COURSE); if ($CFG->version < 2011120100) { @@ -60,7 +62,7 @@ function draw_navbuttons() { } else { $context = context_course::instance($COURSE->id); } - $sections = $DB->get_records('course_sections', array('course' => $COURSE->id), 'section', 'section,visible,summary'); + $sections = $DB->get_records('course_sections', array('course' => $COURSE->id), 'section', 'section,visible,summary,name,id'); /** @var object|null $next */ $next = null; @@ -125,7 +127,8 @@ function draw_navbuttons() { $thismod = (object)[ 'link' => new moodle_url('/mod/'.$mod->modname.'/view.php', array('id' => $mod->id)), - 'name' => strip_tags(format_string($mod->name, true)) + 'name' => strip_tags(format_string($mod->name, true)), + 'sectionnum' => $mod->sectionnum ]; if ($flag) { // Current mod is the 'next' mod. @@ -208,15 +211,35 @@ function draw_navbuttons() { if ($settings->prevbuttonshow && $prev) { list($icon, $bgcolour) = navbutton_get_icon($settings->buttonstype, 'prev', $context, BLOCK_NAVBUTTONS_PREVICON, $settings->backgroundcolour, $settings->customusebackground); - $output .= make_navbutton($icon, $bgcolour, get_string('prevactivity', 'block_navbuttons').': '.$prev->name, - $prev->link, "prev"); + if ($prev->sectionnum != $csnum) { + if ($xsecmode == BLOCK_NAVBUTTONS_XSEC_SECPAGE) { + $cursec = $sections[$csnum]; + $cursecurl = new moodle_url('/course/view.php', array('id' => $COURSE->id, 'section' => $cursec->id)); + $output .= make_navbutton($icon, $bgcolour, + get_string('sectionhome', 'block_navbuttons').': '.$cursec->name, + $cursecurl, "prev"); + } // Else hide button. + } else { + $output .= make_navbutton($icon, $bgcolour, get_string('prevactivity', 'block_navbuttons').': '.$prev->name, + $prev->link, "prev"); + } } if ($settings->nextbuttonshow && $next) { list($icon, $bgcolour) = navbutton_get_icon($settings->buttonstype, 'next', $context, BLOCK_NAVBUTTONS_NEXTICON, $settings->backgroundcolour, $settings->customusebackground); - $output .= make_navbutton($icon, $bgcolour, get_string('nextactivity', 'block_navbuttons').': '.$next->name, - $next->link, "next"); + if ($next->sectionnum != $csnum) { + if ($xsecmode == BLOCK_NAVBUTTONS_XSEC_SECPAGE) { + $nextsec = $sections[$next->sectionnum]; + $nextsecurl = new moodle_url('/course/view.php',array('id' => $COURSE->id, 'section' => $nextsec->id)); + $output .= make_navbutton($icon, $bgcolour, + get_string('nextsection', 'block_navbuttons').': '.$nextsec->name, + $nextsecurl, "next"); + } // Else hide button. + } else { + $output .= make_navbutton($icon, $bgcolour, get_string('nextactivity', 'block_navbuttons').': '.$next->name, + $next->link, "next"); + } } if ($settings->lastbuttonshow) { diff --git a/lang/en/block_navbuttons.php b/lang/en/block_navbuttons.php index 9d219cf..108fe70 100644 --- a/lang/en/block_navbuttons.php +++ b/lang/en/block_navbuttons.php @@ -34,6 +34,10 @@ $string['buttonsenabled'] = 'Navigation buttons enabled for this course'; $string['coursepage'] = 'Course page'; $string['customusebackground'] = 'Use colour for custom icons'; +$string['crosssectionmode'] = 'Behavior when changing section'; +$string['xsecshowbutton'] = 'Go to previous / next activity'; +$string['xsecshowsectionpage'] = 'Go to previous / next section home page'; +$string['xsechidebutton'] = 'Hide button'; $string['displaybutton'] = 'Show this button'; $string['editsettings'] = 'Edit the Navigation Button settings'; $string['extra1'] = 'Extra button 1'; @@ -53,9 +57,11 @@ $string['navbuttons:addinstance'] = 'Add Navbuttons block to My Moodle page'; $string['navbuttons:myaddinstance'] = 'Add new Navbuttons block'; $string['nextactivity'] = 'Next activity'; +$string['nextsection'] = 'Next section'; $string['nextbutton'] = 'Next button'; $string['pluginname'] = 'Navigation Buttons'; $string['prevactivity'] = 'Previous activity'; +$string['sectionhome'] = 'Section home'; $string['prevbutton'] = 'Previous button'; $string['selftest_nofooter'] = 'Navbutton self-test: The line "$output = draw_navbuttons().$this->container_end_all(true);" has not been correctly added to outputrenderers.php - see README.txt for further instructions'; $string['selftest_ok'] = 'Navbuttons self-test: required core modifications have been completed successfully'; diff --git a/lang/fr/block_navbuttons.php b/lang/fr/block_navbuttons.php index 6c6cbc6..d41be65 100644 --- a/lang/fr/block_navbuttons.php +++ b/lang/fr/block_navbuttons.php @@ -35,6 +35,10 @@ $string['buttonsenabled'] = 'Boutons de navigation activés pour ce cours'; $string['coursepage'] = 'Accueil'; $string['customusebackground'] = 'Utiliser cette couleur pour les icônes personnalisées'; +$string['crosssectionmode'] = 'Comportement lors du changement de section'; +$string['xsecshowbutton'] = 'Aller à l\'activité précédente / suivante'; +$string['xsecshowsectionpage'] = 'Aller à la page d\'accueil de la section précédente / suivante'; +$string['xsechidebutton'] = 'Masquer le bouton'; $string['displaybutton'] = 'Afficher ce bouton'; $string['editsettings'] = 'Modifier les réglages des Boutons de Navigation'; $string['extra1'] = 'Bouton extra 1'; @@ -54,9 +58,11 @@ $string['navbuttons:addinstance'] = 'Ajouter un bloc Boutons de Navigation à la page Mon Moodle'; $string['navbuttons:myaddinstance'] = 'Ajouter un bloc Boutons de Navigation'; $string['nextactivity'] = 'Suivant'; +$string['nextsection'] = 'Section suivante'; $string['nextbutton'] = 'Bouton "suivant"'; $string['pluginname'] = 'Boutons de Navigation'; $string['prevactivity'] = 'Précédent'; +$string['sectionhome'] = 'Accueil de la section'; $string['prevbutton'] = 'Bouton "précédent"'; $string['selftest_nofooter'] = 'Auto-test des Boutons de Navigation: La ligne "$output = draw_navbuttons().$this->container_end_all(true);" n\'a pas été ajoutée correctement à outputrenderers.php - lire README.txt pour voir les instructions'; $string['selftest_ok'] = 'Auto-test des Boutons de Navigation: les modifications du cœur requises ont été effectuées avec succès'; diff --git a/version.php b/version.php index 2068ff4..c536f4d 100644 --- a/version.php +++ b/version.php @@ -17,9 +17,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016052000; +$plugin->version = 2016080116; $plugin->release = '2.2+ (Build: 2016052000)'; -$plugin->requires = 2011120100; // Moodle 2.2 +$plugin->requires = 2011120116; // Moodle 2.2 $plugin->cron = 0; $plugin->component = 'block_navbuttons'; $plugin->maturity = MATURITY_STABLE; From 42cee34a63918a112a7c94320bc85736d4616a6b Mon Sep 17 00:00:00 2001 From: Mathias Chouet Date: Mon, 1 Aug 2016 17:07:04 +0200 Subject: [PATCH 2/3] Fixed mistake in db/install.xml : had removed a field --- db/install.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/install.xml b/db/install.xml index 1cf567f..d2daa97 100644 --- a/db/install.xml +++ b/db/install.xml @@ -14,6 +14,7 @@ + @@ -34,4 +35,4 @@ - \ No newline at end of file + From 368272871d83dbd957e75a211617086539e2928f Mon Sep 17 00:00:00 2001 From: Mathias Chouet Date: Tue, 9 Aug 2016 11:17:56 +0200 Subject: [PATCH 3/3] Fixed mistake about section identifier : id > section --- footer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/footer.php b/footer.php index a19a784..8659917 100644 --- a/footer.php +++ b/footer.php @@ -62,7 +62,7 @@ function draw_navbuttons() { } else { $context = context_course::instance($COURSE->id); } - $sections = $DB->get_records('course_sections', array('course' => $COURSE->id), 'section', 'section,visible,summary,name,id'); + $sections = $DB->get_records('course_sections', array('course' => $COURSE->id), 'section', 'section,visible,summary,name'); /** @var object|null $next */ $next = null; @@ -214,7 +214,7 @@ function draw_navbuttons() { if ($prev->sectionnum != $csnum) { if ($xsecmode == BLOCK_NAVBUTTONS_XSEC_SECPAGE) { $cursec = $sections[$csnum]; - $cursecurl = new moodle_url('/course/view.php', array('id' => $COURSE->id, 'section' => $cursec->id)); + $cursecurl = new moodle_url('/course/view.php', array('id' => $COURSE->id, 'section' => $cursec->section)); $output .= make_navbutton($icon, $bgcolour, get_string('sectionhome', 'block_navbuttons').': '.$cursec->name, $cursecurl, "prev"); @@ -231,7 +231,7 @@ function draw_navbuttons() { if ($next->sectionnum != $csnum) { if ($xsecmode == BLOCK_NAVBUTTONS_XSEC_SECPAGE) { $nextsec = $sections[$next->sectionnum]; - $nextsecurl = new moodle_url('/course/view.php',array('id' => $COURSE->id, 'section' => $nextsec->id)); + $nextsecurl = new moodle_url('/course/view.php',array('id' => $COURSE->id, 'section' => $nextsec->section)); $output .= make_navbutton($icon, $bgcolour, get_string('nextsection', 'block_navbuttons').': '.$nextsec->name, $nextsecurl, "next");