Skip to content

Commit

Permalink
section left content removal
Browse files Browse the repository at this point in the history
  • Loading branch information
ewallah committed Oct 12, 2018
1 parent f18a97c commit 9e1d9db
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 95 deletions.
100 changes: 27 additions & 73 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand All @@ -57,18 +57,15 @@ 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'),
'element_type' => 'masonrycolorpicker',
'default' => $color,
'cache' => true,
'help' => 'colordisplay',
'help_component' => 'format_masonry',
)
);
'help_component' => 'format_masonry']];
}

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
48 changes: 48 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/phpunit/phpunit.xsd"
bootstrap="../../../lib/phpunit/bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
backupGlobals="false"
backupStaticAttributes="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
beStrictAboutTestsThatDoNotTestAnything="false"
printerClass="Hint_ResultPrinter"
testSuiteLoaderClass="phpunit_autoloader"
>

<php>
<!--<const name="PHPUNIT_LONGTEST" value="1"/> uncomment to execute also slow or otherwise expensive tests-->
<const name="PHPUNIT_SEQUENCE_START" value="160000"/>

<!--Following constants instruct tests to fetch external test files from alternative location or skip tests if empty, clone https://github.com/moodlehq/moodle-exttests to local web server-->
<!--<const name="TEST_EXTERNAL_FILES_HTTP_URL" value="http://download.moodle.org/unittest"/> uncomment and alter to fetch external test files from alternative location-->
<!--<const name="TEST_EXTERNAL_FILES_HTTPS_URL" value="https://download.moodle.org/unittest"/> uncomment and alter to fetch external test files from alternative location-->
</php>


<testsuites>
<testsuite name="format_masonry_testsuite">
<directory suffix="_test.php">.</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">.</directory>
<exclude>
<directory suffix="_test.php">.</directory>
<file>version.php</file>
<file>settings.php</file>
<file>format.php</file>
</exclude>
</whitelist>
</filter>

</phpunit>
19 changes: 1 addition & 18 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 '';
}
}
Expand Down
18 changes: 14 additions & 4 deletions tests/format_masonry_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -282,7 +292,7 @@ public function test_privacy() {
}

/**
* Test ohter.
* Test other.
*/
public function test_other() {
$this->resetAfterTest(true);
Expand Down

0 comments on commit 9e1d9db

Please sign in to comment.