Browse Source

CONTRIB-6503 block_completion_progress: Fix pass/fail completion

master
Michael de Raadt 9 years ago
parent
commit
9baf619578
  1. 6
      block_completion_progress.php
  2. 1
      lang/en/block_completion_progress.php
  3. 80
      lib.php
  4. 2
      overview.php
  5. 51
      styles.css
  6. 4
      version.php

6
block_completion_progress.php

@ -127,7 +127,13 @@ class block_completion_progress extends block_base {
return $this->content; return $this->content;
} }
// Show a message when the user is not enrolled in any courses.
$courses = enrol_get_my_courses(); $courses = enrol_get_my_courses();
if (($this->page->user_is_editing() || is_siteadmin()) && empty($courses)) {
$this->content->text = get_string('no_courses', 'block_completion_progress');
return $this->content;
}
$coursenametoshow = get_config('block_completion_progress', 'coursenametoshow') ?: $coursenametoshow = get_config('block_completion_progress', 'coursenametoshow') ?:
DEFAULT_COMPLETIONPROGRESS_COURSENAMETOSHOW; DEFAULT_COMPLETIONPROGRESS_COURSENAMETOSHOW;
$sql = "SELECT bi.id, $sql = "SELECT bi.id,

1
lang/en/block_completion_progress.php

@ -69,6 +69,7 @@ $string['mouse_over_prompt'] = 'Mouse over or touch bar for info.';
$string['no_activities_config_message'] = 'There are no activities or resources with activity completion set or no activities or resources have been selected. Set activity completion on activities and resources then configure this block.'; $string['no_activities_config_message'] = 'There are no activities or resources with activity completion set or no activities or resources have been selected. Set activity completion on activities and resources then configure this block.';
$string['no_activities_message'] = 'No activities or resources are being monitored. Use config to set up monitoring.'; $string['no_activities_message'] = 'No activities or resources are being monitored. Use config to set up monitoring.';
$string['no_blocks'] = 'No Completion Progress blocks are set up for your courses.'; $string['no_blocks'] = 'No Completion Progress blocks are set up for your courses.';
$string['no_courses'] = "You are not enrolled in any courses. Only bars from enrolled courses will be shown.";
$string['no_visible_activities_message'] = 'None of the monitored activities are currently visible.'; $string['no_visible_activities_message'] = 'None of the monitored activities are currently visible.';
$string['not_all_expected_set'] = 'Not all activities with completion have an "{$a}" date set.'; $string['not_all_expected_set'] = 'Not all activities with completion have an "{$a}" date set.';
$string['notCompleted_colour'] = '#C71C22'; $string['notCompleted_colour'] = '#C71C22';

80
lib.php

