diff --git a/mod/choice/renderer.php b/mod/choice/renderer.php index 5e2c3cd312a..82a1f4a9920 100644 --- a/mod/choice/renderer.php +++ b/mod/choice/renderer.php @@ -73,6 +73,7 @@ class mod_choice_renderer extends plugin_renderer_base { $html .= html_writer::end_tag('ul'); $html .= html_writer::tag('div', '', array('class'=>'clearfloat')); $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey())); + $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'makechoice')); $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$coursemoduleid)); if (!empty($options['hascapability']) && ($options['hascapability'])) { diff --git a/mod/choice/tests/behat/block_editing.feature b/mod/choice/tests/behat/block_editing.feature new file mode 100644 index 00000000000..e4adf70dfd9 --- /dev/null +++ b/mod/choice/tests/behat/block_editing.feature @@ -0,0 +1,108 @@ +@mod @mod_choice +Feature: Add choice activity + In order to customise choice page + As a teacher or admin + I need to add remove block from the choice page + +# This tests that the hacky block editing is not borked by legacy forms in choice activity. + + @javascript + Scenario: Add a choice activity and complete the activity as a student + Given the following "users" exist: + | username | firstname | lastname | email | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And I log in as "admin" + And I follow "Course 1" + And I turn editing mode on + And I add a "Choice" to section "1" and I fill the form with: + | Choice name | Choice name 1 | + | Description | Choice Description 1 | + | option[0] | Option 1 | + | option[1] | Option 2 | + And I follow "Choice name 1" + + When I add the "Blog menu" block + Then I should see "View all entries about this Choice" + + When I configure the "Blog menu" block + And I press "Save changes" + Then I should see "View all entries about this Choice" + + When I open the "Blog menu" blocks action menu + And I click on "Delete" "link" in the "Blog menu" "block" + And I press "Yes" + Then I should not see "View all entries about this Choice" + And I should see "Choice Description 1" + + @javascript + Scenario: Add a choice activity and complete the activity as a student + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + | student1 | Student | 1 | student1@asd.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Choice" to section "1" and I fill the form with: + | Choice name | Choice name 1 | + | Description | Choice Description 1 | + | option[0] | Option 1 | + | option[1] | Option 2 | + And I follow "Choice name 1" + + When I add the "Blog menu" block + Then I should see "View all entries about this Choice" + + When I configure the "Blog menu" block + And I press "Save changes" + Then I should see "View all entries about this Choice" + + When I open the "Blog menu" blocks action menu + And I click on "Delete" "link" in the "Blog menu" "block" + And I press "Yes" + Then I should not see "View all entries about this Choice" + And I should see "Choice Description 1" + + @javascript + Scenario: Add a choice activity and complete the activity as a student + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | teacher1 | C1 | student | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Choice" to section "1" and I fill the form with: + | Choice name | Choice name 1 | + | Description | Choice Description 1 | + | option[0] | Option 1 | + | option[1] | Option 2 | + And I follow "Choice name 1" + + When I add the "Blog menu" block + Then I should see "View all entries about this Choice" + + When I configure the "Blog menu" block + And I press "Save changes" + Then I should see "View all entries about this Choice" + + When I open the "Blog menu" blocks action menu + And I click on "Delete" "link" in the "Blog menu" "block" + And I press "Yes" + Then I should not see "View all entries about this Choice" + And I should see "Choice Description 1" diff --git a/mod/choice/upgrade.txt b/mod/choice/upgrade.txt new file mode 100644 index 00000000000..4abd3daf60a --- /dev/null +++ b/mod/choice/upgrade.txt @@ -0,0 +1,6 @@ +This files describes API changes in /mod/choice/*, +information provided here is intended especially for developers. + +=== 2.9 === + +* custom renderers must be updated to include action=makechoice field in display_options() diff --git a/mod/choice/view.php b/mod/choice/view.php index 176872d8cad..c9900e5037a 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -7,6 +7,7 @@ require_once($CFG->libdir . '/completionlib.php'); $id = required_param('id', PARAM_INT); // Course Module ID $action = optional_param('action', '', PARAM_ALPHA); $attemptids = optional_param_array('attemptid', array(), PARAM_INT); // array of attempt ids for delete action +$notify = optional_param('notify', '', PARAM_ALPHA); $url = new moodle_url('/mod/choice/view.php', array('id'=>$id)); if ($action !== '') { @@ -43,6 +44,7 @@ if ($action == 'delchoice' and confirm_sesskey() and is_enrolled($context, NULL, if ($completion->is_enabled($cm) && $choice->completionsubmit) { $completion->update_state($cm, COMPLETION_INCOMPLETE); } + redirect("view.php?id=$cm->id"); } } @@ -62,25 +64,35 @@ if (data_submitted() && is_enrolled($context, NULL, 'mod/choice:choose') && conf redirect("view.php?id=$cm->id"); } + // Redirection after all POSTs breaks block editing, we need to be more specific! if ($choice->allowmultiple) { $answer = optional_param_array('answer', array(), PARAM_INT); } else { $answer = optional_param('answer', '', PARAM_INT); } - if (empty($answer)) { - redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice')); - } else { + if ($answer) { choice_user_submit_response($answer, $choice, $USER->id, $course, $cm); + redirect(new moodle_url('/mod/choice/view.php', + array('id' => $cm->id, 'notify' => 'choicesaved', 'sesskey' => sesskey()))); + } else if (empty($answer) and $action === 'makechoice') { + // We cannot use the 'makechoice' alone because there might be some legacy renderers without it, + // outdated renderers will not get the 'mustchoose' message - bad luck. + redirect(new moodle_url('/mod/choice/view.php', + array('id' => $cm->id, 'notify' => 'mustchooseone', 'sesskey' => sesskey()))); } - echo $OUTPUT->header(); - echo $OUTPUT->heading(format_string($choice->name), 2, null); - echo $OUTPUT->notification(get_string('choicesaved', 'choice'),'notifysuccess'); -} else { - echo $OUTPUT->header(); - echo $OUTPUT->heading(format_string($choice->name), 2, null); } +echo $OUTPUT->header(); +echo $OUTPUT->heading(format_string($choice->name), 2, null); + +if ($notify and confirm_sesskey()) { + if ($notify === 'choicesaved') { + echo $OUTPUT->notification(get_string('choicesaved', 'choice'), 'notifysuccess'); + } else if ($notify === 'mustchooseone') { + echo $OUTPUT->notification(get_string('mustchooseone', 'choice'), 'notifyproblem'); + } +} /// Display the choice and possibly results $eventdata = array();