Last active
February 12, 2016 14:01
-
-
Save nadavkav/f2de9daae5d0f7286e91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Following code assumes it get two parameters: $section & $user | |
// (For any question, ask the Penguin: nadavkav@gmail.com) | |
$thissection = $modinfo->get_section_info($section); | |
// 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, $user); | |
if ($completiondata->completionstate == COMPLETION_COMPLETE || | |
$completiondata->completionstate == COMPLETION_COMPLETE_PASS | |
) { | |
$complete++; | |
} | |
} | |
} | |
} | |
// Now that we have $total & $complete (yes!) :-) | |
// Lets display it with redialProgress from D3js... | |
// Output section completion data | |
$o = ''; | |
if ($total > 0) { | |
$a = new stdClass; | |
$a->complete = $complete; | |
$a->total = $total; | |
$o .= html_writer::start_tag('div', array('class' => 'section-summary mdl-right')); | |
//$o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right')); | |
//$o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count')); | |
//$o.= html_writer::end_tag('div'); | |
$o .= html_writer::tag('div', '', array('id' => 'radialprogress' . $thissection->section, 'class' => 'radialprogress', | |
'data-value' => $complete, 'data-maxvalue' => $total)); | |
/* | |
$o.= html_writer::tag('script', | |
"var rp{$section->section} = radialProgress(document.getElementById('radialprogress{$section->section}')) | |
.label('Radial') | |
.diameter(120) | |
.minValue(0) | |
.maxValue({$total}) | |
.value({$complete}) | |
.render();"); | |
*/ | |
//$o.= html_writer::tag('style','.radialprogress{height:120px;}'); | |
if (substr($thissection->name, 0, 1) == '^') { | |
$sectionname = ltrim($thissection->name, '^'); | |
} else { | |
$sectionname = $thissection->name; | |
} | |
$o .= html_writer::tag('div', get_string('section') . ': ' . $sectionname, array('class' => 'section-name')); // hanna took off 18/10/15 | |
$o .= html_writer::tag('div', get_string('activity') . ': ' . $PAGE->activityrecord->name, array('class' => 'activity-name')); // hanna took off 18/10/15 | |
$o .= html_writer::div('', 'bor'); | |
$o .= html_writer::end_tag('div'); | |
// radialProgress | |
// http://www.brightpointinc.com/download/radial-progress-source-code/ | |
$PAGE->requires->js('/theme/academi/javascript/d3js/d3.min.js'); | |
$PAGE->requires->js('/theme/academi/javascript/d3js/radialProgress.js'); | |
$PAGE->requires->js('/theme/academi/javascript/d3js/init.js'); | |
$PAGE->requires->js_init_call('start_radialProgress', array($thissection->section, $complete, $total)); | |
} | |
// added to topics/styles.css | |
//$page->requires->css('/course/format/topics/d3js/style.css'); | |
return $o; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment