From: moodler Date: Mon, 3 Mar 2008 04:42:01 +0000 (+0000) Subject: MDL-13478 Fixing a botched merge X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a61e418846080e90166b376efe9885b24d278bee;p=moodle.git MDL-13478 Fixing a botched merge --- diff --git a/mod/choice/lib.php b/mod/choice/lib.php index c1e44cb5e0..26e66cf50e 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -122,7 +122,7 @@ function choice_update_instance($choice) { } -function choice_show_form($choice, $user, $cm) { +function choice_show_form($choice, $user, $cm, $allresponses) { //$cdisplay is an array of the display info for a choice $cdisplay[$optionid]->text - text name of option. // ->maxanswers -maxanswers for this option @@ -131,45 +131,33 @@ function choice_show_form($choice, $user, $cm) { $aid = 0; $choicefull = false; + $cdisplay = array(); if ($choice->limitanswers) { //set choicefull to true by default if limitanswers. $choicefull = true; } + $context = get_context_instance(CONTEXT_MODULE, $cm->id); foreach ($choice->option as $optionid => $text) { - if (isset($text)) { //make sure there are no dud entries in the db with blank text values. - $countanswers = (get_records("choice_answers", "optionid", $optionid)); - $countans = 0; - if (!empty($countanswers)) { - foreach ($countanswers as $ca) { //only return enrolled users. - if (has_capability('mod/choice:choose', $context, $ca->userid, false)) { - $countans = $countans+1; - } - } - } - if ($countanswers) { - $countanswers = count($countanswers); - } else { - $countanswers = 0; - } - $maxans = $choice->maxanswers[$optionid]; - + if (isset($text) && isset($allresponses[$optionid])) { //make sure there are no dud entries in the db with blank text values. $cdisplay[$aid]->optionid = $optionid; $cdisplay[$aid]->text = $text; - $cdisplay[$aid]->maxanswers = $maxans; - $cdisplay[$aid]->countanswers = $countans; + $cdisplay[$aid]->maxanswers = $choice->maxanswers[$optionid]; + $cdisplay[$aid]->countanswers = count($allresponses[$optionid]); if ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id, 'optionid', $optionid)) { $cdisplay[$aid]->checked = ' checked="checked" '; } else { $cdisplay[$aid]->checked = ''; } - if ($choice->limitanswers && ($countans >= $maxans) && (empty($cdisplay[$aid]->checked)) ) { + if ( $choice->limitanswers && + ($cdisplay[$aid]->countanswers >= $cdisplay[$aid]->maxanswers) && + (empty($cdisplay[$aid]->checked)) ) { $cdisplay[$aid]->disabled = ' disabled="disabled" '; } else { $cdisplay[$aid]->disabled = ''; - if ($choice->limitanswers && ($countans < $maxans)) { + if ($choice->limitanswers && ($cdisplay[$aid]->countanswers < $cdisplay[$aid]->maxanswers)) { $choicefull = false; //set $choicefull to false - as the above condition hasn't been set. } } @@ -294,24 +282,12 @@ function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $ } } - -function choice_show_reportlink($choice, $courseid, $cm, $groupmode) { - - if ($groupmode > 0) { - $currentgroup = groups_get_activity_group($cm); - } else { - $currentgroup = 0; - } - - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - $availableusers = get_users_by_capability($context, 'mod/choice:choose', 'u.id', '','','',$currentgroup, '', true, true); - - $responsecount = 0; - - if(!empty($availableusers)){ - // flatten the users to get a list of userids - $userids = implode( ', ', array_keys($availableusers)); - $responsecount = count_records_select('choice_answers', "choiceid = {$choice->id} AND userid IN ( $userids );"); +function choice_show_reportlink($user, $cm) { + $responsecount =0; + foreach($user as $optionid => $userlist) { + if ($optionid) { + $responsecount += count($userlist); + } } echo ''; } -function choice_show_results($choice, $course, $cm, $forcepublish='') { - - global $CFG, $COLUMN_HEIGHT, $USER; - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - +function choice_show_results($choice, $course, $cm, $users, $forcepublish='') { + global $CFG, $COLUMN_HEIGHT; + print_heading(get_string("responses", "choice")); - if (empty($forcepublish)) { //alow the publish setting to be overridden $forcepublish = $choice->publish; } - $groupmode = groups_get_activity_groupmode($cm); - - if ($groupmode > 0) { - $currentgroup = groups_get_activity_group($cm); - } else { - $currentgroup = 0; - } - - $allresponses = get_records("choice_answers", "choiceid", $choice->id); //get all responses for this choice. - - if ($choice->showunanswered) { - $users = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', true, true); - $allusersnothidden = get_users_by_capability($context, 'mod/choice:choose', 'u.id', 'u.firstname ASC', '', '', $currentgroup, '', false, false); ///MDL-12331 ugly hack to prevent hidden users and admins from being displayed in the unanswered column. needs fixing! - } else { //as we are not showing unanswered column, we only need details on users who have submitted a choice - this should perform much better than the 2 get_users_by_capability calls. - foreach ($allresponses as $usr) { - if (has_capability('mod/choice:choose', $context, $usr->userid, false)) { //if this user is allowed to select a choice. - $users[$usr->userid] = get_record_sql('SELECT id, picture, firstname, lastname, idnumber FROM '. $CFG->prefix .'user WHERE id= '.$usr->userid); - } - } - } - if (!empty($CFG->enablegroupings) && !empty($cm->groupingid) && !empty($users)) { - $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id'); - foreach($users as $key => $user) { - if (!isset($groupingusers[$user->id])) { - unset($users[$key]); - } - } - } - if (!$users) { print_heading(get_string("nousersyet")); } + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); - $answers = array () ; - if (!empty($allresponses)) { - foreach ($allresponses as $aa) { - //TODO: rewrite with SQL - if ($groupmode and $currentgroup) { - if (groups_is_member($currentgroup, $aa->userid)) { - $answers[$aa->userid] = $aa; - } - } else { - $answers[$aa->userid] = $aa; - } - } - } - - $timenow = time(); - - foreach ($choice->option as $optionid => $text) { - $useranswer[$optionid] = array(); - } - if (!empty($users)) { - foreach ($users as $user) { - if (!empty($user->id) and !empty($answers[$user->id])) { - $answer = $answers[$user->id]; - $useranswer[(int)$answer->optionid][] = $user; - } else { - $useranswer[0][] = $user; - } - } - } - foreach ($choice->option as $optionid => $text) { - if (!$choice->option[$optionid]) { - unset($useranswer[$optionid]); // Throw away any data that doesn't apply - } - } - ksort($useranswer); + $hascapfullnames = has_capability('moodle/site:viewfullnames', $context); + + $viewresponses = has_capability('mod/choice:readresponses', $context); switch ($forcepublish) { case CHOICE_PUBLISH_NAMES: - - $tablewidth = (int) (100.0 / count($useranswer)); - if (has_capability('mod/choice:readresponses', $context)) { echo '
'; echo '
'; echo '
'; echo ''; echo ''; - } echo ""; echo ""; - $count = 0; + $columncount = array(); // number of votes in each column - foreach ($useranswer as $optionid => $userlist) { + if ($choice->showunanswered) { + $columncount[0] = 0; + echo ""; + } + $count = 1; + foreach ($choice->option as $optionid => $optiontext) { $columncount[$optionid] = 0; // init counters - if ($optionid) { - echo ""; $count++; } echo ""; - $count = 0; - foreach ($useranswer as $optionid => $userlist) { - if ($optionid) { - echo ""; + echo "
"; + print_string('notanswered', 'choice'); + echo ""; - } else if ($choice->showunanswered) { - echo ""; - } else { - continue; - } - echo format_string(choice_get_option_text($choice, $optionid)); + echo ""; + echo format_string($optiontext); echo "
"; - } else if ($choice->showunanswered) { - echo ""; - } else { - continue; - } - + if ($choice->showunanswered) { + echo ""; // added empty row so that when the next iteration is empty, // we do not get
erro from w3c validator // MDL-7861 echo ""; - foreach ($userlist as $user) { - if (!($optionid==0 AND empty($allusersnothidden[$user->id]))) { //don't show admins or hidden users - $columncount[$optionid] += 1; - echo ""; - if (has_capability('mod/choice:readresponses', $context) && $optionid!=0) { - echo ''; - } - echo ""; - } + foreach ($users[0] as $user) { + echo ""; + echo ""; } - $count++; - echo "
"; - print_user_picture($user->id, $course->id, $user->picture); - echo ""; - echo "wwwroot/user/view.php?id=$user->id&course=$course->id\">"; - echo fullname($user, has_capability('moodle/site:viewfullnames', $context)); - echo ""; - echo "
"; + print_user_picture($user->id, $course->id, $user->picture); + echo ""; + echo "wwwroot/user/view.php?id=$user->id&course=$course->id\">"; + echo fullname($user, $hascapfullnames); + echo ""; + echo "
"; - - echo "
"; + } + $count = 0; + foreach ($choice->option as $optionid => $optiontext) { + echo ''; + + // added empty row so that when the next iteration is empty, + // we do not get
erro from w3c validator + // MDL-7861 + echo ''; + if (isset($users[$optionid])) { + foreach ($users[$optionid] as $user) { + $columncount[$optionid] += 1; + echo ''; + } + } + $count++; + echo '
'; + if ($viewresponses) { + echo ''; + } + echo ''; + print_user_picture($user->id, $course->id, $user->picture); + echo ''; + echo "wwwroot/user/view.php?id=$user->id&course=$course->id\">"; + echo fullname($user, $hascapfullnames); + echo ''; + echo '
'; } echo ""; $count = 0; - foreach ($useranswer as $optionid => $userlist) { - if (!$optionid and !$choice->showunanswered) { - continue; - } + + if ($choice->showunanswered) { + echo ""; + } + + foreach ($choice->option as $optionid => $optiontext) { echo ""; - if ($choice->limitanswers && !$optionid==0) { + if ($choice->limitanswers) { echo get_string("taken", "choice").":"; echo $columncount[$optionid]; echo "
"; @@ -479,15 +402,17 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { $choice_option = get_record("choice_options", "id", $optionid); echo $choice_option->maxanswers; } else { - echo $columncount[$optionid]; + if (isset($columncount[$optionid])) { + echo $columncount[$optionid]; + } } echo ""; $count++; } echo ""; - + /// Print "Select all" etc. - if (has_capability('mod/choice:readresponses', $context)) { + if ($viewresponses) { echo ''; echo ''.get_string('selectall', 'quiz').' / '; echo ''.get_string('selectnone', 'quiz').' '; @@ -500,58 +425,62 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { echo ''; echo ''; } - + echo ""; - if (has_capability('mod/choice:readresponses', $context)) { + if ($viewresponses) { echo "
"; } break; - - + + case CHOICE_PUBLISH_ANONYMOUS: - $tablewidth = (int) (100.0 / count($useranswer)); - echo ""; echo ""; - $count = 0; - foreach ($useranswer as $optionid => $userlist) { - if ($optionid) { - echo ""; - $count++; + $column[0] = 0; + foreach ($users[0] as $user) { + $column[0]++; + } + $maxcolumn = $column[0]; } - echo ""; + $count = 1; - $maxcolumn = 0; - foreach ($useranswer as $optionid => $userlist) { - if (!$optionid and !$choice->showunanswered) { - continue; - } + foreach ($choice->option as $optionid => $optiontext) { + echo ""; + $column[$optionid] = 0; - foreach ($userlist as $user) { - if (!($optionid==0 AND empty($allusersnothidden[$user->id]))) { //don't show admins or hidden users + if (isset($users[$optionid])) { + foreach ($users[$optionid] as $user) { $column[$optionid]++; } - } - if ($column[$optionid] > $maxcolumn) { - $maxcolumn = $column[$optionid]; + if ($column[$optionid] > $maxcolumn) { + $maxcolumn = $column[$optionid]; + } + } else { + $column[$optionid] = 0; } } + echo ""; - echo ""; - $count = 0; - foreach ($useranswer as $optionid => $userlist) { - if (!$optionid and !$choice->showunanswered) { - continue; + $height = 0; + + if ($choice->showunanswered) { + if ($maxcolumn) { + $height = $COLUMN_HEIGHT * ((float)$column[0] / (float)$maxcolumn); } - $height = 0; + echo ""; + } + $count = 1; + foreach ($choice->option as $optionid => $optiontext) { if ($maxcolumn) { $height = $COLUMN_HEIGHT * ((float)$column[$optionid] / (float)$maxcolumn); } @@ -560,16 +489,16 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { echo ""; $count++; } - echo ""; + echo ""; - echo ""; - $count = 0; - foreach ($useranswer as $optionid => $userlist) { - if (!$optionid and !$choice->showunanswered) { - continue; - } + + if ($choice->showunanswered) { + echo ""; + } + $count = 1; + foreach ($choice->option as $optionid => $optiontext) { echo "
"; - } else if ($choice->showunanswered) { - echo ""; - } else { - continue; - } - echo format_string(choice_get_option_text($choice, $optionid)); + $maxcolumn = 0; + if ($choice->showunanswered) { + echo ""; + print_string('notanswered', 'choice'); echo "
"; + echo format_string($optiontext); + echo "
"; + echo "\"\""; + echo "
"; - if ($choice->limitanswers && !$optionid==0) { + if ($choice->limitanswers) { echo get_string("taken", "choice").":"; echo $column[$optionid]; echo "
"; @@ -583,13 +512,13 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { $count++; } echo "
"; - - break; + + break; } } -function choice_delete_responses($attemptids) { +function choice_delete_responses($attemptids, $choiceid) { if(!is_array($attemptids) || empty($attemptids)) { return false; @@ -602,8 +531,8 @@ function choice_delete_responses($attemptids) { } foreach($attemptids as $attemptid) { - if ($todelete = get_record('choice_answers', 'id', $attemptid)) { - delete_records('choice_answers', 'id', $attemptid); + if ($todelete = get_record('choice_answers', 'choiceid', $choiceid, 'userid', $attemptid)) { + delete_records('choice_answers', 'choiceid', $choiceid, 'userid', $attemptid); } } return true; @@ -734,4 +663,41 @@ function choice_reset_userdata($data) { return $status; } +function choice_get_response_data($choice, $cm, $groupmode) { + global $CFG, $USER; + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + +/// Get the current group + if ($groupmode > 0) { + $currentgroup = groups_get_activity_group($cm); + } else { + $currentgroup = 0; + } + +/// Initialise the returned array, which is a matrix: $users[responseid][userid] = responseobject + $users = array(); + +/// First get all the users who have access here +/// To start with we assume they are all "unanswered" then move them later + $users[0] = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', false, true); + +/// Get all the recorded responses for this choice + $allresponses = get_records('choice_answers', 'choiceid', $choice->id); + +/// Use the responses to move users into the correct column + + if ($allresponses) { + foreach ($allresponses as $response) { + if (isset($users[0][$response->userid])) { // This person is enrolled and in correct group + $users[0][$response->userid]->timemodified = $response->timemodified; + $users[$response->optionid][$response->userid] = clone($users[0][$response->userid]); + unset($users[0][$response->userid]); // Remove from unanswered column + } + } + } + + return $users; + +} ?> diff --git a/mod/choice/report.php b/mod/choice/report.php index 842ff43fd0..6e0730f2c7 100644 --- a/mod/choice/report.php +++ b/mod/choice/report.php @@ -34,13 +34,13 @@ if ($action == 'delete' && has_capability('mod/choice:deleteresponses',$context)) { $attemptids = isset($_POST['attemptid']) ? $_POST['attemptid'] : array(); //get array of repsonses to delete. - choice_delete_responses($attemptids); //delete responses. - redirect("report.php?id=$cm->id"); + choice_delete_responses($attemptids, $choice->id); //delete responses. + redirect("report.php?id=$cm->id"); } if (!$download) { - $navigation = build_navigation($strresponses, $cm); + $navigation = build_navigation($strresponses, $cm); print_header_simple(format_string($choice->name).": $strresponses", "", $navigation, "", '', true, update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm)); /// Check to see if groups are being used in this choice @@ -49,52 +49,8 @@ groups_print_activity_menu($cm, 'report.php?id='.$id); } else { $groupmode = groups_get_activity_groupmode($cm); - groups_get_activity_group($cm, true); - } - - $users = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC'); - - if (!empty($CFG->enablegroupings) && !empty($cm->groupingid) && !empty($users)) { - $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id'); - foreach($users as $key => $user) { - if (!isset($groupingusers[$user->id])) { - unset($users[$key]); - } - } - } - - if (!$users) { - print_heading(get_string("nousersyet")); - } - - if ($allresponses = get_records("choice_answers", "choiceid", $choice->id)) { - foreach ($allresponses as $aa) { - $answers[$aa->userid] = $aa; - } - } else { - $answers = array () ; } - - $timenow = time(); - - foreach ($choice->option as $optionid => $text) { - $useranswer[$optionid] = array(); - } - foreach ($users as $user) { - if (!empty($user->id) and !empty($answers[$user->id])) { - $answer = $answers[$user->id]; - $useranswer[(int)$answer->optionid][] = $user; - } else { - $useranswer[0][] = $user; - } - } - foreach ($choice->option as $optionid => $text) { - if (!$choice->option[$optionid]) { - unset($useranswer[$optionid]); // Throw away any data that doesn't apply - } - } - ksort($useranswer); - + $users = choice_get_response_data($choice, $cm, $groupmode); if ($download == "ods" && has_capability('mod/choice:downloadresponses', $context)) { require_once("$CFG->libdir/odslib.class.php"); @@ -114,49 +70,40 @@ $myxls->write_string(0,2,get_string("idnumber")); $myxls->write_string(0,3,get_string("group")); $myxls->write_string(0,4,get_string("choice","choice")); - - + /// generate the data for the body of the spreadsheet $i=0; $row=1; if ($users) { - foreach ($users as $user) { - // this needs fixing - - if (!($optionid==0 && has_capability('mod/choice:readresponses', $context, $user->id))) { - - if (!empty($answers[$user->id]) && !($answers[$user->id]->optionid==0 && has_capability('mod/choice:readresponses', $context, $user->id) && $choice->showunanswered==0)) { // make sure admins and hidden teachers are not shown in not answered yet column, and not answered only shown if set in config page. - - $myxls->write_string($row,0,$user->lastname); - $myxls->write_string($row,1,$user->firstname); - $studentid=(!empty($user->idnumber) ? $user->idnumber : " "); - $myxls->write_string($row,2,$studentid); - $ug2 = ''; - if ($usergrps = groups_get_all_groups($course->id, $user->id)) { - foreach ($usergrps as $ug) { - $ug2 = $ug2. $ug->name; - } + foreach ($users as $option => $userid) { + $option_text = choice_get_option_text($choice, $option); + foreach($userid as $user) { + $myxls->write_string($row,0,$user->lastname); + $myxls->write_string($row,1,$user->firstname); + $studentid=(!empty($user->idnumber) ? $user->idnumber : " "); + $myxls->write_string($row,2,$studentid); + $ug2 = ''; + if ($usergrps = groups_get_all_groups($course->id, $user->id)) { + foreach ($usergrps as $ug) { + $ug2 = $ug2. $ug->name; } - $myxls->write_string($row,3,$ug2); - - $useroption = choice_get_option_text($choice, $answers[$user->id]->optionid); - if (isset($useroption)) { - $myxls->write_string($row,4,format_string($useroption,true)); - } - $row++; } + $myxls->write_string($row,3,$ug2); + + if (isset($option_text)) { + $myxls->write_string($row,4,format_string($useroption,true)); + } + $row++; $pos=4; } } + } + /// Close the workbook + $workbook->close(); - /// Close the workbook - $workbook->close(); - - exit; - } + exit; } - //print spreadsheet if one is asked for: if ($download == "xls" && has_capability('mod/choice:downloadresponses', $context)) { require_once("$CFG->libdir/excellib.class.php"); @@ -182,41 +129,33 @@ $i=0; $row=1; if ($users) { - foreach ($users as $user) { - // this needs fixing - - if (!($optionid==0 && has_capability('mod/choice:readresponses', $context, $user->id))) { - - if (!empty($answers[$user->id]) && !($answers[$user->id]->optionid==0 && has_capability('mod/choice:readresponses', $context, $user->id) && $choice->showunanswered==0)) { // make sure admins and hidden teachers are not shown in not answered yet column, and not answered only shown if set in config page. - - $myxls->write_string($row,0,$user->lastname); - $myxls->write_string($row,1,$user->firstname); - $studentid=(!empty($user->idnumber) ? $user->idnumber : " "); - $myxls->write_string($row,2,$studentid); - $ug2 = ''; - if ($usergrps = groups_get_all_groups($course->id, $user->id)) { - foreach ($usergrps as $ug) { - $ug2 = $ug2. $ug->name; - } + foreach ($users as $option => $userid) { + $option_text = choice_get_option_text($choice, $option); + foreach($userid as $user) { + $myxls->write_string($row,0,$user->lastname); + $myxls->write_string($row,1,$user->firstname); + $studentid=(!empty($user->idnumber) ? $user->idnumber : " "); + $myxls->write_string($row,2,$studentid); + $ug2 = ''; + if ($usergrps = groups_get_all_groups($course->id, $user->id)) { + foreach ($usergrps as $ug) { + $ug2 = $ug2. $ug->name; } - $myxls->write_string($row,3,$ug2); - - $useroption = choice_get_option_text($choice, $answers[$user->id]->optionid); - if (isset($useroption)) { - $myxls->write_string($row,4,format_string($useroption,true)); - } - $row++; } - $pos=4; + $myxls->write_string($row,3,$ug2); + if (isset($option_text)) { + $myxls->write_string($row,4,format_string($option_text,true)); + } + $row++; } } - - /// Close the workbook - $workbook->close(); - - exit; - } + $pos=4; + } + /// Close the workbook + $workbook->close(); + exit; } + // print text file if ($download == "txt" && has_capability('mod/choice:downloadresponses', $context)) { $filename = clean_filename("$course->shortname ".strip_tags(format_string($choice->name,true))).'.txt'; @@ -235,33 +174,35 @@ /// generate the data for the body of the spreadsheet $i=0; - $row=1; - if ($users) foreach ($users as $user) { - if (!empty($answers[$user->id]) && !($answers[$user->id]->optionid==0 && has_capability('mod/choice:readresponses', $context, $user->id) && $choice->showunanswered==0)) { // make sure admins and hidden teachers are not shown in not answered yet column, and not answered only shown if set in config page. - - echo $user->lastname; - echo "\t".$user->firstname; - $studentid = " "; - if (!empty($user->idnumber)) { - $studentid = $user->idnumber; - } - echo "\t". $studentid."\t"; - $ug2 = ''; - if ($usergrps = groups_get_all_groups($course->id, $user->id)) { - foreach ($usergrps as $ug) { - $ug2 = $ug2. $ug->name; + if ($users) { + foreach ($users as $option => $userid) { + $option_text = choice_get_option_text($choice, $option); + foreach($userid as $user) { + echo $user->lastname; + echo "\t".$user->firstname; + $studentid = " "; + if (!empty($user->idnumber)) { + $studentid = $user->idnumber; + } + echo "\t". $studentid."\t"; + $ug2 = ''; + if ($usergrps = groups_get_all_groups($course->id, $user->id)) { + foreach ($usergrps as $ug) { + $ug2 = $ug2. $ug->name; + } } + echo $ug2. "\t"; + if (isset($option_text)) { + echo format_string($option_text,true); + } + echo "\n"; } - echo $ug2. "\t"; - echo format_string(choice_get_option_text($choice, $answers[$user->id]->optionid),true). "\n"; } - $row++; - } + } exit; } + choice_show_results($choice, $course, $cm, $users, $format); //show table with students responses. - choice_show_results($choice, $course, $cm, $format); //show table with students responses. - //now give links for downloading spreadsheets. echo "
\n"; echo "\n"; diff --git a/mod/choice/view.php b/mod/choice/view.php index 383dd6cf4c..b82864d4df 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -66,11 +66,16 @@ /// Check to see if groups are being used in this choice $groupmode = groups_get_activity_groupmode($cm); - groups_get_activity_group($cm, true); - groups_print_activity_menu($cm, 'view.php?id='.$id); - + + if ($groupmode) { + groups_get_activity_group($cm, true); + groups_print_activity_menu($cm, 'view.php?id='.$id); + } + $allresponses = choice_get_response_data($choice, $cm, $groupmode); // Big function, approx 6 SQL calls per user + + if (has_capability('mod/choice:readresponses', $context)) { - choice_show_reportlink($choice, $course->id, $cm, $groupmode); + choice_show_reportlink($allresponses, $cm); } echo '
'; @@ -108,8 +113,8 @@ echo ''; - choice_show_form($choice, $USER, $cm); - + choice_show_form($choice, $USER, $cm, $allresponses); + echo ''; $choiceformshown = true; @@ -152,7 +157,7 @@ ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_ANSWER and $current ) or ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and $choice->timeclose <= time() ) ) { - choice_show_results($choice, $course, $cm); + choice_show_results($choice, $course, $cm, $allresponses); //show table with students responses. } else if (!$choiceformshown) { print_simple_box(get_string('noresultsviewable', 'choice'), 'center');