Merge branch 'wip-MDL-35608-master' of git://github.com/phalacee/moodle

This commit is contained in:
Damyon Wiese 2013-04-09 13:59:45 +08:00
commit 9adb30759f
7 changed files with 184 additions and 153 deletions

View file

@ -29,8 +29,8 @@ defined('MOODLE_INTERNAL') || die();
require_once("{$CFG->libdir}/completionlib.php");
/**
* Course completion status
* Displays overall, and individual criteria status for logged in user
* Course completion status.
* Displays overall, and individual criteria status for logged in user.
*/
class block_completionstatus extends block_base {
@ -38,28 +38,31 @@ class block_completionstatus extends block_base {
$this->title = get_string('pluginname', 'block_completionstatus');
}
function applicable_formats() {
public function applicable_formats() {
return array('all' => true, 'mod' => false, 'tag' => false, 'my' => false);
}
public function get_content() {
global $USER;
// If content is cached
if ($this->content !== NULL) {
$rows = array();
$srows = array();
$prows = array();
// If content is cached.
if ($this->content !== null) {
return $this->content;
}
$course = $this->page->course;
$context = context_course::instance($course->id);
// Create empty content
// Create empty content.
$this->content = new stdClass();
// Can edit settings?
$can_edit = has_capability('moodle/course:update', $context);
// Get course completion data
// Get course completion data.
$info = new completion_info($course);
// Don't display if completion isn't enabled!
@ -76,10 +79,10 @@ class block_completionstatus extends block_base {
return $this->content;
}
// Load criteria to display
// Load criteria to display.
$completions = $info->get_completions($USER->id);
// Check if this course has any criteria
// Check if this course has any criteria.
if (empty($completions)) {
if ($can_edit) {
$this->content->text = get_string('nocriteriaset', 'completion');
@ -87,27 +90,25 @@ class block_completionstatus extends block_base {
return $this->content;
}
// Check this user is enroled
// Check this user is enroled.
if ($info->is_tracked_user($USER->id)) {
// Generate markup for criteria statuses
$shtml = '';
// Generate markup for criteria statuses.
$data = '';
// For aggregating activity completion
// For aggregating activity completion.
$activities = array();
$activities_complete = 0;
// For aggregating course prerequisites
// 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
// Flag to set if current completion data is inconsistent with what is stored in the database.
$pending_update = false;
// Loop through course criteria
// Loop through course criteria.
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$complete = $completion->is_complete();
@ -115,7 +116,7 @@ class block_completionstatus extends block_base {
$pending_update = true;
}
// Activities are a special case, so cache them and leave them till last
// Activities are a special case, so cache them and leave them till last.
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$activities[$criteria->moduleinstance] = $complete;
@ -126,7 +127,7 @@ class block_completionstatus extends block_base {
continue;
}
// Prerequisites are also a special case, so cache them and leave them till last
// 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;
@ -136,50 +137,53 @@ class block_completionstatus extends block_base {
continue;
}
$shtml .= '<tr><td>';
$shtml .= $criteria->get_title();
$shtml .= '</td><td style="text-align: right">';
$shtml .= $completion->get_status();
$shtml .= '</td></tr>';
$row = new html_table_row();
$row->cells[0] = new html_table_cell($criteria->get_title());
$row->cells[1] = new html_table_cell($completion->get_status());
$row->cells[1]->style = 'text-align: right;';
$srows[] = $row;
}
// Aggregate activities
// Aggregate activities.
if (!empty($activities)) {
$shtml .= '<tr><td>';
$shtml .= get_string('activitiescompleted', 'completion');
$shtml .= '</td><td style="text-align: right">';
$a = new stdClass();
$a->first = $activities_complete;
$a->second = count($activities);
$shtml .= get_string('firstofsecond', 'block_completionstatus', $a);
$shtml .= '</td></tr>';
$row = new html_table_row();
$row->cells[0] = new html_table_cell(get_string('activitiescompleted', 'completion'));
$row->cells[1] = new html_table_cell(get_string('firstofsecond', 'block_completionstatus', $a));
$row->cells[1]->style = 'text-align: right;';
$srows[] = $row;
}
// Aggregate prerequisites
// Aggregate prerequisites.
if (!empty($prerequisites)) {
$phtml = '<tr><td>';
$phtml .= get_string('dependenciescompleted', 'completion');
$phtml .= '</td><td style="text-align: right">';
$a = new stdClass();
$a->first = $prerequisites_complete;
$a->second = count($prerequisites);
$phtml .= get_string('firstofsecond', 'block_completionstatus', $a);
$phtml .= '</td></tr>';
$shtml = $phtml . $shtml;
$row = new html_table_row();
$row->cells[0] = new html_table_cell(get_string('dependenciescompleted', 'completion'));
$row->cells[1] = new html_table_cell(get_string('firstofsecond', 'block_completionstatus', $a));
$row->cells[1]->style = 'text-align: right;';
$prows[] = $row;
$srows = array_merge($prows, $srows);
}
// 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> ';
// Display completion status.
$table = new html_table();
$table->width = '100%';
$table->attributes = array('style'=>'font-size: 90%;', 'class'=>'');
$row = new html_table_row();
$content = html_writer::tag('b', get_string('status').': ');
// Is course complete?
$coursecomplete = $info->is_course_complete($USER->id);
// Load course completion
// Load course completion.
$params = array(
'userid' => $USER->id,
'course' => $course->id
@ -190,45 +194,61 @@ class block_completionstatus extends block_base {
$criteriacomplete = $info->count_course_user_data($USER->id);
if ($pending_update) {
$this->content->text .= '<i>'.get_string('pending', 'completion').'</i>';
$content .= html_writer::tag('i', get_string('pending', 'completion'));
} else if ($coursecomplete) {
$this->content->text .= get_string('complete');
$content .= get_string('complete');
} else if (!$criteriacomplete && !$ccompletion->timestarted) {
$this->content->text .= '<i>'.get_string('notyetstarted', 'completion').'</i>';
$content .= html_writer::tag('i', get_string('notyetstarted', 'completion'));
} else {
$this->content->text .= '<i>'.get_string('inprogress','completion').'</i>';
$content .= html_writer::tag('i', get_string('inprogress', 'completion'));
}
$this->content->text .= '</td></tr>';
$this->content->text .= '<tr><td colspan="2">';
$row->cells[0] = new html_table_cell($content);
$row->cells[0]->colspan = '2';
// Get overall aggregation method
$rows[] = $row;
$row = new html_table_row();
$content = "";
// Get overall aggregation method.
$overall = $info->get_aggregation_method();
if ($overall == COMPLETION_AGGREGATION_ALL) {
$this->content->text .= get_string('criteriarequiredall', 'completion');
$content .= get_string('criteriarequiredall', 'completion');
} else {
$this->content->text .= get_string('criteriarequiredany', 'completion');
$content .= get_string('criteriarequiredany', 'completion');
}
$content .= ':';
$row->cells[0] = new html_table_cell($content);
$row->cells[0]->colspan = '2';
$rows[] = $row;
$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>';
$row = new html_table_row();
$row->cells[0] = new html_table_cell(html_writer::tag('b', get_string('requiredcriteria', 'completion')));
$row->cells[1] = new html_table_cell(html_writer::tag('b', get_string('status')));
$row->cells[1]->style = 'text-align: right;';
$rows[] = $row;
// Display link to detailed view
// Array merge $rows and $data here.
$rows = array_merge($rows, $srows);
$table->data = $rows;
$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 = '<br><a href="'.$details->out().'">'.get_string('moredetails', 'completion').'</a>';
$this->content->footer = html_writer::empty_tag('br');
$this->content->footer = html_writer::tag('a', get_string('moredetails', 'completion'), array('href'=>$details->out()));
} else {
// If user is not enrolled, show error
// If user is not enrolled, show error.
$this->content->text = get_string('nottracked', 'completion');
}
if (has_capability('report/completion:view', $context)) {
$report = new moodle_url('/report/completion/index.php', array('course' => $course->id));
$this->content->footer .= '<br /><a href="'.$report->out().'">'.get_string('viewcoursereport', 'completion').'</a>';
$this->content->footer .= html_writer::empty_tag('br');
$this->content->footer .= html_writer::tag('a', get_string('viewcoursereport', 'completion'),
array('href'=>$report->out()));
}
return $this->content;
}
}

View file

@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@ -57,13 +56,9 @@ function xmldb_block_completionstatus_upgrade($oldversion, $block) {
foreach ($blocks as $block) {
blocks_delete_instance($block);
}
}
// Savepoint reached.
upgrade_block_savepoint(true, 2012112901, 'completionstatus');
}
return true;
}

View file

@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Block for displayed logged in user's course completion status
* Block for displaying logged in user's course completion status
*
* @package block
* @subpackage completion
@ -27,43 +27,38 @@
require_once(dirname(__FILE__).'/../../config.php');
require_once("{$CFG->libdir}/completionlib.php");
///
/// Load data
///
// Load data.
$id = required_param('course', PARAM_INT);
$userid = optional_param('user', 0, PARAM_INT);
// Load course
// Load course.
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
// Load user
// Load user.
if ($userid) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
} else {
$user = $USER;
}
// Check permissions
// Check permissions.
require_login();
if (!completion_can_view_data($user->id, $course)) {
print_error('cannotviewreport');
}
// Load completion data
// Load completion data.
$info = new completion_info($course);
$returnurl = new moodle_url('/course/view.php', array('id' => $id));
// Don't display if completion isn't enabled!
// Don't display if completion isn't enabled.
if (!$info->is_enabled()) {
print_error('completionnotenabled', 'completion', $returnurl);
}
// Check this user is enroled
// Check this user is enroled.
if (!$info->is_tracked_user($user->id)) {
if ($USER->id == $user->id) {
print_error('notenroled', 'completion', $returnurl);
@ -72,13 +67,11 @@ if (!$info->is_tracked_user($user->id)) {
}
}
// Display page.
///
/// Display page
///
$PAGE->set_context(context_course::instance($course->id));
// Print header
// Print header.
$page = get_string('completionprogressdetails', 'block_completionstatus');
$title = format_string($course->fullname) . ': ' . $page;
@ -90,17 +83,24 @@ $PAGE->set_heading($title);
echo $OUTPUT->header();
// Display completion status
echo '<table class="generaltable boxaligncenter"><tbody>';
// Display completion status.
echo html_writer::start_tag('table', array('class' => 'generalbox boxaligncenter'));
echo html_writer::start_tag('tbody');
// If not display logged in user, show user name
// If not display logged in user, show user name.
if ($USER->id != $user->id) {
echo '<tr><td colspan="2"><b>'.get_string('showinguser', 'completion').'</b>: ';
echo '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a>';
echo '</td></tr>';
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('showinguser', 'completion'));
$url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
echo html_writer::link($url, fullname($user));
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
}
echo '<tr><td colspan="2"><b>'.get_string('status').':</b> ';
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('status'));
// Is course complete?
$coursecomplete = $info->is_course_complete($user->id);
@ -108,7 +108,7 @@ $coursecomplete = $info->is_course_complete($user->id);
// Has this user completed any criteria?
$criteriacomplete = $info->count_course_user_data($user->id);
// Load course completion
// Load course completion.
$params = array(
'userid' => $user->id,
'course' => $course->id,
@ -118,25 +118,33 @@ $ccompletion = new completion_completion($params);
if ($coursecomplete) {
echo get_string('complete');
} else if (!$criteriacomplete && !$ccompletion->timestarted) {
echo '<i>'.get_string('notyetstarted', 'completion').'</i>';
echo html_writer::tag('i', get_string('notyetstarted', 'completion'));
} else {
echo '<i>'.get_string('inprogress','completion').'</i>';
echo html_writer::tag('i', get_string('inprogress', 'completion'));
}
echo '</td></tr>';
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
// Load criteria to display
// Load criteria to display.
$completions = $info->get_completions($user->id);
// Check if this course has any criteria
// Check if this course has any criteria.
if (empty($completions)) {
echo '<tr><td colspan="2"><br />';
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::start_tag('br');
echo $OUTPUT->box(get_string('err_nocriteria', 'completion'), 'noticebox');
echo '</td></tr></tbody></table>';
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
} else {
echo '<tr><td colspan="2"><b>'.get_string('required').':</b> ';
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('required'));
// Get overall aggregation method
// Get overall aggregation method.
$overall = $info->get_aggregation_method();
if ($overall == COMPLETION_AGGREGATION_ALL) {
@ -145,23 +153,28 @@ if (empty($completions)) {
echo get_string('criteriarequiredany', 'completion');
}
echo '</td></tr></tbody></table>';
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
// Generate markup for criteria statuses
echo '<table class="generaltable 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>';
// Generate markup for criteria statuses.
echo html_writer::start_tag('table',
array('class' => 'generalbox logtable boxaligncenter', 'id' => 'criteriastatus', 'width' => '100%'));
echo html_writer::start_tag('tbody');
echo html_writer::start_tag('tr', array('class' => 'ccheader'));
echo html_writer::tag('th', get_string('criteriagroup', 'block_completionstatus'), array('class' => 'c0 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('criteria', 'completion'), array('class' => 'c1 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('requirement', 'block_completionstatus'), array('class' => 'c2 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('status'), array('class' => 'c3 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('complete'), array('class' => 'c4 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('completiondate', 'report_completion'), array('class' => 'c5 header', 'scope' => 'col'));
echo html_writer::end_tag('tr');
// Save row data
// Save row data.
$rows = array();
// Loop through course criteria
// Loop through course criteria.
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
@ -175,81 +188,77 @@ if (empty($completions)) {
$rows[] = $row;
}
// Print table
// Print table.
$last_type = '';
$agg_type = false;
$oddeven = 0;
foreach ($rows as $row) {
echo '<tr class="r' . $oddeven . '">';
// Criteria group
echo '<td class="cell c0">';
echo html_writer::start_tag('tr', array('class' => 'r' . $oddeven));
// Criteria group.
echo html_writer::start_tag('td', array('class' => 'cell c0'));
if ($last_type !== $row['details']['type']) {
$last_type = $row['details']['type'];
echo $last_type;
// Reset agg type
// Reset agg type.
$agg_type = true;
} else {
// Display aggregation type
// Display aggregation type.
if ($agg_type) {
$agg = $info->get_aggregation_method($row['type']);
echo '(<i>';
echo '('. html_writer::start_tag('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')).')';
echo html_writer::end_tag('i') .strtolower(get_string('required')).')';
$agg_type = false;
}
}
echo '</td>';
echo html_writer::end_tag('td');
// Criteria title
echo '<td class="cell c1">';
// Criteria title.
echo html_writer::start_tag('td', array('class' => 'cell c1'));
echo $row['details']['criteria'];
echo '</td>';
echo html_writer::end_tag('td');
// Requirement
echo '<td class="cell c2">';
// Requirement.
echo html_writer::start_tag('td', array('class' => 'cell c2'));
echo $row['details']['requirement'];
echo '</td>';
echo html_writer::end_tag('td');
// Status
echo '<td class="cell c3">';
// Status.
echo html_writer::start_tag('td', array('class' => 'cell c3'));
echo $row['details']['status'];
echo '</td>';
echo html_writer::end_tag('td');
// Is complete
echo '<td class="cell c4">';
// Is complete.
echo html_writer::start_tag('td', array('class' => 'cell c4'));
echo $row['complete'] ? get_string('yes') : get_string('no');
echo '</td>';
echo html_writer::end_tag('td');
// Completion data
echo '<td class="cell c5">';
// Completion data.
echo html_writer::start_tag('td', array('class' => 'cell c5'));
if ($row['timecompleted']) {
echo userdate($row['timecompleted'], get_string('strftimedate', 'langconfig'));
} else {
echo '-';
}
echo '</td>';
echo '</tr>';
// for row striping
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
// For row striping.
$oddeven = $oddeven ? 0 : 1;
}
echo '</tbody></table>';
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
}
echo '<div class="buttons">';
$courseurl = new moodle_url("/course/view.php", array('id' => $course->id));
echo html_writer::start_tag('div', array('class' => 'buttons'));
echo $OUTPUT->single_button($courseurl, get_string('returntocourse', 'block_completionstatus'), 'get');
echo '</div>';
echo html_writer::end_tag('div');
echo $OUTPUT->footer();

View file

@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify

View file

@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2012112901; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012112900; // Requires this Moodle version
$plugin->version = 2012112901; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2012112900; // Requires this Moodle version.
$plugin->component = 'block_completionstatus';
$plugin->dependencies = array('report_completion' => 2012112900);

View file

@ -32,6 +32,9 @@
.block.hidden .block-hider-hide {display:none;}
.block.hidden .block-hider-show {display:inline;}
.block_completionstatus .generaltable { border: 0px; }
.block_completionstatus .generaltable .cell { border: 0px; }
/** Overide for RTL layout **/
.dir-rtl .block .header,
.dir-rtl .block h2.header {text-align:right;}

View file

@ -1,6 +1,11 @@
This files describes API changes in /theme/* themes,
information provided here is intended especially for theme designer.
=== 2.6 ===
* re-wrote the table for the course completion status block to use html_table - added some CSS classes to the table in the process.
MDL-35608 - Blocks - Updating the Completion Status block to use HTML Writer
=== 2.5 ===
required changes: