Bumping to 1.9.1
[moodle.git] / course / recent_form.php
blob17be91a9831f1b429bf241fb8821637f21f00fe8
1 <?php //$$
3 require_once($CFG->libdir.'/formslib.php');
5 class recent_form extends moodleform {
6 function definition() {
7 global $CFG, $COURSE, $USER;
9 $mform =& $this->_form;
10 $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
11 $modinfo = get_fast_modinfo($COURSE);
13 $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string
15 if ($COURSE->id == SITEID) {
16 $viewparticipants = has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM));
17 } else {
18 $viewparticipants = has_capability('moodle/course:viewparticipants', $context);
21 $viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id));
23 if ($viewparticipants) {
24 $options = array();
25 $options[0] = get_string('allparticipants');
26 if ($guest = get_guest()) {
27 $options[$guest->id] = fullname($guest);
30 if ($courseusers = get_users_by_capability($context, 'moodle/course:view', 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname DESC')) {
31 foreach ($courseusers as $courseuser) {
32 $options[$courseuser->id] = fullname($courseuser, $viewfullnames);
35 $mform->addElement('select', 'user', get_string('participants'), $options);
36 $mform->setAdvanced('user');
39 switch ($COURSE->format) {
40 case 'weeks': $sectiontitle = get_string('week'); break;
41 case 'topics': $sectiontitle = get_string('topic'); break;
42 default: $sectiontitle = get_string('section'); break;
45 $options = array(''=>get_string('allactivities'));
46 $modsused = array();
48 foreach($modinfo->cms as $cm) {
49 if (!$cm->uservisible) {
50 continue;
52 $modsused[$cm->modname] = true;
55 foreach ($modsused as $modname=>$unused) {
56 $libfile = "$CFG->dirroot/mod/$modname/lib.php";
57 if (!file_exists($libfile)) {
58 unset($modsused[$modname]);
59 continue;
61 include_once($libfile);
62 $libfunction = $modname."_get_recent_mod_activity";
63 if (!function_exists($libfunction)) {
64 unset($modsused[$modname]);
65 continue;
67 $options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname));
70 foreach ($modinfo->sections as $section=>$cmids) {
71 $options["section/$section"] = "-- $sectiontitle $section --";
72 foreach ($cmids as $cmid) {
73 $cm = $modinfo->cms[$cmid];
74 if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
75 continue;
77 $options[$cm->id] = format_string($cm->name);
80 $mform->addElement('select', 'modid', get_string('activities'), $options);
81 $mform->setAdvanced('modid');
84 if (has_capability('moodle/site:accessallgroups', $context)) {
85 if ($groups = groups_get_all_groups($COURSE->id)) {
86 $options = array('0'=>get_string('allgroups'));
87 foreach($groups as $group) {
88 $options[$group->id] = format_string($group->name);
90 $mform->addElement('select', 'group', get_string('groups'), $options);
91 $mform->setAdvanced('group');
93 } else {
94 $mform->addElement('hidden','group');
95 $mform->setConstants(array('group'=>0));
98 $options = array('default' => get_string('bycourseorder'),
99 'dateasc' => get_string('datemostrecentlast'),
100 'datedesc' => get_string('datemostrecentfirst'));
101 $mform->addElement('select', 'sortby', get_string('sortby'), $options);
102 $mform->setAdvanced('sortby');
104 $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true));
106 $mform->addElement('hidden','id');
107 $mform->setType('courseid', PARAM_INT);
109 $this->add_action_buttons(false, get_string('showrecent'));