From 37ee40f3e0fc32a5f39c274e0a798f60fb84c4d1 Mon Sep 17 00:00:00 2001 From: Aaron Barnes Date: Thu, 5 Sep 2013 13:18:09 +1200 Subject: [PATCH 1/3] MDL-40241 completion: Default roles unable to manually complete course Thanks to Jon Sharp for authoring the original patch! --- completion/tests/behat/behat_completion.php | 16 +++++++ .../behat/teacher_manual_completion.feature | 45 +++++++++++++++++++ course/togglecompletion.php | 15 ++++--- lib/tests/behat/behat_general.php | 9 ++++ report/completion/index.php | 4 +- .../completion/lang/en/report_completion.php | 1 + 6 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 completion/tests/behat/teacher_manual_completion.feature diff --git a/completion/tests/behat/behat_completion.php b/completion/tests/behat/behat_completion.php index 89b6344b85f..29e96b11905 100644 --- a/completion/tests/behat/behat_completion.php +++ b/completion/tests/behat/behat_completion.php @@ -105,4 +105,20 @@ class behat_completion extends behat_base { return $steps; } + /** + * Toggles completion tracking for course + * + * @When /^completion tracking is "(?P([Ee]nabled|[Dd]isabled)*)" in current course$/ + * @param string $completionstatus + */ + public function completion_is_toggled_in_course($completionstatus) { + + $toggle = strtolower($completionstatus) == 'enabled' ? 'Yes' : 'No'; + + return array( + new Given('I follow "'.get_string('editsettings').'"'), + new Given('I select "'.$toggle.'" from "'.get_string('enablecompletion', 'completion').'"'), + new Given('I press "'.get_string('savechanges').'"') + ); + } } diff --git a/completion/tests/behat/teacher_manual_completion.feature b/completion/tests/behat/teacher_manual_completion.feature new file mode 100644 index 00000000000..f5ced8d7a50 --- /dev/null +++ b/completion/tests/behat/teacher_manual_completion.feature @@ -0,0 +1,45 @@ +@core @core_completion +Feature: Allow teachers to manually mark users as complete when configured + In order for teachers to mark students as complete + As a teacher + I need to be able to use the completion report mark complete functionality + + Scenario: Mark a student as complete using the completion report + Given the following "courses" exists: + | fullname | shortname | category | + | Completion course | CC1 | 0 | + And the following "users" exists: + | username | firstname | lastname | email | + | student1 | Student | First | student1@example.com | + | teacher1 | Teacher | First | teacher1@example.com | + And the following "course enrolments" exists: + | user | course | role | + | student1 | CC1 | student | + | teacher1 | CC1 | editingteacher | + And I log in as "admin" + And I set the following administration settings values: + | Enable completion tracking | 1 | + And I am on homepage + And I follow "Completion course" + And completion tracking is "enabled" in current course + And I follow "Course completion" + And I check "Teacher" + And I press "Save changes" + And I turn editing mode on + And I add the "Course completion status" block + And I log out + And I log in as "student1" + And I follow "Completion course" + And I should see "Status: Not yet started" + And I log out + When I log in as "teacher1" + And I follow "Completion course" + And I follow "View course report" + And I should see "Student First" + And I follow "Click to mark user complete" + And I run the cron + And I am on homepage + And I log out + Then I log in as "student1" + And I follow "Completion course" + And I should see "Status: Complete" diff --git a/course/togglecompletion.php b/course/togglecompletion.php index 53992db8c6c..a23544dfca7 100644 --- a/course/togglecompletion.php +++ b/course/togglecompletion.php @@ -19,6 +19,9 @@ * Toggles the manual completion flag for a particular activity or course completion * and the current user. * + * If by student params: course=2 + * If by manager params: course=2&user=4&rolec=3&sesskey=ghfgsdf + * * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package course */ @@ -31,6 +34,10 @@ $cmid = optional_param('id', 0, PARAM_INT); $courseid = optional_param('course', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_BOOL); +// Check if we are marking a user complete via the completion report +$user = optional_param('user', 0, PARAM_INT); +$rolec = optional_param('rolec', 0, PARAM_INT); + if (!$cmid && !$courseid) { print_error('invalidarguments'); } @@ -45,16 +52,14 @@ if ($courseid) { require_login($course); $completion = new completion_info($course); + $trackeduser = ($user ? $user : $USER->id); + if (!$completion->is_enabled()) { throw new moodle_exception('completionnotenabled', 'completion'); - } elseif (!$completion->is_tracked_user($USER->id)) { + } elseif (!$completion->is_tracked_user($trackeduser)) { throw new moodle_exception('nottracked', 'completion'); } - // Check if we are marking a user complete via the completion report - $user = optional_param('user', 0, PARAM_INT); - $rolec = optional_param('rolec', 0, PARAM_INT); - if ($user && $rolec) { require_sesskey(); diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 6e1934c4f35..c958a770895 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -879,6 +879,15 @@ class behat_general extends behat_base { $this->getSession()->visit($this->locate_path('/admin/cron.php')); } + /** + * This step triggers cron like a user would do going to admin/cron.php (alias for "I trigger cron") + * + * @Given /^I run the cron$/ + */ + public function i_run_the_cron() { + $this->i_trigger_cron(); + } + /** * Checks that an element and selector type exists in another element and selector type on the current page. * diff --git a/report/completion/index.php b/report/completion/index.php index f9002001f17..ae1786c4356 100644 --- a/report/completion/index.php +++ b/report/completion/index.php @@ -672,8 +672,8 @@ foreach ($progress as $user) { ) ); - print ''.$describe.''; + print ''.$describe.''; } else { print ''.$describe.''; } diff --git a/report/completion/lang/en/report_completion.php b/report/completion/lang/en/report_completion.php index fa91fd738be..da96d5fc4c5 100644 --- a/report/completion/lang/en/report_completion.php +++ b/report/completion/lang/en/report_completion.php @@ -24,6 +24,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['clicktomarkusercomplete'] = 'Click to mark user complete'; $string['completion:view'] = 'View course completion report'; $string['completiondate'] = 'Completion date'; $string['id'] = 'ID'; From 525d6ce3979630e771502481d9e9336ef8b1c6ce Mon Sep 17 00:00:00 2001 From: Aaron Barnes Date: Mon, 16 Dec 2013 21:00:40 +1300 Subject: [PATCH 2/3] MDL-40241 blocks_completionstatus: Fix notices --- blocks/completionstatus/block_completionstatus.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/blocks/completionstatus/block_completionstatus.php b/blocks/completionstatus/block_completionstatus.php index c27067b1c70..041bfe87666 100644 --- a/blocks/completionstatus/block_completionstatus.php +++ b/blocks/completionstatus/block_completionstatus.php @@ -57,6 +57,8 @@ class block_completionstatus extends block_base { // Create empty content. $this->content = new stdClass(); + $this->content->text = ''; + $this->content->footer = ''; // Can edit settings? $can_edit = has_capability('moodle/course:update', $context); @@ -67,13 +69,13 @@ class block_completionstatus extends block_base { // Don't display if completion isn't enabled! if (!completion_info::is_enabled_for_site()) { if ($can_edit) { - $this->content->text = get_string('completionnotenabledforsite', 'completion'); + $this->content->text .= get_string('completionnotenabledforsite', 'completion'); } return $this->content; } else if (!$info->is_enabled()) { if ($can_edit) { - $this->content->text = get_string('completionnotenabledforcourse', 'completion'); + $this->content->text .= get_string('completionnotenabledforcourse', 'completion'); } return $this->content; } @@ -84,7 +86,7 @@ class block_completionstatus extends block_base { // Check if this course has any criteria. if (empty($completions)) { if ($can_edit) { - $this->content->text = get_string('nocriteriaset', 'completion'); + $this->content->text .= get_string('nocriteriaset', 'completion'); } return $this->content; } @@ -230,11 +232,11 @@ class block_completionstatus extends block_base { $rows = array_merge($rows, $srows); $table->data = $rows; - $this->content->text = html_writer::table($table); + $this->content->text .= html_writer::table($table); // Display link to detailed view. $details = new moodle_url('/blocks/completionstatus/details.php', array('course' => $course->id)); - $this->content->footer = html_writer::link($details, get_string('moredetails', 'completion')); + $this->content->footer .= html_writer::link($details, get_string('moredetails', 'completion')); } else { // If user is not enrolled, show error. $this->content->text = get_string('nottracked', 'completion'); From 95d1a366ea1cfb6ad50c389a09efa41ad610785d Mon Sep 17 00:00:00 2001 From: David Monllao Date: Fri, 28 Nov 2014 17:23:37 +0800 Subject: [PATCH 3/3] MDL-40241 core_completion: Minor fixes to provided patch Thanks to Aaron Barnes and Jon Sharp for working on this issue. --- completion/tests/behat/behat_completion.php | 10 +-- .../behat/teacher_manual_completion.feature | 84 +++++++++---------- course/togglecompletion.php | 4 +- lib/tests/behat/behat_general.php | 9 -- report/completion/index.php | 3 +- 5 files changed, 51 insertions(+), 59 deletions(-) diff --git a/completion/tests/behat/behat_completion.php b/completion/tests/behat/behat_completion.php index 29e96b11905..807c7fea7f0 100644 --- a/completion/tests/behat/behat_completion.php +++ b/completion/tests/behat/behat_completion.php @@ -106,18 +106,18 @@ class behat_completion extends behat_base { } /** - * Toggles completion tracking for course + * Toggles completion tracking for course being in the course page. * - * @When /^completion tracking is "(?P([Ee]nabled|[Dd]isabled)*)" in current course$/ - * @param string $completionstatus + * @When /^completion tracking is "(?PEnabled|Disabled)" in current course$/ + * @param string $completionstatus The status, enabled or disabled. */ public function completion_is_toggled_in_course($completionstatus) { - $toggle = strtolower($completionstatus) == 'enabled' ? 'Yes' : 'No'; + $toggle = strtolower($completionstatus) == 'enabled' ? get_string('yes') : get_string('no'); return array( new Given('I follow "'.get_string('editsettings').'"'), - new Given('I select "'.$toggle.'" from "'.get_string('enablecompletion', 'completion').'"'), + new Given('I set the field "'.get_string('enablecompletion', 'completion').'" to "'.$toggle.'"'), new Given('I press "'.get_string('savechanges').'"') ); } diff --git a/completion/tests/behat/teacher_manual_completion.feature b/completion/tests/behat/teacher_manual_completion.feature index f5ced8d7a50..d15691a41a8 100644 --- a/completion/tests/behat/teacher_manual_completion.feature +++ b/completion/tests/behat/teacher_manual_completion.feature @@ -1,45 +1,45 @@ @core @core_completion Feature: Allow teachers to manually mark users as complete when configured - In order for teachers to mark students as complete - As a teacher - I need to be able to use the completion report mark complete functionality + In order for teachers to mark students as complete + As a teacher + I need to be able to use the completion report mark complete functionality - Scenario: Mark a student as complete using the completion report - Given the following "courses" exists: - | fullname | shortname | category | - | Completion course | CC1 | 0 | - And the following "users" exists: - | username | firstname | lastname | email | - | student1 | Student | First | student1@example.com | - | teacher1 | Teacher | First | teacher1@example.com | - And the following "course enrolments" exists: - | user | course | role | - | student1 | CC1 | student | - | teacher1 | CC1 | editingteacher | - And I log in as "admin" - And I set the following administration settings values: - | Enable completion tracking | 1 | - And I am on homepage - And I follow "Completion course" - And completion tracking is "enabled" in current course - And I follow "Course completion" - And I check "Teacher" - And I press "Save changes" - And I turn editing mode on - And I add the "Course completion status" block - And I log out - And I log in as "student1" - And I follow "Completion course" - And I should see "Status: Not yet started" - And I log out - When I log in as "teacher1" - And I follow "Completion course" - And I follow "View course report" - And I should see "Student First" - And I follow "Click to mark user complete" - And I run the cron - And I am on homepage - And I log out - Then I log in as "student1" - And I follow "Completion course" - And I should see "Status: Complete" + Scenario: Mark a student as complete using the completion report + Given the following "courses" exist: + | fullname | shortname | category | + | Completion course | CC1 | 0 | + And the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | First | student1@example.com | + | teacher1 | Teacher | First | teacher1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | student1 | CC1 | student | + | teacher1 | CC1 | editingteacher | + And I log in as "admin" + And I set the following administration settings values: + | Enable completion tracking | 1 | + And I am on homepage + And I follow "Completion course" + And completion tracking is "Enabled" in current course + And I follow "Course completion" + And I set the field "Teacher" to "1" + And I press "Save changes" + And I turn editing mode on + And I add the "Course completion status" block + And I log out + And I log in as "student1" + And I follow "Completion course" + And I should see "Status: Not yet started" + And I log out + When I log in as "teacher1" + And I follow "Completion course" + And I follow "View course report" + And I should see "Student First" + And I follow "Click to mark user complete" + And I trigger cron + And I am on homepage + And I log out + Then I log in as "student1" + And I follow "Completion course" + And I should see "Status: Complete" diff --git a/course/togglecompletion.php b/course/togglecompletion.php index a23544dfca7..234b8c89e09 100644 --- a/course/togglecompletion.php +++ b/course/togglecompletion.php @@ -34,7 +34,7 @@ $cmid = optional_param('id', 0, PARAM_INT); $courseid = optional_param('course', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_BOOL); -// Check if we are marking a user complete via the completion report +// Check if we are marking a user complete via the completion report. $user = optional_param('user', 0, PARAM_INT); $rolec = optional_param('rolec', 0, PARAM_INT); @@ -56,7 +56,7 @@ if ($courseid) { if (!$completion->is_enabled()) { throw new moodle_exception('completionnotenabled', 'completion'); - } elseif (!$completion->is_tracked_user($trackeduser)) { + } else if (!$completion->is_tracked_user($trackeduser)) { throw new moodle_exception('nottracked', 'completion'); } diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index c958a770895..6e1934c4f35 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -879,15 +879,6 @@ class behat_general extends behat_base { $this->getSession()->visit($this->locate_path('/admin/cron.php')); } - /** - * This step triggers cron like a user would do going to admin/cron.php (alias for "I trigger cron") - * - * @Given /^I run the cron$/ - */ - public function i_run_the_cron() { - $this->i_trigger_cron(); - } - /** * Checks that an element and selector type exists in another element and selector type on the current page. * diff --git a/report/completion/index.php b/report/completion/index.php index ae1786c4356..51ddda7ea9e 100644 --- a/report/completion/index.php +++ b/report/completion/index.php @@ -672,7 +672,8 @@ foreach ($progress as $user) { ) ); - print 'out().'" title="'.get_string('clicktomarkusercomplete', 'report_completion').'">' . + ''.$describe.''; } else { print ''.$describe.'';