$choice->timeclose = 0;
}
- //insert answers
+ //insert answers
if ($choice->id = insert_record("choice", $choice)) {
- foreach ($choice as $name => $value) {
+ foreach ($choice as $name => $value) {
if (strstr($name, "newoption")) { /// New option
$value = trim($value);
if (isset($value) && $value <> '') {
$option->maxanswers = $choice->{'newlimit'.substr($name, 9)};
}
$option->timemodified = time();
- insert_record("choice_options", $option);
+ insert_record("choice_options", $option);
}
}
}
$choice->timeopen = 0;
$choice->timeclose = 0;
}
-
+
//update answers
-
- foreach ($choice as $name => $value) {
+
+ foreach ($choice as $name => $value) {
$value = trim($value);
if (strstr($name, "oldoption")) { // Old option
$option->maxanswers = $choice->{'newlimit'.substr($name, 9)};
}
$option->timemodified = time();
- insert_record("choice_options", $option);
+ insert_record("choice_options", $option);
}
- }
+ }
}
return update_record('choice', $choice);
-
+
}
function choice_show_form($choice, $user, $cm) {
$countans = 0;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!empty($countanswers)) {
- foreach ($countanswers as $ca) { //only return enrolled users.
+ foreach ($countanswers as $ca) { //only return enrolled users.
if (has_capability('mod/choice:choose', $context)) {
$countans = $countans+1;
}
$cdisplay[$aid]->countanswers = $countans;
if ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id, 'optionid', $optionid)) {
- $cdisplay[$aid]->checked = ' checked="checked" ';
+ $cdisplay[$aid]->checked = ' checked="checked" ';
} else {
- $cdisplay[$aid]->checked = '';
+ $cdisplay[$aid]->checked = '';
}
if ($choice->limitanswers && ($countans >= $maxans) && (empty($cdisplay[$aid]->checked)) ) {
- $cdisplay[$aid]->disabled = ' disabled="disabled" ';
+ $cdisplay[$aid]->disabled = ' disabled="disabled" ';
} else {
$cdisplay[$aid]->disabled = '';
}
foreach ($cdisplay as $cd) {
echo "<td align=\"center\" valign=\"top\">";
- echo "<input type=\"radio\" name=\"answer\" value=\"".$cd->optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />";
+ echo "<input type=\"radio\" name=\"answer\" value=\"".$cd->optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />";
if (!empty($cd->disabled)) {
- echo format_text($cd->text."<br /><strong>".get_string('full', 'choice')."</strong>");
+ echo format_text($cd->text."<br /><strong>".get_string('full', 'choice')."</strong>");
} else {
echo format_text($cd->text);
}
- echo "</td>";
+ echo "</td>";
}
echo "</tr>";
echo "</table>";
case CHOICE_DISPLAY_VERTICAL:
$displayoptions->para = false;
echo "<table cellpadding=\"10\" cellspacing=\"10\" align=\"center\">";
- foreach ($cdisplay as $cd) {
+ foreach ($cdisplay as $cd) {
echo "<tr><td align=\"left\">";
- echo "<input type=\"radio\" name=\"answer\" value=\"".$cd->optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />";
+ echo "<input type=\"radio\" name=\"answer\" value=\"".$cd->optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />";
echo format_text($cd->text. ' ', FORMAT_MOODLE, $displayoptions); //display text for option.
-
+
if ($choice->limitanswers && ($choice->showresults==CHOICE_SHOWRESULTS_ALWAYS) ){ //if limit is enabled, and show results always has been selected, display info beside each choice.
echo "</td><td>";
-
+
if (!empty($cd->disabled)) {
echo get_string('full', 'choice');
} elseif(!empty($cd->checked)) {
if (has_capability('mod/choice:choose', $context)) {
$countans = $countans+1;
}
- }
-
- $countanswers = count($countans);
+ }
+
+ $countanswers = $countans;
} else {
$countanswers = 0;
}
$maxans = $choice->maxanswers[$formanswer];
-
- if (!($choice->limitanswers && ($countanswers >= $maxans) )) {
+
+ if (!($choice->limitanswers && ($countanswers >= $maxans) )) {
if ($current) {
$newanswer = $current;
}
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"));
+ print_heading(get_string("responses", "choice"));
if (empty($forcepublish)) { //alow the publish setting to be overridden
$forcepublish = $choice->publish;
- }
-
+ }
+
/// Check to see if groups are being used in this choice
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
$currentgroup = setup_and_print_groups($course, $groupmode, $_SERVER['PHP_SELF']."?id=$cm->id");
echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
echo '<input type="hidden" name="mode" value="overview" />';
}
-
+
echo "<table cellpadding=\"5\" cellspacing=\"10\" align=\"center\" class=\"results names\">";
echo "<tr>";
$count = 0;
continue;
}
echo "<td align=\"center\" class=\"count\">";
- $countanswers = get_records("choice_answers", "optionid", $optionid);
+ $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', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ foreach ($countanswers as $ca) { //only return enrolled users.
+ if (has_capability('mod/choice:choose', get_context_instance(CONTEXT_MODULE, $cm->id))) {
$countans = $countans+1;
- }
+ }
}
}
if ($choice->limitanswers && !$optionid==0) {
case CHOICE_PUBLISH_ANONYMOUS:
-
+
$tablewidth = (int) (100.0 / count($useranswer));
echo "<table cellpadding=\"5\" cellspacing=\"0\" align=\"center\" class=\"results anonymous\">";
return $result->text;
} else {
return get_string("notanswered", "choice");
- }
+ }
}
function choice_get_choice($choiceid) {
-// Gets a full choice record
+// Gets a full choice record
if ($choice = get_record("choice", "id", $choiceid)) {
if ($options = get_records("choice_options", "choiceid", $choiceid, "id")) {
- foreach ($options as $option) {
+ foreach ($options as $option) {
$choice->option[$option->id] = $option->text;
$choice->maxanswers[$option->id] = $option->maxanswers;
- }
+ }
return $choice;
}
}