From d9203fb7750f1ac97ac043a440778c037957aff8 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 3 Oct 2013 14:44:07 +0800 Subject: [PATCH] MDL-41611 format_singleactivity: Only hide unnecessary elements --- course/format/lib.php | 18 ++++++++++++++++++ course/format/singleactivity/lib.php | 10 ++++++++++ course/format/singleactivity/styles.css | 10 ++-------- course/moodleform_mod.php | 19 +++++++++++++++---- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/course/format/lib.php b/course/format/lib.php index 84017f72f4b..1980441d8ec 100644 --- a/course/format/lib.php +++ b/course/format/lib.php @@ -250,6 +250,24 @@ abstract class format_base { return $this->course; } + /** + * Returns true if the course has a front page. + * + * This function is called to determine if the course has a view page, whether or not + * it contains a listing of activities. It can be useful to set this to false when the course + * format has only one activity and ignores the course page. Or if there are multiple + * activities but no page to see the centralised information. + * + * Initially this was created to know if forms should add a button to return to the course page. + * So if 'Return to course' does not make sense in your format your should probably return false. + * + * @return boolean + * @since 2.6 + */ + public function has_view_page() { + return true; + } + /** * Returns true if this course format uses sections * diff --git a/course/format/singleactivity/lib.php b/course/format/singleactivity/lib.php index 6e5a4f209ff..396e4d6e5c4 100644 --- a/course/format/singleactivity/lib.php +++ b/course/format/singleactivity/lib.php @@ -457,4 +457,14 @@ class format_singleactivity extends format_base { $activitynode->remove(); } } + + /** + * Returns true if the course has a front page. + * + * @return boolean false + */ + public function has_view_page() { + return false; + } + } diff --git a/course/format/singleactivity/styles.css b/course/format/singleactivity/styles.css index 65f7875b826..77cef6fe51d 100644 --- a/course/format/singleactivity/styles.css +++ b/course/format/singleactivity/styles.css @@ -1,10 +1,4 @@ -/* Hide confusing form elements "Display description on course page" and -"Save and return to course" from module edit form because they -are not applicable in single activity course format */ -body.format-singleactivity.path-mod.pagelayout-admin form.mform #fitem_id_showdescription, -body.format-singleactivity.path-mod.pagelayout-admin form.mform .fitem_actionbuttons#fgroup_id_buttonar #id_submitbutton {display:none;} - /* In mod_quiz hide "Back to course" button */ -body.format-singleactivity.path-mod-quiz .quizattempt .continuebutton {display:none;} +.format-singleactivity.path-mod-quiz .quizattempt .continuebutton {display:none;} -body.format-singleactivity .tree_item.orphaned a {color:red;} +.format-singleactivity .tree_item.orphaned a {color:red;} diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index 5b489bfe7d4..b398be469b3 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -55,7 +55,12 @@ abstract class moodleform_mod extends moodleform { */ protected $applyadminlockedflags = false; + /** @var object The course format of the current course. */ + protected $courseformat; + function moodleform_mod($current, $section, $cm, $course) { + global $CFG; + $this->current = $current; $this->_instance = $current->instance; $this->_section = $section; @@ -66,6 +71,10 @@ abstract class moodleform_mod extends moodleform { $this->context = context_course::instance($course->id); } + // Set the course format. + require_once($CFG->dirroot . '/course/format/lib.php'); + $this->courseformat = course_get_format($course); + // Guess module name $matches = array(); if (!preg_match('/^mod_([^_]+)_mod_form$/', get_class($this), $matches)) { @@ -831,9 +840,9 @@ abstract class moodleform_mod extends moodleform { $mform->addRule('introeditor', get_string('required'), 'required', null, 'client'); } - // If the 'show description' feature is enabled, this checkbox appears - // below the intro. - if ($this->_features->showdescription) { + // If the 'show description' feature is enabled, this checkbox appears below the intro. + // We want to hide that when using the singleactivity course format because it is confusing. + if ($this->_features->showdescription && $this->courseformat->has_view_page()) { $mform->addElement('checkbox', 'showdescription', get_string('showdescription')); $mform->addHelpButton('showdescription', 'showdescription'); } @@ -861,7 +870,9 @@ abstract class moodleform_mod extends moodleform { // elements in a row need a group $buttonarray = array(); - if ($submit2label !== false) { + // Label for the submit button to return to the course. + // Ignore this button in single activity format because it is confusing. + if ($submit2label !== false && $this->courseformat->has_view_page()) { $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label); }