Merge branch 'MDL-26445' of git://github.com/timhunt/moodle
[moodle.git] / course / recent_form.php
bloba9f78ef41c337793184851e076de9cbd49770106
1 <?php
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.
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/>.
18 /**
19 * Display all recent activity in a flexible way
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
26 if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
30 require_once($CFG->libdir.'/formslib.php');
32 class recent_form extends moodleform {
33 function definition() {
34 global $CFG, $COURSE, $USER;
36 $mform =& $this->_form;
37 $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
38 $modinfo = get_fast_modinfo($COURSE);
39 $sections = get_all_sections($COURSE->id);
41 $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string
43 if ($COURSE->id == SITEID) {
44 $viewparticipants = has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM));
45 } else {
46 $viewparticipants = has_capability('moodle/course:viewparticipants', $context);
49 $viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id));
51 if ($viewparticipants) {
52 $options = array();
53 $options[0] = get_string('allparticipants');
54 $options[$CFG->siteguest] = get_string('guestuser');
56 if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS) {
57 $groups = groups_get_user_groups($COURSE->id);
58 $group = $groups[0];
59 } else {
60 $group = '';
63 if ($enrolled = get_enrolled_users($context, null, $group, user_picture::fields('u'))) {
64 foreach ($enrolled as $euser) {
65 $options[$euser->id] = fullname($euser, $viewfullnames);
68 $mform->addElement('select', 'user', get_string('participants'), $options);
69 $mform->setAdvanced('user');
72 $sectiontitle = get_string('sectionname', 'format_'.$COURSE->format);
74 $options = array(''=>get_string('allactivities'));
75 $modsused = array();
77 foreach($modinfo->cms as $cm) {
78 if (!$cm->uservisible) {
79 continue;
81 $modsused[$cm->modname] = true;
84 foreach ($modsused as $modname=>$unused) {
85 $libfile = "$CFG->dirroot/mod/$modname/lib.php";
86 if (!file_exists($libfile)) {
87 unset($modsused[$modname]);
88 continue;
90 include_once($libfile);
91 $libfunction = $modname."_get_recent_mod_activity";
92 if (!function_exists($libfunction)) {
93 unset($modsused[$modname]);
94 continue;
96 $options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname));
99 foreach ($modinfo->sections as $section=>$cmids) {
100 $options["section/$section"] = "-- ".get_section_name($COURSE, $sections[$section])." --";
101 foreach ($cmids as $cmid) {
102 $cm = $modinfo->cms[$cmid];
103 if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
104 continue;
106 $options[$cm->id] = format_string($cm->name);
109 $mform->addElement('select', 'modid', get_string('activities'), $options);
110 $mform->setAdvanced('modid');
113 if (has_capability('moodle/site:accessallgroups', $context)) {
114 if ($groups = groups_get_all_groups($COURSE->id)) {
115 $options = array('0'=>get_string('allgroups'));
116 foreach($groups as $group) {
117 $options[$group->id] = format_string($group->name);
119 $mform->addElement('select', 'group', get_string('groups'), $options);
120 $mform->setAdvanced('group');
121 } else {
122 $mform->addElement('hidden','group');
123 $mform->setType('group', PARAM_INT);
124 $mform->setConstants(array('group'=>0));
126 } else {
127 $mform->addElement('hidden','group');
128 $mform->setType('group', PARAM_INT);
129 $mform->setConstants(array('group'=>0));
132 $options = array('default' => get_string('bycourseorder'),
133 'dateasc' => get_string('datemostrecentlast'),
134 'datedesc' => get_string('datemostrecentfirst'));
135 $mform->addElement('select', 'sortby', get_string('sortby'), $options);
136 $mform->setAdvanced('sortby');
138 $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true));
140 $mform->addElement('hidden','id');
141 $mform->setType('id', PARAM_INT);
142 $mform->setType('courseid', PARAM_INT);
144 $this->add_action_buttons(false, get_string('showrecent'));