From 6de3eee04c898698369ef84ebc9af9844fa4089e Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Mon, 20 Jan 2014 11:35:12 +0000 Subject: [PATCH] MDL-43770 mod_choice: Exclude responses from inactive users --- mod/choice/lib.php | 18 ++++++++++++------ mod/choice/report.php | 6 +++++- mod/choice/view.php | 6 +++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/mod/choice/lib.php b/mod/choice/lib.php index fff0e08f455..8d620763081 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -697,9 +697,10 @@ function choice_reset_userdata($data) { * @param object $choice * @param object $cm * @param int $groupmode + * @param bool $onlyactive Whether to get response data for active users only. * @return array */ -function choice_get_response_data($choice, $cm, $groupmode) { +function choice_get_response_data($choice, $cm, $groupmode, $onlyactive) { global $CFG, $USER, $DB; $context = context_module::instance($cm->id); @@ -716,7 +717,8 @@ function choice_get_response_data($choice, $cm, $groupmode) { /// First get all the users who have access here /// To start with we assume they are all "unanswered" then move them later - $allresponses[0] = get_enrolled_users($context, 'mod/choice:choose', $currentgroup, user_picture::fields('u', array('idnumber'))); + $allresponses[0] = get_enrolled_users($context, 'mod/choice:choose', $currentgroup, + user_picture::fields('u', array('idnumber')), null, 0, 0, $onlyactive); /// Get all the recorded responses for this choice $rawresponses = $DB->get_records('choice_answers', array('choiceid' => $choice->id)); @@ -790,10 +792,14 @@ function choice_extend_settings_navigation(settings_navigation $settings, naviga if ($groupmode) { groups_get_activity_group($PAGE->cm, true); } - // We only actually need the choice id here - $choice = new stdClass; - $choice->id = $PAGE->cm->instance; - $allresponses = choice_get_response_data($choice, $PAGE->cm, $groupmode); // Big function, approx 6 SQL calls per user + + $choice = choice_get_choice($PAGE->cm->instance); + + // Check if we want to include responses from inactive users. + $onlyactive = $choice->includeinactive ? false : true; + + // Big function, approx 6 SQL calls per user. + $allresponses = choice_get_response_data($choice, $PAGE->cm, $groupmode, $onlyactive); $responsecount =0; foreach($allresponses as $optionid => $userlist) { diff --git a/mod/choice/report.php b/mod/choice/report.php index d5c2f4a9c62..9620cf14d7e 100644 --- a/mod/choice/report.php +++ b/mod/choice/report.php @@ -72,7 +72,11 @@ } else { $groupmode = groups_get_activity_groupmode($cm); } - $users = choice_get_response_data($choice, $cm, $groupmode); + + // Check if we want to include responses from inactive users. + $onlyactive = $choice->includeinactive ? false : true; + + $users = choice_get_response_data($choice, $cm, $groupmode, $onlyactive); if ($download == "ods" && has_capability('mod/choice:downloadresponses', $context)) { require_once("$CFG->libdir/odslib.class.php"); diff --git a/mod/choice/view.php b/mod/choice/view.php index acc5059d808..6f6c987ba3b 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -111,7 +111,11 @@ if ($groupmode) { groups_get_activity_group($cm, true); groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choice/view.php?id='.$id); } -$allresponses = choice_get_response_data($choice, $cm, $groupmode); // Big function, approx 6 SQL calls per user + +// Check if we want to include responses from inactive users. +$onlyactive = $choice->includeinactive ? false : true; + +$allresponses = choice_get_response_data($choice, $cm, $groupmode, $onlyactive); // Big function, approx 6 SQL calls per user. if (has_capability('mod/choice:readresponses', $context)) {