### Eclipse Workspace Patch 1.0
#P moodle
Index: mod/choice/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/choice/index.php,v
retrieving revision 1.42
diff -u -r1.42 index.php
--- mod/choice/index.php 23 May 2008 07:03:17 -0000 1.42
+++ mod/choice/index.php 20 Jun 2008 19:07:08 -0000
@@ -1,11 +1,11 @@
-get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}
@@ -27,12 +27,12 @@
}
$sql = "SELECT cha.*
- FROM {$CFG->prefix}choice ch, {$CFG->prefix}choice_answers cha
+ FROM {choice} ch, {choice_answers} cha
WHERE cha.choiceid = ch.id AND
- ch.course = $course->id AND cha.userid = $USER->id";
+ ch.course = ? AND cha.userid = ?";
$answers = array () ;
- if (isloggedin() and !isguestuser() and $allanswers = get_records_sql($sql)) {
+ if (isloggedin() and !isguestuser() and $allanswers = $DB->get_records_sql($sql, array($course->id, $USER->id))) {
foreach ($allanswers as $aa) {
$answers[$aa->choiceid] = $aa;
}
@@ -56,13 +56,22 @@
$currentsection = "";
foreach ($choices as $choice) {
+ $aa = NULL;
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));
+ $text = $DB->get_records('choice_answers', array('choiceid' => $choice->id));
+ foreach ($text as $cah)
+ {
+ if( $cah->userid==$USER->id)
+ {
+ $ee = format_string(choice_get_option_text($choice,$cah->optionid));//choice_get_option_text($choice, $answer->optionid));
+ if($aa==NULL){$aa = $ee;}else {$aa .= ", ".$ee;}
+ }
+ }
} else {
$aa = "";
}
@@ -76,7 +85,7 @@
}
$currentsection = $choice->section;
}
-
+
//Calculate the href
if (!$choice->visible) {
//Show dimmed if the mod is hidden
Index: mod/choice/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/choice/lib.php,v
retrieving revision 1.82
diff -u -r1.82 lib.php
--- mod/choice/lib.php 09 Jun 2008 16:53:44 -0000 1.88
+++ mod/choice/lib.php 21 Jun 2008 08:51:39 -0000
@@ -167,32 +171,43 @@
$aid++;
}
}
-
+ $contad=NULL;
switch ($choice->display) {
case CHOICE_DISPLAY_HORIZONTAL:
echo "
";
break;
case CHOICE_DISPLAY_VERTICAL:
+ $contad=NULL;
$displayoptions->para = false;
echo "";
break;
@@ -239,18 +255,20 @@
}
function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $cm) {
-
- $current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $userid);
+ global $DB;
+
+ $current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid));
+ $current2 = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid,'optionid' => $formanswer));
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
- $countanswers = get_records("choice_answers", "optionid", $formanswer);
+ $countanswers = $DB->get_records("choice_answers", array('optionid'=> $formanswer));
if ($countanswers) {
+
$countans = 0;
foreach ($countanswers as $ca) { //only return enrolled users.
if (has_capability('mod/choice:choose', $context, $ca->userid, false)) {
$countans = $countans+1;
}
}
-
$countanswers = $countans;
} else {
$countanswers = 0;
@@ -259,21 +277,29 @@
if (!($choice->limitanswers && ($countanswers >= $maxans) )) {
if ($current) {
-
- $newanswer = $current;
- $newanswer->optionid = $formanswer;
- $newanswer->timemodified = time();
- if (! update_record("choice_answers", $newanswer)) {
- print_error('cannotupdatechoice', 'choice');
- }
- add_to_log($courseid, "choice", "choose again", "view.php?id=$cm->id", $choice->id, $cm->id);
+ if($choice->allowupdate==2) //multiplechoice MOD
+ {
+ if ($allanswers = $DB->get_records('choice_answers', array('choiceid' => $choice->id)))
+ {
+ if(!($current2->optionid == $formanswer)){
+ if (! $DB->insert_record("choice_answers", array('choiceid' => $choice->id, 'userid' => $userid,'optionid' => $formanswer, 'timemodified' => time()))) {
+ print_error('cannotsavechoice', 'choice');
+ }
+ add_to_log($courseid, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id);
+ }else
+ {
+ print_error('cannotsavechoice', 'choice');
+ }
+ }
+ } else
+ { //update
+ if (! $DB->update_record("choice_answers", array('choiceid' => $choice->id, 'userid' => $userid,'optionid' => $formanswer, 'timemodified' => time()))) {
+ print_error('cannotupdatechoice', 'choice');
+ }
+ add_to_log($courseid, "choice", "choose again", "view.php?id=$cm->id", $choice->id, $cm->id);
+ }
} else {
- $newanswer = NULL;
- $newanswer->choiceid = $choice->id;
- $newanswer->userid = $userid;
- $newanswer->optionid = $formanswer;
- $newanswer->timemodified = time();
- if (! insert_record("choice_answers", $newanswer)) {
+ if (! $DB-> insert_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid,'optionid' => $formanswer, 'timemodified' => time()))) {
print_error('cannotsavechoice', 'choice');
}
add_to_log($courseid, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id);
@@ -705,7 +734,10 @@
if (isset($allresponses[0][$response->userid])) { // This person is enrolled and in correct group
$allresponses[0][$response->userid]->timemodified = $response->timemodified;
$allresponses[$response->optionid][$response->userid] = clone($allresponses[0][$response->userid]);
- unset($allresponses[0][$response->userid]); // Remove from unanswered column
+ if(!$choice->allowupdate==2) //multiplechoice MOD
+ {
+ unset($allresponses[0][$response->userid]); // Remove from unanswered column
+ }
}
}
}
Index: mod/choice/mod_form.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/choice/mod_form.php,v
retrieving revision 1.22
diff -u -r1.22 mod_form.php
--- mod/choice/mod_form.php 15 May 2008 21:40:11 -0000 1.22
+++ mod/choice/mod_form.php 20 Jun 2008 19:06:49 -0000
@@ -81,7 +81,8 @@
$mform->addElement('select', 'publish', get_string("privacy", "choice"), $CHOICE_PUBLISH);
$mform->disabledIf('publish', 'showresults', 'eq', 0);
- $mform->addElement('selectyesno', 'allowupdate', get_string("allowupdate", "choice"));
+ $menuoptions[2] = get_string("multichoice","choice");
+ $mform->addElement('select', 'allowupdate', get_string("allowupdate", "choice"), $menuoptions);
$mform->addElement('selectyesno', 'showunanswered', get_string("showunanswered", "choice"));
Index: lang/en_utf8/choice.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/choice.php,v
retrieving revision 1.10
diff -u -r1.10 choice.php
--- lang/en_utf8/choice.php 23 May 2008 07:10:37 -0000 1.10
+++ lang/en_utf8/choice.php 20 Jun 2008 19:06:07 -0000
@@ -28,6 +28,7 @@
$string['limitanswers'] = 'Limit the number of responses allowed';
$string['modulename'] = 'Choice';
$string['modulenameplural'] = 'Choices';
+$string['multichoice'] = 'Multiple choice';
$string['mustchooseone'] = 'You must choose an answer before saving. Nothing was saved.';
$string['noguestchoose'] = 'Sorry, guests are not allowed to make choices.';
$string['noresultsviewable'] = 'The results are not currently viewable.';
Index: mod/choice/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/choice/view.php,v
retrieving revision 1.111
diff -u -r1.111 view.php
--- mod/choice/view.php 23 May 2008 07:03:17 -0000 1.111
+++ mod/choice/view.php 20 Jun 2008 19:06:23 -0000
@@ -20,38 +20,63 @@
if (!$choice = choice_get_choice($cm->instance)) {
print_error('invalidcoursemodule');
}
-
+
$strchoice = get_string('modulename', 'choice');
$strchoices = get_string('modulenameplural', 'choice');
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
-
+
+ $cont = NULL;
if ($action == 'delchoice') {
- if ($answer = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $USER->id)) {
- //print_object($answer);
- delete_records('choice_answers', 'id', $answer->id);
- }
+ if($choice->allowupdate==2){
+ foreach ($choice->option as $optionid => $text) {
+ $answername = 'answer'.$cont;
+ $answerparam = optional_param($answername, '', PARAM_INT);
+ if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) {
+ //print_object($answer);
+ $DB->delete_records('choice_answers', array('id' => $answer->id));
+ }
+ $cont++;
+ }
+ }else{
+ if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) {
+ //print_object($answer);
+ $DB->delete_records('choice_answers', array('id' => $answer->id));
+ }
+ }
}
/// Submit any new data if there is any
-
if ($form = data_submitted() && has_capability('mod/choice:choose', $context)) {
- $timenow = time();
+ $timenow = time();
if (has_capability('mod/choice:deleteresponses', $context)) {
if ($action == 'delete') { //some responses need to be deleted
- choice_delete_responses($attemptids); //delete responses.
+ choice_delete_responses($attemptids, $choice->id); //delete responses.
redirect("view.php?id=$cm->id");
}
}
- $answer = optional_param('answer', '', PARAM_INT);
-
- if (empty($answer)) {
- redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice'));
- } else {
- choice_user_submit_response($answer, $choice, $USER->id, $course->id, $cm);
- }
+
+ $cont = NULL;
+ if($choice->allowupdate==2){
+ foreach ($choice->option as $optionid => $text) {
+ $answername = 'answer'.$cont;
+ $answer = optional_param($answername, '', PARAM_INT);
+ if (!empty($answer) && (!$DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid,'optionid' => $answer)))) { //only the checked options
+ choice_user_submit_response($answer, $choice, $USER->id, $course->id, $cm);
+ }
+ $cont++;
+ }
+ }
+ else
+ { $answer = optional_param('answer', '', PARAM_INT);
+ if (empty($answer)) {
+ redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice'));
+ } else {
+ choice_user_submit_response($answer, $choice, $USER->id, $course->id, $cm);
+ }
+ }
redirect("view.php?id=$cm->id");
exit;
}