diff --git a/mod/choice/lib.php b/mod/choice/lib.php index a8407a7a92e..e9c36eadbfd 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -67,7 +67,7 @@ function choice_add_instance($choice) { //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 <> '') { @@ -78,7 +78,7 @@ function choice_add_instance($choice) { $option->maxanswers = $choice->{'newlimit'.substr($name, 9)}; } $option->timemodified = time(); - insert_record("choice_options", $option); + insert_record("choice_options", $option); } } } @@ -105,10 +105,10 @@ function choice_update_instance($choice) { $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 @@ -134,13 +134,13 @@ function choice_update_instance($choice) { $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) { @@ -154,10 +154,10 @@ $cdisplay = array(); 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; + $countans = 0; if (!empty($countanswers)) { - foreach ($countanswers as $ca) { //only return enrolled users. - if (isstudent($cm->course, $ca->userid) or isteacher($cm->course, $ca->userid)) { + foreach ($countanswers as $ca) { //only return enrolled users. + if (isstudent($cm->course, $ca->userid) or isteacher($cm->course, $ca->userid)) { $countans = $countans+1; } } @@ -169,21 +169,21 @@ $cdisplay = array(); } $maxans = $choice->maxanswers[$optionid]; - $cdisplay[$aid]->optionid = $optionid; - $cdisplay[$aid]->text = $text; - $cdisplay[$aid]->maxanswers = $maxans; - $cdisplay[$aid]->countanswers = $countans; + $cdisplay[$aid]->optionid = $optionid; + $cdisplay[$aid]->text = $text; + $cdisplay[$aid]->maxanswers = $maxans; + $cdisplay[$aid]->countanswers = $countans; - if ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id, 'optionid', $optionid)) { - $cdisplay[$aid]->checked = ' checked="checked" '; - } else { - $cdisplay[$aid]->checked = ''; - } + 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)) ) { - $cdisplay[$aid]->disabled = ' disabled="disabled" '; - } else { - $cdisplay[$aid]->disabled = ''; - } + $cdisplay[$aid]->disabled = ' disabled="disabled" '; + } else { + $cdisplay[$aid]->disabled = ''; + } $aid++; } } @@ -191,16 +191,16 @@ $cdisplay = array(); switch ($choice->display) { case CHOICE_DISPLAY_HORIZONTAL: echo ""; - + foreach ($cdisplay as $cd) { echo ""; + echo ""; } echo ""; echo "
"; echo "optionid."\" alt=\"".strip_tags(format_text($cd->text))."\"". $cd->checked.$cd->disabled." />"; - if (!empty($cd->disabled)) { + if (!empty($cd->disabled)) { echo format_text($cd->text."
".get_string('full', 'choice').""); - } else { + } else { echo format_text($cd->text); } - echo "
"; @@ -220,8 +220,8 @@ $cdisplay = array(); if (!empty($cd->disabled)) { echo get_string('full', 'choice'); - } elseif(!empty($cd->checked)) { - //currently do nothing - maybe some text could be added here to signfy that the choice has been 'selected' + } elseif(!empty($cd->checked)) { + //currently do nothing - maybe some text could be added here to signfy that the choice has been 'selected' } elseif ($cd->maxanswers-$cd->countanswers==1) { echo ($cd->maxanswers - $cd->countanswers); echo " ".get_string('spaceleft', 'choice'); @@ -254,25 +254,25 @@ $cdisplay = array(); function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $cm) { $current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $userid); - - $countanswers = get_records("choice_answers", "optionid", $formanswer); + + $countanswers = get_records("choice_answers", "optionid", $formanswer); if ($countanswers) { $countans = 0; foreach ($countanswers as $ca) { //only return enrolled users. - if (isstudent($courseid, $ca->userid) or isteacher($courseid, $ca->userid)) { - $countans = $countans+1; - } - } - - $countanswers = count($countans); + if (isstudent($courseid, $ca->userid) or isteacher($courseid, $ca->userid)) { + $countans = $countans+1; + } + } + + $countanswers = $countans; } else { $countanswers = 0; } $maxans = $choice->maxanswers[$formanswer]; - if (!($choice->limitanswers && ($countanswers >= $maxans) )) { + if (!($choice->limitanswers && ($countanswers >= $maxans) )) { if ($current) { - + $newanswer = $current; $newanswer->optionid = $formanswer; $newanswer->timemodified = time(); @@ -300,7 +300,7 @@ $current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user function choice_show_reportlink($choice, $courseid, $cmid) { - if ( $allanswers = get_records("choice_answers", "choiceid", $choice->id)) { + if ( $allanswers = get_records("choice_answers", "choiceid", $choice->id)) { $responsecount = 0; foreach ($allanswers as $aa) { if (isstudent($courseid, $aa->userid) or isteacher($courseid, $aa->userid)) { //check to make sure user is enrolled in course. @@ -318,11 +318,11 @@ function choice_show_reportlink($choice, $courseid, $cmid) { function choice_show_results($choice, $course, $cm, $forcepublish='') { global $CFG, $COLUMN_HEIGHT, $USER; - 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; - } - + $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"); @@ -379,12 +379,12 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { $tablewidth = (int) (100.0 / count($useranswer)); if (isteacher($course->id, $USER->id)) { - echo '
'; + echo '
'; echo '
'; echo ''; echo ''; } - + echo ""; echo ""; $count = 0; @@ -440,14 +440,14 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { continue; } echo "
"; - $countanswers = get_records("choice_answers", "optionid", $optionid); - $countans = 0; - if (!empty($countanswers)) { - foreach ($countanswers as $ca) { //only return enrolled users. - if (isstudent($course->id, $ca->userid) or isteacher($course->id, $ca->userid)) { - $countans = $countans+1; - } - } + $countanswers = get_records("choice_answers", "optionid", $optionid); + $countans = 0; + if (!empty($countanswers)) { + foreach ($countanswers as $ca) { //only return enrolled users. + if (isstudent($course->id, $ca->userid) or isteacher($course->id, $ca->userid)) { + $countans = $countans+1; + } + } } if ($choice->limitanswers && !$optionid==0) { echo get_string("taken", "choice").":"; @@ -480,13 +480,13 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { echo "
"; if (isteacher($course->id, $USER->id)) { - echo "
"; - } + echo "
"; + } break; case CHOICE_PUBLISH_ANONYMOUS: - + $tablewidth = (int) (100.0 / count($useranswer)); echo ""; @@ -562,13 +562,13 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') { echo "
"; break; - } + } } function choice_delete_responses($attemptids) { - - if(!is_array($attemptids) || empty($attemptids)) { + + if(!is_array($attemptids) || empty($attemptids)) { return false; } @@ -647,10 +647,10 @@ function choice_get_choice($choiceid) { 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; } }