Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lang/en/checklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@

$string['showcompletemymoodle'] = 'Show completed Checklists on \'My Moodle\' page';
$string['showfulldetails'] = 'Show full details';
$string['showhidechecked'] = 'Show/hide selected items';
$string['showupdateablemymoodle'] = 'Show only updatable Checklists on \'My Moodle\' page';
$string['showmymoodle'] = 'Show Checklists on \'My Moodle\' page';
$string['showprogressbars'] = 'Show progress bars';
Expand Down
74 changes: 48 additions & 26 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,9 @@ protected function view_edit_items() {
if ($this->editdates) {
$thispage->param('editdates', 'on');
}
if ($itemid = optional_param('itemid', null, PARAM_INT)) {
$thispage->param('itemid', $itemid);
}

if ($this->checklist->autoupdate && $this->checklist->autopopulate) {
if ($this->checklist->teacheredit == CHECKLIST_MARKING_STUDENT) {
Expand All @@ -1436,6 +1439,17 @@ protected function view_edit_items() {
if ($this->items) {
$lastitem = count($this->items);
$lastindent = 0;

echo html_writer::start_tag('form', array('action' => $thispage->out_omit_querystring(), 'method' => 'post'));
echo html_writer::input_hidden_params($thispage);

if ($this->checklist->autopopulate) {
echo html_writer::empty_tag('input', array(
'type' => 'submit', 'name' => 'showhideitems',
'value' => get_string('showhidechecked', 'checklist')
));
}

foreach ($this->items as $item) {

while ($item->indent > $currindent) {
Expand Down Expand Up @@ -1481,6 +1495,14 @@ protected function view_edit_items() {
$hasauto = $hasauto || ($item->moduleid != 0);

echo '<li>';

echo html_writer::start_span('', array('style' => 'display: inline-block; width: 16px;'));
if ($autoitem && $item->hidden != CHECKLIST_HIDDEN_BYMODULE) {
echo html_writer::checkbox('items[' . $item->id . ']', $item->id, false, '',
array('title' => $item->displaytext));
}
echo html_writer::end_span();

if ($item->itemoptional == CHECKLIST_OPTIONAL_YES) {
$title = '"'.get_string('optionalitem', 'checklist').'"';
echo '<a href="'.$thispage->out(true, array('action' => 'makeheading')).'">';
Expand Down Expand Up @@ -1515,23 +1537,16 @@ protected function view_edit_items() {
}

if (isset($item->editme)) {
echo '<form style="display:inline" action="'.$thispage->out_omit_querystring().'" method="post">';
echo '<input type="text" size="'.CHECKLIST_TEXT_INPUT_WIDTH.'" name="displaytext" value="'.
s($item->displaytext).'" id="updateitembox" />';
echo '<input type="hidden" name="action" value="updateitem" />';
echo html_writer::input_hidden_params($thispage);
if ($this->editdates) {
$this->print_edit_date($item->duetime);
}
echo '<input type="submit" name="updateitem" value="'.get_string('updateitem', 'checklist').'" />';
echo '</form>';

$focusitem = 'updateitembox';

echo '<form style="display:inline" action="'.$thispage->out_omit_querystring().'" method="get">';
echo html_writer::input_hidden_params($thispage, array('sesskey', 'itemid'));
echo '<input type="submit" name="canceledititem" value="'.get_string('canceledititem', 'checklist').'" />';
echo '</form>';

$addatend = false;

Expand Down Expand Up @@ -1611,9 +1626,6 @@ protected function view_edit_items() {
if ($this->additemafter == $item->id) {
$addatend = false;
echo '<li>';
echo '<form style="display:inline;" action="'.$thispage->out_omit_querystring().'" method="post">';
echo html_writer::input_hidden_params($thispage);
echo '<input type="hidden" name="action" value="additem" />';
echo '<input type="hidden" name="position" value="'.($item->position + 1).'" />';
echo '<input type="hidden" name="indent" value="'.$item->indent.'" />';
echo '<img src="'.$OUTPUT->pix_url('tick_box', 'checklist').'" /> ';
Expand All @@ -1622,12 +1634,7 @@ protected function view_edit_items() {
$this->print_edit_date();
}
echo '<input type="submit" name="additem" value="'.get_string('additem', 'checklist').'" />';
echo '</form>';

echo '<form style="display:inline" action="'.$thispage->out_omit_querystring().'" method="get">';
echo html_writer::input_hidden_params($thispage, array('sesskey', 'additemafter'));
echo '<input type="submit" name="canceledititem" value="'.get_string('canceledititem', 'checklist').'" />';
echo '</form>';
echo '</li>';

if (!$focusitem) {
Expand All @@ -1639,6 +1646,8 @@ protected function view_edit_items() {

echo '</li>';
}

echo html_writer::end_tag('form');
}

$thispage->remove_params(array('itemid'));
Expand Down Expand Up @@ -2189,9 +2198,7 @@ protected function process_view_actions() {
return;
}

if (!confirm_sesskey()) {
error('Invalid sesskey');
}
require_sesskey();

$itemid = optional_param('itemid', 0, PARAM_INT);

Expand Down Expand Up @@ -2237,7 +2244,7 @@ protected function process_view_actions() {
break;

default:
error('Invalid action - "'.s($action).'"');
throw new moodle_exception('invalidaction', 'mod_checklist', '', $action);
}

if ($action != 'updatechecks') {
Expand All @@ -2254,22 +2261,29 @@ protected function process_edit_actions() {
if ($removeauto) {
// Remove any automatically generated items from the list
// (if no longer using automatic items).
if (!confirm_sesskey()) {
error('Invalid sesskey');
}
require_sesskey();
$this->removeauto();
return;
}

$action = optional_param('action', false, PARAM_TEXT);
if (!$action) {
if (optional_param('additem', false, PARAM_BOOL)) {
$action = 'additem';
} else if (optional_param('updateitem', false, PARAM_BOOL)) {
$action = 'updateitem';
} else if (optional_param('showhideitems', false, PARAM_BOOL)) {
$action = 'showhideitems';
} else if (optional_param('canceledititem', false, PARAM_BOOL)) {
$additemafter = false;
}
}
if (!$action) {
$this->additemafter = $additemafter;
return;
}

if (!confirm_sesskey()) {
error('Invalid sesskey');
}
require_sesskey();

$itemid = optional_param('itemid', 0, PARAM_INT);

Expand Down Expand Up @@ -2344,8 +2358,16 @@ protected function process_edit_actions() {
case 'nextcolour':
$this->nextcolour($itemid);
break;

case 'showhideitems':
$itemids = optional_param_array('items', array(), PARAM_INT);
foreach ($itemids as $itemid) {
$this->toggledisableitem($itemid);
}
break;

default:
error('Invalid action - "'.s($action).'"');
throw new moodle_exception('invalidaction', 'mod_checklist', '', $action);
}

if ($additemafter) {
Expand Down
56 changes: 56 additions & 0 deletions tests/behat/show_hide_multiple_items.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@mod @mod_checklist @checklist
Feature: Multiple autopopulate items can be shown/hidden at once

Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@asd.com |
| student1 | Student | 1 | student1@asd.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | section | idnumber | name | intro |
| assign | C1 | 1 | assign1 | Test assignment | This is an assignment |
| data | C1 | 1 | data1 | Test database | This is a database |
| checklist | C1 | 1 | checklist1 | Test checklist | This is a checklist |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Checklist" to section "1" and I fill the form with:
| Checklist | Test auto-pop checklist |
| Introduction | This is an auto-populated checklist |
| Show course modules in checklist | Whole course |
And I log out

Scenario: When viewing an auto-populated checklist, a student should see items corresponding to the course modules
When I log in as "student1"
And I follow "Course 1"
And I follow "Test auto-pop checklist"
Then I should see "Test auto-pop checklist"
And I should see "This is an auto-populated checklist"
And I should see "Test assignment"
And I should see "Test database"

Scenario: When I select multiple items and click the 'Show/hide' button, the items' visibility should toggle
Given I log in as "teacher1"
And I follow "Course 1"
And I follow "Test auto-pop checklist"
And I follow "Edit checklist"
And I set the field with xpath "//input[@type='checkbox' and @title='Test assignment']" to "1"
And I set the field with xpath "//input[@type='checkbox' and @title='Test database']" to "1"
And I press "Show/hide selected items"
And I set the field with xpath "//input[@type='checkbox' and @title='Test database']" to "1"
And I set the field with xpath "//input[@type='checkbox' and @title='Test checklist']" to "1"
And I press "Show/hide selected items"
And I log out
When I log in as "student1"
And I follow "Course 1"
And I follow "Test auto-pop checklist"
Then I should not see "Test assignment" in the "#region-main" "css_element"
And I should see "Test database" in the "#region-main" "css_element"
And I should not see "Test checklist" in the "#region-main" "css_element"
2 changes: 2 additions & 0 deletions tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/

defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/mod/checklist/lib.php');

class mod_checklist_generator extends testing_module_generator {
public function create_instance($record = null, array $options = null) {
Expand Down
6 changes: 3 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
$plugin = new stdClass();
}
// Used by M2.6 and above.
$plugin->version = 2015122300; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2016031400; // The current module version (Date: YYYYMMDDXX)
$plugin->cron = 60; // Period for cron to check this module (secs).
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '2.x (Build: 2015122300)';
$plugin->release = '2.x (Build: 2016031400)';
$plugin->requires = 2010112400;
$plugin->component = 'mod_checklist';

Expand All @@ -45,4 +45,4 @@
$module->release = $plugin->release;
$module->requires = $plugin->requires;
$module->component = $plugin->component;
}
}