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
));
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) {
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
);
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'));
55 foreach($modinfo->cms
as $cm) {
56 if (!$cm->uservisible
) {
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]);
68 include_once($libfile);
69 $libfunction = $modname."_get_recent_mod_activity";
70 if (!function_exists($libfunction)) {
71 unset($modsused[$modname]);
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
) {
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');
101 $mform->addElement('hidden','group');
102 $mform->setType('group', PARAM_INT
);
103 $mform->setConstants(array('group'=>0));
106 $options = array('default' => get_string('bycourseorder'),
107 'dateasc' => get_string('datemostrecentlast'),
108 'datedesc' => get_string('datemostrecentfirst'));
109 $mform->addElement('select', 'sortby', get_string('sortby'), $options);
110 $mform->setAdvanced('sortby');
112 $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true));
114 $mform->addElement('hidden','id');
115 $mform->setType('id', PARAM_INT
);
116 $mform->setType('courseid', PARAM_INT
);
118 $this->add_action_buttons(false, get_string('showrecent'));