/** * Definition method. */ public function definition() { global $COURSE; $mform = $this->_form; if (isset($this->_customdata)) { // Hardcoding plugin names here is hacky. $features = $this->_customdata; } else { $features = array(); } // Course id needs to be passed for auth purposes. $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT)); $mform->setType('id', PARAM_INT); $mform->addElement('header', 'general', get_string('pluginname', 'gradeimport_direct')); // Data upload from copy/paste. $mform->addElement('textarea', 'userdata', 'Data', array('rows' => 10, 'class' => 'gradeimport_data_area')); $mform->addRule('userdata', null, 'required'); $mform->setType('userdata', PARAM_RAW); $encodings = core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings); if (!empty($features['verbosescales'])) { $options = array(1 => get_string('yes'), 0 => get_string('no')); $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options); } $options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000); $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); $mform->setType('previewrows', PARAM_INT); $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE)); $mform->setType('groupid', PARAM_INT); $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); }
/** * Export the data. * * @param renderer_base $output * @return stdClass */ public function export_for_template(renderer_base $output) { global $CFG, $DB, $PAGE; $context = context_course::instance($this->courseid); $data = new stdClass(); $data->userid = $this->userid; $data->competencyid = $this->competencyid; $data->courseid = $this->courseid; $data->baseurl = $this->baseurl; $data->groupselector = ''; if (has_any_capability(array('moodle/competency:usercompetencyview', 'moodle/competency:coursecompetencymanage'), $context)) { $course = $DB->get_record('course', array('id' => $this->courseid)); $currentgroup = groups_get_course_group($course, true); if ($currentgroup !== false) { $select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup); $data->groupselector = $select; } // Fetch showactive. $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context); $users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 'u.*', null, 0, 0, $showonlyactiveenrol); $data->users = array(); foreach ($users as $user) { $exporter = new user_summary_exporter($user); $user = $exporter->export($output); if ($user->id == $this->userid) { $user->selected = true; } $data->users[] = $user; } $data->hasusers = true; } else { $data->users = array(); $data->hasusers = false; } $coursecompetencies = \core_competency\api::list_course_competencies($this->courseid); $data->competencies = array(); $contextcache = array(); foreach ($coursecompetencies as $coursecompetency) { $frameworkid = $coursecompetency['competency']->get_competencyframeworkid(); if (!isset($contextcache[$frameworkid])) { $contextcache[$frameworkid] = $coursecompetency['competency']->get_context(); } $context = $contextcache[$frameworkid]; $coursecompetencycontext = $context; $exporter = new competency_exporter($coursecompetency['competency'], array('context' => $coursecompetencycontext)); $competency = $exporter->export($output); if ($competency->id == $this->competencyid) { $competency->selected = true; } $data->competencies[] = $competency; } $data->hascompetencies = count($data->competencies); return $data; }
public function __construct() { global $DB; parent::__construct(get_string('gradedistributionbar', 'gradereport_visual')); $this->layout = visualization::LAYOUT_AXIS; $this->layoutsettings = null; //array('false', 'true'); $this->nodeshape = visualization::SHAPE_VERTICAL_BAR; $this->xaxis = 'grade'; $this->yaxis = 'students'; $this->xaxislabelformat = '0\\%'; //$this->xaxismax = 100 + grade_distribution::RANGE; //$this->xaxismin = grade_distribution::RANGE; $this->xaxisxoffset = -27; $this->xaxislabel = get_string('grade', 'gradereport_visual'); if ($this->percent) { $this->yaxislabelformat = '0\\%'; $this->yaxislabel = get_string('percentstudents', 'gradereport_visual'); } else { $this->yaxislabel = get_string('numberstudents', 'gradereport_visual'); } $this->title = get_string('gradedistribution:title', 'gradereport_visual'); $this->capability = 'gradereport/visual:vis:grade_distribution_bar'; $this->usegroups = true; $options = array(); foreach (groups_get_all_groups(required_param('id')) as $groupkey => $group) { $options[$groupkey] = grade_report_visual::truncate($group->name); } $options[0] = 'All Groups'; if (isset($DB) && !is_null($DB)) { $course = $DB->get_record('course', array('id' => required_param('id'))); } else { $course = get_record('course', 'id', required_param('id')); } if (!$course) { print_error('nocourseid'); } $active = groups_get_course_group($course, true); if (!$active) { $active = 0; } $this->selector = new selector('group', $options, $active); $this->selectors = array($this->selector); $this->colorencoder = new encoder(encoder::ENCODER_COLOR, 'item'); $this->encoders = array($this->colorencoder); $this->itemlegend = new legend($this->colorencoder, array(get_string('coursetotal', 'grades'))); $this->legends = array($this->itemlegend); }
/** * This function extends the navigation with the report items * * @param navigation_node $navigation The navigation node to extend * @param stdClass $course The course to object for the report * @param stdClass $context The context of the course */ function progress_report_extend_navigation($navigation, $course, $context) { global $CFG, $OUTPUT; $showonnavigation = has_capability('coursereport/progress:view', $context); $group = groups_get_course_group($course, true); // Supposed to verify group if ($group === 0 && $course->groupmode == SEPARATEGROUPS) { $showonnavigation = $showonnavigation && has_capability('moodle/site:accessallgroups', $context); } $completion = new completion_info($course); $showonnavigation = $showonnavigation && $completion->is_enabled() && count($completion->get_activities()) > 0; if ($showonnavigation) { $url = new moodle_url('/course/report/progress/index.php', array('course' => $course->id)); $navigation->add(get_string('pluginname', 'coursereport_progress'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); } }
function definition() { global $COURSE; $mform =& $this->_form; if (isset($this->_customdata)) { // hardcoding plugin names here is hacky $features = $this->_customdata; } else { $features = array(); } // course id needs to be passed for auth purposes $mform->addElement('header', 'general', get_string('importfile', 'grades')); // file upload $mform->addElement('filepicker', 'userfile', get_string('file')); $mform->addRule('userfile', null, 'required'); $encodings = core_text::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings); if (!empty($features['includeseparator'])) { $radio = array(); $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab'); $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma'); $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon'); $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon'); $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false); $mform->setDefault('separator', 'comma'); } if (!empty($features['verbosescales'])) { $options = array(1 => get_string('yes'), 0 => get_string('no')); $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options); } $options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000); $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize $mform->setType('previewrows', PARAM_INT); $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE)); $mform->setType('groupid', PARAM_INT); $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); }
$datestring->secs = get_string('secs'); if ($mode !== null) { $mode = (int) $mode; $SESSION->userindexmode = $mode; } else { if (isset($SESSION->userindexmode)) { $mode = (int) $SESSION->userindexmode; } else { $mode = MODE_BRIEF; } } // Check to see if groups are being used in this course // and if so, set $currentgroup to reflect the current group. $groupmode = groups_get_course_groupmode($course); // Groups are being used. $currentgroup = groups_get_course_group($course, true); if (!$currentgroup) { // To make some other functions work better later. $currentgroup = null; } $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)); $PAGE->set_title("{$course->shortname}: " . get_string('participants')); $PAGE->set_heading($course->fullname); $PAGE->set_pagetype('course-view-' . $course->format); $PAGE->add_body_class('path-user'); // So we can style it independently. $PAGE->set_other_editing_capability('moodle/course:manageactivities'); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('participants')); echo '<div class="userlist">'; if ($isseparategroups and !$currentgroup) {
/** * Adds essential course nodes to the navigation for the given course. * * This method adds nodes such as reports, blogs and participants * * @param navigation_node $coursenode * @param stdClass $course * @return bool returns true on successful addition of a node. */ public function add_course_essentials($coursenode, stdClass $course) { global $CFG, $SITE; if ($course->id == $SITE->id) { return $this->add_front_page_course_essentials($coursenode, $course); } if ($coursenode == false || !$coursenode instanceof navigation_node || $coursenode->get('participants', navigation_node::TYPE_CONTAINER)) { return true; } //Participants if (has_capability('moodle/course:viewparticipants', $this->page->context)) { $participants = $coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id=' . $course->id), self::TYPE_CONTAINER, get_string('participants'), 'participants'); if (!empty($CFG->enableblogs)) { if (($CFG->bloglevel == BLOG_GLOBAL_LEVEL or $CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser())) and has_capability('moodle/blog:view', context_system::instance())) { $blogsurls = new moodle_url('/blog/index.php'); if ($currentgroup = groups_get_course_group($course, true)) { $blogsurls->param('groupid', $currentgroup); } else { $blogsurls->param('courseid', $course->id); } $participants->add(get_string('blogscourse', 'blog'), $blogsurls->out(), self::TYPE_SETTING, null, 'courseblogs'); } } if (!empty($CFG->enablenotes) && (has_capability('moodle/notes:manage', $this->page->context) || has_capability('moodle/notes:view', $this->page->context))) { $participants->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('filtertype' => 'course', 'filterselect' => $course->id)), self::TYPE_SETTING, null, 'currentcoursenotes'); } } else { if (count($this->extendforuser) > 0 || $this->page->course->id == $course->id) { $participants = $coursenode->add(get_string('participants'), null, self::TYPE_CONTAINER, get_string('participants'), 'participants'); } } // Badges. if (!empty($CFG->enablebadges) && !empty($CFG->badges_allowcoursebadges) && has_capability('moodle/badges:viewbadges', $this->page->context)) { $url = new moodle_url('/badges/view.php', array('type' => 2, 'id' => $course->id)); $coursenode->add(get_string('coursebadges', 'badges'), null, navigation_node::TYPE_CONTAINER, null, 'coursebadges'); $coursenode->get('coursebadges')->add(get_string('badgesview', 'badges'), $url, navigation_node::TYPE_SETTING, null, 'badgesview', new pix_icon('i/badge', get_string('badgesview', 'badges'))); } return true; }
if ($format !== '') { $url->param('format', $format); } if ($start !== 0) { $url->param('start', $start); } $PAGE->set_url($url); $PAGE->set_pagelayout('report'); require_login($course); // Check basic permission require_capability('report/progress:view',$context); // Get group mode $group = groups_get_course_group($course,true); // Supposed to verify group if ($group===0 && $course->groupmode==SEPARATEGROUPS) { require_capability('moodle/site:accessallgroups',$context); } // Get data on activities and progress of all users, and give error if we've // nothing to display (no users or no activities) $reportsurl = $CFG->wwwroot.'/course/report.php?id='.$course->id; $completion = new completion_info($course); $activities = $completion->get_activities(); // Generate where clause $where = array(); $where_params = array(); if ($sifirst !== 'all') {
/** * Print group menu selector for course level. * * @global object * @global object * @param object $course course object * @param string $urlroot return address * @param boolean $return return as string instead of printing * @return mixed void or string depending on $return param */ function groups_print_course_menu($course, $urlroot, $return = false) { global $CFG, $USER, $SESSION, $OUTPUT; if (!($groupmode = $course->groupmode)) { if ($return) { return ''; } else { return; } } $context = get_context_instance(CONTEXT_COURSE, $course->id); if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) { $allowedgroups = groups_get_all_groups($course->id, 0, $course->defaultgroupingid); // detect changes related to groups and fix active group if (!empty($SESSION->activegroup[$course->id][VISIBLEGROUPS][0])) { if (!array_key_exists($SESSION->activegroup[$course->id][VISIBLEGROUPS][0], $allowedgroups)) { // active does not exist anymore unset($SESSION->activegroup[$course->id][VISIBLEGROUPS][0]); } } if (!empty($SESSION->activegroup[$course->id]['aag'][0])) { if (!array_key_exists($SESSION->activegroup[$course->id]['aag'][0], $allowedgroups)) { // active group does not exist anymore unset($SESSION->activegroup[$course->id]['aag'][0]); } } } else { $allowedgroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid); // detect changes related to groups and fix active group if (isset($SESSION->activegroup[$course->id][SEPARATEGROUPS][0])) { if ($SESSION->activegroup[$course->id][SEPARATEGROUPS][0] == 0) { if ($allowedgroups) { // somebody must have assigned at least one group, we can select it now - yay! unset($SESSION->activegroup[$course->id][SEPARATEGROUPS][0]); } } else { if (!array_key_exists($SESSION->activegroup[$course->id][SEPARATEGROUPS][0], $allowedgroups)) { // active group not allowed or does not exist anymore unset($SESSION->activegroup[$course->id][SEPARATEGROUPS][0]); } } } } $activegroup = groups_get_course_group($course, true); $groupsmenu = array(); if (!$allowedgroups or $groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) { $groupsmenu[0] = get_string('allparticipants'); } if ($allowedgroups) { foreach ($allowedgroups as $group) { $groupsmenu[$group->id] = format_string($group->name); } } if ($groupmode == VISIBLEGROUPS) { $grouplabel = get_string('groupsvisible'); } else { $grouplabel = get_string('groupsseparate'); } if (count($groupsmenu) == 1) { $groupname = reset($groupsmenu); $output = $grouplabel . ': ' . $groupname; } else { $select = new single_select(new moodle_url($urlroot), 'group', $groupsmenu, $activegroup, null, 'selectgroup'); $select->label = $grouplabel; $output = $OUTPUT->render($select); } $output = '<div class="groupselector">' . $output . '</div>'; if ($return) { return $output; } else { echo $output; } }
function definition() { global $CFG, $COURSE; $mform =& $this->_form; // this is an array of headers $header = $this->_customdata['header']; // course id $mform->addElement('header', 'general', get_string('identifier', 'grades')); $mapfromoptions = array(); if ($header) { foreach ($header as $i => $h) { $mapfromoptions[$i] = s($h); } } $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions); $maptooptions = array('userid' => get_string('userid', 'grades'), 'username' => get_string('username'), 'useridnumber' => get_string('idnumber'), 'useremail' => get_string('email'), '0' => get_string('ignore', 'grades')); $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions); $mform->addElement('header', 'general', get_string('mappings', 'grades')); // Add a feedback option. $feedbacks = array(); if ($gradeitems = $this->_customdata['gradeitems']) { foreach ($gradeitems as $itemid => $itemname) { $feedbacks['feedback_' . $itemid] = get_string('feedbackforgradeitems', 'grades', $itemname); } } if ($header) { $i = 0; // index foreach ($header as $h) { $h = trim($h); // This is what each header maps to. $headermapsto = array(get_string('others', 'grades') => array('0' => get_string('ignore', 'grades'), 'new' => get_string('newitem', 'grades')), get_string('gradeitems', 'grades') => $gradeitems, get_string('feedbacks', 'grades') => $feedbacks); $mform->addElement('selectgroups', 'mapping_' . $i, s($h), $headermapsto); $i++; } } // course id needs to be passed for auth purposes $mform->addElement('hidden', 'map', 1); $mform->setType('map', PARAM_INT); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'iid'); $mform->setType('iid', PARAM_INT); $mform->addElement('hidden', 'importcode'); $mform->setType('importcode', PARAM_FILE); $mform->addElement('hidden', 'verbosescales', 1); $mform->setType('verbosescales', PARAM_INT); $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE)); $mform->setType('groupid', PARAM_INT); $this->add_action_buttons(false, get_string('uploadgrades', 'grades')); }
/** * Sets up this object's group variables, mainly to restrict the selection of users to display. */ function setup_groups() { global $CFG; /// find out current groups mode if ($this->groupmode = groups_get_course_groupmode($this->course)) { $this->currentgroup = groups_get_course_group($this->course, true); $this->group_selector = groups_print_course_menu($this->course, $this->pbarurl, true); if ($this->groupmode == SEPARATEGROUPS and !$this->currentgroup and !has_capability('moodle/site:accessallgroups', $this->context)) { $this->currentgroup = -2; // means can not accesss any groups at all } if ($this->currentgroup) { $this->groupsql = " JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id "; $this->groupwheresql = " AND gm.groupid = {$this->currentgroup} "; } } }
function get_content() { global $CFG, $SITE, $USER, $DB; if (empty($CFG->usetags) || empty($CFG->bloglevel)) { $this->content->text = ''; return $this->content; } if (empty($this->config->timewithin)) { $this->config->timewithin = BLOGDEFAULTTIMEWITHIN; } if (empty($this->config->numberoftags)) { $this->config->numberoftags = BLOGDEFAULTNUMBEROFTAGS; } if (empty($this->config->sort)) { $this->config->sort = BLOGDEFAULTSORT; } if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; /// Get a list of tags $timewithin = time() - $this->config->timewithin * 24 * 60 * 60; /// convert to seconds // admins should be able to read all tags $type = ''; if (!has_capability('moodle/user:readuserblogs', get_context_instance(CONTEXT_SYSTEM))) { $type = " AND (p.publishstate = 'site' or p.publishstate='public')"; } $sql = "SELECT t.id, t.tagtype, t.rawname, t.name, COUNT(DISTINCT ti.id) AS ct\n FROM {tag} t, {tag_instance} ti, {post} p\n WHERE t.id = ti.tagid AND p.id = ti.itemid\n {$type}\n AND ti.itemtype = 'post'\n AND ti.timemodified > {$timewithin}\n GROUP BY t.id, t.tagtype, t.name, t.rawname\n ORDER BY ct DESC, t.name ASC"; if ($tags = $DB->get_records_sql($sql, null, 0, $this->config->numberoftags)) { /// There are 2 things to do: /// 1. tags with the same count should have the same size class /// 2. however many tags we have should be spread evenly over the /// 20 size classes $totaltags = count($tags); $currenttag = 0; $size = 20; $lasttagct = -1; $etags = array(); foreach ($tags as $tag) { $currenttag++; if ($currenttag == 1) { $lasttagct = $tag->ct; $size = 20; } else { if ($tag->ct != $lasttagct) { $lasttagct = $tag->ct; $size = 20 - (int) (($currenttag - 1) / $totaltags * 20); } } $tag->class = "{$tag->tagtype} s{$size}"; $etags[] = $tag; } /// Now we sort the tag display order $CFG->tagsort = $this->config->sort; usort($etags, "blog_tags_sort"); /// Finally we create the output /// Accessibility: markup as a list. $this->content->text .= "\n<ul class='inline-list'>\n"; foreach ($etags as $tag) { switch ($CFG->bloglevel) { case BLOG_USER_LEVEL: $filtertype = 'user'; $filterselect = $USER->id; break; case BLOG_GROUP_LEVEL: $filtertype = 'group'; $filterselect = groups_get_course_group($this->page->course); break; case BLOG_COURSE_LEVEL: $filtertype = 'course'; $filterselect = $this->page->course->id; break; default: if ($this->page->course->id != SITEID) { $filtertype = 'course'; $filterselect = $this->page->course->id; } else { $filtertype = 'site'; $filterselect = SITEID; } break; } $link = $CFG->wwwroot . '/blog/index.php?filtertype=' . $filtertype . '&filterselect=' . $filterselect . '&tagid=' . $tag->id; $this->content->text .= '<li><a href="' . $link . '" ' . 'class="' . $tag->class . '" ' . 'title="' . get_string('numberofentries', 'blog', $tag->ct) . '">' . tag_display_name($tag) . '</a></li> '; } $this->content->text .= "\n</ul>\n"; } return $this->content; }
/** * Sets up this object's group variables, mainly to restrict the selection of users to display. */ function setup_groups() { global $CFG; /// find out current groups mode $this->group_selector = groups_print_course_menu($this->course, $this->pbarurl, true); $this->currentgroup = groups_get_course_group($this->course); if ($this->currentgroup) { $this->groupsql = " LEFT JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id "; $this->groupwheresql = " AND gm.groupid = {$this->currentgroup} "; } }
// course id if (!($course = get_record('course', 'id', $id))) { print_error('nocourseid'); } require_login($course); $context = get_context_instance(CONTEXT_COURSE, $id); require_capability('moodle/grade:export', $context); require_capability('gradeexport/txt:view', $context); $strgrades = get_string('grades', 'grades'); $actionstr = get_string('modulename', 'gradeexport_txt'); $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id)); print_header($course->shortname . ': ' . get_string('grades'), $course->fullname, $navigation); print_grade_plugin_selector($id, 'export', 'txt'); if (!empty($CFG->gradepublishing)) { $CFG->gradepublishing = has_capability('gradeexport/txt:publish', $context); } $mform = new grade_export_form(null, array('includeseparator' => true, 'publishing' => true)); // process post information if ($data = $mform->get_data()) { $export = new grade_export_txt($course, groups_get_course_group($course)); // print the grades on screen for feedback $export->process_form($data); $export->print_continue(); $export->display_preview(); print_footer($course); exit; } groups_print_course_menu($course, 'index.php?id=' . $id); echo '<div class="clearer"></div>'; $mform->display(); print_footer();
function get_content() { global $COURSE, $CFG, $USER; if ($this->content !== NULL) { return $this->content; } $filteropt = new stdClass(); $filteropt->overflowdiv = true; if ($this->content_is_trusted()) { // fancy html allowed only on course, category and system blocks. $filteropt->noclean = true; } $this->content = new stdClass(); $this->content->text = ''; $usegroupmenu = true; if (has_capability('moodle/site:accessallgroups', context_course::instance($COURSE->id))) { $usegroupmenu = true; } else { $usergroupings = groups_get_user_groups($COURSE->id, $USER->id); if (count($usergroupings) == 1) { $usergroups = array_pop($usergroupings); if (count($usergroups) == 1) { $usegroupmenu = false; $uniquegroup = array_pop($usergroups); } } } $coursegroups = groups_get_all_groups($COURSE->id); if ($coursegroups && $usegroupmenu) { $this->content->text .= groups_print_course_menu($COURSE, $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id, true); } $gid = 0 + groups_get_course_group($COURSE, $USER->id); if (@$uniquegroup && !$gid) { $gid = $uniquegroup; } $textkeys = array('text_all'); if (!empty($coursegroups)) { $textkeys[] = 'text_' . $gid; } foreach ($textkeys as $tk) { if (isset($this->config->{$tk})) { $format = FORMAT_HTML; // Check to see if the format has been properly set on the config $formatkey = str_replace('text_', 'format_', $tk); if (isset($this->config->{$formatkey})) { $format = $this->config->{$formatkey}; } // rewrite url $this->config->{$tk} = file_rewrite_pluginfile_urls($this->config->{$tk}, 'pluginfile.php', $this->context->id, 'block_groupspecifichtml', 'content', NULL); // Default to FORMAT_HTML which is what will have been used before the // editor was properly implemented for the block. $this->content->text .= format_text($this->config->{$tk}, $format, $filteropt); } else { $this->content->text .= ''; } } $this->content->footer = ''; unset($filteropt); // memory footprint if (empty($this->content->text)) { $this->content->text = ' '; } return $this->content; }
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require __DIR__ . '/../../config.php'; $courseid = required_param('courseid', PARAM_INT); require_login($courseid); $manager = block_xp_manager::get($courseid); $context = $manager->get_context(); if (!$manager->can_view_ladder_page()) { throw new moodle_exception('nopermissions', '', '', 'view_ladder_page'); } // Some stuff. $url = new moodle_url('/blocks/xp/ladder.php', array('courseid' => $courseid)); $strladder = get_string('ladder', 'block_xp'); // Page info. $PAGE->set_context($context); $PAGE->set_pagelayout('course'); $PAGE->set_title($strladder); $PAGE->set_heading($COURSE->fullname); $PAGE->set_url($url); $manager = block_xp_manager::get($courseid); $group = groups_get_course_group($manager->get_course(), true); $renderer = $PAGE->get_renderer('block_xp'); echo $OUTPUT->header(); echo $OUTPUT->heading($strladder); echo $renderer->navigation($manager, 'ladder'); echo $renderer->notices($manager); groups_print_course_menu($manager->get_course(), $url); $table = new block_xp_ladder_table('block_xp_ladder', $courseid, $group, array('identitymode' => $manager->get_config('identitymode'), 'rankmode' => $manager->get_config('rankmode'), 'neighboursonly' => $manager->get_config('neighbours') > 0, 'neighboursabove' => $manager->get_config('neighbours'), 'neighboursbelow' => $manager->get_config('neighbours'))); $table->define_baseurl($url); echo $table->out(20, false); echo $OUTPUT->footer();
/** * Sets up this object's group variables, mainly to restrict the selection of users to display. */ protected function setup_groups() { /// find out current groups mode if ($this->groupmode = groups_get_course_groupmode($this->course)) { $this->currentgroup = groups_get_course_group($this->course, true); $this->group_selector = groups_print_course_menu($this->course, $this->pbarurl, true); if ($this->groupmode == SEPARATEGROUPS and !$this->currentgroup and !has_capability('moodle/site:accessallgroups', $this->context)) { $this->currentgroup = -2; // means can not access any groups at all } if ($this->currentgroup) { $this->groupsql = " JOIN {groups_members} gm ON gm.userid = u.id "; $this->groupwheresql = " AND gm.groupid = :gr_grpid "; $this->groupwheresql_params = array('gr_grpid' => $this->currentgroup); } } }
/** * Return the current user roles and groups in the current course * @return array Array in the first element the groups in the second the user roles */ public function get_groups_roles() { global $USER; $groups = array(); $roles = array(); if (!has_capability('moodle/course:viewparticipants', $this->context)) { return array($groups, $roles); } if ($groupmode = $this->course->groupmode) { $aag = has_capability('moodle/site:accessallgroups', $this->context); if ($groupmode == VISIBLEGROUPS or $aag) { $allowedgroups = groups_get_all_groups($this->course->id, 0, $this->course->defaultgroupingid); } else { $allowedgroups = groups_get_all_groups($this->course->id, $USER->id, $this->course->defaultgroupingid); } $activegroup = groups_get_course_group($this->course, true, $allowedgroups); $groupsmenu = array(); if (!$allowedgroups or $groupmode == VISIBLEGROUPS or $aag) { $groupsmenu[0] = get_string('allparticipants'); } if ($allowedgroups) { foreach ($allowedgroups as $group) { $groupsmenu[$group->id] = format_string($group->name); } } $groups = $groupsmenu; } $allroles = get_all_roles(); $roles = get_profile_roles($this->context); $allrolenames = array(); $rolenames = array(0 => get_string('allparticipants')); foreach ($allroles as $role) { $allrolenames[$role->id] = strip_tags(role_get_name($role, $this->context)); if (isset($roles[$role->id])) { $rolenames[$role->id] = $allrolenames[$role->id]; } } $roles = $rolenames; return array($groups, $roles); }
} $form->format = $defaultformat; if (!empty($header)) { $header = ' (' . $header . ')'; } echo '<div class="header">' . get_string('newevent', 'calendar') . $header . '</div>'; if ($eventtype == 'select') { $courseid = optional_param('courseid', $SESSION->cal_course_referer, PARAM_INT); if ($courseid == 0) { // workaround by Dan for bug #6130 $courseid = SITEID; } if (!($course = get_record('course', 'id', $courseid))) { error('Incorrect course ID'); } $groupid = groups_get_course_group($course); echo '<h2>' . get_string('eventkind', 'calendar') . ':</h2>'; echo '<div id="selecteventtype">'; include 'event_select.html'; echo '</div>'; } else { include 'event_new.html'; if ($usehtmleditor) { use_html_editor("description"); } } break; } echo '</td>'; // START: Last column (3-month display) $defaultcourses = calendar_get_default_courses();
function get_content() { global $USER, $CFG, $COURSE; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } $timetoshowusers = 300; //Seconds default if (isset($CFG->block_online_users_timetosee)) { $timetoshowusers = $CFG->block_online_users_timetosee * 60; } $timefrom = 100 * floor((time() - $timetoshowusers) / 100); // Round to nearest 100 seconds for better query cache // Get context so we can check capabilities. $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); //Calculate if we are in separate groups $isseparategroups = $COURSE->groupmode == SEPARATEGROUPS && $COURSE->groupmodeforce && !has_capability('moodle/site:accessallgroups', $context); //Get the user current group $currentgroup = $isseparategroups ? groups_get_course_group($COURSE) : NULL; $groupmembers = ""; $groupselect = ""; //Add this to the SQL to show only group users if ($currentgroup !== NULL) { $groupmembers = ", {$CFG->prefix}groups_members gm "; $groupselect = " AND u.id = gm.userid AND gm.groupid = '{$currentgroup}'"; } if ($COURSE->id == SITEID) { // Site-level $select = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, max(u.lastaccess) as lastaccess "; $from = "FROM {$CFG->prefix}user u \n {$groupmembers} "; $where = "WHERE u.lastaccess > {$timefrom}\n {$groupselect} "; $order = "ORDER BY lastaccess DESC "; } else { // Course-level $courseselect = "AND ul.courseid = '" . $COURSE->id . "'"; $select = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, max(ul.timeaccess) as lastaccess "; $from = "FROM {$CFG->prefix}user_lastaccess ul,\n {$CFG->prefix}user u\n {$groupmembers} "; $where = "WHERE ul.timeaccess > {$timefrom}\n AND u.id = ul.userid\n AND ul.courseid = {$COURSE->id}\n {$groupselect} "; $order = "ORDER BY lastaccess DESC "; } $groupby = "GROUP BY u.id, u.username, u.firstname, u.lastname, u.picture "; $SQL = $select . $from . $where . $groupby . $order; $users = array(); $pcontext = get_related_contexts_string($context); if ($pusers = get_records_sql($SQL, 0, 50)) { // We'll just take the most recent 50 maximum foreach ($pusers as $puser) { // if current user can't view hidden role assignment in this context and // user has a hidden role assigned at this context or any parent contexts, // ignore this user $SQL = "SELECT id FROM {$CFG->prefix}role_assignments\n WHERE userid = {$puser->id}\n AND contextid {$pcontext}\n AND hidden = 1"; if (!has_capability('moodle/role:viewhiddenassigns', $context) && record_exists_sql($SQL)) { // can't see this user as the current user has no capability // and this user has a hidden assignment at this context or higher continue; } $puser->fullname = fullname($puser); $users[$puser->id] = $puser; } } //Calculate minutes $minutes = floor($timetoshowusers / 60); $this->content->text = "<div class=\"info\">(" . get_string("periodnminutes", "block_online_users", $minutes) . ")</div>"; //Now, we have in users, the list of users to show //Because they are online if (!empty($users)) { //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string). //Accessibility: Converted <div> to <ul>, inherit existing classes & styles. $this->content->text .= "<ul class='list'>\n"; foreach ($users as $user) { $this->content->text .= '<li class="listentry">'; $timeago = format_time(time() - $user->lastaccess); //bruno to calculate correctly on frontpage if ($user->username == 'guest') { $this->content->text .= '<div class="user">' . print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false); $this->content->text .= get_string('guestuser') . '</div>'; } else { $this->content->text .= '<div class="user"><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $COURSE->id . '" title="' . $timeago . '">'; $this->content->text .= print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false); $this->content->text .= $user->fullname . '</a></div>'; } if (!empty($USER->id) and $USER->id != $user->id and !empty($CFG->messaging) and !isguest() and $user->username != 'guest') { // Only when logged in and messaging active etc $this->content->text .= '<div class="message"><a title="' . get_string('messageselectadd') . '" href="' . $CFG->wwwroot . '/message/discussion.php?id=' . $user->id . '" onclick="this.target=\'message_' . $user->id . '\';return openpopup(\'/message/discussion.php?id=' . $user->id . '\', \'message_' . $user->id . '\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">' . '<img class="iconsmall" src="' . $CFG->pixpath . '/t/message.gif" alt="' . get_string('messageselectadd') . '" /></a></div>'; } $this->content->text .= "</li>\n"; } $this->content->text .= '</ul><div class="clearer"><!-- --></div>'; } else { $this->content->text .= "<div class=\"info\">" . get_string("none") . "</div>"; } return $this->content; }
} } if (!$acess) { print_error('dennyacess', 'block_uniquelogin_list', '', $courseid); } $PAGE->set_context($context); $PAGE->set_course($course); $PAGE->set_url('/blocks/uniquelogin_list/list_users.php', array('courseid' => $courseid)); $PAGE->navbar->add(get_string("blocktitle", "block_uniquelogin_list")); $PAGE->set_title(get_string("blocktitle", "block_uniquelogin_list")); $PAGE->set_heading(get_string("blocktitle", "block_uniquelogin_list")); $PAGE->set_pagetype(get_string("blocktitle", "block_uniquelogin_list")); $PAGE->set_pagelayout('standard'); //Calculate if we are in separate groups $isseparategroups = $PAGE->course->groupmode == SEPARATEGROUPS && $PAGE->course->groupmodeforce && !has_capability('moodle/site:accessallgroups', $PAGE->context); $currentgroup = $isseparategroups ? groups_get_course_group($PAGE->course) : NULL; $aUsers = getUserList($currentgroup, $courseid, $PAGE->context->contextlevel, $PAGE->context); echo $OUTPUT->header(); echo '<h3>' . get_string("blocktitle_list", "block_uniquelogin_list") . '</h3>'; $baseurl = new moodle_url('/blocks/uniquelogin_list/list_users.php', array('contextid' => $context->id, 'courseid' => $courseid, 'perpage' => $perpage)); $table = new flexible_table('user-index-participants-' . $courseid); $table->define_columns(array('userpic', 'firstname', 'lastname', 'lastip', 'lastaccess', 'deletesession')); $table->define_headers(array(get_string('userpic'), get_string('firstname'), get_string('lastname'), 'IP', get_string('lastaccess'), get_string("deletesession", "block_uniquelogin_list"))); $table->define_baseurl($baseurl->out()); if (!isset($hiddenfields['lastaccess'])) { $table->sortable(true, 'lastaccess', SORT_DESC); } else { $table->sortable(true, 'firstname', SORT_ASC); } $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'participants');
/** * Adds essential course nodes to the navigation for the given course. * * This method adds nodes such as reports, blogs and participants * * @param navigation_node $coursenode * @param stdClass $course * @return bool returns true on successful addition of a node. */ public function add_course_essentials($coursenode, stdClass $course) { global $CFG, $SITE; require_once $CFG->dirroot . '/course/lib.php'; if ($course->id == $SITE->id) { return $this->add_front_page_course_essentials($coursenode, $course); } if ($coursenode == false || !$coursenode instanceof navigation_node || $coursenode->get('participants', navigation_node::TYPE_CONTAINER)) { return true; } $navoptions = course_get_user_navigation_options($this->page->context); //Participants if ($navoptions->participants) { $participants = $coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id=' . $course->id), self::TYPE_CONTAINER, get_string('participants'), 'participants'); if ($navoptions->blogs) { $blogsurls = new moodle_url('/blog/index.php'); if ($currentgroup = groups_get_course_group($course, true)) { $blogsurls->param('groupid', $currentgroup); } else { $blogsurls->param('courseid', $course->id); } $participants->add(get_string('blogscourse', 'blog'), $blogsurls->out(), self::TYPE_SETTING, null, 'courseblogs'); } if ($navoptions->notes) { $participants->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('filtertype' => 'course', 'filterselect' => $course->id)), self::TYPE_SETTING, null, 'currentcoursenotes'); } } else { if (count($this->extendforuser) > 0 || $this->page->course->id == $course->id) { $participants = $coursenode->add(get_string('participants'), null, self::TYPE_CONTAINER, get_string('participants'), 'participants'); } } // Badges. if ($navoptions->badges) { $url = new moodle_url('/badges/view.php', array('type' => 2, 'id' => $course->id)); $coursenode->add(get_string('coursebadges', 'badges'), null, navigation_node::TYPE_CONTAINER, null, 'coursebadges'); $coursenode->get('coursebadges')->add(get_string('badgesview', 'badges'), $url, navigation_node::TYPE_SETTING, null, 'badgesview', new pix_icon('i/badge', get_string('badgesview', 'badges'))); } return true; }
function csv_quote($value) { global $excel; if ($excel) { $tl = textlib_get_instance(); return $tl->convert('"' . str_replace('"', "'", $value) . '"', 'UTF-8', 'UTF-16LE'); } else { return '"' . str_replace('"', "'", $value) . '"'; } } // Check permissions require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('coursereport/completion:view', $context); // Get group mode $group = groups_get_course_group($course, true); // Supposed to verify group if ($group === 0 && $course->groupmode == SEPARATEGROUPS) { require_capability('moodle/site:accessallgroups', $context); } /** * Load data */ // Get criteria for course $completion = new completion_info($course); if (!$completion->has_criteria()) { print_error('err_nocriteria', 'completion', $CFG->wwwroot . '/course/report.php?id=' . $course->id); } // Get criteria and put in correct order $criteria = array(); foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE) as $criterion) {
} // Output the roles menu. $sql = "SELECT DISTINCT r.id, r.name, r.shortname\n FROM {role} r, {role_assignments} a\n WHERE a.contextid = :contextid\n AND r.id = a.roleid"; $params = array('contextid' => $context->id); $roles = role_fix_names($DB->get_records_sql($sql, $params), $context); $rolestodisplay = array(0 => get_string('allparticipants')); foreach ($roles as $role) { $rolestodisplay[$role->id] = $role->localname; } echo ' ' . get_string('role'); echo $OUTPUT->single_select($PAGE->url, 'role', $rolestodisplay, $roleselected); echo $OUTPUT->container_end(); // Apply group restrictions. $params = array(); $groupjoin = ''; $groupselected = groups_get_course_group($course); if ($groupselected && $groupselected != 0) { $groupjoin = 'JOIN {groups_members} g ON (g.groupid = :groupselected AND g.userid = u.id)'; $params['groupselected'] = $groupselected; } // Get the list of users enrolled in the course. $picturefields = user_picture::fields('u'); $sql = "SELECT DISTINCT {$picturefields}, COALESCE(l.timeaccess, 0) AS lastonlinetime\n FROM {user} u\n JOIN {role_assignments} a ON (a.contextid = :contextid AND a.userid = u.id {$rolewhere})\n {$groupjoin}\n LEFT JOIN {user_lastaccess} l ON (l.courseid = :courseid AND l.userid = u.id)"; $params['contextid'] = $context->id; $params['courseid'] = $course->id; $userrecords = $DB->get_records_sql($sql, $params); if (get_config('block_progress', 'showinactive') != 1) { extract_suspended_users($context, $userrecords); } $userids = array_keys($userrecords); $users = array_values($userrecords);
/** * Print group menu selector for course level. * * @category group * @param stdClass $course course object * @param mixed $urlroot return address. Accepts either a string or a moodle_url * @param bool $return return as string instead of printing * @return mixed void or string depending on $return param */ function groups_print_course_menu($course, $urlroot, $return = false) { global $USER, $OUTPUT; if (!($groupmode = $course->groupmode)) { if ($return) { return ''; } else { return; } } $context = context_course::instance($course->id); $aag = has_capability('moodle/site:accessallgroups', $context); $usergroups = array(); if ($groupmode == VISIBLEGROUPS or $aag) { $allowedgroups = groups_get_all_groups($course->id, 0, $course->defaultgroupingid); // Get user's own groups and put to the top. $usergroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid); } else { $allowedgroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid); } $activegroup = groups_get_course_group($course, true, $allowedgroups); $groupsmenu = array(); if (!$allowedgroups or $groupmode == VISIBLEGROUPS or $aag) { $groupsmenu[0] = get_string('allparticipants'); } $groupsmenu += groups_sort_menu_options($allowedgroups, $usergroups); if ($groupmode == VISIBLEGROUPS) { $grouplabel = get_string('groupsvisible'); } else { $grouplabel = get_string('groupsseparate'); } if ($aag and $course->defaultgroupingid) { if ($grouping = groups_get_grouping($course->defaultgroupingid)) { $grouplabel = $grouplabel . ' (' . format_string($grouping->name) . ')'; } } if (count($groupsmenu) == 1) { $groupname = reset($groupsmenu); $output = $grouplabel . ': ' . $groupname; } else { $select = new single_select(new moodle_url($urlroot), 'group', $groupsmenu, $activegroup, null, 'selectgroup'); $select->label = $grouplabel; $output = $OUTPUT->render($select); } $output = '<div class="groupselector">' . $output . '</div>'; if ($return) { return $output; } else { echo $output; } }
// course id if (!($course = get_record('course', 'id', $id))) { print_error('nocourseid'); } require_login($course); $context = get_context_instance(CONTEXT_COURSE, $id); require_capability('moodle/grade:export', $context); require_capability('gradeexport/txt:view', $context); $strgrades = get_string('grades', 'grades'); $actionstr = get_string('modulename', 'gradeexport_txt'); $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id)); print_header($course->shortname . ': ' . get_string('grades'), $course->fullname, $navigation); print_grade_plugin_selector($id, 'export', 'txt'); if (!empty($CFG->gradepublishing)) { $CFG->gradepublishing = has_capability('gradeexport/txt:publish', $context); } $mform = new grade_export_form(null, array('includeseparator' => true, 'publishing' => true)); // process post information if ($data = $mform->get_data()) { $export = new grade_export_txt($course, groups_get_course_group($course), '', false, false, $data->display, $data->decimals); // print the grades on screen for feedback $export->process_form($data); $export->print_continue(); $export->display_preview(); print_footer($course); exit; } groups_print_course_menu($course, 'index.php?id=' . $id); echo '<div class="clearer"></div>'; $mform->display(); print_footer();
function get_content() { global $USER, $CFG, $DB, $OUTPUT; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } $timetoshowusers = 300; //Seconds default if (isset($CFG->block_online_users_timetosee)) { $timetoshowusers = $CFG->block_online_users_timetosee * 60; } $now = time(); //Calculate if we are in separate groups $isseparategroups = $this->page->course->groupmode == SEPARATEGROUPS && $this->page->course->groupmodeforce && !has_capability('moodle/site:accessallgroups', $this->page->context); //Get the user current group $currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : NULL; $sitelevel = $this->page->course->id == SITEID || $this->page->context->contextlevel < CONTEXT_COURSE; $onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $this->page->context, $sitelevel, $this->page->course->id); //Calculate minutes $minutes = floor($timetoshowusers / 60); // Verify if we can see the list of users, if not just print number of users if (!has_capability('block/online_users:viewlist', $this->page->context)) { if (!($usercount = $onlineusers->count_users())) { $usercount = get_string("none"); } $this->content->text = "<div class=\"info\">" . get_string("periodnminutes", "block_online_users", $minutes) . ": {$usercount}</div>"; return $this->content; } $userlimit = 50; // We'll just take the most recent 50 maximum. if ($users = $onlineusers->get_users($userlimit)) { foreach ($users as $user) { $users[$user->id]->fullname = fullname($user); } } else { $users = array(); } $usercount = $onlineusers->count_users(); $usercount = ": {$usercount}"; $this->content->text = "<div class=\"info\">(" . get_string("periodnminutes", "block_online_users", $minutes) . "{$usercount})</div>"; //Now, we have in users, the list of users to show //Because they are online if (!empty($users)) { //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string). //Accessibility: Converted <div> to <ul>, inherit existing classes & styles. $this->content->text .= "<ul class='list'>\n"; if (isloggedin() && has_capability('moodle/site:sendmessage', $this->page->context) && !empty($CFG->messaging) && !isguestuser()) { $canshowicon = true; } else { $canshowicon = false; } foreach ($users as $user) { $this->content->text .= '<li class="listentry">'; $timeago = format_time($now - $user->lastaccess); //bruno to calculate correctly on frontpage if (isguestuser($user)) { $this->content->text .= '<div class="user">' . $OUTPUT->user_picture($user, array('size' => 16, 'alttext' => false)); $this->content->text .= get_string('guestuser') . '</div>'; } else { $this->content->text .= '<div class="user">'; $this->content->text .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $this->page->course->id . '" title="' . $timeago . '">'; $this->content->text .= $OUTPUT->user_picture($user, array('size' => 16, 'alttext' => false, 'link' => false)) . $user->fullname . '</a></div>'; } if ($canshowicon and $USER->id != $user->id and !isguestuser($user)) { // Only when logged in and messaging active etc $anchortagcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/message') . '" alt="' . get_string('messageselectadd') . '" />'; $anchorurl = new moodle_url('/message/index.php', array('id' => $user->id)); $anchortag = html_writer::link($anchorurl, $anchortagcontents, array('title' => get_string('messageselectadd'))); $this->content->text .= '<div class="message">' . $anchortag . '</div>'; } $this->content->text .= "</li>\n"; } $this->content->text .= '</ul><div class="clearer"><!-- --></div>'; } else { $this->content->text .= "<div class=\"info\">" . get_string("none") . "</div>"; } return $this->content; }
public function get_content() { global $USER, $CFG, $DB, $OUTPUT; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } if (!isloggedin()) { $this->content->text = get_string('pleaselogin', 'block_iomad_online_users'); return $this->content; } $timetoshowusers = 300; // Seconds default. if (isset($CFG->block_iomad_online_users_timetosee)) { $timetoshowusers = $CFG->block_iomad_online_users_timetosee * 60; } $timefrom = 100 * floor((time() - $timetoshowusers) / 100); // Round to nearest 100 seconds for better query cache. $now = time(); // Calculate if we are in separate groups. $isseparategroups = $this->page->course->groupmode == SEPARATEGROUPS && $this->page->course->groupmodeforce && !iomad::has_capability('moodle/site:accessallgroups', $this->page->context); // Get the user current group. $currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : null; $groupmembers = ""; $groupselect = ""; $rafrom = ""; $rawhere = ""; $params = array(); $params['now'] = $now; $params['timefrom'] = $timefrom; // Add this to the SQL to show only group users. if ($currentgroup !== null) { $groupmembers = ", {groups_members} gm"; $groupselect = "AND u.id = gm.userid AND gm.groupid = :currentgroup"; $params['currentgroup'] = $currentgroup; } $companyselect = ""; $companyusersjoin = ""; if (company_user::is_company_user()) { company_user::load_company(); $companyusersjoin = ", {user_info_data} muid, {user_info_field} muif"; $companyselect = " AND muif.id = muid.fieldid\n AND u.id = muid.userid\n AND muif.shortname = 'company'\n AND muid.data = :companyshortname "; $params['companyshortname'] = $USER->company->shortname; } $userfields = user_picture::fields('u', array('username')); if ($this->page->course->id == SITEID) { // Site-level. $sql = "SELECT {$userfields}, MAX(u.lastaccess) AS lastaccess\n FROM {user} u {$groupmembers} {$companyusersjoin}\n WHERE u.lastaccess > {$timefrom}\n {$groupselect}\n {$companyselect}\n GROUP BY {$userfields}\n ORDER BY lastaccess DESC "; $csql = "SELECT COUNT(u.id), u.id\n FROM {user} u {$groupmembers} {$companyusersjoin}\n WHERE u.lastaccess > {$timefrom}\n {$groupselect}\n {$companyselect}\n GROUP BY u.id"; } else { // Course level - show only enrolled users for now. // TODO: add a new capability for viewing of all users (guests+enrolled+viewing). list($esqljoin, $eparams) = get_enrolled_sql($this->page->context); $params = array_merge($params, $eparams); $sql = "SELECT {$userfields}, MAX(ul.timeaccess) AS lastaccess\n FROM {user_lastaccess} ul {$groupmembers}, {user} u\n JOIN ({$esqljoin}) euj ON euj.id = u.id\n WHERE ul.timeaccess > :timefrom\n AND u.id = ul.userid\n AND ul.courseid = :courseid\n AND ul.timeaccess <= :now\n AND u.deleted = 0\n {$groupselect}\n GROUP BY {$userfields}\n ORDER BY lastaccess DESC"; $csql = "SELECT COUNT(u.id)\n FROM {user_lastaccess} ul {$groupmembers}, {user} u\n JOIN ({$esqljoin}) euj ON euj.id = u.id\n WHERE ul.timeaccess > :timefrom\n AND u.id = ul.userid\n AND ul.courseid = :courseid\n AND ul.timeaccess <= :now\n AND u.deleted = 0\n {$groupselect}"; $params['courseid'] = $this->page->course->id; } // Calculate minutes. $minutes = floor($timetoshowusers / 60); // Verify if we can see the list of users, if not just print number of users. if (!iomad::has_capability('block/online_users:viewlist', $this->page->context)) { if (!($usercount = $DB->count_records_sql($csql, $params))) { $usercount = get_string("none"); } $this->content->text = "<div class=\"info\">" . get_string("periodnminutes", "block_iomad_online_users", $minutes) . ": {$usercount}</div>"; return $this->content; } if ($users = $DB->get_records_sql($sql, $params, 0, 50)) { // We'll just take the most recent 50 maximum. foreach ($users as $user) { $users[$user->id]->fullname = fullname($user); } } else { $users = array(); } if (count($users) < 50) { $usercount = ""; } else { $usercount = $DB->count_records_sql($csql, $params); $usercount = ": {$usercount}"; } $this->content->text = "<h3>Recent Online Company Users</h3><div class=\"info\">(" . get_string("periodnminutes", "block_iomad_online_users", $minutes) . "{$usercount})</div>"; // Now, we have in users, the list of users to show. // Because they are online. if (!empty($users)) { // Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link // (existing lang string). // Accessibility: Converted <div> to <ul>, inherit existing classes & styles. $this->content->text .= "<ul class='list'>\n"; if (isloggedin() && iomad::has_capability('moodle/site:sendmessage', $this->page->context) && !empty($CFG->messaging) && !isguestuser()) { $canshowicon = true; } else { $canshowicon = false; } foreach ($users as $user) { $this->content->text .= '<li class="listentry">'; $timeago = format_time(time() - $user->lastaccess); // Bruno to calculate correctly on frontpage. if (isguestuser($user)) { $this->content->text .= '<div class="user">' . $OUTPUT->user_picture($user, array('size' => 16)); $this->content->text .= get_string('guestuser') . '</div>'; } else { $this->content->text .= '<div class="user">' . $OUTPUT->user_picture($user, array('size' => 16)); $this->content->text .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $this->page->course->id . '" title="' . $timeago . '">' . $user->fullname . '</a></div>'; } if ($canshowicon and $USER->id != $user->id and !isguestuser($user)) { // Only when logged in and messaging active etc. $anchortagcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/message') . '" alt="' . get_string('messageselectadd') . '" />'; $anchortag = '<a href="' . $CFG->wwwroot . '/message/index.php?id=' . $user->id . '" title="' . get_string('messageselectadd') . '">' . $anchortagcontents . '</a>'; $this->content->text .= '<div class="message">' . $anchortag . '</div>'; } $this->content->text .= "</li>\n"; } $this->content->text .= '</ul><div class="clearer"><!-- --></div>'; } else { $this->content->text .= "<div class=\"info\">" . get_string("none") . "</div>"; } return $this->content; }
/** * Adds essential course nodes to the navigation for the given course. * * This method adds nodes such as reports, blogs and participants * * @param navigation_node $coursenode * @param stdClass $course * @return bool returns true on successful addition of a node. */ public function add_course_essentials($coursenode, stdClass $course) { global $CFG, $SITE; if ($course->id == $SITE->id) { return $this->add_front_page_course_essentials($coursenode, $course); } if ($coursenode == false || !$coursenode instanceof navigation_node || $coursenode->get('participants', navigation_node::TYPE_CONTAINER)) { return true; } //Participants if (has_capability('moodle/course:viewparticipants', $this->page->context)) { $participants = $coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id=' . $course->id), self::TYPE_CONTAINER, get_string('participants'), 'participants'); $currentgroup = groups_get_course_group($course, true); if ($course->id == $SITE->id) { $filterselect = ''; } else { if ($course->id && !$currentgroup) { $filterselect = $course->id; } else { $filterselect = $currentgroup; } } $filterselect = clean_param($filterselect, PARAM_INT); if (($CFG->bloglevel == BLOG_GLOBAL_LEVEL or $CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser())) and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) { $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); $participants->add(get_string('blogscourse', 'blog'), $blogsurls->out()); } if (!empty($CFG->enablenotes) && (has_capability('moodle/notes:manage', $this->page->context) || has_capability('moodle/notes:view', $this->page->context))) { $participants->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('filtertype' => 'course', 'filterselect' => $course->id))); } } else { if (count($this->extendforuser) > 0 || $this->page->course->id == $course->id) { $participants = $coursenode->add(get_string('participants'), null, self::TYPE_CONTAINER, get_string('participants'), 'participants'); } } // View course reports if (has_capability('moodle/site:viewreports', $this->page->context)) { // basic capability for listing of reports $reportnav = $coursenode->add(get_string('reports'), null, self::TYPE_CONTAINER, null, null, new pix_icon('i/stats', '')); $coursereports = get_plugin_list('coursereport'); // deprecated foreach ($coursereports as $report => $dir) { $libfile = $CFG->dirroot . '/course/report/' . $report . '/lib.php'; if (file_exists($libfile)) { require_once $libfile; $reportfunction = $report . '_report_extend_navigation'; if (function_exists($report . '_report_extend_navigation')) { $reportfunction($reportnav, $course, $this->page->context); } } } $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php'); foreach ($reports as $reportfunction) { $reportfunction($reportnav, $course, $this->page->context); } } return true; }
/** * Validate access permissions to the report * * @param int $courseid the courseid * @param int $userid the user id to retrieve data from * @param int $groupid the group id * @return array with the parameters cleaned and other required information * @since Moodle 3.2 */ protected static function check_report_access($courseid, $userid, $groupid = 0) { global $USER; // Validate the parameter. $params = self::validate_parameters(self::get_grades_table_parameters(), array('courseid' => $courseid, 'userid' => $userid, 'groupid' => $groupid)); // Compact/extract functions are not recommended. $courseid = $params['courseid']; $userid = $params['userid']; $groupid = $params['groupid']; // Function get_course internally throws an exception if the course doesn't exist. $course = get_course($courseid); $context = context_course::instance($courseid); self::validate_context($context); // Specific capabilities. require_capability('gradereport/user:view', $context); $user = null; if (empty($userid)) { require_capability('moodle/grade:viewall', $context); } else { $user = core_user::get_user($userid, '*', MUST_EXIST); core_user::require_active_user($user); // Check if we can view the user group (if any). // When userid == 0, we are retrieving all the users, we'll check then if a groupid is required. if (!groups_user_groups_visible($course, $user->id)) { throw new moodle_exception('notingroup'); } } $access = false; if (has_capability('moodle/grade:viewall', $context)) { // Can view all course grades. $access = true; } else { if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) { // View own grades. $access = true; } } if (!$access) { throw new moodle_exception('nopermissiontoviewgrades', 'error'); } if (!empty($groupid)) { // Determine is the group is visible to user. if (!groups_group_visible($groupid, $course)) { throw new moodle_exception('notingroup'); } } else { // Check to see if groups are being used here. if ($groupmode = groups_get_course_groupmode($course)) { $groupid = groups_get_course_group($course); // Determine is the group is visible to user (this is particullary for the group 0). if (!groups_group_visible($groupid, $course)) { throw new moodle_exception('notingroup'); } } else { $groupid = 0; } } return array($params, $course, $context, $user, $groupid); }