@@ -1011,6 +1011,19 @@ function choice_print_overview($courses, &$htmlarray) {
1011
1011
}
1012
1012
1013
1013
1014
+ /**
1015
+ * Get responses of a given user on a given choice.
1016
+ *
1017
+ * @param stdClass $choice Choice record
1018
+ * @param int $userid User id
1019
+ * @return array of choice answers records
1020
+ * @since Moodle 3.6
1021
+ */
1022
+ function choice_get_user_response ($ choice , $ userid ) {
1023
+ global $ DB ;
1024
+ return $ DB ->get_records ('choice_answers ' , array ('choiceid ' => $ choice ->id , 'userid ' => $ userid ), 'optionid ' );
1025
+ }
1026
+
1014
1027
/**
1015
1028
* Get my responses on a given choice.
1016
1029
*
@@ -1019,8 +1032,8 @@ function choice_print_overview($courses, &$htmlarray) {
1019
1032
* @since Moodle 3.0
1020
1033
*/
1021
1034
function choice_get_my_response ($ choice ) {
1022
- global $ DB , $ USER ;
1023
- return $ DB -> get_records ( ' choice_answers ' , array ( ' choiceid ' => $ choice-> id , ' userid ' => $ USER ->id ), ' optionid ' );
1035
+ global $ USER ;
1036
+ return choice_get_user_response ( $ choice, $ USER ->id );
1024
1037
}
1025
1038
1026
1039
@@ -1216,12 +1229,25 @@ function choice_check_updates_since(cm_info $cm, $from, $filter = array()) {
1216
1229
*
1217
1230
* @param calendar_event $event
1218
1231
* @param \core_calendar\action_factory $factory
1232
+ * @param int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
1219
1233
* @return \core_calendar\local\event\entities\action_interface|null
1220
1234
*/
1221
1235
function mod_choice_core_calendar_provide_event_action (calendar_event $ event ,
1222
- \core_calendar \action_factory $ factory ) {
1236
+ \core_calendar \action_factory $ factory ,
1237
+ int $ userid = 0 ) {
1238
+ global $ USER ;
1239
+
1240
+ if (!$ userid ) {
1241
+ $ userid = $ USER ->id ;
1242
+ }
1243
+
1244
+ $ cm = get_fast_modinfo ($ event ->courseid , $ userid )->instances ['choice ' ][$ event ->instance ];
1245
+
1246
+ if (!$ cm ->uservisible ) {
1247
+ // The module is not visible to the user for any reason.
1248
+ return null ;
1249
+ }
1223
1250
1224
- $ cm = get_fast_modinfo ($ event ->courseid )->instances ['choice ' ][$ event ->instance ];
1225
1251
$ now = time ();
1226
1252
1227
1253
if (!empty ($ cm ->customdata ['timeclose ' ]) && $ cm ->customdata ['timeclose ' ] < $ now ) {
@@ -1233,7 +1259,7 @@ function mod_choice_core_calendar_provide_event_action(calendar_event $event,
1233
1259
// in the past.
1234
1260
$ actionable = (empty ($ cm ->customdata ['timeopen ' ]) || $ cm ->customdata ['timeopen ' ] <= $ now );
1235
1261
1236
- if ($ actionable && choice_get_my_response ((object )['id ' => $ event ->instance ])) {
1262
+ if ($ actionable && choice_get_user_response ((object )['id ' => $ event ->instance ], $ userid )) {
1237
1263
// There is no action if the user has already submitted their choice.
1238
1264
return null ;
1239
1265
}
0 commit comments