Skip to content

Commit

Permalink
MDL-41265 resource: Page resource option to show/hide last modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Geshoski committed Jun 25, 2018
1 parent 6153be6 commit f721ac6
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 13 deletions.
2 changes: 2 additions & 0 deletions mod/page/lang/en/page.php
Expand Up @@ -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';
3 changes: 3 additions & 0 deletions mod/page/lib.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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);
}
Expand Down
32 changes: 22 additions & 10 deletions mod/page/mod_form.php
Expand Up @@ -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) {
Expand All @@ -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'];
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions mod/page/settings.php
Expand Up @@ -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',
Expand Down
62 changes: 62 additions & 0 deletions 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"
3 changes: 3 additions & 0 deletions mod/page/tests/generator/lib.php
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion mod/page/version.php
Expand Up @@ -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;
6 changes: 4 additions & 2 deletions mod/page/view.php
Expand Up @@ -88,7 +88,9 @@
$content = format_text($content, $page->contentformat, $formatoptions);
echo $OUTPUT->box($content, "generalbox center clearfix");

$strlastmodified = get_string("lastmodified");
echo "<div class=\"modified\">$strlastmodified: ".userdate($page->timemodified)."</div>";
if (!isset($options['printlastmodified']) || !empty($options['printlastmodified'])) {
$strlastmodified = get_string("lastmodified");
echo html_writer::div("$strlastmodified: " . userdate($page->timemodified), 'modified');
}

echo $OUTPUT->footer();

0 comments on commit f721ac6

Please sign in to comment.