Skip to content

Commit

Permalink
Merge branch 'MDL-63135-35' of git://github.com/rezaies/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_35_STABLE
  • Loading branch information
David Monllao committed Sep 19, 2018
2 parents d2bceb2 + e64487e commit de8c8a4
Show file tree
Hide file tree
Showing 2 changed files with 327 additions and 12 deletions.
36 changes: 31 additions & 5 deletions mod/choice/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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. * Get my responses on a given choice.
* *
Expand All @@ -1019,8 +1032,8 @@ function choice_print_overview($courses, &$htmlarray) {
* @since Moodle 3.0 * @since Moodle 3.0
*/ */
function choice_get_my_response($choice) { function choice_get_my_response($choice) {
global $DB, $USER; global $USER;
return $DB->get_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id), 'optionid'); return choice_get_user_response($choice, $USER->id);
} }




Expand Down Expand Up @@ -1216,12 +1229,25 @@ function choice_check_updates_since(cm_info $cm, $from, $filter = array()) {
* *
* @param calendar_event $event * @param calendar_event $event
* @param \core_calendar\action_factory $factory * @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 * @return \core_calendar\local\event\entities\action_interface|null
*/ */
function mod_choice_core_calendar_provide_event_action(calendar_event $event, 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(); $now = time();


if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < $now) { if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < $now) {
Expand All @@ -1233,7 +1259,7 @@ function mod_choice_core_calendar_provide_event_action(calendar_event $event,
// in the past. // in the past.
$actionable = (empty($cm->customdata['timeopen']) || $cm->customdata['timeopen'] <= $now); $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. // There is no action if the user has already submitted their choice.
return null; return null;
} }
Expand Down
Loading

0 comments on commit de8c8a4

Please sign in to comment.