Differences Between: [Versions 310 and 311] [Versions 39 and 311]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * Display all recent activity in a flexible way 20 * 21 * @copyright 1999 Martin Dougiamas http://dougiamas.com 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 * @package course 24 */ 25 26 if (!defined('MOODLE_INTERNAL')) { 27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 28 } 29 30 require_once($CFG->dirroot . '/course/lib.php'); 31 require_once($CFG->libdir.'/formslib.php'); 32 33 class recent_form extends moodleform { 34 function definition() { 35 global $CFG, $COURSE, $USER; 36 37 $mform =& $this->_form; 38 $context = context_course::instance($COURSE->id); 39 $modinfo = get_fast_modinfo($COURSE); 40 41 $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string 42 43 $groupoptions = array(); 44 if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { 45 // limited group access 46 $groups = groups_get_user_groups($COURSE->id); 47 $allgroups = groups_get_all_groups($COURSE->id); 48 if (!empty($groups[$COURSE->defaultgroupingid])) { 49 foreach ($groups[$COURSE->defaultgroupingid] AS $groupid) { 50 $groupoptions[$groupid] = format_string($allgroups[$groupid]->name, true, array('context'=>$context)); 51 } 52 } 53 } else { 54 $groupoptions = array('0'=>get_string('allgroups')); 55 if (has_capability('moodle/site:accessallgroups', $context)) { 56 // user can see all groups 57 $allgroups = groups_get_all_groups($COURSE->id); 58 } else { 59 // user can see course level groups 60 $allgroups = groups_get_all_groups($COURSE->id, 0, $COURSE->defaultgroupingid); 61 } 62 foreach($allgroups as $group) { 63 $groupoptions[$group->id] = format_string($group->name, true, array('context'=>$context)); 64 } 65 } 66 67 if ($COURSE->id == SITEID) { 68 $viewparticipants = course_can_view_participants(context_system::instance()); 69 } else { 70 $viewparticipants = course_can_view_participants($context); 71 } 72 73 if ($viewparticipants) { 74 $viewfullnames = has_capability('moodle/site:viewfullnames', context_course::instance($COURSE->id)); 75 76 $options = array(); 77 $options[0] = get_string('allparticipants'); 78 $options[$CFG->siteguest] = get_string('guestuser'); 79 80 $userfieldsapi = \core_user\fields::for_userpic(); 81 $ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects; 82 83 if (isset($groupoptions[0])) { 84 // can see all enrolled users 85 if ($enrolled = get_enrolled_users($context, null, 0, $ufields)) { 86 foreach ($enrolled as $euser) { 87 $options[$euser->id] = fullname($euser, $viewfullnames); 88 } 89 } 90 } else { 91 // can see users from some groups only 92 foreach ($groupoptions as $groupid=>$unused) { 93 if ($enrolled = get_enrolled_users($context, null, $groupid, $ufields)) { 94 foreach ($enrolled as $euser) { 95 if (!array_key_exists($euser->id, $options)) { 96 $options[$euser->id] = fullname($euser, $viewfullnames); 97 } 98 } 99 } 100 } 101 } 102 103 $mform->addElement('select', 'user', get_string('participants'), $options); 104 $mform->setAdvanced('user'); 105 } else { 106 // Default to no user. 107 $mform->addElement('hidden', 'user', 0); 108 $mform->setType('user', PARAM_INT); 109 $mform->setConstant('user', 0); 110 } 111 112 $options = array(''=>get_string('allactivities')); 113 $modsused = array(); 114 115 foreach($modinfo->cms as $cm) { 116 if (!$cm->uservisible) { 117 continue; 118 } 119 $modsused[$cm->modname] = true; 120 } 121 122 foreach ($modsused as $modname=>$unused) { 123 $libfile = "$CFG->dirroot/mod/$modname/lib.php"; 124 if (!file_exists($libfile)) { 125 unset($modsused[$modname]); 126 continue; 127 } 128 include_once($libfile); 129 $libfunction = $modname."_get_recent_mod_activity"; 130 if (!function_exists($libfunction)) { 131 unset($modsused[$modname]); 132 continue; 133 } 134 $options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname)); 135 } 136 137 foreach ($modinfo->sections as $section=>$cmids) { 138 $options["section/$section"] = "-- ".get_section_name($COURSE, $section)." --"; 139 foreach ($cmids as $cmid) { 140 $cm = $modinfo->cms[$cmid]; 141 if (empty($modsused[$cm->modname]) or !$cm->uservisible) { 142 continue; 143 } 144 $options[$cm->id] = format_string($cm->name); 145 } 146 } 147 $mform->addElement('select', 'modid', get_string('activities'), $options); 148 $mform->setAdvanced('modid'); 149 150 151 if ($groupoptions) { 152 $mform->addElement('select', 'group', get_string('groups'), $groupoptions); 153 $mform->setAdvanced('group'); 154 } else { 155 // no access to groups in separate mode 156 $mform->addElement('hidden','group'); 157 $mform->setType('group', PARAM_INT); 158 $mform->setConstants(array('group'=>-1)); 159 } 160 161 $options = array('default' => get_string('bycourseorder'), 162 'dateasc' => get_string('datemostrecentlast'), 163 'datedesc' => get_string('datemostrecentfirst')); 164 $mform->addElement('select', 'sortby', get_string('sortby'), $options); 165 $mform->setAdvanced('sortby'); 166 167 $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true)); 168 169 $mform->addElement('hidden','id'); 170 $mform->setType('id', PARAM_INT); 171 $mform->setType('courseid', PARAM_INT); 172 173 $this->add_action_buttons(false, get_string('showrecent')); 174 } 175 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body