From f721ac68d4f30ee96bad7381eec8844dfc450f30 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 20 Jun 2018 15:18:46 +0800 Subject: [PATCH] MDL-41265 resource: Page resource option to show/hide last modified --- mod/page/lang/en/page.php | 2 + mod/page/lib.php | 3 + mod/page/mod_form.php | 32 ++++++---- mod/page/settings.php | 2 + mod/page/tests/behat/page_appearance.feature | 62 ++++++++++++++++++++ mod/page/tests/generator/lib.php | 3 + mod/page/version.php | 2 +- mod/page/view.php | 6 +- 8 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 mod/page/tests/behat/page_appearance.feature diff --git a/mod/page/lang/en/page.php b/mod/page/lang/en/page.php index c105fd7a7c011..7400a71b12c20 100644 --- a/mod/page/lang/en/page.php +++ b/mod/page/lang/en/page.php @@ -64,5 +64,7 @@ $string['printheadingexplain'] = 'Display page name above content?'; $string['printintro'] = 'Display page description'; $string['printintroexplain'] = 'Display page description above content?'; +$string['printlastmodified'] = 'Display last modified date'; +$string['printlastmodifiedexplain'] = 'Display last modified date below content?'; $string['privacy:metadata'] = 'The Page resource plugin does not store any personal data.'; $string['search:activity'] = 'Page'; diff --git a/mod/page/lib.php b/mod/page/lib.php index 67135ad02c007..3b6f59636a0db 100644 --- a/mod/page/lib.php +++ b/mod/page/lib.php @@ -113,6 +113,7 @@ function page_add_instance($data, $mform = null) { } $displayoptions['printheading'] = $data->printheading; $displayoptions['printintro'] = $data->printintro; + $displayoptions['printlastmodified'] = $data->printlastmodified; $data->displayoptions = serialize($displayoptions); if ($mform) { @@ -162,6 +163,7 @@ function page_update_instance($data, $mform) { } $displayoptions['printheading'] = $data->printheading; $displayoptions['printintro'] = $data->printintro; + $displayoptions['printlastmodified'] = $data->printlastmodified; $data->displayoptions = serialize($displayoptions); $data->content = $data->page['text']; @@ -495,6 +497,7 @@ function page_dndupload_handle($uploadinfo) { $data->popupwidth = $config->popupwidth; $data->printheading = $config->printheading; $data->printintro = $config->printintro; + $data->printlastmodified = $config->printlastmodified; return page_add_instance($data, null); } diff --git a/mod/page/mod_form.php b/mod/page/mod_form.php index a411f1aa55553..b8ff4ab05a3a1 100644 --- a/mod/page/mod_form.php +++ b/mod/page/mod_form.php @@ -92,6 +92,8 @@ function definition() { $mform->setDefault('printheading', $config->printheading); $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page')); $mform->setDefault('printintro', $config->printintro); + $mform->addElement('advcheckbox', 'printlastmodified', get_string('printlastmodified', 'page')); + $mform->setDefault('printlastmodified', $config->printlastmodified); // add legacy files flag only if used if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) { @@ -113,26 +115,36 @@ function definition() { $mform->setDefault('revision', 1); } - function data_preprocessing(&$default_values) { + /** + * Enforce defaults here. + * + * @param array $defaultvalues Form defaults + * @return void + **/ + public function data_preprocessing(&$defaultvalues) { if ($this->current->instance) { $draftitemid = file_get_submitted_draft_itemid('page'); - $default_values['page']['format'] = $default_values['contentformat']; - $default_values['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page', 'content', 0, page_get_editor_options($this->context), $default_values['content']); - $default_values['page']['itemid'] = $draftitemid; + $defaultvalues['page']['format'] = $defaultvalues['contentformat']; + $defaultvalues['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page', + 'content', 0, page_get_editor_options($this->context), $defaultvalues['content']); + $defaultvalues['page']['itemid'] = $draftitemid; } - if (!empty($default_values['displayoptions'])) { - $displayoptions = unserialize($default_values['displayoptions']); + if (!empty($defaultvalues['displayoptions'])) { + $displayoptions = unserialize($defaultvalues['displayoptions']); if (isset($displayoptions['printintro'])) { - $default_values['printintro'] = $displayoptions['printintro']; + $defaultvalues['printintro'] = $displayoptions['printintro']; } if (isset($displayoptions['printheading'])) { - $default_values['printheading'] = $displayoptions['printheading']; + $defaultvalues['printheading'] = $displayoptions['printheading']; + } + if (isset($displayoptions['printlastmodified'])) { + $defaultvalues['printlastmodified'] = $displayoptions['printlastmodified']; } if (!empty($displayoptions['popupwidth'])) { - $default_values['popupwidth'] = $displayoptions['popupwidth']; + $defaultvalues['popupwidth'] = $displayoptions['popupwidth']; } if (!empty($displayoptions['popupheight'])) { - $default_values['popupheight'] = $displayoptions['popupheight']; + $defaultvalues['popupheight'] = $displayoptions['popupheight']; } } } diff --git a/mod/page/settings.php b/mod/page/settings.php index 64242048d6ba7..a1c9e0640c896 100644 --- a/mod/page/settings.php +++ b/mod/page/settings.php @@ -43,6 +43,8 @@ get_string('printheading', 'page'), get_string('printheadingexplain', 'page'), 1)); $settings->add(new admin_setting_configcheckbox('page/printintro', get_string('printintro', 'page'), get_string('printintroexplain', 'page'), 0)); + $settings->add(new admin_setting_configcheckbox('page/printlastmodified', + get_string('printlastmodified', 'page'), get_string('printlastmodifiedexplain', 'page'), 1)); $settings->add(new admin_setting_configselect('page/display', get_string('displayselect', 'page'), get_string('displayselectexplain', 'page'), RESOURCELIB_DISPLAY_OPEN, $displayoptions)); $settings->add(new admin_setting_configtext('page/popupwidth', diff --git a/mod/page/tests/behat/page_appearance.feature b/mod/page/tests/behat/page_appearance.feature new file mode 100644 index 0000000000000..efcee45417bdf --- /dev/null +++ b/mod/page/tests/behat/page_appearance.feature @@ -0,0 +1,62 @@ +@mod @mod_page +Feature: Configure page appearance + In order to change the appearance of the page resource + As an admin + I need to configure the page appearance settings + + Background: + Given the following "courses" exist: + | shortname | fullname | + | C1 | Course 1 | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | page | PageName1 | PageDesc1 | C1 | PAGE1 | + And I log in as "admin" + + @javascript + Scenario: Hide and display the page name + Given I am on "Course 1" course homepage + When I follow "PageName1" + Then I should see "PageName1" in the "region-main" "region" + And I navigate to "Edit settings" in current page administration + And I follow "Appearance" + When I click on "Display page name" "checkbox" + And I press "Save and display" + Then I should not see "PageName1" in the "region-main" "region" + And I navigate to "Edit settings" in current page administration + And I follow "Appearance" + When I click on "Display page name" "checkbox" + And I press "Save and display" + Then I should see "PageName1" in the "region-main" "region" + + @javascript + Scenario: Display and hide the page description + Given I am on "Course 1" course homepage + When I follow "PageName1" + Then I should not see "PageDesc1" in the "region-main" "region" + And I navigate to "Edit settings" in current page administration + And I follow "Appearance" + When I click on "Display page description" "checkbox" + And I press "Save and display" + Then I should see "PageDesc1" in the "region-main" "region" + And I navigate to "Edit settings" in current page administration + And I follow "Appearance" + When I click on "Display page description" "checkbox" + And I press "Save and display" + Then I should not see "PageDesc1" in the "region-main" "region" + + @javascript + Scenario: Display and hide the last modified date + Given I am on "Course 1" course homepage + When I follow "PageName1" + Then I should see "Last modified:" in the "region-main" "region" + And I navigate to "Edit settings" in current page administration + And I follow "Appearance" + When I click on "Display last modified date" "checkbox" + And I press "Save and display" + Then I should not see "Last modified:" in the "region-main" "region" + And I navigate to "Edit settings" in current page administration + And I follow "Appearance" + When I click on "Display last modified date" "checkbox" + And I press "Save and display" + Then I should see "Last modified:" in the "region-main" "region" diff --git a/mod/page/tests/generator/lib.php b/mod/page/tests/generator/lib.php index 9ca99ee4b4b7c..2121a9ecce699 100644 --- a/mod/page/tests/generator/lib.php +++ b/mod/page/tests/generator/lib.php @@ -57,6 +57,9 @@ public function create_instance($record = null, array $options = null) { if (!isset($record->printintro)) { $record->printintro = 0; } + if (!isset($record->printlastmodified)) { + $record->printlastmodified = 1; + } return parent::create_instance($record, (array)$options); } diff --git a/mod/page/version.php b/mod/page/version.php index 93ffa6558d0ff..6033a00b0d3db 100644 --- a/mod/page/version.php +++ b/mod/page/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2018051400; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2018051401; // The current module version (Date: YYYYMMDDXX) $plugin->requires = 2018050800; // Requires this Moodle version $plugin->component = 'mod_page'; // Full name of the plugin (used for diagnostics) $plugin->cron = 0; diff --git a/mod/page/view.php b/mod/page/view.php index 149e0b109a1ed..4297a7fb7f061 100644 --- a/mod/page/view.php +++ b/mod/page/view.php @@ -88,7 +88,9 @@ $content = format_text($content, $page->contentformat, $formatoptions); echo $OUTPUT->box($content, "generalbox center clearfix"); -$strlastmodified = get_string("lastmodified"); -echo "
$strlastmodified: ".userdate($page->timemodified)."
"; +if (!isset($options['printlastmodified']) || !empty($options['printlastmodified'])) { + $strlastmodified = get_string("lastmodified"); + echo html_writer::div("$strlastmodified: " . userdate($page->timemodified), 'modified'); +} echo $OUTPUT->footer();