From cfb005891878fe7a7e7c7eefd6d2edc69b705f6c Mon Sep 17 00:00:00 2001 From: dbnschools Date: Mon, 19 Nov 2018 10:13:21 -0500 Subject: [PATCH] Tab Topic Completion color change --- LICENSE | 0 README.txt | 0 .../restore_format_onetopic_plugin.class.php | 0 composer.json | 0 db/upgrade.php | 0 db/upgradelib.php | 0 duplicate.php | 0 format.js | 0 format.php | 2 +- lang/en/format_onetopic.php | 0 lang/es/format_onetopic.php | 0 lib.php | 0 renderer.php | 103 ++++++++++++++++-- styles.css | 4 + version.php | 0 15 files changed, 101 insertions(+), 8 deletions(-) mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.txt mode change 100644 => 100755 backup/moodle2/restore_format_onetopic_plugin.class.php mode change 100644 => 100755 composer.json mode change 100644 => 100755 db/upgrade.php mode change 100644 => 100755 db/upgradelib.php mode change 100644 => 100755 duplicate.php mode change 100644 => 100755 format.js mode change 100644 => 100755 format.php mode change 100644 => 100755 lang/en/format_onetopic.php mode change 100644 => 100755 lang/es/format_onetopic.php mode change 100644 => 100755 lib.php mode change 100644 => 100755 renderer.php mode change 100644 => 100755 styles.css mode change 100644 => 100755 version.php diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.txt b/README.txt old mode 100644 new mode 100755 diff --git a/backup/moodle2/restore_format_onetopic_plugin.class.php b/backup/moodle2/restore_format_onetopic_plugin.class.php old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 diff --git a/db/upgrade.php b/db/upgrade.php old mode 100644 new mode 100755 diff --git a/db/upgradelib.php b/db/upgradelib.php old mode 100644 new mode 100755 diff --git a/duplicate.php b/duplicate.php old mode 100644 new mode 100755 diff --git a/format.js b/format.js old mode 100644 new mode 100755 diff --git a/format.php b/format.php old mode 100644 new mode 100755 index 6d4adb4..20cfa23 --- a/format.php +++ b/format.php @@ -67,7 +67,7 @@ } else { if (isset($USER->display[$course->id]) && $renderer->numsections >= $USER->display[$course->id]) { $displaysection = $USER->display[$course->id]; - } else if ($course->marker && $course->marker > 0 && $course->marker < $renderer->numsections) { + } else if ($course->marker && $course->marker > 0) { $USER->display[$course->id] = $course->marker; $displaysection = $course->marker; } else { diff --git a/lang/en/format_onetopic.php b/lang/en/format_onetopic.php old mode 100644 new mode 100755 diff --git a/lang/es/format_onetopic.php b/lang/es/format_onetopic.php old mode 100644 new mode 100755 diff --git a/lib.php b/lib.php old mode 100644 new mode 100755 diff --git a/renderer.php b/renderer.php old mode 100644 new mode 100755 index 6a5e631..dde371d --- a/renderer.php +++ b/renderer.php @@ -314,9 +314,18 @@ public function print_single_section_page($course, $sections, $mods, $modnames, } } + + if ($this->section_activity_summary($thissection, $course, null)){ + $topiccomplete = 'topiccomplete'; + $topiccompleteicon = ' '; + } else { + $topiccomplete = ''; + $topiccompleteicon = ''; + } + $newtab = new tabobject("tab_topic_" . $section, $url, - '
' . - '' . $sectionname . "
", $sectionname); + '
' . + '' . $sectionname . "" . $topiccompleteicon . "
", $sectionname); if (is_array($formatoptions) && isset($formatoptions['level'])) { @@ -337,8 +346,15 @@ public function print_single_section_page($course, $sections, $mods, $modnames, } else { $firsttabtext = get_string('index', 'format_onetopic'); } - $tabs[$parentindex]->subtree[0]->text = '
' . - $firsttabtext . "
"; + if ($this->section_activity_summary($parentsection, $course, null)){ + $topiccomplete = 'topiccomplete'; + $topiccompleteicon = ' '; + } else { + $topiccomplete = ''; + $topiccompleteicon = ''; + } + $tabs[$parentindex]->subtree[0]->text = '
' . + $firsttabtext . "" . $topiccompleteicon . "
"; $tabs[$parentindex]->subtree[0]->level = 2; if ($displaysection == $section - 1) { @@ -431,7 +447,6 @@ public function print_single_section_page($course, $sections, $mods, $modnames, } else if ($this->_course->templatetopic == format_onetopic::TEMPLATETOPIC_LIST) { echo $this->custom_course_section_cm_list($course, $thissection, $displaysection); } - echo $this->courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection); echo $this->section_footer(); echo $this->end_section_list(); @@ -441,8 +456,8 @@ public function print_single_section_page($course, $sections, $mods, $modnames, // Display section bottom navigation. $sectionbottomnav = ''; $sectionbottomnav .= html_writer::start_tag('div', array('class' => 'section-navigation mdl-bottom')); - $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left')); - $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right')); + $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'float-left btn btn-secondary')); + $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'float-right btn btn-secondary')); $sectionbottomnav .= html_writer::end_tag('div'); echo $sectionbottomnav; @@ -526,6 +541,80 @@ public function print_single_section_page($course, $sections, $mods, $modnames, } } + + /** + * Generate a summary of the activites in a section + * + * @param stdClass $section The course_section entry from DB + * @param stdClass $course the course record from DB + * @param array $mods (argument not used) + * @return string HTML to output. + */ + protected function section_activity_summary($thissection, $course, $mods) { + global $PAGE; + $modinfo = get_fast_modinfo($course); + if (empty($modinfo->sections[$thissection->section])) { + return ''; + } + // Generate array with count of activities in this section. + $sectionmods = array(); + $total = 0; + $complete = 0; + $cancomplete = isloggedin() && !isguestuser(); + $completioninfo = new completion_info($course); + foreach ($modinfo->sections[$thissection->section] as $cmid) { + $thismod = $modinfo->cms[$cmid]; + + if ($thismod->modname == 'label') { + // Labels are special (not interesting for students)! + continue; + } + + if ($thismod->uservisible) { + if (isset($sectionmods[$thismod->modname])) { + $sectionmods[$thismod->modname]['name'] = $thismod->modplural; + $sectionmods[$thismod->modname]['count']++; + } + else { + $sectionmods[$thismod->modname]['name'] = $thismod->modfullname; + $sectionmods[$thismod->modname]['count'] = 1; + } + if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) { + $total++; + $completiondata = $completioninfo->get_data($thismod, true); + if ($completiondata->completionstate == COMPLETION_COMPLETE || $completiondata->completionstate == COMPLETION_COMPLETE_PASS) { + $complete++; + } + } + } + } + + if (empty($sectionmods)) { + // No sections. + return ''; + } + + + if ($total > 0) { + $completion = new stdClass; + $completion->complete = $complete; + $completion->total = $total; + + $percent = 0; + if ($complete > 0) { + $percent = (int)(($complete / $total) * 100); + } + + if($percent == 100) { + return true; + } + + } + + return false; + } + + /** * Generate the display of the header part of a section before * course modules are included diff --git a/styles.css b/styles.css old mode 100644 new mode 100755 index a72fa68..67aaf82 --- a/styles.css +++ b/styles.css @@ -96,4 +96,8 @@ .format-onetopic .onetopic .content > .summary .iconhelp { cursor: pointer; +} + +.format-onetopic .onetopic .topiccomplete { + background-color: #3dff44; } \ No newline at end of file diff --git a/version.php b/version.php old mode 100644 new mode 100755