Skip to content

Commit

Permalink
course completion MDL-2631 Course completion feature - Thanks to Aaro…
Browse files Browse the repository at this point in the history
…n Barnes and Catalyst IT for this significant contribution. It is now officially possible to finish a course!

Even though I've tweaked this and done some polishing, there is still plenty to do on it now in HEAD, mostly to do with UI, usability and strings, so we'll keep working on it.  Aaron already has a number of improvements to add to it.
  • Loading branch information
moodler committed Apr 30, 2010
1 parent 2589eb8 commit 2be4d09
Show file tree
Hide file tree
Showing 46 changed files with 5,879 additions and 42 deletions.
10 changes: 10 additions & 0 deletions admin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@
events_cron();
mtrace('done.');


if ($CFG->enablecompletion) {
// Completion cron
mtrace('Starting the completion cron...');
require_once($CFG->libdir . '/completion/cron.php');
completion_cron();
mtrace('done');
}


if ($CFG->enableportfolios) {
// Portfolio cron
mtrace('Starting the portfolio cron...');
Expand Down
10 changes: 5 additions & 5 deletions admin/settings/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@
$languages += get_string_manager()->get_list_of_translations();
$temp->add(new admin_setting_configselect('moodlecourse/lang', get_string('forcelanguage'), '',key($languages),$languages));

if (!empty($CFG->enablecompletion)) {
$temp->add(new admin_setting_heading('progress', get_string('progress','completion'), ''));
$temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', get_string('completion','completion'), '',
1, array(0 => get_string('completiondisabled','completion'), 1 => get_string('completionenabled','completion'))));
}
$temp->add(new admin_setting_heading('progress', get_string('progress','completion'), ''));
$temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', get_string('completion','completion'), '',
1, array(0 => get_string('completiondisabled','completion'), 1 => get_string('completionenabled','completion'))));

$temp->add(new admin_setting_configcheckbox('moodlecourse/completionstartonenrol', get_string('completionstartonenrol','completion'), get_string('completionstartonenrolhelp', 'completion'), 1));
$ADMIN->add('courses', $temp);

/// "courserequests" settingpage
Expand Down
198 changes: 198 additions & 0 deletions blocks/completionstatus/block_completionstatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
* Block for displayed logged in user's course completion status
*
* @package moodlecore
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->libdir.'/completionlib.php');

/**
* Course completion status
* Displays overall, and individual criteria status for logged in user
*/
class block_completionstatus extends block_base {

public function init() {
$this->title = get_string('completionstatus', 'block_completionstatus');
$this->version = 2009072800;
}

public function get_content() {
global $USER, $CFG, $DB, $COURSE;

// If content is cached
if ($this->content !== NULL) {
return $this->content;
}

// Create empty content
$this->content = new stdClass;

// Don't display if completion isn't enabled!
if (!$this->page->course->enablecompletion) {
return $this->content;
}

// Load criteria to display
$info = new completion_info($this->page->course);
$completions = $info->get_completions($USER->id);

// Check if this course has any criteria
if (empty($completions)) {
return $this->content;
}

// Check this user is enroled
$users = $info->internal_get_tracked_users(true);
if (!in_array($USER->id, array_keys($users))) {

// If not enrolled, but are can view the report:
if (has_capability('coursereport/completion:view', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
$this->content->text = '<a href="'.$CFG->wwwroot.'/course/report/completion/index.php?course='.$COURSE->id.
'">'.get_string('viewcoursereport', 'completion').'</a>';
return $this->content;
}

// Otherwise, show error
$this->content->text = get_string('notenroled', 'completion');
return $this->content;
}

// Generate markup for criteria statuses
$shtml = '';

// For aggregating activity completion
$activities = array();
$activities_complete = 0;

// For aggregating course prerequisites
$prerequisites = array();
$prerequisites_complete = 0;

// Flag to set if current completion data is inconsistent with
// what is stored in the database
$pending_update = false;

// Loop through course criteria
foreach ($completions as $completion) {

$criteria = $completion->get_criteria();
$complete = $completion->is_complete();

if (!$pending_update && $criteria->is_pending($completion)) {
$pending_update = true;
}

// Activities are a special case, so cache them and leave them till last
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$activities[$criteria->moduleinstance] = $complete;

if ($complete) {
$activities_complete++;
}

continue;
}

// Prerequisites are also a special case, so cache them and leave them till last
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
$prerequisites[$criteria->courseinstance] = $complete;

if ($complete) {
$prerequisites_complete++;
}

continue;
}

$shtml .= '<tr><td>';
$shtml .= $criteria->get_title();
$shtml .= '</td><td style="text-align: right">';
$shtml .= $completion->get_status();
$shtml .= '</td></tr>';
}

// Aggregate activities
if (!empty($activities)) {

$shtml .= '<tr><td>';
$shtml .= get_string('activitiescompleted', 'completion');
$shtml .= '</td><td style="text-align: right">';
$shtml .= $activities_complete.' of '.count($activities);
$shtml .= '</td></tr>';
}

// Aggregate prerequisites
if (!empty($prerequisites)) {

$phtml = '<tr><td>';
$phtml .= get_string('prerequisitescompleted', 'completion');
$phtml .= '</td><td style="text-align: right">';
$phtml .= $prerequisites_complete.' of '.count($prerequisites);
$phtml .= '</td></tr>';

$shtml = $phtml . $shtml;
}

// Display completion status
$this->content->text = '<table width="100%" style="font-size: 90%;"><tbody>';
$this->content->text .= '<tr><td colspan="2"><b>'.get_string('status').':</b> ';

// Is course complete?
$coursecomplete = $info->is_course_complete($USER->id);

// Has this user completed any criteria?
$criteriacomplete = $info->count_course_user_data($USER->id);

if ($pending_update) {
$this->content->text .= '<i>'.get_string('pending', 'completion').'</i>';
} else if ($coursecomplete) {
$this->content->text .= get_string('complete');
} else if (!$criteriacomplete) {
$this->content->text .= '<i>'.get_string('notyetstarted', 'completion').'</i>';
} else {
$this->content->text .= '<i>'.get_string('inprogress','completion').'</i>';
}

$this->content->text .= '</td></tr>';
$this->content->text .= '<tr><td colspan="2">';

// Get overall aggregation method
$overall = $info->get_aggregation_method();

if ($overall == COMPLETION_AGGREGATION_ALL) {
$this->content->text .= get_string('criteriarequiredall', 'completion');
} else {
$this->content->text .= get_string('criteriarequiredany', 'completion');
}

$this->content->text .= ':</td></tr>';
$this->content->text .= '<tr><td><b>'.get_string('requiredcriteria', 'completion').'</b></td><td style="text-align: right"><b>'.get_string('status').'</b></td></tr>';
$this->content->text .= $shtml.'</tbody></table>';

// Display link to detailed view
$this->content->footer = '<br><a href="'.$CFG->wwwroot.'/blocks/completionstatus/details.php?course='.$COURSE->id.'">More details</a>';

return $this->content;
}
}
Loading

0 comments on commit 2be4d09

Please sign in to comment.