Permalink
Browse files

Merge branch 'MDL-63135-34' of git://github.com/rezaies/moodle into M…

…OODLE_34_STABLE
  • Loading branch information...
dmonllao committed Sep 19, 2018
2 parents cd47523 + 75bad7d commit a0b0988443ed070ab9d9215a4fcc1a135a799f90
Showing with 327 additions and 12 deletions.
  1. +31 −5 mod/choice/lib.php
  2. +296 −7 mod/choice/tests/lib_test.php
@@ -1011,6 +1011,19 @@ function choice_print_overview($courses, &$htmlarray) {
}
/**
* Get responses of a given user on a given choice.
*
* @param stdClass $choice Choice record
* @param int $userid User id
* @return array of choice answers records
* @since Moodle 3.6
*/
function choice_get_user_response($choice, $userid) {
global $DB;
return $DB->get_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid), 'optionid');
}
/**
* Get my responses on a given choice.
*
@@ -1019,8 +1032,8 @@ function choice_print_overview($courses, &$htmlarray) {
* @since Moodle 3.0
*/
function choice_get_my_response($choice) {
global $DB, $USER;
return $DB->get_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id), 'optionid');
global $USER;
return choice_get_user_response($choice, $USER->id);
}
@@ -1216,12 +1229,25 @@ function choice_check_updates_since(cm_info $cm, $from, $filter = array()) {
*
* @param calendar_event $event
* @param \core_calendar\action_factory $factory
* @param int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
* @return \core_calendar\local\event\entities\action_interface|null
*/
function mod_choice_core_calendar_provide_event_action(calendar_event $event,
\core_calendar\action_factory $factory) {
\core_calendar\action_factory $factory,
int $userid = 0) {
global $USER;
if (!$userid) {
$userid = $USER->id;
}
$cm = get_fast_modinfo($event->courseid, $userid)->instances['choice'][$event->instance];
if (!$cm->uservisible) {
// The module is not visible to the user for any reason.
return null;
}
$cm = get_fast_modinfo($event->courseid)->instances['choice'][$event->instance];
$now = time();
if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < $now) {
@@ -1233,7 +1259,7 @@ function mod_choice_core_calendar_provide_event_action(calendar_event $event,
// in the past.
$actionable = (empty($cm->customdata['timeopen']) || $cm->customdata['timeopen'] <= $now);
if ($actionable && choice_get_my_response((object)['id' => $event->instance])) {
if ($actionable && choice_get_user_response((object)['id' => $event->instance], $userid)) {
// There is no action if the user has already submitted their choice.
return null;
}
Oops, something went wrong.

0 comments on commit a0b0988

Please sign in to comment.