diff --git a/block_completion_progress.php b/block_completion_progress.php index 2683790..6a6ef9a 100644 --- a/block_completion_progress.php +++ b/block_completion_progress.php @@ -127,7 +127,13 @@ class block_completion_progress extends block_base { return $this->content; } + // Show a message when the user is not enrolled in any 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') ?: DEFAULT_COMPLETIONPROGRESS_COURSENAMETOSHOW; $sql = "SELECT bi.id, diff --git a/lang/en/block_completion_progress.php b/lang/en/block_completion_progress.php index 8befed3..f49589d 100644 --- a/lang/en/block_completion_progress.php +++ b/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_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_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['not_all_expected_set'] = 'Not all activities with completion have an "{$a}" date set.'; $string['notCompleted_colour'] = '#C71C22'; diff --git a/lib.php b/lib.php index d490351..4bb4aa6 100644 --- a/lib.php +++ b/lib.php @@ -317,8 +317,8 @@ function block_completion_progress_completions($activities, $userid, $course, $s foreach ($activities as $activity) { $cm->id = $activity['id']; $activitycompletion = $completion->get_data($cm, true, $userid); - $completions[$activity['id']] = $activitycompletion->completionstate >= 1; - if (!$completions[$activity['id']] && in_array($activity['id'], $submissions)) { + $completions[$activity['id']] = $activitycompletion->completionstate; + if ($completions[$activity['id']] === COMPLETION_INCOMPLETE && in_array($activity['id'], $submissions)) { $completions[$activity['id']] = 'submitted'; } } @@ -342,6 +342,7 @@ function block_completion_progress_bar($activities, $completions, $config, $user global $OUTPUT, $CFG, $USER; $content = ''; $now = time(); + $usingrtl = right_to_left(); $numactivities = count($activities); $dateformat = get_string('strftimedate', 'langconfig'); $alternatelinks = block_completion_progress_modules_with_alternate_links(); @@ -366,6 +367,7 @@ function block_completion_progress_bar($activities, $completions, $config, $user $displaynow = $orderby == 'orderbytime'; $showpercentage = isset($config->showpercentage) ? $config->showpercentage : DEFAULT_COMPLETIONPROGRESS_SHOWPERCENTAGE; $rowoptions = array(); + $rowoptions['style'] = ''; $content .= HTML_WRITER::start_div('barContainer'); // Determine the segment width. @@ -384,7 +386,7 @@ function block_completion_progress_bar($activities, $completions, $config, $user $cellwidth = DEFAULT_COMPLETIONPROGRESS_SCROLLCELLWIDTH; $cellunit = 'px'; $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')); $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')); @@ -396,7 +398,8 @@ function block_completion_progress_bar($activities, $completions, $config, $user $celldisplay = 'table-cell'; } - // Place now arrow. + // Determine where to put the NOW indicator. + $nowpos = -1; if ($orderby == 'orderbytime' && $longbars != 'wrap' && $displaynow == 1 && !$simple) { // 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) { $nowpos++; } - $content .= HTML_WRITER::start_div('nowRow', $rowoptions); + $rowoptions['style'] .= 'margin-top: 25px;'; $nowstring = get_string('now_indicator', 'block_completion_progress'); - if ($nowpos < $numactivities / 2) { - for ($i = 0; $i < $nowpos; $i++) { - $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(); + $leftarrowimg = $OUTPUT->pix_icon('left', $nowstring, 'block_completion_progress', array('class' => 'nowicon')); + $rightarrowimg = $OUTPUT->pix_icon('right', $nowstring, 'block_completion_progress', array('class' => 'nowicon')); } // Determine links to activities. @@ -462,11 +450,12 @@ function block_completion_progress_bar($activities, $completions, $config, $user $celloptions['style'] .= $colours['submittednotcomplete_colour'].';'; $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'].';'; $cellcontent = $OUTPUT->pix_icon($useicons == 1 ? 'tick' : 'blank', '', 'block_completion_progress'); } else if ( + $complete == COMPLETION_COMPLETE_FAIL || (!isset($config->orderby) || $config->orderby == 'orderbytime') && (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) { $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++; $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'); // 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) { $completed = $completions[$activity['id']]; $divoptions = array('class' => 'progressEventInfo', @@ -535,17 +546,23 @@ function block_completion_progress_bar($activities, $completions, $config, $user $content .= $text; } $content .= HTML_WRITER::empty_tag('br'); - if ($completed && $completed !== 'failed' && $completed !== 'submitted') { - $content .= get_string('completed', 'completion').' '; + if ($completed == COMPLETION_COMPLETE) { + $content .= $stringcomplete.' '; + $icon = 'tick'; + } else if ($completed == COMPLETION_COMPLETE_PASS) { + $content .= $stringpassed.' '; $icon = 'tick'; + } else if ($completed == COMPLETION_COMPLETE_FAIL) { + $content .= $stringfailed.' '; + $icon = 'cross'; } else { - $content .= get_string('completion-n', 'completion').' '; + $content .= $stringincomplete .' '; $icon = 'cross'; + if ($completed === 'submitted') { + $content .= '(' . $stringsubmitted . ') '; + } } $content .= $OUTPUT->pix_icon($icon, '', 'block_completion_progress', array('class' => 'iconInInfo')); - if ($completed === 'submitted') { - $content .= ' (' . get_string('submitted', 'block_completion_progress') . ')'; - } $content .= HTML_WRITER::empty_tag('br'); if ($activity['expected'] != 0) { $content .= HTML_WRITER::start_tag('div', array('class' => 'expectedBy')); @@ -570,7 +587,10 @@ function block_completion_progress_percentage($activities, $completions) { $completecount = 0; foreach ($activities as $activity) { - if ($completions[$activity['id']] == 1) { + if ( + $completions[$activity['id']] == COMPLETION_COMPLETE || + $completions[$activity['id']] == COMPLETION_COMPLETE_PASS) + { $completecount++; } } diff --git a/overview.php b/overview.php index 591eb48..7ef5112 100644 --- a/overview.php +++ b/overview.php @@ -183,7 +183,7 @@ $submissions = block_completion_progress_course_submissions($course->id); foreach ($submissions as $mapping) { $mapvalues = explode('-', $mapping); $index = 0; - while ($users[$index]->id != $mapvalues[0] && $index < $numberofusers) { + while ($index < $numberofusers && $users[$index]->id != $mapvalues[0]) { $index++; } if ($index < $numberofusers) { diff --git a/styles.css b/styles.css index f53909b..2cbb4f0 100644 --- a/styles.css +++ b/styles.css @@ -32,6 +32,7 @@ .block_completion_progress .nowRow .blankDiv { display: table-cell; + height: 25px; } .block_completion_progress .progressBarCell { @@ -43,14 +44,59 @@ cursor: pointer; border-left: 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 { border-radius: 4px 0 0 4px; 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-left: solid 1px #e3e3e3; } @@ -59,9 +105,10 @@ 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-left: none; + border-right: solid 1px #e3e3e3; } .block_completion_progress .progressBarCell img { diff --git a/version.php b/version.php index 83f6ac7..22f14ef 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2016051400; +$plugin->version = 2016061800; $plugin->requires = 2014051200; // Moodle 2.7. -$plugin->maturity = MATURITY_RC; +$plugin->maturity = MATURITY_STABLE; $plugin->release = 'Version for Moodle 2.7 onwards'; $plugin->component = 'block_completion_progress';