@ -317,8 +317,8 @@ function block_completion_progress_completions($activities, $userid, $course, $s
foreach ($activities as $activity) { foreach ($activities as $activity) {
$cm->id = $activity['id']; $cm->id = $activity['id'];
$activitycompletion = $completion->get_data($cm, true, $userid); $activitycompletion = $completion->get_data($cm, true, $userid);
$completions[$activity['id']] = $activitycompletion->completionstate >= 1; $completions[$activity['id']] = $activitycompletion->completionstate;
if (!$completions[$activity['id']] && in_array($activity['id'], $submissions)) { if ($completions[$activity['id']] === COMPLETION_INCOMPLETE && in_array($activity['id'], $submissions)) {
$completions[$activity['id']] = 'submitted'; $completions[$activity['id']] = 'submitted';
} }
} }
@ -342,6 +342,7 @@ function block_completion_progress_bar($activities, $completions, $config, $user
global $OUTPUT, $CFG, $USER; global $OUTPUT, $CFG, $USER;
$content = ''; $content = '';
$now = time(); $now = time();
$usingrtl = right_to_left();
$numactivities = count($activities); $numactivities = count($activities);
$dateformat = get_string('strftimedate', 'langconfig'); $dateformat = get_string('strftimedate', 'langconfig');
$alternatelinks = block_completion_progress_modules_with_alternate_links(); $alternatelinks = block_completion_progress_modules_with_alternate_links();
@ -366,6 +367,7 @@ function block_completion_progress_bar($activities, $completions, $config, $user
$displaynow = $orderby == 'orderbytime'; $displaynow = $orderby == 'orderbytime';
$showpercentage = isset($config->showpercentage) ? $config->showpercentage : DEFAULT_COMPLETIONPROGRESS_SHOWPERCENTAGE; $showpercentage = isset($config->showpercentage) ? $config->showpercentage : DEFAULT_COMPLETIONPROGRESS_SHOWPERCENTAGE;
$rowoptions = array(); $rowoptions = array();
$rowoptions['style'] = '';
$content .= HTML_WRITER::start_div('barContainer'); $content .= HTML_WRITER::start_div('barContainer');
// Determine the segment width. // Determine the segment width.
@ -384,7 +386,7 @@ function block_completion_progress_bar($activities, $completions, $config, $user
$cellwidth = DEFAULT_COMPLETIONPROGRESS_SCROLLCELLWIDTH; $cellwidth = DEFAULT_COMPLETIONPROGRESS_SCROLLCELLWIDTH;
$cellunit = 'px'; $cellunit = 'px';
$celldisplay = 'inline-block'; $celldisplay = 'inline-block';
$rowoptions['style'] = 'white-space: nowrap;'; $rowoptions['style'] .= 'white-space: nowrap;';
$leftpoly = HTML_WRITER::tag('polygon', '', array('points' => '30,0 0,15 30,30', 'class' => 'triangle-polygon')); $leftpoly = HTML_WRITER::tag('polygon', '', array('points' => '30,0 0,15 30,30', 'class' => 'triangle-polygon'));
$rightpoly = HTML_WRITER::tag('polygon', '', array('points' => '0,0 30,15 0,30', 'class' => 'triangle-polygon')); $rightpoly = HTML_WRITER::tag('polygon', '', array('points' => '0,0 30,15 0,30', 'class' => 'triangle-polygon'));
$content .= HTML_WRITER::tag('svg', $leftpoly, array('class' => 'left-arrow-svg', 'height' => '30', 'width' => '30')); $content .= HTML_WRITER::tag('svg', $leftpoly, array('class' => 'left-arrow-svg', 'height' => '30', 'width' => '30'));
@ -396,7 +398,8 @@ function block_completion_progress_bar($activities, $completions, $config, $user
$celldisplay = 'table-cell'; $celldisplay = 'table-cell';
} }
// Place now arrow. // Determine where to put the NOW indicator.
$nowpos = -1;
if ($orderby == 'orderbytime' && $longbars != 'wrap' && $displaynow == 1 && !$simple) { if ($orderby == 'orderbytime' && $longbars != 'wrap' && $displaynow == 1 && !$simple) {
// Find where to put now arrow. // Find where to put now arrow.
@ -404,25 +407,10 @@ function block_completion_progress_bar($activities, $completions, $config, $user
while ($nowpos < $numactivities && $now > $activities[$nowpos]['expected'] && $activities[$nowpos]['expected'] != 0) { while ($nowpos < $numactivities && $now > $activities[$nowpos]['expected'] && $activities[$nowpos]['expected'] != 0) {
$nowpos++; $nowpos++;
} }
$content .= HTML_WRITER::start_div('nowRow', $rowoptions); $rowoptions['style'] .= 'margin-top: 25px;';
$nowstring = get_string('now_indicator', 'block_completion_progress'); $nowstring = get_string('now_indicator', 'block_completion_progress');
if ($nowpos < $numactivities / 2) { $leftarrowimg = $OUTPUT->pix_icon('left', $nowstring, 'block_completion_progress', array('class' => 'nowicon'));
for ($i = 0; $i < $nowpos; $i++) { $rightarrowimg = $OUTPUT->pix_icon('right', $nowstring, 'block_completion_progress', array('class' => 'nowicon'));
$content .= HTML_WRITER::div(null, 'blankDiv', array('style' => "width:$cellwidth$cellunit;"));
}
$celloptions = array('style' => "text-align:left; width:$cellwidth;");
$content .= HTML_WRITER::start_div('nowDiv', $celloptions);
$content .= $OUTPUT->pix_icon('left', $nowstring, 'block_completion_progress', array('class' => 'nowicon'));
$content .= $nowstring;
$content .= HTML_WRITER::end_div();
} else {
$celloptions = array('style' => 'text-align:right; width:'. ($cellwidth * $nowpos) . $cellunit .';');
$content .= HTML_WRITER::start_div('nowdiv', $celloptions);
$content .= $nowstring;
$content .= $OUTPUT->pix_icon('right', $nowstring, 'block_completion_progress', array('class' => 'nowicon'));
$content .= HTML_WRITER::end_div();
}
$content .= HTML_WRITER::end_div();
} }
// Determine links to activities. // Determine links to activities.
@ -462,11 +450,12 @@ function block_completion_progress_bar($activities, $completions, $config, $user
$celloptions['style'] .= $colours['submittednotcomplete_colour'].';'; $celloptions['style'] .= $colours['submittednotcomplete_colour'].';';
$cellcontent = $OUTPUT->pix_icon('blank', '', 'block_completion_progress'); $cellcontent = $OUTPUT->pix_icon('blank', '', 'block_completion_progress');
} else if ($complete === true) { } else if ($complete == COMPLETION_COMPLETE || $complete == COMPLETION_COMPLETE_PASS) {
$celloptions['style'] .= $colours['completed_colour'].';'; $celloptions['style'] .= $colours['completed_colour'].';';
$cellcontent = $OUTPUT->pix_icon($useicons == 1 ? 'tick' : 'blank', '', 'block_completion_progress'); $cellcontent = $OUTPUT->pix_icon($useicons == 1 ? 'tick' : 'blank', '', 'block_completion_progress');
} else if ( } else if (
$complete == COMPLETION_COMPLETE_FAIL ||
(!isset($config->orderby) || $config->orderby == 'orderbytime') && (!isset($config->orderby) || $config->orderby == 'orderbytime') &&
(isset($activity['expected']) && $activity['expected'] > 0 && $activity['expected'] < $now) (isset($activity['expected']) && $activity['expected'] > 0 && $activity['expected'] < $now)
) { ) {
@ -488,6 +477,23 @@ function block_completion_progress_bar($activities, $completions, $config, $user
if ($longbars != 'wrap' && $counter == $numactivities) { if ($longbars != 'wrap' && $counter == $numactivities) {
$celloptions['class'] .= ' lastProgressBarCell'; $celloptions['class'] .= ' lastProgressBarCell';
} }
// Place the NOW indicator.
if ($nowpos >= 0) {
if ($nowpos == 0 && $counter == 1) {
$nowcontent = $usingrtl ? $rightarrowimg.$nowstring : $leftarrowimg.$nowstring;
$cellcontent .= HTML_WRITER::div($nowcontent, 'nowDiv firstNow');
} else if ($nowpos == $counter) {
if ($nowpos < $numactivities / 2) {
$nowcontent = $usingrtl ? $rightarrowimg.$nowstring : $leftarrowimg.$nowstring;
$cellcontent .= HTML_WRITER::div($nowcontent, 'nowDiv firstHalfNow');
} else {
$nowcontent = $usingrtl ? $nowstring.$leftarrowimg : $nowstring.$rightarrowimg;
$cellcontent .= HTML_WRITER::div($nowcontent, 'nowDiv lastHalfNow');
}
}
}
$counter++; $counter++;
$content .= HTML_WRITER::div($cellcontent, null, $celloptions); $content .= HTML_WRITER::div($cellcontent, null, $celloptions);
} }
@ -518,6 +524,11 @@ function block_completion_progress_bar($activities, $completions, $config, $user
$content .= HTML_WRITER::end_tag('div'); $content .= HTML_WRITER::end_tag('div');
// Add hidden divs for activity information. // Add hidden divs for activity information.
$stringincomplete = get_string('completion-n', 'completion');
$stringcomplete = get_string('completed', 'completion');
$stringpassed = get_string('completion-pass', 'completion');
$stringfailed = get_string('completion-fail', 'completion');
$stringsubmitted = get_string('submitted', 'block_completion_progress');
foreach ($activities as $activity) { foreach ($activities as $activity) {
$completed = $completions[$activity['id']]; $completed = $completions[$activity['id']];
$divoptions = array('class' => 'progressEventInfo', $divoptions = array('class' => 'progressEventInfo',
@ -535,17 +546,23 @@ function block_completion_progress_bar($activities, $completions, $config, $user
$content .= $text; $content .= $text;
} }
$content .= HTML_WRITER::empty_tag('br'); $content .= HTML_WRITER::empty_tag('br');
if ($completed && $completed !== 'failed' && $completed !== 'submitted') { if ($completed == COMPLETION_COMPLETE) {
$content .= get_string('completed', 'completion').'&nbsp;'; $content .= $stringcomplete.'&nbsp;';
$icon = 'tick'; $icon = 'tick';
} else if ($completed == COMPLETION_COMPLETE_PASS) {
$content .= $stringpassed.'&nbsp;';
$icon = 'tick';
} else if ($completed == COMPLETION_COMPLETE_FAIL) {
$content .= $stringfailed.'&nbsp;';
$icon = 'cross';
} else { } else {
$content .= get_string('completion-n', 'completion').'&nbsp;'; $content .= $stringincomplete .'&nbsp;';
$icon = 'cross'; $icon = 'cross';
}
$content .= $OUTPUT->pix_icon($icon, '', 'block_completion_progress', array('class' => 'iconInInfo'));
if ($completed === 'submitted') { if ($completed === 'submitted') {
$content .= ' (' . get_string('submitted', 'block_completion_progress') . ')'; $content .= '(' . $stringsubmitted . ')&nbsp;';
}
} }
$content .= $OUTPUT->pix_icon($icon, '', 'block_completion_progress', array('class' => 'iconInInfo'));
$content .= HTML_WRITER::empty_tag('br'); $content .= HTML_WRITER::empty_tag('br');
if ($activity['expected'] != 0) { if ($activity['expected'] != 0) {
$content .= HTML_WRITER::start_tag('div', array('class' => 'expectedBy')); $content .= HTML_WRITER::start_tag('div', array('class' => 'expectedBy'));
@ -570,7 +587,10 @@ function block_completion_progress_percentage($activities, $completions) {
$completecount = 0; $completecount = 0;
foreach ($activities as $activity) { foreach ($activities as $activity) {
if ($completions[$activity['id']] == 1) { if (
$completions[$activity['id']] == COMPLETION_COMPLETE ||
$completions[$activity['id']] == COMPLETION_COMPLETE_PASS)
{
$completecount++; $completecount++;
} }
} }

2
overview.php

@ -183,7 +183,7 @@ $submissions = block_completion_progress_course_submissions($course->id);
foreach ($submissions as $mapping) { foreach ($submissions as $mapping) {
$mapvalues = explode('-', $mapping); $mapvalues = explode('-', $mapping);
$index = 0; $index = 0;
while ($users[$index]->id != $mapvalues[0] && $index < $numberofusers) { while ($index < $numberofusers && $users[$index]->id != $mapvalues[0]) {
$index++; $index++;
} }
if ($index < $numberofusers) { if ($index < $numberofusers) {

51
styles.css

@ -32,6 +32,7 @@
.block_completion_progress .nowRow .blankDiv { .block_completion_progress .nowRow .blankDiv {
display: table-cell; display: table-cell;
height: 25px;
} }
.block_completion_progress .progressBarCell { .block_completion_progress .progressBarCell {
@ -43,14 +44,59 @@
cursor: pointer; cursor: pointer;
border-left: solid 1px #e3e3e3; border-left: solid 1px #e3e3e3;
border-top: solid 1px #e3e3e3; border-top: solid 1px #e3e3e3;
position: relative;
}
.block_completion_progress .progressBarCell .nowDiv {
position: absolute;
top: -25px;
white-space: nowrap;
width: 100px;
}
.block_completion_progress .progressBarCell .firstNow {
left: 0;
text-align: left;
}
.dir-rtl .block_completion_progress .progressBarCell .firstNow {
right: 0;
text-align: right;
}
.block_completion_progress .progressBarCell .firstHalfNow {
left: 100%;
text-align: left;
}
.dir-rtl .block_completion_progress .progressBarCell .firstHalfNow {
right: 100%;
left: initial;
text-align: right;
}
.block_completion_progress .progressBarCell .lastHalfNow {
right: 0;
text-align: right;
}
.dir-rtl .block_completion_progress .progressBarCell .lastHalfNow {
left: 0;
text-align: left;
right: initial;
}
.block_completion_progress .progressBarCell .nowicon {
width: auto;
} }
.block_completion_progress .progressBarCell.firstProgressBarCell { .block_completion_progress .progressBarCell.firstProgressBarCell {
border-radius: 4px 0 0 4px; border-radius: 4px 0 0 4px;
border-left: none; border-left: none;
border-right: solid 1px #e3e3e3;
} }
.dir-rtl .block_progress .progressBarCell.firstProgressBarCell { .dir-rtl .block_completion_progress .progressBarCell.firstProgressBarCell {
border-radius: 0px 4px 4px 0px; border-radius: 0px 4px 4px 0px;
border-left: solid 1px #e3e3e3; border-left: solid 1px #e3e3e3;
} }
@ -59,9 +105,10 @@
border-radius: 0 4px 4px 0; border-radius: 0 4px 4px 0;
} }
.dir-rtl .block_progress .progressBarCell.lastProgressBarCell { .dir-rtl .block_completion_progress .progressBarCell.lastProgressBarCell {
border-radius: 4px 0px 0px 4px; border-radius: 4px 0px 0px 4px;
border-left: none; border-left: none;
border-right: solid 1px #e3e3e3;
} }
.block_completion_progress .progressBarCell img { .block_completion_progress .progressBarCell img {

4
version.php

@ -25,8 +25,8 @@
defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;
$plugin->version = 2016051400; $plugin->version = 2016061800;
$plugin->requires = 2014051200; // Moodle 2.7. $plugin->requires = 2014051200; // Moodle 2.7.
$plugin->maturity = MATURITY_RC; $plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Version for Moodle 2.7 onwards'; $plugin->release = 'Version for Moodle 2.7 onwards';
$plugin->component = 'block_completion_progress'; $plugin->component = 'block_completion_progress';

Loading…
Cancel
Save