diff --git a/lib.php b/lib.php index 078276c..92b1b72 100644 --- a/lib.php +++ b/lib.php @@ -44,9 +44,9 @@ class format_masonry extends format_topics { * 'sr' (int) used by multipage formats to specify to which section to return * @return null|moodle_url */ - public function get_view_url($section, $options = array()) { + public function get_view_url($section, $options = []) { $course = $this->get_course(); - return new moodle_url('/course/view.php', array('id' => $course->id)); + return new moodle_url('/course/view.php', ['id' => $course->id]); } /** @@ -57,8 +57,7 @@ public function get_view_url($section, $options = array()) { */ public function section_format_options($foreditform = false) { $color = get_config('format_masonry', 'defaultbordercolor'); - return array( - 'backcolor' => array( + return ['backcolor' => [ 'type' => PARAM_RAW, 'name' => 'bordercolor', 'label' => get_string('backgroundcolor', 'format_masonry'), @@ -66,9 +65,7 @@ public function section_format_options($foreditform = false) { 'default' => $color, 'cache' => true, 'help' => 'colordisplay', - 'help_component' => 'format_masonry', - ) - ); + 'help_component' => 'format_masonry']]; } /** @@ -88,89 +85,46 @@ public function course_format_options($foreditform = false) { static $courseformatoptions = false; if ($courseformatoptions === false) { $courseconfig = get_config('moodlecourse'); - $courseformatoptions = array( - 'numsections' => array( - 'default' => $courseconfig->numsections, - 'type' => PARAM_INT, - ), - 'hiddensections' => array( - 'type' => PARAM_INT, - 'default' => 1 - ), - 'coursedisplay' => array( - 'type' => PARAM_INT, - 'default' => 1 - ), - 'borderwidth' => array( - 'type' => PARAM_INT, - 'default' => 1 - ), - 'bordercolor' => array( - 'type' => PARAM_TEXT, - 'default' => '#F0F0F0' - ), - 'backcolor' => array( - 'type' => PARAM_TEXT, - 'default' => '#F0F0F0' - ) - ); + $courseformatoptions = [ + 'numsections' => ['default' => $courseconfig->numsections, 'type' => PARAM_INT], + 'hiddensections' => ['type' => PARAM_INT, 'default' => 1], + 'coursedisplay' => ['type' => PARAM_INT, 'default' => 1], + 'borderwidth' => ['type' => PARAM_INT, 'default' => 1], + 'bordercolor' => ['type' => PARAM_TEXT, 'default' => '#F0F0F0'], + 'backcolor' => ['type' => PARAM_TEXT, 'default' => '#F0F0F0']]; } if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) { $courseconfig = get_config('moodlecourse'); - $max = $courseconfig->maxsections; - if (!isset($max) || !is_numeric($max)) { - $max = 100; - } - $sectionmenu = array(); + $max = (int)$courseconfig->maxsections; + $sectionmenu = []; for ($i = 0; $i <= $max; $i++) { $sectionmenu[$i] = "$i"; } - $courseoptionsedit = array( - 'numsections' => array( + $courseoptionsedit = [ + 'numsections' => [ 'label' => new lang_string('numberweeks'), 'element_type' => 'select', - 'element_attributes' => array($sectionmenu), - ), - 'hiddensections' => array( + 'element_attributes' => [$sectionmenu]], + 'hiddensections' => [ 'label' => 'hidden1', 'element_type' => 'hidden', - 'element_attributes' => array( - array( - // Forced for Masonry course format. - 1 => new lang_string('hiddensectionsinvisible') - ) - ), - ), - 'coursedisplay' => array( + 'element_attributes' => [[1 => new lang_string('hiddensectionsinvisible')]]], + 'coursedisplay' => [ 'label' => 'hidden2', 'element_type' => 'hidden', - 'element_attributes' => array( - array( - COURSE_DISPLAY_SINGLEPAGE => new lang_string('coursedisplay_single') - // Disabled for Masonry course format. - // COURSE_DISPLAY_MULTIPAGE => new lang_string('coursedisplay_multi'). - ) - ), - ), - 'borderwidth' => array( + 'element_attributes' => [[COURSE_DISPLAY_SINGLEPAGE => new lang_string('coursedisplay_single')]]], + 'borderwidth' => [ 'label' => get_string('borderwidth', 'format_masonry'), 'element_type' => 'select', - 'element_attributes' => array( - array(0 => '0', 1 => '1', 2 => '2') - ), - ), - 'bordercolor' => array( + 'element_attributes' => [[0 => '0', 1 => '1', 2 => '2']]], + 'bordercolor' => [ 'label' => get_string('bordercolor', 'format_masonry'), 'element_type' => 'text', - 'element_type' => 'hidden' - ), - 'backcolor' => array( + 'element_type' => 'hidden'], + 'backcolor' => [ 'label' => get_string('bordercolor', 'format_masonry'), 'element_type' => 'masonrycolorpicker', - 'element_attributes' => array(array('value' => $courseformatoptions['bordercolor']['default'])) - ) - - ); + 'element_attributes' => [['value' => $courseformatoptions['bordercolor']['default']]]]]; $courseformatoptions = array_merge_recursive($courseformatoptions, $courseoptionsedit); } return $courseformatoptions; @@ -248,7 +202,7 @@ function format_masonry_inplace_editable($itemtype, $itemid, $newvalue) { if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') { $section = $DB->get_record_sql( 'SELECT s.* FROM {course_sections} s JOIN {course} c ON s.course = c.id WHERE s.id = ? AND c.format = ?', - array($itemid, 'masonry'), MUST_EXIST); + [$itemid, 'masonry'], MUST_EXIST); return course_get_format($section->course)->inplace_editable_update_section_name($section, $itemtype, $newvalue); } } \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..2f1f02d --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + . + + + + + . + + . + version.php + settings.php + format.php + + + + + diff --git a/renderer.php b/renderer.php index bde6b04..ba2e76a 100644 --- a/renderer.php +++ b/renderer.php @@ -72,23 +72,6 @@ protected function page_title() { return get_string('topicoutline'); } - /** - * Generate the content to displayed on the left part of a section - * before course modules are included - * - * @param stdClass $section The course_section entry from DB - * @param stdClass $course The course entry from DB - * @param bool $onsectionpage true if being printed on a section page - * @return string HTML to output. - */ - protected function section_left_content($section, $course, $onsectionpage) { - global $PAGE; - if ($PAGE->user_is_editing()) { - return parent::section_left_content($section, $course, $onsectionpage); - } - return ''; - } - /** * Generate the display of the header part of a section before * course modules are included @@ -107,7 +90,7 @@ protected function section_header($section, $course, $onsectionpage, $sectionret $style .= ' opacity:0.3;filter:alpha(opacity=30);'; } else { // No need for empty first sections. - if ($section->id == 0 && empty($section->sequence)) { + if ($section->section == 0 && empty($section->sequence)) { return ''; } } diff --git a/tests/format_masonry_test.php b/tests/format_masonry_test.php index 9686e49..d884baa 100644 --- a/tests/format_masonry_test.php +++ b/tests/format_masonry_test.php @@ -208,9 +208,8 @@ public function test_renderer() { $this->setAdminUser(); $generator = $this->getDataGenerator(); $course = $generator->create_course(['numsections' => 5, 'format' => 'masonry'], ['createsections' => true]); - $generator->get_plugin_generator('mod_forum')->create_instance(['course' => $course->id]); - $generator->get_plugin_generator('mod_wiki')->create_instance(['course' => $course->id]); - set_section_visible($course->id, 0, 0); + $generator->get_plugin_generator('mod_forum')->create_instance(['course' => $course->id, 'section' => 1]); + $generator->get_plugin_generator('mod_wiki')->create_instance(['course' => $course->id, 'section' => 1]); set_section_visible($course->id, 2, 0); $page = new moodle_page(); $page->set_context(context_course::instance($course->id)); @@ -244,6 +243,7 @@ public function test_renderer() { $PAGE->set_pagetype('course-view'); $PAGE->set_url('/course/view.php?id=' . $course->id); $PAGE->requires->js('/course/format/topics/format.js'); + $renderer = $PAGE->get_renderer('format_topics'); ob_start(); $renderer->print_single_section_page($course, null, null, null, null, 0); @@ -255,6 +255,16 @@ public function test_renderer() { $this->assertContains('Topic 1', $out2); $course->marker = 2; course_set_marker($course->id, 2); + + $renderer = $PAGE->get_renderer('format_masonry'); + ob_start(); + $renderer->print_single_section_page($course, null, null, null, null, 0); + $out3 = ob_get_contents(); + $renderer->print_multiple_section_page($course, null, null, null, null, null); + $out4 = ob_get_contents(); + ob_end_clean(); + $this->assertContains(' Add an activity', $out3); + $this->assertContains('Topic 1', $out4); } /** @@ -282,7 +292,7 @@ public function test_privacy() { } /** - * Test ohter. + * Test other. */ public function test_other() { $this->resetAfterTest(true);