From c186374c3b6b00a3b42068f0af62b3092d19e4ed Mon Sep 17 00:00:00 2001 From: Aaron Barnes Date: Tue, 21 Aug 2012 13:07:57 +1200 Subject: [PATCH] MDL-30020 blocks/completion: Some criteria do not display complete Also includes a spruce up of the code --- .../block_completionstatus.php | 26 +- blocks/completionstatus/details.php | 239 ++++++++++-------- .../lang/en/block_completionstatus.php | 1 + 3 files changed, 142 insertions(+), 124 deletions(-) diff --git a/blocks/completionstatus/block_completionstatus.php b/blocks/completionstatus/block_completionstatus.php index 612272376b9e4..aa2cb2a21738c 100644 --- a/blocks/completionstatus/block_completionstatus.php +++ b/blocks/completionstatus/block_completionstatus.php @@ -19,15 +19,14 @@ * * @package block * @subpackage completion - * @copyright 2009 Catalyst IT Ltd + * @copyright 2009-2012 Catalyst IT Ltd * @author Aaron Barnes * @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 @@ -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()) { @@ -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 = ''.get_string('viewcoursereport', 'completion').''; + 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 = ''.get_string('viewcoursereport', 'completion').''; return $this->content; } @@ -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); @@ -221,7 +222,8 @@ public function get_content() { $this->content->text .= $shtml.''; // Display link to detailed view - $this->content->footer = '
'.get_string('moredetails', 'completion').''; + $details = new moodle_url('/blocks/completionstatus/details.php', array('course' => $course->id)); + $this->content->footer = '
'.get_string('moredetails', 'completion').''; return $this->content; } diff --git a/blocks/completionstatus/details.php b/blocks/completionstatus/details.php index a1ac77177b053..84406e3820663 100644 --- a/blocks/completionstatus/details.php +++ b/blocks/completionstatus/details.php @@ -19,27 +19,23 @@ * * @package block * @subpackage completion - * @copyright 2009 Catalyst IT Ltd + * @copyright 2009-2012 Catalyst IT Ltd * @author Aaron Barnes * @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) { @@ -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) { @@ -104,6 +92,7 @@ /// /// Display page /// +$PAGE->set_context(context_course::instance($course->id)); // Print header $page = get_string('completionprogressdetails', 'block_completionstatus'); @@ -111,7 +100,7 @@ $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(); @@ -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 ''.get_string('notyetstarted', 'completion').''; } else { echo ''.get_string('inprogress','completion').''; } echo ''; -echo ''.get_string('required').': '; -// 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 '
'; + echo $OUTPUT->box(get_string('err_nocriteria', 'completion'), 'noticebox'); + echo ''; } else { - echo get_string('criteriarequiredany', 'completion'); -} + echo ''.get_string('required').': '; -echo ''; - -// Generate markup for criteria statuses -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; -echo ''; - -// 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 '
'.get_string('criteriagroup', 'block_completionstatus').''.get_string('criteria', 'completion').''.get_string('requirement', 'block_completionstatus').''.get_string('status').''.get_string('complete').''.get_string('completiondate', 'report_completion').'
'; + + // Generate markup for criteria statuses + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; -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 ''; - if ($agg == COMPLETION_AGGREGATION_ALL) { - echo strtolower(get_string('all', 'completion')); - } else { - echo strtolower(get_string('any', 'completion')); - } + // Criteria group + echo ''; + + // Criteria title + echo ''; + + // Requirement + echo ''; + + // Status + echo ''; + + // Is complete + echo ''; + + // Completion data + echo ''; + echo ''; + // for row striping + $oddeven = $oddeven ? 0 : 1; } - echo ''; - - // Criteria title - echo ''; - - // Requirement - echo ''; - - // Status - echo ''; - - // Is complete - echo ''; - - // Completion data - echo ''; - echo ''; + + echo '
'.get_string('criteriagroup', 'block_completionstatus').''.get_string('criteria', 'completion').''.get_string('requirement', 'block_completionstatus').''.get_string('status').''.get_string('complete').''.get_string('completiondate', 'report_completion').'
'; - 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 '('; + echo '
'; + 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 ' '.strtolower(get_string('required')).')'; - $agg_type = false; + echo '('; + + if ($agg == COMPLETION_AGGREGATION_ALL) { + echo strtolower(get_string('aggregateall', 'completion')); + } else { + echo strtolower(get_string('aggregateany', 'completion')); + } + + echo ' '.strtolower(get_string('required')).')'; + $agg_type = false; + } } + echo ''; + echo $row['details']['criteria']; + echo ''; + echo $row['details']['requirement']; + echo ''; + echo $row['details']['status']; + echo ''; + echo $row['complete'] ? get_string('yes') : get_string('no'); + echo ''; + if ($row['timecompleted']) { + echo userdate($row['timecompleted'], get_string('strftimedate', 'langconfig')); + } else { + echo '-'; + } + echo '
'; - echo $row['details']['criteria']; - echo ''; - echo $row['details']['requirement']; - echo ''; - echo $row['details']['status']; - echo ''; - echo ($row['status'] === get_string('yes')) ? get_string('yes') : get_string('no'); - echo ''; - if ($row['timecompleted']) { - echo userdate($row['timecompleted'], '%e %B %G'); - } else { - echo '-'; - } - echo '
'; } -echo ''; +echo '
'; +$courseurl = new moodle_url("/course/view.php", array('id' => $course->id)); +echo $OUTPUT->single_button($courseurl, get_string('returntocourse', 'block_completionstatus'), 'get'); +echo '
'; echo $OUTPUT->footer(); diff --git a/blocks/completionstatus/lang/en/block_completionstatus.php b/blocks/completionstatus/lang/en/block_completionstatus.php index 50bea4e88d16c..340b051c5ce6c 100644 --- a/blocks/completionstatus/lang/en/block_completionstatus.php +++ b/blocks/completionstatus/lang/en/block_completionstatus.php @@ -6,3 +6,4 @@ $string['firstofsecond'] = '{$a->first} of {$a->second}'; $string['pluginname'] = 'Course completion status'; $string['requirement'] = 'Requirement'; +$string['returntocourse'] = 'Return to course';