function choice_user_complete($course, $user, $mod, $choice) { if ($answer = get_record('choice_answers', "choiceid", $choice->id, "userid", $user->id)) { $result->info = "'" . format_string(choice_get_option_text($choice, $answer->optionid)) . "'"; $result->time = $answer->timemodified; echo get_string("answered", "choice") . ": {$result->info}. " . get_string("updated", '', userdate($result->time)); } else { print_string("notanswered", "choice"); } }
/** * Callback for the "Complete" report - prints the activity summary for the given user * * @param object $course * @param object $user * @param object $mod * @param object $choice */ function choice_user_complete($course, $user, $mod, $choice) { global $DB; if ($answers = $DB->get_records('choice_answers', array("choiceid" => $choice->id, "userid" => $user->id))) { $info = []; foreach ($answers as $answer) { $info[] = "'" . format_string(choice_get_option_text($choice, $answer->optionid)) . "'"; } core_collator::asort($info); echo get_string("answered", "choice") . ": " . join(', ', $info) . ". " . get_string("updated", '', userdate($answer->timemodified)); } else { print_string("notanswered", "choice"); } }
$allresponses = choice_get_response_data($choice, $cm, $groupmode, $onlyactive); // Big function, approx 6 SQL calls per user. if (has_capability('mod/choice:readresponses', $context)) { choice_show_reportlink($allresponses, $cm); } echo '<div class="clearer"></div>'; if ($choice->intro) { echo $OUTPUT->box(format_module_intro('choice', $choice, $cm->id), 'generalbox', 'intro'); } $timenow = time(); $current = choice_get_my_response($choice); //if user has already made a selection, and they are not allowed to update it or if choice is not open, show their selected answer. if (isloggedin() && !empty($current) && (empty($choice->allowupdate) || $timenow > $choice->timeclose)) { $choicetexts = array(); foreach ($current as $c) { $choicetexts[] = format_string(choice_get_option_text($choice, $c->optionid)); } echo $OUTPUT->box(get_string("yourselection", "choice", userdate($choice->timeopen)) . ": " . implode('; ', $choicetexts), 'generalbox', 'yourselection'); } /// Print the form $choiceopen = true; if ($choice->timeclose != 0) { if ($choice->timeopen > $timenow) { if ($choice->showpreview) { echo $OUTPUT->box(get_string('previewonly', 'choice', userdate($choice->timeopen)), 'generalbox alert'); } else { echo $OUTPUT->box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "generalbox notopenyet"); echo $OUTPUT->footer(); exit; } } else {
if ($download == "txt" && has_capability('mod/choice:downloadresponses', $context)) { $filename = clean_filename("{$course->shortname} " . strip_tags(format_string($choice->name, true))) . '.txt'; header("Content-Type: application/download\n"); header("Content-Disposition: attachment; filename=\"{$filename}\""); header("Expires: 0"); header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); header("Pragma: public"); /// Print names of all the fields echo get_string("lastname") . "\t" . get_string("firstname") . "\t" . get_string("idnumber") . "\t"; echo get_string("group") . "\t"; echo get_string("choice", "choice") . "\n"; /// generate the data for the body of the spreadsheet $i = 0; 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";
print_header_simple(format_string($choice->name), "", $navigation, "", "", true, update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm)); add_to_log($course->id, "choice", "view", "view.php?id={$cm->id}", $choice->id, $cm->id); /// 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 (has_capability('mod/choice:readresponses', $context)) { choice_show_reportlink($choice, $course->id, $cm, $groupmode); } echo '<div class="clearer"></div>'; if ($choice->text) { print_box(format_text($choice->text, $choice->format), 'generalbox', 'intro'); } //if user has already made a selection, and they are not allowed to update it, show their selected answer. if (!empty($USER->id) && ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $USER->id)) && empty($choice->allowupdate)) { print_simple_box(get_string("yourselection", "choice", userdate($choice->timeopen)) . ": " . format_string(choice_get_option_text($choice, $current->optionid)), "center"); } /// Print the form $timenow = time(); if ($choice->timeclose != 0) { if ($choice->timeopen > $timenow) { print_simple_box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "center"); print_footer($course); exit; } else { if ($timenow > $choice->timeclose) { print_simple_box(get_string("expired", "choice", userdate($choice->timeclose)), "center"); print_footer($course); exit; } }
} $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($allresponses, $cm); } echo '<div class="clearer"></div>'; if ($choice->intro) { echo $OUTPUT->box(format_module_intro('choice', $choice, $cm->id), 'generalbox', 'intro'); } $timenow = time(); $current = false; // Initialise for later //if user has already made a selection, and they are not allowed to update it or if choice is not open, show their selected answer. if (isloggedin() && ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) && (empty($choice->allowupdate) || $timenow > $choice->timeclose)) { echo $OUTPUT->box(get_string("yourselection", "choice", userdate($choice->timeopen)) . ": " . format_string(choice_get_option_text($choice, $current->optionid)), 'generalbox', 'yourselection'); } /// Print the form $choiceopen = true; if ($choice->timeclose != 0) { if ($choice->timeopen > $timenow) { echo $OUTPUT->box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "generalbox notopenyet"); echo $OUTPUT->footer(); exit; } else { if ($timenow > $choice->timeclose) { echo $OUTPUT->box(get_string("expired", "choice", userdate($choice->timeclose)), "generalbox expired"); $choiceopen = false; } } }
// 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; } } 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, $format); //show table with students responses. //now give links for downloading spreadsheets. echo "<br />\n"; echo "<table class=\"downloadreport\"><tr>\n"; echo "<td>"; $options = array(); $options["id"] = "{$cm->id}"; $options["download"] = "ods";
function choice_show_results($choice, $course, $cm, $forcepublish = '') { global $CFG, $COLUMN_HEIGHT, $USER; $context = get_context_instance(CONTEXT_MODULE, $cm->id); 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; } $users = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', false, true); 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")); } $answers = array(); if ($allresponses = get_records("choice_answers", "choiceid", $choice->id)) { 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); switch ($forcepublish) { case CHOICE_PUBLISH_NAMES: $tablewidth = (int) (100.0 / count($useranswer)); if (has_capability('mod/choice:readresponses', $context)) { echo '<div id="tablecontainer">'; echo '<form id="attemptsform" method="post" action="' . $_SERVER['PHP_SELF'] . '" onsubmit="var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? \'' . addslashes(get_string('deleteattemptcheck', 'quiz')) . '\' : true);">'; echo '<div>'; echo '<input type="hidden" name="id" value="' . $cm->id . '" />'; echo '<input type="hidden" name="mode" value="overview" />'; } echo "<table cellpadding=\"5\" cellspacing=\"10\" class=\"results names\">"; echo "<tr>"; $count = 0; $columncount = array(); // number of votes in each column foreach ($useranswer as $optionid => $userlist) { $columncount[$optionid] = 0; // init counters if ($optionid) { echo "<th class=\"col{$count} header\" style=\"width:{$tablewidth}%\" scope=\"col\">"; } else { if ($choice->showunanswered) { echo "<th class=\"col{$count} header\" style=\"width:{$tablewidth}%\" scope=\"col\">"; } else { continue; } } echo format_string(choice_get_option_text($choice, $optionid)); echo "</th>"; $count++; } echo "</tr><tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if ($optionid) { echo "<td class=\"col{$count} data\" style=\"width:{$tablewidth}%;\">"; } else { if ($choice->showunanswered) { echo "<td class=\"col{$count} data\" style=\"width:{$tablewidth}%;\">"; } else { continue; } } // added empty row so that when the next iteration is empty, // we do not get <table></table> erro from w3c validator // MDL-7861 echo "<table class=\"choiceresponse\"><tr><td></td></tr>"; foreach ($userlist as $user) { if ($optionid != 0 or has_capability('mod/choice:choose', $context, $user->id, false)) { $columncount[$optionid] += 1; echo "<tr>"; if (has_capability('mod/choice:readresponses', $context) && $optionid != 0) { echo '<td class="attemptcell"><input type="checkbox" name="attemptid[]" value="' . $answers[$user->id]->id . '" /></td>'; } echo "<td class=\"picture\">"; print_user_picture($user->id, $course->id, $user->picture); echo "</td><td class=\"fullname\">"; echo "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$course->id}\">"; echo fullname($user, has_capability('moodle/site:viewfullnames', $context)); echo "</a>"; echo "</td></tr>"; } } $count++; echo "</table>"; echo "</td>"; } echo "</tr><tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if (!$optionid and !$choice->showunanswered) { continue; } echo "<td align=\"center\" class=\"count\">"; if ($choice->limitanswers && !$optionid == 0) { echo get_string("taken", "choice") . ":"; echo $columncount[$optionid]; echo "<br/>"; echo get_string("limit", "choice") . ":"; $choice_option = get_record("choice_options", "id", $optionid); echo $choice_option->maxanswers; } else { echo $columncount[$optionid]; } echo "</td>"; $count++; } echo "</tr>"; /// Print "Select all" etc. if (has_capability('mod/choice:readresponses', $context)) { echo '<tr><td></td><td>'; echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectall', 'quiz') . '</a> / '; echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectnone', 'quiz') . '</a> '; echo ' '; $options = array('delete' => get_string('delete')); echo choose_from_menu($options, 'action', '', get_string('withselected', 'quiz'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true); echo '<noscript id="noscriptmenuaction" style="display: inline;">'; echo '<div>'; echo '<input type="submit" value="' . get_string('go') . '" /></div></noscript>'; echo '<script type="text/javascript">' . "\n<!--\n" . 'document.getElementById("noscriptmenuaction").style.display = "none";' . "\n-->\n" . '</script>'; echo '</td><td></td></tr>'; } echo "</table>"; if (has_capability('mod/choice:readresponses', $context)) { echo "</div></form></div>"; } break; case CHOICE_PUBLISH_ANONYMOUS: $tablewidth = (int) (100.0 / count($useranswer)); echo "<table cellpadding=\"5\" cellspacing=\"0\" class=\"results anonymous\">"; echo "<tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if ($optionid) { echo "<th style=\"width:{$tablewidth}%\" class=\"col{$count} header\" scope=\"col\">"; } else { if ($choice->showunanswered) { echo "<th style=\"width:{$tablewidth}%\" class=\"col{$count} header\" scope=\"col\">"; } else { continue; } } echo format_string(choice_get_option_text($choice, $optionid)); echo "</th>"; $count++; } echo "</tr>"; $maxcolumn = 0; foreach ($useranswer as $optionid => $userlist) { if (!$optionid and !$choice->showunanswered) { continue; } $column[$optionid] = 0; foreach ($userlist as $user) { if ($optionid != 0 or has_capability('mod/choice:choose', $context, $user->id, false)) { $column[$optionid]++; } } if ($column[$optionid] > $maxcolumn) { $maxcolumn = $column[$optionid]; } } echo "<tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if (!$optionid and !$choice->showunanswered) { continue; } $height = 0; if ($maxcolumn) { $height = $COLUMN_HEIGHT * ((double) $column[$optionid] / (double) $maxcolumn); } echo "<td style=\"vertical-align:bottom\" align=\"center\" class=\"col{$count} data\">"; echo "<img src=\"column.png\" height=\"{$height}\" width=\"49\" alt=\"\" />"; echo "</td>"; $count++; } echo "</tr>"; echo "<tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if (!$optionid and !$choice->showunanswered) { continue; } echo "<td align=\"center\" class=\"col{$count} count\">"; if ($choice->limitanswers && !$optionid == 0) { echo get_string("taken", "choice") . ":"; echo $column[$optionid]; echo "<br/>"; echo get_string("limit", "choice") . ":"; $choice_option = get_record("choice_options", "id", $optionid); echo $choice_option->maxanswers; } else { echo $column[$optionid]; } echo "</td>"; $count++; } echo "</tr></table>"; break; } }
/** * @global object * @param object $course * @param object $user * @param object $mod * @param object $choice * @return string|void */ function choice_user_complete($course, $user, $mod, $choice) { global $DB; if ($answer = $DB->get_record('choice_answers', array("choiceid" => $choice->id, "userid" => $user->id))) { $result = new stdClass(); $result->info = "'".format_string(choice_get_option_text($choice, $answer->optionid))."'"; $result->time = $answer->timemodified; echo get_string("answered", "choice").": $result->info. ".get_string("updated", '', userdate($result->time)); } else { print_string("notanswered", "choice"); } }
if ($usesections) { $table->head = array($strsectionname, get_string("question"), get_string("answer")); $table->align = array("center", "left", "left"); } else { $table->head = array(get_string("question"), get_string("answer")); $table->align = array("left", "left"); } $currentsection = ""; foreach ($choices as $choice) { if (!empty($answers[$choice->id])) { $answer = $answers[$choice->id]; } else { $answer = ""; } if (!empty($answer->optionid)) { $aa = format_string(choice_get_option_text($choice, $answer->optionid)); } else { $aa = ""; } if ($usesections) { $printsection = ""; if ($choice->section !== $currentsection) { if ($choice->section) { $printsection = get_section_name($course, $choice->section); } if ($currentsection !== "") { $table->data[] = 'hr'; } $currentsection = $choice->section; } }
if ($usesections) { $table->head = array($strsectionname, get_string("question"), get_string("answer")); $table->align = array("center", "left", "left"); } else { $table->head = array(get_string("question"), get_string("answer")); $table->align = array("left", "left"); } $currentsection = ""; foreach ($choices as $quickfeedback) { if (!empty($answers[$quickfeedback->id])) { $answer = $answers[$quickfeedback->id]; } else { $answer = ""; } if (!empty($answer->optionid)) { $aa = format_string(choice_get_option_text($quickfeedback, $answer->optionid)); } else { $aa = ""; } if ($usesections) { $printsection = ""; if ($quickfeedback->section !== $currentsection) { if ($quickfeedback->section) { $printsection = get_section_name($course, $sections[$quickfeedback->section]); } if ($currentsection !== "") { $table->data[] = 'hr'; } $currentsection = $quickfeedback->section; } }