Ejemplo n.º 1
0
$table->no_sorting('picture');
$table->no_sorting('progressbar');
$table->define_baseurl($PAGE->url);
$table->setup();
// Build table of progress bars as they are marked
for ($i = 0; $i < $numberofusers; $i++) {
    $picture = $OUTPUT->user_picture($users[$i], array('course' => $course->id));
    $name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $users[$i]->id . '&course=' . $course->id . '">' . fullname($users[$i]) . '</a>';
    if ($users[$i]->lastaccess == 0) {
        $lastonline = get_string('never');
    } else {
        $lastonline = userdate($users[$i]->lastaccess);
    }
    $attempts = get_attempts($modules, $config, $events, $users[$i]->id, $course->id);
    $progressbar = progress_bar($modules, $config, $events, $users[$i]->id, $course->id, $attempts, true);
    $progressvalue = get_progess_percentage($events, $attempts);
    $progress = $progressvalue . '%';
    $rows[] = array('firstname' => $users[$i]->firstname, 'lastname' => strtoupper($users[$i]->lastname), 'picture' => $picture, 'fullname' => $name, 'lastonlinetime' => $users[$i]->lastaccess, 'lastonline' => $lastonline, 'progressbar' => $progressbar, 'progressvalue' => $progressvalue, 'progress' => $progress);
    //Inserting the values into created table
    $result = $DB->get_records_sql('SELECT * FROM {progress_percent} WHERE uid = ? AND cid = ?', array($users[$i]->id, $course->id));
    $val = array_values($result);
    $record = new stdClass();
    $record->uid = $users[$i]->id;
    $record->cid = $course->id;
    $record->progress_percentage = $progressvalue;
    if (count($result) != 0) {
        $record->id = $val[0]->id;
    }
    count($result) == 0 ? $DB->insert_record('progress_percent', $record, false) : $DB->update_record('progress_percent', $record, false);
}
//End table creation
Ejemplo n.º 2
0
/**
 * 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, $config, $events, $userid, $instance, $attempts, $simple = false)
{
    global $OUTPUT, $CFG;
    $now = time();
    $numevents = count($events);
    $dateformat = get_string('date_format', 'block_progress');
    $tableoptions = array('class' => 'progressBarProgressTable', 'cellpadding' => '0', 'cellspacing' => '0');
    $content = HTML_WRITER::start_tag('table', $tableoptions);
    // Place now arrow
    if ($config->displayNow == 1 && !$simple) {
        // 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', 'block_progress');
        if ($nowpos < $numevents / 2) {
            for ($i = 0; $i < $nowpos; $i++) {
                $content .= HTML_WRITER::tag('td', '&nbsp;', 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, 'block_progress');
            $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, 'block_progress');
            $content .= HTML_WRITER::end_tag('td');
            for ($i = $nowpos; $i < $numevents; $i++) {
                $content .= HTML_WRITER::tag('td', '&nbsp;', array('class' => 'progressBarHeader'));
            }
        }
        $content .= HTML_WRITER::end_tag('tr');
    }
    // Start progress bar
    $width = 100 / $numevents;
    $content .= HTML_WRITER::start_tag('tr');
    foreach ($events as $event) {
        $attempted = $attempts[$event['type'] . $event['id']];
        // A cell in the progress bar
        $celloptions = array('class' => 'progressBarCell', 'width' => $width . '%', 'onclick' => 'document.location=\'' . $CFG->wwwroot . '/mod/' . $event['type'] . '/view.php?id=' . $event['cmid'] . '\';', 'onmouseover' => 'M.block_progress.showInfo(\'' . $event['type'] . '\', \'' . get_string($event['type'], 'block_progress') . '\', \'' . $event['cmid'] . '\', \'' . addslashes($event['name']) . '\', \'' . get_string($config->{'action_' . $event['type'] . $event['id']}, 'block_progress') . '\', \'' . userdate($event['expected'], $dateformat, $CFG->timezone) . '\', \'' . $instance . '\', \'' . $userid . '\', \'' . ($attempted ? 'tick' : 'cross') . '\');', 'style' => 'background-color:');
        if ($attempted) {
            $celloptions['style'] .= get_string('attempted_colour', 'block_progress') . ';';
            $cellcontent = $OUTPUT->pix_icon(isset($config->progressBarIcons) && $config->progressBarIcons == 1 ? 'tick' : 'blank', '', 'block_progress');
        } else {
            if ($event['expected'] < $now) {
                $celloptions['style'] .= get_string('notAttempted_colour', 'block_progress') . ';';
                $cellcontent = $OUTPUT->pix_icon(isset($config->progressBarIcons) && $config->progressBarIcons == 1 ? 'cross' : 'blank', '', 'block_progress');
            } else {
                $celloptions['style'] .= get_string('futureNotAttempted_colour', 'block_progress') . ';';
                $cellcontent = $OUTPUT->pix_icon('blank', '', 'block_progress');
            }
        }
        $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' => 'progressBarInfo' . $instance . 'user' . $userid);
    $content .= HTML_WRITER::start_tag('div', $divoptions);
    if (!$simple) {
        if (isset($config->showpercentage) && $config->showpercentage == 1) {
            $progress = get_progess_percentage($events, $attempts);
            $content .= get_string('progress', 'block_progress') . ': ';
            $content .= $progress . '%' . HTML_WRITER::empty_tag('br');
        }
        $content .= get_string('mouse_over_prompt', 'block_progress');
    }
    $content .= HTML_WRITER::end_tag('div');
    return $content;
}