MDL-20353 adding missing data types of hidden form fields
[moodle.git] / course / recent_form.php
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.
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/>.
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  */
26 require_once($CFG->libdir.'/formslib.php');
28 class recent_form extends moodleform {
29     function definition() {
30         global $CFG, $COURSE, $USER;
32         $mform =& $this->_form;
33         $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
34         $modinfo = get_fast_modinfo($COURSE);
36         $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string
38         if ($COURSE->id == SITEID) {
39             $viewparticipants = has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM));
40         } else {
41             $viewparticipants = has_capability('moodle/course:viewparticipants', $context);
42         }
44         $viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id));
46         if ($viewparticipants) {
47             $options = array();
48             $options[0] = get_string('allparticipants');
49             if ($guest = get_complete_user_data('username', 'guest')) {
50                 $options[$guest->id] = fullname($guest);
51             }
53             if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS) {
54                 $groups = groups_get_user_groups($COURSE->id);
55                 $groups = $groups[0];
56             } else {
57                 $groups = '';
58             }
59             
60             if ($courseusers = get_users_by_capability($context, 'moodle/course:view', 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname DESC', '', '', $groups)) {
61                 foreach ($courseusers as $courseuser) {
62                     $options[$courseuser->id] = fullname($courseuser, $viewfullnames);
63                 }
64             }
65             $mform->addElement('select', 'user', get_string('participants'), $options);
66             $mform->setAdvanced('user');
67         }
69         switch ($COURSE->format) {
70             case 'weeks':  $sectiontitle = get_string('week'); break;
71             case 'topics': $sectiontitle = get_string('topic'); break;
72             default: $sectiontitle = get_string('section'); break;
73         }
75         $options = array(''=>get_string('allactivities'));
76         $modsused = array();
78         foreach($modinfo->cms as $cm) {
79             if (!$cm->uservisible) {
80                 continue;
81             }
82             $modsused[$cm->modname] = true;
83         }
85         foreach ($modsused as $modname=>$unused) {
86             $libfile = "$CFG->dirroot/mod/$modname/lib.php";
87             if (!file_exists($libfile)) {
88                 unset($modsused[$modname]);
89                 continue;
90             }
91             include_once($libfile);
92             $libfunction = $modname."_get_recent_mod_activity";
93             if (!function_exists($libfunction)) {
94                 unset($modsused[$modname]);
95                 continue;
96             }
97             $options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname));
98         }
100         foreach ($modinfo->sections as $section=>$cmids) {
101             $options["section/$section"] = "-- $sectiontitle $section --";
102             foreach ($cmids as $cmid) {
103                 $cm = $modinfo->cms[$cmid];
104                 if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
105                     continue;
106                 }
107                 $options[$cm->id] = format_string($cm->name);
108             }
109         }
110         $mform->addElement('select', 'modid', get_string('activities'), $options);
111         $mform->setAdvanced('modid');
114         if (has_capability('moodle/site:accessallgroups', $context)) {
115             if ($groups = groups_get_all_groups($COURSE->id)) {
116                 $options = array('0'=>get_string('allgroups'));
117                 foreach($groups as $group) {
118                     $options[$group->id] = format_string($group->name);
119                 }
120                 $mform->addElement('select', 'group', get_string('groups'), $options);
121                 $mform->setAdvanced('group');
122             }
123         } else {
124             $mform->addElement('hidden','group');
125             $mform->setType('group', PARAM_INT);
126             $mform->setConstants(array('group'=>0));
127         }
129         $options = array('default'  => get_string('bycourseorder'),
130                          'dateasc'  => get_string('datemostrecentlast'),
131                          'datedesc' => get_string('datemostrecentfirst'));
132         $mform->addElement('select', 'sortby', get_string('sortby'), $options);
133         $mform->setAdvanced('sortby');
135         $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true));
137         $mform->addElement('hidden','id');
138         $mform->setType('id', PARAM_INT);
139         $mform->setType('courseid', PARAM_INT);
141         $this->add_action_buttons(false, get_string('showrecent'));
142     }