From: Florent Bruneau Date: Sun, 30 Jan 2011 15:54:16 +0000 (+0100) Subject: Save answers. X-Git-Tag: xorg/1.1.0~164 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=2f854773c646a58688a06c24c6dcf19479c91837;p=platal.git Save answers. Signed-off-by: Florent Bruneau --- diff --git a/modules/survey.php b/modules/survey.php index 5a6069f..66b65c4 100644 --- a/modules/survey.php +++ b/modules/survey.php @@ -57,6 +57,8 @@ class SurveyModule extends PLModule $this->setup_page($page); $page->changeTpl('survey/vote.tpl'); + XDB::execute('delete from survey_votes'); + XDB::execute('delete from survey_voters'); $survey = Survey::get($name); if (is_null($survey)) { return PL_NOT_FOUND; diff --git a/modules/survey/multiple.inc.php b/modules/survey/multiple.inc.php index e9ce0fb..c073da7 100644 --- a/modules/survey/multiple.inc.php +++ b/modules/survey/multiple.inc.php @@ -30,26 +30,40 @@ class SurveyQuestionMultiple extends SurveyQuestion protected function buildAnswer(SurveyAnswer $answer, PlDict $data) { $content = $data->v($this->qid); - $value = $content['answer']; + $value = $content['answers']; if (empty($value)) { $answer->answer = null; return true; } - $id = to_integer($value); - if ($id === false) { - if ($value != 'other') { - $answer->answers = null; - return false; + if ($this->parameters['subtype'] == 'radio') { + if (count($value) > 1) { + throw new Exception("You cannot select more than one answer"); } - if (@$this->parameters['allow_other']) { - $answer->answer = array('other' => $content['text']); + } + $answers = array(); + $answers['answers'] = array(); + foreach ($value as $key=>$text) { + if (can_convert_to_integer($key)) { + $key = to_integer($key); + if ($text != $this->parameters['answers'][$key]) { + throw new Exception("Answer text does not match"); + } + $answers['answers'][] = $key; + } else if ($key != 'other') { + throw new Exception("Unsupported answer id $key"); + } else if (!$this->parameters['allow_other']) { + throw new Exception("Got 'Other' answer while not supported"); + } else if (!isset($content['other'])) { + $answers['other'] = ''; + } else { + $answers['other'] = $content['other']; } + } + if (empty($value)) { + $answer->answer = null; + return false; } else { - if ($id >= count($this->parameters['answers'])) { - $answer->answers = null; - return false; - } - $answer->answer = array('answer' => $id); + $answer->answer = $answers; } return true; } diff --git a/templates/survey/edit.questions.tpl b/templates/survey/edit.questions.tpl index 0c3fba9..cb225ee 100644 --- a/templates/survey/edit.questions.tpl +++ b/templates/survey/edit.questions.tpl @@ -82,8 +82,12 @@
Permettre la sélection de plusieurs réponses ?
diff --git a/templates/survey/vote.questions.tpl b/templates/survey/vote.questions.tpl index e8ca444..a7ad4e1 100644 --- a/templates/survey/vote.questions.tpl +++ b/templates/survey/vote.questions.tpl @@ -54,11 +54,11 @@
${label}
{{each answers}} - ${$value}
+ ${$value}
{{/each}} {{if allow_other}} - Autre, préciser : - + Autre, préciser : + {{/if}}