Skip to content

Commit

Permalink
MDL-30020 blocks/completion: Some criteria do not display complete
Browse files Browse the repository at this point in the history
Also includes a spruce up of the code
  • Loading branch information
Aaron Barnes committed Aug 27, 2012
1 parent 4ff0f02 commit c186374
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 124 deletions.
26 changes: 14 additions & 12 deletions blocks/completionstatus/block_completionstatus.php
Expand Up @@ -19,15 +19,14 @@
*
* @package block
* @subpackage completion
* @copyright 2009 Catalyst IT Ltd
* @copyright 2009-2012 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();


require_once($CFG->libdir.'/completionlib.php');
require_once("{$CFG->libdir}/completionlib.php");

/**
* Course completion status
Expand All @@ -40,21 +39,23 @@ public function init() {
}

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

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

$course = $this->page->course;

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

// Can edit settings?
$can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
$can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));

// Get course completion data
$info = new completion_info($this->page->course);
$info = new completion_info($course);

// Don't display if completion isn't enabled!
if (!completion_info::is_enabled_for_site()) {
Expand Down Expand Up @@ -84,9 +85,9 @@ public function get_content() {
// Check this user is enroled
if (!$info->is_tracked_user($USER->id)) {
// If not enrolled, but are can view the report:
if (has_capability('report/completion:view', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
$this->content->text = '<a href="'.$CFG->wwwroot.'/report/completion/index.php?course='.$COURSE->id.
'">'.get_string('viewcoursereport', 'completion').'</a>';
if (has_capability('report/completion:view', get_context_instance(CONTEXT_COURSE, $course->id))) {
$report = new moodle_url('/report/completion/index.php', array('course' => $course->id));
$this->content->text = '<a href="'.$report->out().'">'.get_string('viewcoursereport', 'completion').'</a>';
return $this->content;
}

Expand Down Expand Up @@ -187,7 +188,7 @@ public function get_content() {
// Load course completion
$params = array(
'userid' => $USER->id,
'course' => $COURSE->id
'course' => $course->id
);
$ccompletion = new completion_completion($params);

Expand Down Expand Up @@ -221,7 +222,8 @@ public function get_content() {
$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.'">'.get_string('moredetails', 'completion').'</a>';
$details = new moodle_url('/blocks/completionstatus/details.php', array('course' => $course->id));
$this->content->footer = '<br><a href="'.$details->out().'">'.get_string('moredetails', 'completion').'</a>';

return $this->content;
}
Expand Down
239 changes: 127 additions & 112 deletions blocks/completionstatus/details.php
Expand Up @@ -19,27 +19,23 @@
*
* @package block
* @subpackage completion
* @copyright 2009 Catalyst IT Ltd
* @copyright 2009-2012 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../../config.php');
require_once($CFG->libdir.'/completionlib.php');


// TODO: Make this page Moodle 2.0 compliant
require_once(dirname(__FILE__).'/../../config.php');
require_once("{$CFG->libdir}/completionlib.php");


///
/// Load data
///
$id = required_param('course', PARAM_INT);
// User id
$userid = optional_param('user', 0, PARAM_INT);

// Load course
$course = $DB->get_record('course', array('id' => $id));
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);

// Load user
if ($userid) {
Expand Down Expand Up @@ -76,21 +72,13 @@
// Load completion data
$info = new completion_info($course);

$returnurl = "{$CFG->wwwroot}/course/view.php?id={$id}";
$returnurl = new moodle_url('/course/view.php', array('id' => $id));

// Don't display if completion isn't enabled!
if (!$info->is_enabled()) {
print_error('completionnotenabled', 'completion', $returnurl);
}

// Load criteria to display
$completions = $info->get_completions($user->id);

// Check if this course has any criteria
if (empty($completions)) {
print_error('nocriteriaset', 'completion', $returnurl);
}

// Check this user is enroled
if (!$info->is_tracked_user($user->id)) {
if ($USER->id == $user->id) {
Expand All @@ -104,14 +92,15 @@
///
/// Display page
///
$PAGE->set_context(context_course::instance($course->id));

// Print header
$page = get_string('completionprogressdetails', 'block_completionstatus');
$title = format_string($course->fullname) . ': ' . $page;

$PAGE->navbar->add($page);
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id));
$PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id));
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($title);
echo $OUTPUT->header();
Expand All @@ -135,122 +124,148 @@
// Has this user completed any criteria?
$criteriacomplete = $info->count_course_user_data($user->id);

// Load course completion
$params = array(
'userid' => $user->id,
'course' => $course->id,
);
$ccompletion = new completion_completion($params);

if ($coursecomplete) {
echo get_string('complete');
} else if (!$criteriacomplete) {
} else if (!$criteriacomplete && !$ccompletion->timestarted) {
echo '<i>'.get_string('notyetstarted', 'completion').'</i>';
} else {
echo '<i>'.get_string('inprogress','completion').'</i>';
}

echo '</td></tr>';
echo '<tr><td colspan="2"><b>'.get_string('required').':</b> ';

// Get overall aggregation method
$overall = $info->get_aggregation_method();
// Load criteria to display
$completions = $info->get_completions($user->id);

if ($overall == COMPLETION_AGGREGATION_ALL) {
echo get_string('criteriarequiredall', 'completion');
// Check if this course has any criteria
if (empty($completions)) {
echo '<tr><td colspan="2"><br />';
echo $OUTPUT->box(get_string('err_nocriteria', 'completion'), 'noticebox');
echo '</td></tr></tbody></table>';
} else {
echo get_string('criteriarequiredany', 'completion');
}
echo '<tr><td colspan="2"><b>'.get_string('required').':</b> ';

echo '</td></tr></tbody></table>';

// Generate markup for criteria statuses
echo '<table class="generalbox boxaligncenter" cellpadding="3"><tbody>';
echo '<tr class="ccheader">';
echo '<th class="c0 header" scope="col">'.get_string('criteriagroup', 'block_completionstatus').'</th>';
echo '<th class="c1 header" scope="col">'.get_string('criteria', 'completion').'</th>';
echo '<th class="c2 header" scope="col">'.get_string('requirement', 'block_completionstatus').'</th>';
echo '<th class="c3 header" scope="col">'.get_string('status').'</th>';
echo '<th class="c4 header" scope="col">'.get_string('complete').'</th>';
echo '<th class="c5 header" scope="col">'.get_string('completiondate', 'report_completion').'</th>';
echo '</tr>';

// Save row data
$rows = array();

global $COMPLETION_CRITERIA_TYPES;

// Loop through course criteria
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$complete = $completion->is_complete();

$row = array();
$row['type'] = $criteria->criteriatype;
$row['title'] = $criteria->get_title();
$row['status'] = $completion->get_status();
$row['timecompleted'] = $completion->timecompleted;
$row['details'] = $criteria->get_details($completion);
$rows[] = $row;
}
// Get overall aggregation method
$overall = $info->get_aggregation_method();

// Print table
$last_type = '';
$agg_type = false;
if ($overall == COMPLETION_AGGREGATION_ALL) {
echo get_string('criteriarequiredall', 'completion');
} else {
echo get_string('criteriarequiredany', 'completion');
}

echo '</td></tr></tbody></table>';

// Generate markup for criteria statuses
echo '<table class="generalbox logtable boxaligncenter" id="criteriastatus" width="100%"><tbody>';
echo '<tr class="ccheader">';
echo '<th class="c0 header" scope="col">'.get_string('criteriagroup', 'block_completionstatus').'</th>';
echo '<th class="c1 header" scope="col">'.get_string('criteria', 'completion').'</th>';
echo '<th class="c2 header" scope="col">'.get_string('requirement', 'block_completionstatus').'</th>';
echo '<th class="c3 header" scope="col">'.get_string('status').'</th>';
echo '<th class="c4 header" scope="col">'.get_string('complete').'</th>';
echo '<th class="c5 header" scope="col">'.get_string('completiondate', 'report_completion').'</th>';
echo '</tr>';

foreach ($rows as $row) {
// Save row data
$rows = array();

// Loop through course criteria
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();

$row = array();
$row['type'] = $criteria->criteriatype;
$row['title'] = $criteria->get_title();
$row['status'] = $completion->get_status();
$row['complete'] = $completion->is_complete();
$row['timecompleted'] = $completion->timecompleted;
$row['details'] = $criteria->get_details($completion);
$rows[] = $row;
}

// Criteria group
echo '<td class="c0">';
if ($last_type !== $row['details']['type']) {
$last_type = $row['details']['type'];
echo $last_type;
// Print table
$last_type = '';
$agg_type = false;
$oddeven = 0;

// Reset agg type
$agg_type = true;
} else {
// Display aggregation type
if ($agg_type) {
$agg = $info->get_aggregation_method($row['type']);
foreach ($rows as $row) {

echo '(<i>';
echo '<tr class="r' . $oddeven . '">';

if ($agg == COMPLETION_AGGREGATION_ALL) {
echo strtolower(get_string('all', 'completion'));
} else {
echo strtolower(get_string('any', 'completion'));
}
// Criteria group
echo '<td class="cell c0">';
if ($last_type !== $row['details']['type']) {
$last_type = $row['details']['type'];
echo $last_type;

// Reset agg type
$agg_type = true;
} else {
// Display aggregation type
if ($agg_type) {
$agg = $info->get_aggregation_method($row['type']);

echo '</i> '.strtolower(get_string('required')).')';
$agg_type = false;
echo '(<i>';

if ($agg == COMPLETION_AGGREGATION_ALL) {
echo strtolower(get_string('aggregateall', 'completion'));
} else {
echo strtolower(get_string('aggregateany', 'completion'));
}

echo '</i> '.strtolower(get_string('required')).')';
$agg_type = false;
}
}
echo '</td>';

// Criteria title
echo '<td class="cell c1">';
echo $row['details']['criteria'];
echo '</td>';

// Requirement
echo '<td class="cell c2">';
echo $row['details']['requirement'];
echo '</td>';

// Status
echo '<td class="cell c3">';
echo $row['details']['status'];
echo '</td>';

// Is complete
echo '<td class="cell c4">';
echo $row['complete'] ? get_string('yes') : get_string('no');
echo '</td>';

// Completion data
echo '<td class="cell c5">';
if ($row['timecompleted']) {
echo userdate($row['timecompleted'], get_string('strftimedate', 'langconfig'));
} else {
echo '-';
}
echo '</td>';
echo '</tr>';
// for row striping
$oddeven = $oddeven ? 0 : 1;
}
echo '</td>';

// Criteria title
echo '<td class="c1">';
echo $row['details']['criteria'];
echo '</td>';

// Requirement
echo '<td class="c2">';
echo $row['details']['requirement'];
echo '</td>';

// Status
echo '<td class="c3">';
echo $row['details']['status'];
echo '</td>';

// Is complete
echo '<td class="c4">';
echo ($row['status'] === get_string('yes')) ? get_string('yes') : get_string('no');
echo '</td>';

// Completion data
echo '<td class="c5">';
if ($row['timecompleted']) {
echo userdate($row['timecompleted'], '%e %B %G');
} else {
echo '-';
}
echo '</td>';
echo '</tr>';

echo '</tbody></table>';
}

echo '</tbody></table>';
echo '<div class="buttons">';
$courseurl = new moodle_url("/course/view.php", array('id' => $course->id));
echo $OUTPUT->single_button($courseurl, get_string('returntocourse', 'block_completionstatus'), 'get');
echo '</div>';

echo $OUTPUT->footer();
1 change: 1 addition & 0 deletions blocks/completionstatus/lang/en/block_completionstatus.php
Expand Up @@ -6,3 +6,4 @@
$string['firstofsecond'] = '{$a->first} of {$a->second}';
$string['pluginname'] = 'Course completion status';
$string['requirement'] = 'Requirement';
$string['returntocourse'] = 'Return to course';

0 comments on commit c186374

Please sign in to comment.