/**
 * 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
    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', '&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, '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', '&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($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 = $this->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;
    }
Пример #3
0
 /**
  * Creates the block's main content
  *
  * @return string
  */
 public function get_content()
 {
     global $USER, $OUTPUT, $CFG;
     if (isset($this->content)) {
         return $this->content;
     }
     // Establish settings variables based on instance config.
     $showserverclock = !isset($this->config->show_clocks) || $this->config->show_clocks == B_SIMPLE_CLOCK_SHOW_BOTH || $this->config->show_clocks == B_SIMPLE_CLOCK_SHOW_SERVER_ONLY;
     $showuserclock = !isset($this->config->show_clocks) || $this->config->show_clocks == B_SIMPLE_CLOCK_SHOW_BOTH || $this->config->show_clocks == B_SIMPLE_CLOCK_SHOW_USER_ONLY;
     $showicons = !isset($this->config->show_icons) || $this->config->show_icons == 1;
     $showseconds = isset($this->config->show_seconds) && $this->config->show_seconds == 1;
     $showday = isset($this->config->show_day) && $this->config->show_day == 1;
     $show24hrtime = isset($this->config->twenty_four_hour_time) && $this->config->twenty_four_hour_time == 1;
     // Start the content, which is primarily a table.
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     $table = new html_table();
     $table->attributes = array('class' => 'clockTable');
     // First item added is the server's clock.
     if ($showserverclock) {
         $row = array();
         if ($showicons) {
             $alt = get_string('server', 'block_simple_clock');
             $usingie = false;
             if (class_exists('core_useragent')) {
                 $usingie = core_useragent::is_ie();
             } else {
                 $usingie = check_browser_version('MSIE');
             }
             if ($usingie) {
                 $servericon = $OUTPUT->pix_icon('server', $alt, 'block_simple_clock');
             } else {
                 $servericon = $OUTPUT->pix_icon('favicon', $alt, 'theme');
             }
             $row[] = $servericon;
         }
         $row[] = get_string('server', 'block_simple_clock') . ':';
         $attributes = array();
         $attributes['class'] = 'clock';
         $attributes['id'] = 'block_progress_serverTime';
         $attributes['value'] = get_string('loading', 'block_simple_clock');
         $row[] = HTML_WRITER::empty_tag('input', $attributes);
         $table->data[] = $row;
     }
     // Next item is the user's clock.
     if ($showuserclock) {
         $row = array();
         if ($showicons) {
             if ($USER->id != 0) {
                 $userpictureparams = array('size' => 16, 'link' => false, 'alt' => 'User');
                 $userpicture = $OUTPUT->user_picture($USER, $userpictureparams);
                 $row[] = $userpicture;
             } else {
                 $row[] = '';
             }
         }
         $row[] = get_string('you', 'block_simple_clock') . ':';
         $attributes = array();
         $attributes['class'] = 'clock';
         $attributes['id'] = 'block_progress_youTime';
         $attributes['value'] = get_string('loading', 'block_simple_clock');
         $row[] = HTML_WRITER::empty_tag('input', $attributes);
         $table->data[] = $row;
     }
     $this->content->text .= HTML_WRITER::table($table);
     // Set up JavaScript code needed to keep the clock going.
     $noscriptstring = get_string('javascript_disabled', 'block_simple_clock');
     $this->content->text .= HTML_WRITER::tag('noscript', $noscriptstring);
     if ($CFG->timezone != 99) {
         // Ensure that the Moodle timezone is set correctly.
         $date = new DateTime('now', new DateTimeZone(core_date::normalise_timezone($CFG->timezone)));
         $moodletimeoffset = $date->getOffset();
         // + dst_offset_on(time(), $CFG->timezone);
         $servertimeoffset = date_offset_get(new DateTime());
         $timearray = localtime(time() + $moodletimeoffset - $servertimeoffset, true);
     } else {
         // Ensure that the server timezone is set.
         // From 2.9 onwards, this should never happen.
         $timearray = localtime(time(), true);
     }
     $arguments = array($showserverclock, $showuserclock, $showseconds, $showday, $show24hrtime, $timearray['tm_year'] + 1900, $timearray['tm_mon'], $timearray['tm_mday'], $timearray['tm_hour'], $timearray['tm_min'], $timearray['tm_sec'] + 2);
     $jsmodule = array('name' => 'block_simple_clock', 'fullpath' => '/blocks/simple_clock/module.js', 'requires' => array(), 'strings' => array(array('clock_separator', 'block_simple_clock'), array('before_noon', 'block_simple_clock'), array('after_noon', 'block_simple_clock'), array('day_names', 'block_simple_clock')));
     $this->page->requires->js_init_call('M.block_simple_clock.initSimpleClock', $arguments, false, $jsmodule);
     $this->content->footer = '';
     return $this->content;
 }
Пример #4
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;
}