/** * @method progress_bar * @todo Draws a progress bar * @param array $modules The modules used in the course * @param stdClass $config The blocks configuration settings * @param array $events The possible events that can occur for modules * @param int $userid The user's id * @param int instance The block instance (incase more than one is being displayed) * @param array $attempts The user's attempts on course activities * @param bool $simple Controls whether instructions are shown below a progress bar */ function progress_bar($modules, $events, $userid, $attempts) { global $OUTPUT, $CFG; $simple = true; $now = time(); $numevents = count($events); $dateformat = get_string('date_format', 'local_dashboard'); $tableoptions = array('class' => 'progressBarProgressTable', 'cellpadding' => '0', 'cellspacing' => '0'); /* added for solution */ $default = $modules['defaultAction']; $progressBarIcons = 1; $orderby = 'orderbytime'; $showpercentage = 1; $displayNow = 1; // Place now arrow. if ((!isset($orderby) || $orderby == 'orderbytime') && $displayNow == 1 && !$simple) { $content = HTML_WRITER::start_tag('table', $tableoptions); // Find where to put now arrow. $nowpos = 0; while ($nowpos < $numevents && $now > $events[$nowpos]['expected']) { $nowpos++; } $content .= HTML_WRITER::start_tag('tr'); $nowstring = get_string('now_indicator', 'local_dashboard'); if ($nowpos < $numevents / 2) { for ($i = 0; $i < $nowpos; $i++) { $content .= HTML_WRITER::tag('td', ' ', array('class' => 'progressBarHeader')); } $celloptions = array('colspan' => $numevents - $nowpos, 'class' => 'progressBarHeader', 'style' => 'text-align:left;'); $content .= HTML_WRITER::start_tag('td', $celloptions); $content .= $OUTPUT->pix_icon('left', $nowstring, 'local_dashboard'); $content .= $nowstring; $content .= HTML_WRITER::end_tag('td'); } else { $celloptions = array('colspan' => $nowpos, 'class' => 'progressBarHeader', 'style' => 'text-align:right;'); $content .= HTML_WRITER::start_tag('td', $celloptions); $content .= $nowstring; $content .= $OUTPUT->pix_icon('right', $nowstring, 'local_dashboard'); $content .= HTML_WRITER::end_tag('td'); for ($i = $nowpos; $i < $numevents; $i++) { $content .= HTML_WRITER::tag('td', ' ', array('class' => 'progressBarHeader')); } } $content .= HTML_WRITER::end_tag('tr'); } else { $tableoptions['class'] = 'progressBarProgressTable noNow'; $content = HTML_WRITER::start_tag('table', $tableoptions); } // Start progress bar. $width = 100 / $numevents; $content .= HTML_WRITER::start_tag('tr'); $counter = 1; foreach ($events as $event) { $attempted = $attempts[$event['type'] . $event['id']]; $action = isset($default) ? $default : $modules[$event['type']]['defaultAction']; // A cell in the progress bar. $celloptions = array( 'class' => 'progressBarCell', 'id' => '', 'width' => $width . '%', 'onclick' => 'document.location=\'' . $CFG->wwwroot . '/mod/' . $event['type'] . '/view.php?id=' . $event['cmid'] . '\';', // 'onmouseover' => 'M.local_dashboard.showInfo('. // '\''.$event['type'].'\', '. // '\''.addslashes(get_string($event['type'], 'local_dashboard')).'\', '. // '\''.$event['cmid'].'\', '. // '\''.addslashes($event['name']).'\', '. // '\''.addslashes(get_string($action, 'local_dashboard')).'\', '. // '\''.addslashes(userdate($event['expected'], $dateformat, $CFG->timezone)).'\', '. // '\''.$userid.'\', '. // '\''.($attempted === true ? 'tick' : 'cross').'\''. // ');', 'style' => 'background-color:'); if ($attempted === true) { $celloptions['style'] .= get_string('attempted_colour', 'local_dashboard') . ';'; // $cellcontent = $OUTPUT->pix_icon( // isset($progressBarIcons) && $progressBarIcons == 1 ? // 'tick' : 'blank', '', 'local_dashboard'); } else if (((!isset($orderby) || $orderby == 'orderbytime') && $event['expected'] < $now) || ($attempted === 'failed')) { $celloptions['style'] .= get_string('notAttempted_colour', 'local_dashboard') . ';'; // $cellcontent = $OUTPUT->pix_icon( // isset($progressBarIcons) && $progressBarIcons == 1 ? // 'cross':'blank', '', 'local_dashboard'); } else { $celloptions['style'] .= get_string('futureNotAttempted_colour', 'local_dashboard') . ';'; $cellcontent = $OUTPUT->pix_icon('blank', '', 'local_dashboard'); } if ($counter == 1) { $celloptions['id'] .= 'first'; } if ($counter == $numevents) { $celloptions['id'] .= 'last'; } $counter++; $content .= HTML_WRITER::tag('td', $cellcontent, $celloptions); } $content .= HTML_WRITER::end_tag('tr'); $content .= HTML_WRITER::end_tag('table'); // Add the info box below the table. $divoptions = array('class' => 'progressEventInfo', 'id' => 'progressBarInfouser' . $userid); $content .= HTML_WRITER::start_tag('div', $divoptions); if (!$simple) { if (isset($showpercentage) && $showpercentage == 1) { $progress = progress_percentage($events, $attempts); $content .= get_string('progress', 'local_dashboard') . ': '; $content .= $progress . '%' . HTML_WRITER::empty_tag('br'); } $content .= get_string('mouse_over_prompt', 'local_dashboard'); } $content .= HTML_WRITER::end_tag('div'); return $content; }
$PAGE->set_url('/local/dashboard/index.php'); $PAGE->requires->css('/local/dashboard/styles.css'); // Header and the navigation bar $PAGE->set_heading($SITE->fullname); $string = get_string('pluginname', 'local_dashboard'); // $PAGE->set_title($string); $PAGE->navbar->add(get_string('dashboard', 'local_dashboard'), new moodle_url('/local/dashboard/index.php')); $PAGE->navbar->add(get_string('dashboard', 'local_dashboard')); $strheading = get_string('dashboard', 'local_dashboard'); echo $OUTPUT->header(); $modules = progress_modules_in_use($id); $events = progress_event_information($modules, $id); $attempts = progress_attempts($modules, $id, $events, $USER->id); $course_name = $DB->get_field('course', 'fullname', array('id' => $id)); $percent = progress_percentage($events, $attempts); echo HTML_WRITER::start_tag('div', array('class' => 'course_name')); echo $course_name; echo HTML_WRITER::end_tag('div'); $bar = '<div class="outer"><div class="dynamic_bar" style="max-width:' . $percent . '%"></div></div>'; $table = table_completion($events, $attempts, $id); if (empty($table)) { echo HTML_WRITER::start_tag('div', array('class' => 'empty')); echo 'No Activities created for this Course still...'; echo HTML_WRITER::end_tag('div'); } else { echo '<div class="main_list_bar"> <span class="task_total">No.of Tasks : ' . count($events) . '</span> <span class="task_bar">' . $bar . '</span> <span class="percent">' . $percent . '%' . '</span> </div>';