Skip to content

Commit

Permalink
MDL-41611 format_singleactivity: Only hide unnecessary elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Oct 4, 2013
1 parent 640ef17 commit d9203fb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
18 changes: 18 additions & 0 deletions course/format/lib.php
Expand Up @@ -250,6 +250,24 @@ public function get_course() {
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
*
Expand Down
10 changes: 10 additions & 0 deletions course/format/singleactivity/lib.php
Expand Up @@ -457,4 +457,14 @@ public function page_set_cm(moodle_page $page) {
$activitynode->remove();
}
}

/**
* Returns true if the course has a front page.
*
* @return boolean false
*/
public function has_view_page() {
return false;
}

}
10 changes: 2 additions & 8 deletions 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;}
19 changes: 15 additions & 4 deletions course/moodleform_mod.php
Expand Up @@ -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;
Expand All @@ -66,6 +71,10 @@ function moodleform_mod($current, $section, $cm, $course) {
$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)) {
Expand Down Expand Up @@ -831,9 +840,9 @@ function add_intro_editor($required=false, $customlabel=null) {
$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');
}
Expand Down Expand Up @@ -861,7 +870,9 @@ function add_action_buttons($cancel=true, $submitlabel=null, $submit2label=null)
// 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);
}

Expand Down

0 comments on commit d9203fb

Please sign in to comment.