|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 if (!defined('MOODLE_INTERNAL')) { 00027 die('Direct access to this script is forbidden.'); 00028 } 00029 00030 require_once($CFG->libdir.'/formslib.php'); 00031 00032 class recent_form extends moodleform { 00033 function definition() { 00034 global $CFG, $COURSE, $USER; 00035 00036 $mform =& $this->_form; 00037 $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); 00038 $modinfo = get_fast_modinfo($COURSE); 00039 $sections = get_all_sections($COURSE->id); 00040 00041 $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string 00042 00043 $groupoptions = array(); 00044 if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { 00045 // limited group access 00046 $groups = groups_get_user_groups($COURSE->id); 00047 $allgroups = groups_get_all_groups($COURSE->id); 00048 if (!empty($groups[$COURSE->defaultgroupingid])) { 00049 foreach ($groups[$COURSE->defaultgroupingid] AS $groupid) { 00050 $groupoptions[$groupid] = format_string($allgroups[$groupid]->name, true, array('context'=>$context)); 00051 } 00052 } 00053 } else { 00054 $groupoptions = array('0'=>get_string('allgroups')); 00055 if (has_capability('moodle/site:accessallgroups', $context)) { 00056 // user can see all groups 00057 $allgroups = groups_get_all_groups($COURSE->id); 00058 } else { 00059 // user can see course level groups 00060 $allgroups = groups_get_all_groups($COURSE->id, 0, $COURSE->defaultgroupingid); 00061 } 00062 foreach($allgroups as $group) { 00063 $groupoptions[$group->id] = format_string($group->name, true, array('context'=>$context)); 00064 } 00065 } 00066 00067 if ($COURSE->id == SITEID) { 00068 $viewparticipants = has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM)); 00069 } else { 00070 $viewparticipants = has_capability('moodle/course:viewparticipants', $context); 00071 } 00072 00073 if ($viewparticipants) { 00074 $viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id)); 00075 00076 $options = array(); 00077 $options[0] = get_string('allparticipants'); 00078 $options[$CFG->siteguest] = get_string('guestuser'); 00079 00080 if (isset($groupoptions[0])) { 00081 // can see all enrolled users 00082 if ($enrolled = get_enrolled_users($context, null, 0, user_picture::fields('u'))) { 00083 foreach ($enrolled as $euser) { 00084 $options[$euser->id] = fullname($euser, $viewfullnames); 00085 } 00086 } 00087 } else { 00088 // can see users from some groups only 00089 foreach ($groupoptions as $groupid=>$unused) { 00090 if ($enrolled = get_enrolled_users($context, null, $groupid, user_picture::fields('u'))) { 00091 foreach ($enrolled as $euser) { 00092 if (!array_key_exists($euser->id, $options)) { 00093 $options[$euser->id] = fullname($euser, $viewfullnames); 00094 } 00095 } 00096 } 00097 } 00098 } 00099 00100 $mform->addElement('select', 'user', get_string('participants'), $options); 00101 $mform->setAdvanced('user'); 00102 } 00103 00104 $sectiontitle = get_string('sectionname', 'format_'.$COURSE->format); 00105 00106 $options = array(''=>get_string('allactivities')); 00107 $modsused = array(); 00108 00109 foreach($modinfo->cms as $cm) { 00110 if (!$cm->uservisible) { 00111 continue; 00112 } 00113 $modsused[$cm->modname] = true; 00114 } 00115 00116 foreach ($modsused as $modname=>$unused) { 00117 $libfile = "$CFG->dirroot/mod/$modname/lib.php"; 00118 if (!file_exists($libfile)) { 00119 unset($modsused[$modname]); 00120 continue; 00121 } 00122 include_once($libfile); 00123 $libfunction = $modname."_get_recent_mod_activity"; 00124 if (!function_exists($libfunction)) { 00125 unset($modsused[$modname]); 00126 continue; 00127 } 00128 $options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname)); 00129 } 00130 00131 foreach ($modinfo->sections as $section=>$cmids) { 00132 $options["section/$section"] = "-- ".get_section_name($COURSE, $sections[$section])." --"; 00133 foreach ($cmids as $cmid) { 00134 $cm = $modinfo->cms[$cmid]; 00135 if (empty($modsused[$cm->modname]) or !$cm->uservisible) { 00136 continue; 00137 } 00138 $options[$cm->id] = format_string($cm->name); 00139 } 00140 } 00141 $mform->addElement('select', 'modid', get_string('activities'), $options); 00142 $mform->setAdvanced('modid'); 00143 00144 00145 if ($groupoptions) { 00146 $mform->addElement('select', 'group', get_string('groups'), $groupoptions); 00147 $mform->setAdvanced('group'); 00148 } else { 00149 // no access to groups in separate mode 00150 $mform->addElement('hidden','group'); 00151 $mform->setType('group', PARAM_INT); 00152 $mform->setConstants(array('group'=>-1)); 00153 } 00154 00155 $options = array('default' => get_string('bycourseorder'), 00156 'dateasc' => get_string('datemostrecentlast'), 00157 'datedesc' => get_string('datemostrecentfirst')); 00158 $mform->addElement('select', 'sortby', get_string('sortby'), $options); 00159 $mform->setAdvanced('sortby'); 00160 00161 $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true)); 00162 00163 $mform->addElement('hidden','id'); 00164 $mform->setType('id', PARAM_INT); 00165 $mform->setType('courseid', PARAM_INT); 00166 00167 $this->add_action_buttons(false, get_string('showrecent')); 00168 } 00169 }