コード例 #1
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 (in case 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
 * @return string  Progress Bar HTML content
 */
function block_progress_bar($modules, $config, $events, $userid, $instance, $attempts, $course, $simple = false)
{
    global $OUTPUT, $CFG;
    $now = time();
    $numevents = count($events);
    $dateformat = get_string('strftimerecentfull', 'langconfig');
    $tableoptions = array('class' => 'progressBarProgressTable', 'cellpadding' => '0', 'cellspacing' => '0');
    // Get colours and use defaults if they are not set in global settings.
    $colournames = array('attempted_colour' => 'attempted_colour', 'notattempted_colour' => 'notAttempted_colour', 'futurenotattempted_colour' => 'futureNotAttempted_colour');
    $colours = array();
    foreach ($colournames as $name => $stringkey) {
        if (get_config('block_progress', $name)) {
            $colours[$name] = get_config('block_progress', $name);
        } else {
            $colours[$name] = get_string('block_progress', $stringkey);
        }
    }
    // Place now arrow.
    if ((!isset($config->orderby) || $config->orderby == 'orderbytime') && $config->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', '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');
    } 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($config->{'action_' . $event['type'] . $event['id']}) ? $config->{'action_' . $event['type'] . $event['id']} : $modules[$event['type']]['defaultAction'];
        // A cell in the progress bar.
        $celloptions = array('class' => 'progressBarCell', 'id' => '', 'width' => $width . '%', 'onmouseover' => 'M.block_progress.showInfo(' . $instance . ',' . $userid . ',' . $event['cm']->id . ');', 'style' => 'background-color:');
        if ($attempted === true) {
            $celloptions['style'] .= $colours['attempted_colour'] . ';';
            $cellcontent = $OUTPUT->pix_icon(isset($config->progressBarIcons) && $config->progressBarIcons == 1 ? 'tick' : 'blank', '', 'block_progress');
        } else {
            if ((!isset($config->orderby) || $config->orderby == 'orderbytime') && $event['expected'] < $now || $attempted === 'failed') {
                $celloptions['style'] .= $colours['notattempted_colour'] . ';';
                $cellcontent = $OUTPUT->pix_icon(isset($config->progressBarIcons) && $config->progressBarIcons == 1 ? 'cross' : 'blank', '', 'block_progress');
            } else {
                $celloptions['style'] .= $colours['futurenotattempted_colour'] . ';';
                $cellcontent = $OUTPUT->pix_icon('blank', '', 'block_progress');
            }
        }
        if (!empty($event['cm']->available)) {
            $celloptions['onclick'] = 'document.location=\'' . $CFG->wwwroot . '/mod/' . $event['type'] . '/view.php?id=' . $event['cm']->id . '\';';
        }
        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' => 'progressBarInfo' . $instance . '-' . $userid . '-info');
    $content .= HTML_WRITER::start_tag('div', $divoptions);
    if (!$simple) {
        if (isset($config->showpercentage) && $config->showpercentage == 1) {
            $progress = block_progress_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');
    // Add hidden divs for activity information.
    $displaydate = (!isset($config->orderby) || $config->orderby == 'orderbytime') && (!isset($config->displayNow) || $config->displayNow == 1);
    foreach ($events as $event) {
        $attempted = $attempts[$event['type'] . $event['id']];
        $action = isset($config->{'action_' . $event['type'] . $event['id']}) ? $config->{'action_' . $event['type'] . $event['id']} : $modules[$event['type']]['defaultAction'];
        $divoptions = array('class' => 'progressEventInfo', 'id' => 'progressBarInfo' . $instance . '-' . $userid . '-' . $event['cm']->id, 'style' => 'display: none;');
        $content .= HTML_WRITER::start_tag('div', $divoptions);
        $link = '/mod/' . $event['type'] . '/view.php?id=' . $event['cm']->id;
        $text = $OUTPUT->pix_icon('icon', '', $event['type'], array('class' => 'moduleIcon')) . s($event['name']);
        if (!empty($event['cm']->available)) {
            $content .= $OUTPUT->action_link($link, $text);
        } else {
            $content .= $text;
        }
        $content .= HTML_WRITER::empty_tag('br');
        $content .= get_string($action, 'block_progress') . '&nbsp;';
        $icon = $attempted && $attempted !== 'failed' ? 'tick' : 'cross';
        $content .= $OUTPUT->pix_icon($icon, '', 'block_progress');
        $content .= HTML_WRITER::empty_tag('br');
        if ($displaydate) {
            $content .= HTML_WRITER::start_tag('div', array('class' => 'expectedBy'));
            $content .= get_string('time_expected', 'block_progress') . ': ';
            $content .= userdate($event['expected'], $dateformat, $CFG->timezone);
            $content .= HTML_WRITER::end_tag('div');
        }
        $content .= HTML_WRITER::end_tag('div');
    }
    return $content;
}
コード例 #2
0
    if ($CFG->enablenotes || $CFG->messaging) {
        $selectattributes = array('type' => 'checkbox', 'class' => 'usercheckbox', 'name' => 'user' . $users[$i]->id);
        $select = html_writer::empty_tag('input', $selectattributes);
    }
    $picture = $OUTPUT->user_picture($users[$i], array('course' => $course->id));
    $namelink = html_writer::link($CFG->wwwroot . '/user/view.php?id=' . $users[$i]->id . '&course=' . $course->id, fullname($users[$i]));
    if (empty($users[$i]->lastonlinetime)) {
        $lastonline = get_string('never');
    } else {
        $lastonline = userdate($users[$i]->lastonlinetime);
    }
    $userevents = block_progress_filter_visibility($events, $users[$i]->id, $context, $course);
    if (!empty($userevents)) {
        $attempts = block_progress_attempts($modules, $progressconfig, $userevents, $users[$i]->id, $course->id);
        $progressbar = block_progress_bar($modules, $progressconfig, $userevents, $users[$i]->id, $progressblock->id, $attempts, $course->id, true);
        $progressvalue = block_progress_percentage($userevents, $attempts, true);
        $progress = $progressvalue . '%';
    } else {
        $progressbar = get_string('no_visible_events_message', 'block_progress');
        $progressvalue = 0;
        $progress = '?';
    }
    $rows[] = array('firstname' => $users[$i]->firstname, 'lastname' => strtoupper($users[$i]->lastname), 'select' => $select, 'picture' => $picture, 'fullname' => $namelink, 'lastonlinetime' => $users[$i]->lastonlinetime, 'lastonline' => $lastonline, 'progressbar' => $progressbar, 'progressvalue' => $progressvalue, 'progress' => $progress);
}
// Build the table content and output.
if ($sortbyprogress) {
    usort($rows, 'block_progress_compare_rows');
}
if ($numberofusers > 0) {
    foreach ($rows as $row) {
        $table->add_data(array($row['select'], $row['picture'], $row['fullname'], $row['lastonline'], $row['progressbar'], $row['progress']));