Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / course / recent_form.php
blobdde3dbe45c8c8bab0e13eff752071f1a0d8a38b4
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 (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS) {
31 $groups = groups_get_user_groups($COURSE->id);
32 $groups = $groups[0];
33 } else {
34 $groups = '';
37 if ($courseusers = get_users_by_capability($context, 'moodle/course:view', 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname DESC', '', '', $groups)) {
38 foreach ($courseusers as $courseuser) {
39 $options[$courseuser->id] = fullname($courseuser, $viewfullnames);
42 $mform->addElement('select', 'user', get_string('participants'), $options);
43 $mform->setAdvanced('user');
46 switch ($COURSE->format) {
47 case 'weeks': $sectiontitle = get_string('week'); break;
48 case 'topics': $sectiontitle = get_string('topic'); break;
49 default: $sectiontitle = get_string('section'); break;
52 $options = array(''=>get_string('allactivities'));
53 $modsused = array();
55 foreach($modinfo->cms as $cm) {
56 if (!$cm->uservisible) {
57 continue;
59 $modsused[$cm->modname] = true;
62 foreach ($modsused as $modname=>$unused) {
63 $libfile = "$CFG->dirroot/mod/$modname/lib.php";
64 if (!file_exists($libfile)) {
65 unset($modsused[$modname]);
66 continue;
68 include_once($libfile);
69 $libfunction = $modname."_get_recent_mod_activity";
70 if (!function_exists($libfunction)) {
71 unset($modsused[$modname]);
72 continue;
74 $options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname));
77 foreach ($modinfo->sections as $section=>$cmids) {
78 $options["section/$section"] = "-- $sectiontitle $section --";
79 foreach ($cmids as $cmid) {
80 $cm = $modinfo->cms[$cmid];
81 if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
82 continue;
84 $options[$cm->id] = format_string($cm->name);
87 $mform->addElement('select', 'modid', get_string('activities'), $options);
88 $mform->setAdvanced('modid');
91 if (has_capability('moodle/site:accessallgroups', $context)) {
92 if ($groups = groups_get_all_groups($COURSE->id)) {
93 $options = array('0'=>get_string('allgroups'));
94 foreach($groups as $group) {
95 $options[$group->id] = format_string($group->name);
97 $mform->addElement('select', 'group', get_string('groups'), $options);
98 $mform->setAdvanced('group');
100 } else {
101 $mform->addElement('hidden','group');
102 $mform->setConstants(array('group'=>0));
105 $options = array('default' => get_string('bycourseorder'),
106 'dateasc' => get_string('datemostrecentlast'),
107 'datedesc' => get_string('datemostrecentfirst'));
108 $mform->addElement('select', 'sortby', get_string('sortby'), $options);
109 $mform->setAdvanced('sortby');
111 $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true));
113 $mform->addElement('hidden','id');
114 $mform->setType('courseid', PARAM_INT);
116 $this->add_action_buttons(false, get_string('showrecent'));