Skip to content

Commit a0b0988

Browse files
author
David Monllao
committed
Merge branch 'MDL-63135-34' of git://github.com/rezaies/moodle into MOODLE_34_STABLE
2 parents cd47523 + 75bad7d commit a0b0988

File tree

2 files changed

+327
-12
lines changed

2 files changed

+327
-12
lines changed

mod/choice/lib.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,19 @@ function choice_print_overview($courses, &$htmlarray) {
10111011
}
10121012

10131013

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+
10141027
/**
10151028
* Get my responses on a given choice.
10161029
*
@@ -1019,8 +1032,8 @@ function choice_print_overview($courses, &$htmlarray) {
10191032
* @since Moodle 3.0
10201033
*/
10211034
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);
10241037
}
10251038

10261039

@@ -1216,12 +1229,25 @@ function choice_check_updates_since(cm_info $cm, $from, $filter = array()) {
12161229
*
12171230
* @param calendar_event $event
12181231
* @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).
12191233
* @return \core_calendar\local\event\entities\action_interface|null
12201234
*/
12211235
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+
}
12231250

1224-
$cm = get_fast_modinfo($event->courseid)->instances['choice'][$event->instance];
12251251
$now = time();
12261252

12271253
if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < $now) {
@@ -1233,7 +1259,7 @@ function mod_choice_core_calendar_provide_event_action(calendar_event $event,
12331259
// in the past.
12341260
$actionable = (empty($cm->customdata['timeopen']) || $cm->customdata['timeopen'] <= $now);
12351261

1236-
if ($actionable && choice_get_my_response((object)['id' => $event->instance])) {
1262+
if ($actionable && choice_get_user_response((object)['id' => $event->instance], $userid)) {
12371263
// There is no action if the user has already submitted their choice.
12381264
return null;
12391265
}

0 commit comments

Comments
 (0)