diff --git a/blocks/navigation/tests/behat/expand_courses_node.feature b/blocks/navigation/tests/behat/expand_courses_node.feature index 2fd28caf442..9ebf78e2965 100644 --- a/blocks/navigation/tests/behat/expand_courses_node.feature +++ b/blocks/navigation/tests/behat/expand_courses_node.feature @@ -40,7 +40,7 @@ Feature: Expand the courses nodes within the navigation block And I click on "Edit settings" "link" in the "Administration" "block" And I set the following fields to these values: | Allow guest access | Yes | - And I press "Save changes" + And I press "Save and return" And I set the following administration settings values: | Show all courses | 1 | And I log out diff --git a/course/classes/management/helper.php b/course/classes/management/helper.php index f13757b7d67..b553923a969 100644 --- a/course/classes/management/helper.php +++ b/course/classes/management/helper.php @@ -315,7 +315,7 @@ class helper { // Edit. if ($course->can_edit()) { $actions[] = array( - 'url' => new \moodle_url('/course/edit.php', array('id' => $course->id)), + 'url' => new \moodle_url('/course/edit.php', array('id' => $course->id, 'returnto' => 'catmanage')), 'icon' => new \pix_icon('t/edit', \get_string('edit')), 'attributes' => array('class' => 'action-edit') ); diff --git a/course/edit.php b/course/edit.php index f21ca884276..2b4c30d5e82 100644 --- a/course/edit.php +++ b/course/edit.php @@ -29,6 +29,38 @@ require_once('edit_form.php'); $id = optional_param('id', 0, PARAM_INT); // Course id. $categoryid = optional_param('category', 0, PARAM_INT); // Course category - can be changed in edit form. $returnto = optional_param('returnto', 0, PARAM_ALPHANUM); // Generic navigation return page switch. +$returnurl = optional_param('returnurl', '', PARAM_LOCALURL); // A return URL. returnto must also be set to 'url'. + +if ($returnto === 'url' && confirm_sesskey() && $returnurl) { + // If returnto is 'url' then $returnurl may be used as the destination to return to after saving or cancelling. + // Sesskey must be specified, and would be set by the form anyway. + $returnurl = new moodle_url($returnurl); +} else { + switch ($returnto) { + case 'category': + $returnurl = new moodle_url($CFG->wwwroot.'/course/index.php', array('categoryid' => $categoryid)); + break; + case 'catmanage': + $returnurl = new moodle_url($CFG->wwwroot.'/course/management.php', array('categoryid' => $categoryid)); + break; + case 'topcatmanage': + $returnurl = new moodle_url($CFG->wwwroot.'/course/management.php'); + break; + case 'topcat': + $returnurl = new moodle_url($CFG->wwwroot.'/course/'); + break; + case 'url': + // You may be wondering about this, but the url case should be dealt with above. + // If we get here than either sesskey was not given or returnurl was not provided. + default: + if (!empty($course->id)) { + $returnurl = new moodle_url($CFG->wwwroot.'/course/view.php', array('id' => $course->id)); + } else { + $returnurl = new moodle_url($CFG->wwwroot.'/course/'); + } + break; + } +} $PAGE->set_pagelayout('admin'); if ($id) { @@ -36,6 +68,12 @@ if ($id) { } else { $pageparams = array('category' => $categoryid); } +if ($returnto !== 0) { + $pageparams['returnto'] = $returnto; + if ($returnto === 'url' && $returnurl) { + $pageparams['returnurl'] = $returnurl; + } +} $PAGE->set_url('/course/edit.php', $pageparams); // Basic access control checks. @@ -98,31 +136,17 @@ if (!empty($course)) { } // First create the form. -$editform = new course_edit_form(NULL, array('course'=>$course, 'category'=>$category, 'editoroptions'=>$editoroptions, 'returnto'=>$returnto)); +$args = array( + 'course' => $course, + 'category' => $category, + 'editoroptions' => $editoroptions, + 'returnto' => $returnto, + 'returnurl' => $returnurl +); +$editform = new course_edit_form(null, $args); if ($editform->is_cancelled()) { - switch ($returnto) { - case 'category': - $url = new moodle_url($CFG->wwwroot.'/course/index.php', array('categoryid' => $categoryid)); - break; - case 'catmanage': - $url = new moodle_url($CFG->wwwroot.'/course/management.php', array('categoryid' => $categoryid)); - break; - case 'topcatmanage': - $url = new moodle_url($CFG->wwwroot.'/course/management.php'); - break; - case 'topcat': - $url = new moodle_url($CFG->wwwroot.'/course/'); - break; - default: - if (!empty($course->id)) { - $url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id)); - } else { - $url = new moodle_url($CFG->wwwroot.'/course/'); - } - break; - } - redirect($url); - + // The form has been cancelled, take them back to what ever the return to is. + redirect($returnurl); } else if ($data = $editform->get_data()) { // Process data if submitted. if (empty($course->id)) { @@ -136,14 +160,20 @@ if ($editform->is_cancelled()) { // Deal with course creators - enrol them internally with default role. enrol_try_internal_enrol($course->id, $USER->id, $CFG->creatornewroleid); } - if (!is_enrolled($context)) { + + // The URL to take them to if they chose save and display. + $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); + + // If they choose to save and display, and they are not enrolled take them to the enrolments page instead. + if (!is_enrolled($context) && isset($data->saveanddisplay)) { // Redirect to manual enrolment page if possible. $instances = enrol_get_instances($course->id, true); foreach($instances as $instance) { if ($plugin = enrol_get_plugin($instance->enrol)) { if ($plugin->get_manual_enrol_link($instance)) { // We know that the ajax enrol UI will have an option to enrol. - redirect(new moodle_url('/enrol/users.php', array('id'=>$course->id))); + $courseurl = new moodle_url('/enrol/users.php', array('id' => $course->id)); + break; } } } @@ -151,10 +181,17 @@ if ($editform->is_cancelled()) { } else { // Save any changes to the files used in the editor. update_course($data, $editoroptions); + // Set the URL to take them too if they choose save and display. + $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); } - // Redirect user to newly created/updated course. - redirect(new moodle_url('/course/view.php', array('id' => $course->id))); + if (isset($data->saveanddisplay)) { + // Redirect user to newly created/updated course. + redirect($courseurl); + } else { + // Save and return. Take them back to wherever. + redirect($returnurl); + } } // Print the form. diff --git a/course/edit_form.php b/course/edit_form.php index 1de01c93539..54359aac772 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -27,6 +27,7 @@ class course_edit_form extends moodleform { $category = $this->_customdata['category']; $editoroptions = $this->_customdata['editoroptions']; $returnto = $this->_customdata['returnto']; + $returnurl = $this->_customdata['returnurl']; $systemcontext = context_system::instance(); $categorycontext = context_coursecat::instance($category->id); @@ -51,6 +52,10 @@ class course_edit_form extends moodleform { $mform->setType('returnto', PARAM_ALPHANUM); $mform->setConstant('returnto', $returnto); + $mform->addElement('hidden', 'returnurl', null); + $mform->setType('returnurl', PARAM_LOCALURL); + $mform->setConstant('returnurl', $returnurl); + $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); @@ -296,7 +301,15 @@ class course_edit_form extends moodleform { } } - $this->add_action_buttons(); + // When two elements we need a group. + $buttonarray = array(); + if ($returnto !== 0) { + $buttonarray[] = &$mform->createElement('submit', 'saveandreturn', get_string('savechangesandreturn')); + } + $buttonarray[] = &$mform->createElement('submit', 'saveanddisplay', get_string('savechangesanddisplay')); + $buttonarray[] = &$mform->createElement('cancel'); + $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->closeHeaderBefore('buttonar'); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); diff --git a/course/tests/behat/activities_group_icons.feature b/course/tests/behat/activities_group_icons.feature index 35dbee9162b..3380e36f180 100644 --- a/course/tests/behat/activities_group_icons.feature +++ b/course/tests/behat/activities_group_icons.feature @@ -25,7 +25,7 @@ Feature: Toggle activities groups mode from the course page And I set the following fields to these values: | Group mode | No groups | | Force group mode | No | - When I press "Save changes" + When I press "Save and display" Then "No groups (Click to change)" "link" should exist And "//a/child::img[contains(@src, 'groupn')]" "xpath_element" should exist And I click on "No groups (Click to change)" "link" in the "Test forum name" activity diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index aaacef472a7..a2d102cf458 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -108,7 +108,7 @@ class behat_course extends behat_base { $steps[] = new Given('I set the following fields to these values:', $table); } - $steps[] = new Given('I press "' . get_string('savechanges') . '"'); + $steps[] = new Given('I press "' . get_string('savechangesanddisplay') . '"'); return $steps; } diff --git a/course/tests/behat/course_creation.feature b/course/tests/behat/course_creation.feature index 668a50dd528..27a334ac736 100644 --- a/course/tests/behat/course_creation.feature +++ b/course/tests/behat/course_creation.feature @@ -29,3 +29,21 @@ Feature: Managers can create courses And I follow "News forum" And "Add a new topic" "button" should not exist And I should see "Forced subscription" in the "Administration" "block" + + Scenario: Create a course from the management interface and return to it + Given the following "courses" exist: + | fullname | shortname | idnumber | + | Course 1 | Course 1 | C1 | + And I log in as "admin" + And I go to the courses management page + And I should see the "Categories" management page + And I click on category "Miscellaneous" in the management interface + And I should see the "Course categories and courses" management page + And I click on "Create new course" "link" in the "#course-listing" "css_element" + When I set the following fields to these values: + | Course full name | Course 2 | + | Course short name | Course 2 | + | Course summary | Course 2 summary | + And I press "Save and return" + Then I should see the "Course categories and courses" management page + And I should see course listing "Course 1" before "Course 2" diff --git a/course/tests/behat/create_delete_course.feature b/course/tests/behat/create_delete_course.feature index 2cff137f052..1c74098666b 100644 --- a/course/tests/behat/create_delete_course.feature +++ b/course/tests/behat/create_delete_course.feature @@ -23,9 +23,8 @@ Feature: Test we can both create and delete a course. | Course short name | TCCAC | | Course ID number | TC3401 | | Course summary | This course has been created by automated tests. | - And I press "Save changes" + And I press "Save and return" # Redirect - And I go to the courses management page And I should see the "Course categories and courses" management page And I click on category "Cat 1" in the management interface # Redirect diff --git a/course/tests/behat/edit_settings.feature b/course/tests/behat/edit_settings.feature index 11e0f09ff1a..30b9b6a97f9 100644 --- a/course/tests/behat/edit_settings.feature +++ b/course/tests/behat/edit_settings.feature @@ -22,7 +22,7 @@ Feature: Edit course settings | Course full name | Edited course fullname | | Course short name | Edited course shortname | | Course summary | Edited course summary | - And I press "Save changes" + And I press "Save and display" And I follow "Edited course fullname" Then I should not see "Course 1" And I should not see "C1" @@ -34,3 +34,23 @@ Feature: Edit course settings And the field "Course summary" matches value "Edited course summary" And I am on homepage And I should see "Edited course fullname" + + Scenario: Edit course settings and return to the management interface + Given the following "categories" exist: + | name | category | idnumber | + | Cat 1 | 0 | CAT1 | + And the following "courses" exist: + | category | fullname | shortname | idnumber | + | CAT1 | Course 1 | Course 1 | C1 | + And I log in as "admin" + And I go to the courses management page + And I should see the "Categories" management page + And I click on category "Cat 1" in the management interface + And I should see the "Course categories and courses" management page + When I click on "edit" action for "Course 1" in management course listing + And I set the following fields to these values: + | Course full name | Edited course fullname | + | Course short name | Edited course shortname | + | Course summary | Edited course summary | + And I press "Save and return" + Then I should see the "Course categories and courses" management page \ No newline at end of file diff --git a/course/tests/behat/force_group_mode.feature b/course/tests/behat/force_group_mode.feature index 73fe95e0bdd..41975e0cd16 100644 --- a/course/tests/behat/force_group_mode.feature +++ b/course/tests/behat/force_group_mode.feature @@ -27,7 +27,7 @@ Feature: Force group mode in a course Given I set the following fields to these values: | Group mode | Separate groups | | Force group mode | Yes | - When I press "Save changes" + When I press "Save and display" Then "//a/child::img[contains(@alt, 'Separate groups (forced mode)')]" "xpath_element" should not exist And "//img[contains(@alt, 'Separate groups (forced mode)')]" "xpath_element" should not exist @@ -36,7 +36,7 @@ Feature: Force group mode in a course Given I set the following fields to these values: | Group mode | Visible groups | | Force group mode | Yes | - And I press "Save changes" + And I press "Save and display" Then "//a/child::img[contains(@alt, 'Visible groups (forced mode)')]" "xpath_element" should not exist And "//img[contains(@alt, 'Visible groups (forced mode)')]" "xpath_element" should not exist @@ -45,7 +45,7 @@ Feature: Force group mode in a course Given I set the following fields to these values: | Group mode | No groups | | Force group mode | Yes | - And I press "Save changes" + And I press "Save and display" Then "//a/child::img[contains(@alt, 'No groups (forced mode)')]" "xpath_element" should not exist And "//img[contains(@alt, 'No groups (forced mode)')]" "xpath_element" should not exist diff --git a/course/tests/behat/move_activities.feature b/course/tests/behat/move_activities.feature index 68abd0f0e40..f2cde5bf991 100644 --- a/course/tests/behat/move_activities.feature +++ b/course/tests/behat/move_activities.feature @@ -36,7 +36,7 @@ Feature: Activities can be moved between sections Given I click on "Edit settings" "link" in the "Administration" "block" And I set the following fields to these values: | Course layout | Show one section per page | - And I press "Save changes" + And I press "Save and display" When I move "Test forum name" activity to section "2" Then I should see "Test forum name" in the "#section-2" "css_element" And I should not see "Test forum name" in the "#section-1" "css_element" @@ -45,7 +45,7 @@ Feature: Activities can be moved between sections Given I click on "Edit settings" "link" in the "Administration" "block" And I set the following fields to these values: | Course layout | Show one section per page | - And I press "Save changes" + And I press "Save and display" And I add a "Forum" to section "1" and I fill the form with: | Forum name | Second forum name | | Description | Second forum description | diff --git a/course/tests/behat/move_sections.feature b/course/tests/behat/move_sections.feature index b56a0b98352..a4772feefb7 100644 --- a/course/tests/behat/move_sections.feature +++ b/course/tests/behat/move_sections.feature @@ -31,7 +31,7 @@ Feature: Sections can be moved Given I click on "Edit settings" "link" in the "Administration" "block" And I set the following fields to these values: | Course layout | Show one section per page | - And I press "Save changes" + And I press "Save and display" And I add a "Forum" to section "1" and I fill the form with: | Forum name | Test forum name | | Description | Test forum description | @@ -44,7 +44,7 @@ Feature: Sections can be moved Given I click on "Edit settings" "link" in the "Administration" "block" And I set the following fields to these values: | Course layout | Show one section per page | - And I press "Save changes" + And I press "Save and display" And I add a "Forum" to section "2" and I fill the form with: | Forum name | Test forum name | | Description | Test forum description | diff --git a/course/tests/behat/rename_roles.feature b/course/tests/behat/rename_roles.feature index 082242cea0c..f0195bd0c5c 100644 --- a/course/tests/behat/rename_roles.feature +++ b/course/tests/behat/rename_roles.feature @@ -25,7 +25,7 @@ Feature: Rename roles within a course And I set the following fields to these values: | Your word for 'Non-editing teacher' | Tutor | | Your word for 'Student' | Learner | - And I press "Save changes" + And I press "Save and display" And I expand "Switch role to..." node Then I should see "Tutor" And I should see "Learner" @@ -37,7 +37,7 @@ Feature: Rename roles within a course And I set the following fields to these values: | Your word for 'Non-editing teacher' | | | Your word for 'Student' | | - And I press "Save changes" + And I press "Save and display" And I expand "Switch role to..." node And I should see "Teacher" And I should see "Student" diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 4e45ae2f344..577d72e55b6 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1566,6 +1566,7 @@ $string['saveandnext'] = 'Save and show next'; $string['savedat'] = 'Saved at:'; $string['savechanges'] = 'Save changes'; $string['savechangesanddisplay'] = 'Save and display'; +$string['savechangesandreturn'] = 'Save and return'; $string['savechangesandreturntocourse'] = 'Save and return to course'; $string['savecomment'] = 'Save comment'; $string['savepreferences'] = 'Save preferences';