Skip to content

Commit

Permalink
MDL-40241 completion: Default roles unable to manually complete course
Browse files Browse the repository at this point in the history
Thanks to Jon Sharp for authoring the original patch!
  • Loading branch information
Aaron Barnes authored and David Monllao committed Nov 28, 2014
1 parent ca0e301 commit 37ee40f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
16 changes: 16 additions & 0 deletions completion/tests/behat/behat_completion.php
Expand Up @@ -105,4 +105,20 @@ public function go_to_the_current_course_activity_completion_report() {
return $steps;
}

/**
* Toggles completion tracking for course
*
* @When /^completion tracking is "(?P<completion_status_string>([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').'"')
);
}
}
45 changes: 45 additions & 0 deletions 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"
15 changes: 10 additions & 5 deletions course/togglecompletion.php
Expand Up @@ -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
*/
Expand All @@ -31,6 +34,10 @@
$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');
}
Expand All @@ -45,16 +52,14 @@
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();

Expand Down
9 changes: 9 additions & 0 deletions lib/tests/behat/behat_general.php
Expand Up @@ -879,6 +879,15 @@ public function i_trigger_cron() {
$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.
*
Expand Down
4 changes: 2 additions & 2 deletions report/completion/index.php
Expand Up @@ -672,8 +672,8 @@
)
);

print '<a href="'.$toggleurl->out().'"><img src="'.$OUTPUT->pix_url('i/completion-manual-'.($is_complete ? 'y' : 'n')).
'" alt="'.$describe.'" class="icon" title="'.get_string('markcomplete', 'completion').'" /></a></td>';
print '<a href="'.$toggleurl->out().'" title="'.get_string('clicktomarkusercomplete', 'report_completion').'"><img src="'.$OUTPUT->pix_url('i/completion-manual-'.($is_complete ? 'y' : 'n')).
'" alt="'.$describe.'" class="icon" /></a></td>';
} else {
print '<img src="'.$OUTPUT->pix_url('i/'.$completionicon).'" alt="'.$describe.'" class="icon" title="'.$fulldescribe.'" /></td>';
}
Expand Down
1 change: 1 addition & 0 deletions report/completion/lang/en/report_completion.php
Expand Up @@ -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';
Expand Down

0 comments on commit 37ee40f

Please sign in to comment.