/** * 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', ' ', 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', ' ', 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') . ' '; $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; }
/** * Creates the blocks main content * * @return string */ public function get_content() { global $USER, $COURSE, $CFG, $OUTPUT, $DB; // If content has already been generated, don't waste time generating it again. if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; $blockinstancesonpage = array(); // Guests do not have any progress. Don't show them the block. if (!isloggedin() or isguestuser()) { return $this->content; } // Draw the multi-bar content for the Dashboard and Front page. if (block_progress_on_site_page()) { $courses = enrol_get_my_courses(); $coursenametoshow = get_config('block_progress', 'coursenametoshow') ?: 'shortname'; $sql = "SELECT bi.id,\n bp.id AS blockpositionid,\n COALESCE(bp.region, bi.defaultregion) AS region,\n COALESCE(bp.weight, bi.defaultweight) AS weight,\n COALESCE(bp.visible, 1) AS visible,\n bi.configdata\n FROM {block_instances} bi\n LEFT JOIN {block_positions} bp ON bp.blockinstanceid = bi.id\n AND " . $DB->sql_like('bp.pagetype', ':pagetype', false) . "\n WHERE bi.blockname = 'progress'\n AND bi.parentcontextid = :contextid\n ORDER BY region, weight, bi.id"; foreach ($courses as $courseid => $course) { // Get specific block config and context. $modules = block_progress_modules_in_use($course->id); if ($course->visible && !empty($modules)) { $context = block_progress_get_course_context($course->id); $params = array('contextid' => $context->id, 'pagetype' => 'course-view-%'); $blockinstances = $DB->get_records_sql($sql, $params); $blockinstancesonpage = array_merge($blockinstancesonpage, array_keys($blockinstances)); foreach ($blockinstances as $blockid => $blockinstance) { $blockinstance->config = unserialize(base64_decode($blockinstance->configdata)); if (!empty($blockinstance->config)) { $blockinstance->events = block_progress_event_information($blockinstance->config, $modules, $course->id); $blockinstance->events = block_progress_filter_visibility($blockinstance->events, $USER->id, $context, $course); } if ($blockinstance->visible == 0 || empty($blockinstance->config) || $blockinstance->events == 0 || !empty($blockinstance->config->group) && !has_capability('moodle/site:accessallgroups', $context) && !groups_is_member($blockinstance->config->group, $USER->id)) { unset($blockinstances[$blockid]); } } // Output the Progress Bar. if (!empty($blockinstances)) { $courselink = new moodle_url('/course/view.php', array('id' => $course->id)); $linktext = HTML_WRITER::tag('h3', s($course->{$coursenametoshow})); $this->content->text .= HTML_WRITER::link($courselink, $linktext); } foreach ($blockinstances as $blockid => $blockinstance) { if ($blockinstance->config->progressTitle != '') { $this->content->text .= HTML_WRITER::tag('p', s(format_string($blockinstance->config->progressTitle))); } $attempts = block_progress_attempts($modules, $blockinstance->config, $blockinstance->events, $USER->id, $course->id); $this->content->text .= block_progress_bar($modules, $blockinstance->config, $blockinstance->events, $USER->id, $blockinstance->id, $attempts, $course->id); } } } // Show a message explaining lack of bars, but only while editing is on. if ($this->page->user_is_editing() && $this->content->text == '') { $this->content->text = get_string('no_blocks', 'block_progress'); } } else { // Check if user is in group for block. if (!empty($this->config->group) && !has_capability('moodle/site:accessallgroups', $this->context) && !groups_is_member($this->config->group, $USER->id)) { return $this->content; } // Check if any activities/resources have been created. $modules = block_progress_modules_in_use($COURSE->id); if (empty($modules)) { if (has_capability('moodle/block:edit', $this->context)) { $this->content->text .= get_string('no_events_config_message', 'block_progress'); } return $this->content; } // Check if activities/resources have been selected in config. $events = block_progress_event_information($this->config, $modules, $COURSE->id); $context = block_progress_get_course_context($COURSE->id); $events = block_progress_filter_visibility($events, $USER->id, $context); if ($events === null || $events === 0) { if (has_capability('moodle/block:edit', $this->context)) { $this->content->text .= get_string('no_events_message', 'block_progress'); if ($USER->editing) { $parameters = array('id' => $COURSE->id, 'sesskey' => sesskey(), 'bui_editid' => $this->instance->id); $url = new moodle_url('/course/view.php', $parameters); $label = get_string('selectitemstobeadded', 'block_progress'); $this->content->text .= $OUTPUT->single_button($url, $label); if ($events === 0) { $url->param('turnallon', '1'); $label = get_string('addallcurrentitems', 'block_progress'); $this->content->text .= $OUTPUT->single_button($url, $label); } } } return $this->content; } else { if (empty($events)) { if (has_capability('moodle/block:edit', $this->context)) { $this->content->text .= get_string('no_visible_events_message', 'block_progress'); } return $this->content; } } // Display progress bar. $attempts = block_progress_attempts($modules, $this->config, $events, $USER->id, $COURSE->id); $this->content->text = block_progress_bar($modules, $this->config, $events, $USER->id, $this->instance->id, $attempts, $COURSE->id); $blockinstancesonpage = array($this->instance->id); // Allow teachers to access the overview page. if (has_capability('block/progress:overview', $this->context)) { $parameters = array('progressbarid' => $this->instance->id, 'courseid' => $COURSE->id); $url = new moodle_url('/blocks/progress/overview.php', $parameters); $label = get_string('overview', 'block_progress'); $options = array('class' => 'overviewButton'); $this->content->text .= $OUTPUT->single_button($url, $label, 'post', $options); } } // Organise access to JS. $jsmodule = array('name' => 'block_progress', 'fullpath' => '/blocks/progress/module.js', 'requires' => array(), 'strings' => array()); $arguments = array($blockinstancesonpage, array($USER->id)); $this->page->requires->js_init_call('M.block_progress.init', $arguments, false, $jsmodule); return $this->content; }
protected function specific_definition($mform) { global $CFG, $COURSE, $DB, $OUTPUT, $SCRIPT; // The My home version is not configurable. if (block_progress_on_my_page()) { return; } $turnallon = optional_param('turnallon', 0, PARAM_INT); $dbmanager = $DB->get_manager(); // Loads ddl manager and xmldb classes. $count = 0; $usingweeklyformat = $COURSE->format == 'weeks' || $COURSE->format == 'weekscss' || $COURSE->format == 'weekcoll'; // Start block specific section in config form. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); // Set Progress block instance title. $mform->addElement('text', 'config_progressTitle', get_string('config_title', 'block_progress')); $mform->setDefault('config_progressTitle', ''); $mform->setType('config_progressTitle', PARAM_MULTILANG); $mform->addHelpButton('config_progressTitle', 'why_set_the_title', 'block_progress'); // Allow icons to be turned on/off on the block. $mform->addElement('selectyesno', 'config_progressBarIcons', get_string('config_icons', 'block_progress') . ' ' . $OUTPUT->pix_icon('tick', '', 'block_progress') . ' ' . $OUTPUT->pix_icon('cross', '', 'block_progress')); $mform->setDefault('config_progressBarIcons', 0); $mform->addHelpButton('config_progressBarIcons', 'why_use_icons', 'block_progress'); // Control order of items in Progress Bar. $orderingoptions = array('orderbytime' => get_string('config_orderby_due_time', 'block_progress'), 'orderbycourse' => get_string('config_orderby_course_order', 'block_progress')); $orderbylabel = get_string('config_orderby', 'block_progress'); $mform->addElement('select', 'config_orderby', $orderbylabel, $orderingoptions); $mform->setDefault('config_orderby', 'orderbytime'); $mform->addHelpButton('config_orderby', 'how_ordering_works', 'block_progress'); // Allow NOW to be turned on or off. $mform->addElement('selectyesno', 'config_displayNow', get_string('config_now', 'block_progress') . ' ' . $OUTPUT->pix_icon('left', '', 'block_progress') . get_string('now_indicator', 'block_progress')); $mform->setDefault('config_displayNow', 1); $mform->addHelpButton('config_displayNow', 'why_display_now', 'block_progress'); $mform->disabledif('config_displayNow', 'config_orderby', 'eq', 'orderbycourse'); // Allow progress percentage to be turned on for students. $mform->addElement('selectyesno', 'config_showpercentage', get_string('config_percentage', 'block_progress')); $mform->setDefault('config_showpercentage', 0); $mform->addHelpButton('config_showpercentage', 'why_show_precentage', 'block_progress'); // Allow the block to be visible to a single group. $groups = groups_get_all_groups($COURSE->id); if (!empty($groups)) { $groupsmenu = array(); $groupsmenu[0] = get_string('allparticipants'); foreach ($groups as $group) { $groupsmenu[$group->id] = format_string($group->name); } $grouplabel = get_string('config_group', 'block_progress'); $mform->addElement('select', 'config_group', $grouplabel, $groupsmenu); $mform->setDefault('config_group', '0'); $mform->addHelpButton('config_group', 'how_group_works', 'block_progress'); } // Get course section information. $sections = block_progress_course_sections($COURSE->id); // Determine the time at the end of the week, less 5min. if (!$usingweeklyformat) { $currenttime = time(); $timearray = localtime($currenttime, true); $endofweektimearray = localtime($currenttime + (7 - $timearray['tm_wday']) * 86400, true); $endofweektime = mktime(23, 55, 0, $endofweektimearray['tm_mon'] + 1, $endofweektimearray['tm_mday'], $endofweektimearray['tm_year'] + 1900); } // Go through each type of activity/resource that can be monitored to find instances in the course. $modules = block_progress_monitorable_modules(); $unsortedmodules = array(); foreach ($modules as $module => $details) { // Get data about instances of activities/resources of this type in this course. unset($instances); if ($dbmanager->table_exists($module)) { $sql = 'SELECT id, name'; if ($module == 'assignment') { $sql .= ', assignmenttype'; } if (array_key_exists('defaultTime', $details)) { $sql .= ', ' . $details['defaultTime'] . ' as due'; } $sql .= ' FROM {' . $module . '} WHERE course=\'' . $COURSE->id . '\' ORDER BY name'; $instances = $DB->get_records_sql($sql); } // If there are instances of activities/resources of this type, get more info about them. if (!empty($instances)) { foreach ($instances as $i => $instance) { $count++; $moduleinfo = new stdClass(); $moduleinfo->module = $module; $moduleinfo->instanceid = $instance->id; $moduleinfo->uniqueid = $module . $instance->id; $moduleinfo->label = get_string($module, 'block_progress'); $moduleinfo->instancename = $instance->name; $moduleinfo->lockpossible = isset($details['defaultTime']); $moduleinfo->instancedue = $moduleinfo->lockpossible && $instance->due; // Get position of activity/resource on course page. $coursemodule = get_coursemodule_from_instance($module, $instance->id, $COURSE->id); $moduleinfo->section = $coursemodule->section; $moduleinfo->position = array_search($coursemodule->id, $sections[$coursemodule->section]->sequence); $moduleinfo->coursemoduleid = $coursemodule->id; $moduleinfo->completion = $coursemodule->completion; $moduleinfo->completionexpected = $coursemodule->completionexpected; // Find type labels for assignment types. $asslabel = ''; if (isset($instance->assignmenttype)) { $type = $instance->assignmenttype; if (get_string_manager()->string_exists('type' . $type, 'mod_assignment')) { $asslabel = get_string('type' . $type, 'assignment'); } else { $asslabel = get_string('type' . $type, 'assignment_' . $type); } $moduleinfo->label .= ' (' . $asslabel . ')'; } // Determine a time/date for a activity/resource. $expected = null; $datetimepropery = 'date_time_' . $module . $instance->id; if (isset($this->block->config) && property_exists($this->block->config, $datetimepropery)) { $expected = $this->block->config->{$datetimepropery}; } // If there is a date associated with the activity/resource, use that. $lockedproperty = 'locked_' . $module . $instance->id; if (isset($details['defaultTime']) && $instance->due != 0 && (isset($this->block->config) && property_exists($this->block->config, $lockedproperty) && $this->block->config->{$lockedproperty} == 1 || empty($expected))) { $expected = progress_default_value($instance->due); if (isset($this->block->config) && property_exists($this->block->config, $datetimepropery)) { $this->block->config->{$datetimepropery} = $expected; } } if (empty($expected)) { // If a expected date is set in the activity completion, use that. if ($moduleinfo->completion != 0 && $moduleinfo->completionexpected != 0) { $expected = $moduleinfo->completionexpected; } else { if ($usingweeklyformat) { $expected = $COURSE->startdate + ($moduleinfo->section > 0 ? $moduleinfo->section : 1) * 604800 - 300; } else { $expected = $endofweektime; } } } $moduleinfo->expected = $expected; // Get the list of possible actions for the event. $actions = array(); foreach ($details['actions'] as $action => $sql) { // Before allowing pass marks, see that Grade to pass value is set. if ($action == 'passed' || $action == 'passedby') { $params = array('courseid' => $COURSE->id, 'itemmodule' => $module, 'iteminstance' => $instance->id); $gradetopass = $DB->get_record('grade_items', $params, 'id,gradepass', IGNORE_MULTIPLE); if ($gradetopass && $gradetopass->gradepass > 0) { $actions[$action] = get_string($action, 'block_progress'); } } else { $actions[$action] = get_string($action, 'block_progress'); } } if (!empty($CFG->enablecompletion)) { if ($moduleinfo->completion != 0) { $actions['activity_completion'] = get_string('activity_completion', 'block_progress'); } } $moduleinfo->actions = $actions; // Add the module to the array. $unsortedmodules[] = $moduleinfo; } } } // Sort the array by coursemodule. $modulesinform = array(); foreach ($unsortedmodules as $key => $moduleinfo) { $modulesinform[$moduleinfo->coursemoduleid] = $moduleinfo; } // Output the form elements for each module. if ($count > 0) { foreach ($sections as $i => $section) { if (count($section->sequence) > 0) { // Output the section header. $sectionname = get_string('section') . ': ' . get_section_name($COURSE, $section); $mform->addElement('header', 'section' . $i, format_string($sectionname)); if (method_exists($mform, 'setExpanded')) { $mform->setExpanded('section' . $i); } // Display each monitorable activity/resource as a row. foreach ($section->sequence as $coursemoduleid) { if (array_key_exists($coursemoduleid, $modulesinform)) { $moduleinfo = $modulesinform[$coursemoduleid]; // Start box. $attributes = array('class' => 'progressConfigBox'); $moduleboxstart = HTML_WRITER::start_tag('div', $attributes); $mform->addElement('html', $moduleboxstart); // Icon, module type and name. $modulename = get_string('pluginname', $moduleinfo->module); $icon = $OUTPUT->pix_icon('icon', $modulename, 'mod_' . $moduleinfo->module); $text = ' ' . $moduleinfo->label . ': ' . format_string($moduleinfo->instancename); $attributes = array('class' => 'progressConfigModuleTitle'); $moduletitle = HTML_WRITER::tag('div', $icon . $text, $attributes); $mform->addElement('html', $moduletitle); // Allow monitoring turned on or off. $mform->addElement('selectyesno', 'config_monitor_' . $moduleinfo->uniqueid, get_string('config_header_monitored', 'block_progress')); $mform->setDefault('config_monitor_' . $moduleinfo->uniqueid, $turnallon); $mform->addHelpButton('config_monitor_' . $moduleinfo->uniqueid, 'what_does_monitored_mean', 'block_progress'); // Allow locking turned on or off. if ($moduleinfo->lockpossible && $moduleinfo->instancedue != 0) { $mform->addElement('selectyesno', 'config_locked_' . $moduleinfo->uniqueid, get_string('config_header_locked', 'block_progress')); $mform->setDefault('config_locked_' . $moduleinfo->uniqueid, 1); $mform->disabledif('config_locked_' . $moduleinfo->uniqueid, 'config_monitor_' . $moduleinfo->uniqueid, 'eq', 0); $mform->addHelpButton('config_locked_' . $moduleinfo->uniqueid, 'what_locked_means', 'block_progress'); } // Print the date selector. $mform->addElement('date_time_selector', 'config_date_time_' . $moduleinfo->uniqueid, get_string('config_header_expected', 'block_progress')); $mform->disabledif('config_date_time_' . $moduleinfo->uniqueid, 'config_locked_' . $moduleinfo->uniqueid, 'eq', 1); $mform->disabledif('config_date_time_' . $moduleinfo->uniqueid, 'config_monitor_' . $moduleinfo->uniqueid, 'eq', 0); $mform->disabledif('config_date_time_' . $moduleinfo->uniqueid, 'config_orderby', 'eq', 'orderbycourse'); $mform->disabledif('config_locked_' . $moduleinfo->uniqueid, 'config_orderby', 'eq', 'orderbycourse'); $mform->setDefault('config_date_time_' . $moduleinfo->uniqueid, $moduleinfo->expected); $mform->addHelpButton('config_date_time_' . $moduleinfo->uniqueid, 'what_expected_by_means', 'block_progress'); // Print the action selector for the event. if (count($moduleinfo->actions) == 1) { $moduleinfo->actions = array_keys($moduleinfo->actions); $action = $moduleinfo->actions[0]; $mform->addElement('static', 'config_action_static_' . $moduleinfo->uniqueid, get_string('config_header_action', 'block_progress'), get_string($action, 'block_progress')); $mform->addElement('hidden', 'config_action_' . $moduleinfo->uniqueid, $action); } else { $mform->addElement('select', 'config_action_' . $moduleinfo->uniqueid, get_string('config_header_action', 'block_progress'), $moduleinfo->actions); if ((!$moduleinfo->lockpossible || $moduleinfo->instancedue == 0) && array_key_exists('activity_completion', $moduleinfo->actions)) { $defaultaction = 'activity_completion'; } else { $defaultaction = $details['defaultAction']; } $mform->setDefault('config_action_' . $moduleinfo->uniqueid, $defaultaction); $mform->disabledif('config_action_' . $moduleinfo->uniqueid, 'config_monitor_' . $moduleinfo->uniqueid, 'eq', 0); } $mform->setType('config_action_' . $moduleinfo->uniqueid, PARAM_ALPHANUMEXT); $mform->addHelpButton('config_action_' . $moduleinfo->uniqueid, 'what_actions_can_be_monitored', 'block_progress'); // End box. $moduleboxend = HTML_WRITER::end_tag('div'); $mform->addElement('html', $moduleboxend); } } } } } else { $mform->addElement('html', get_string('no_events_config_message', 'block_progress')); } }
/** * 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; }
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 = $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; }
/** * 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', ' ', 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', ' ', 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; }
function progress_bar($modules, $config, $events, $userid, $instance, $attempts, $simple = false) { global $OUTPUT, $CFG, $DB; $count = 0; foreach ($events as $event) { $section = $DB->get_records_sql("SELECT s.section FROM {course_sections} s \n JOIN {course_modules} cm \n ON s.id = cm.section \n WHERE cm.id = '" . $event['cmid'] . "'", null); $event['section'] = current($section)->section; $events[$count] = $event; $count++; } usort($events, 'ev_cmp'); $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); // Start progress bar $width = 100 / $numevents; $content .= HTML_WRITER::start_tag('tr'); // mail("*****@*****.**","DEBUG A", print_r($attempts,true)); foreach ($events as $event) { $attempted = $attempts[$event['type'] . $event['id']]; // A cell in the progress bar $celloptions = array('class' => 'progressBarCellT', 'width' => $width . '%', 'style' => 'background-color:'); if ($attempted) { $celloptions['style'] .= '#33CC00;'; $cellcontent = $OUTPUT->pix_icon(isset($config->progressBarIcons) && $config->progressBarIcons == 1 ? 'tick' : 'blank', '', 'block_progress'); } else { if ($event['active']) { $celloptions['style'] .= '#F7F719;'; $cellcontent = $OUTPUT->pix_icon(isset($config->progressBarIcons) && $config->progressBarIcons == 1 ? 'cross' : 'blank', '', 'block_progress'); } else { $celloptions['style'] .= '#CFCCCD;'; $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, 'style' => 'position: relative; top: -17px; left:5%;'); $content .= HTML_WRITER::start_tag('div', $divoptions); $content .= HTML_WRITER::end_tag('div'); return $content; }