@@ -36,7 +36,7 @@ class search extends \moodleform {
36
36
* @return void
37
37
*/
38
38
function definition () {
39
- global $ CFG ;
39
+ global $ USER ;
40
40
41
41
$ mform =& $ this ->_form ;
42
42
$ mform ->disable_form_change_checker ();
@@ -95,9 +95,42 @@ function definition() {
95
95
$ mform ->addElement ('course ' , 'courseids ' , get_string ('courses ' , 'core ' ), $ options );
96
96
$ mform ->setType ('courseids ' , PARAM_INT );
97
97
98
- // Course options should be hidden if we choose to search within a specific location.
99
98
if (!empty ($ this ->_customdata ['searchwithin ' ])) {
99
+ // Course options should be hidden if we choose to search within a specific location.
100
100
$ mform ->hideIf ('courseids ' , 'searchwithin ' , 'ne ' , '' );
101
+
102
+ // Get groups on course (we don't show group selector if there aren't any).
103
+ $ courseid = $ this ->_customdata ['withincourseid ' ];
104
+ $ allgroups = groups_get_all_groups ($ courseid );
105
+ if ($ allgroups && $ search ->get_engine ()->supports_groups ()) {
106
+ $ groupnames = [];
107
+ foreach ($ allgroups as $ group ) {
108
+ $ groupnames [$ group ->id ] = $ group ->name ;
109
+ }
110
+
111
+ // Create group autocomplete option.
112
+ $ options = array (
113
+ 'multiple ' => true ,
114
+ 'noselectionstring ' => get_string ('allgroups ' ),
115
+ );
116
+ $ mform ->addElement ('autocomplete ' , 'groupids ' , get_string ('groups ' ), $ groupnames , $ options );
117
+
118
+ // Is the second 'search within' option a cm?
119
+ if (!empty ($ this ->_customdata ['withincmid ' ])) {
120
+ // Find out if the cm supports groups.
121
+ $ modinfo = get_fast_modinfo ($ courseid );
122
+ $ cm = $ modinfo ->get_cm ($ this ->_customdata ['withincmid ' ]);
123
+ if ($ cm ->effectivegroupmode != NOGROUPS ) {
124
+ // If it does, group ids are available when you have course or module selected.
125
+ $ mform ->hideIf ('groupids ' , 'searchwithin ' , 'eq ' , '' );
126
+ } else {
127
+ // Group ids are only available if you have course selected.
128
+ $ mform ->hideIf ('groupids ' , 'searchwithin ' , 'ne ' , 'course ' );
129
+ }
130
+ } else {
131
+ $ mform ->hideIf ('groupids ' , 'searchwithin ' , 'eq ' , '' );
132
+ }
133
+ }
101
134
}
102
135
103
136
$ mform ->addElement ('date_time_selector ' , 'timestart ' , get_string ('fromtime ' , 'search ' ), array ('optional ' => true ));
0 commit comments