From: Florent Bruneau Date: Tue, 11 Jan 2011 22:06:05 +0000 (+0100) Subject: Start working on multiple choice questions. X-Git-Tag: xorg/1.1.0~192 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=3ddf2584d3158f89c2c8dda45ee5499717c71044;p=platal.git Start working on multiple choice questions. Signed-off-by: Florent Bruneau --- diff --git a/modules/survey.php b/modules/survey.php index 832d3a4..d1626a8 100644 --- a/modules/survey.php +++ b/modules/survey.php @@ -106,6 +106,7 @@ class SurveyModule extends PLModule $q_edit = Post::v('q_edit'); $qs = array(); + $survey->clearQuestions(); foreach ($q_edit as $qid => $q_desc) { if (isset($q_desc['parent'])) { $parent = $qs[$q_desc['parent']]; diff --git a/modules/survey/multiple.inc.php b/modules/survey/multiple.inc.php new file mode 100644 index 0000000..e9ce0fb --- /dev/null +++ b/modules/survey/multiple.inc.php @@ -0,0 +1,58 @@ +type = "multiple"; + } + + protected function buildAnswer(SurveyAnswer $answer, PlDict $data) + { + $content = $data->v($this->qid); + $value = $content['answer']; + 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['allow_other']) { + $answer->answer = array('other' => $content['text']); + } + } else { + if ($id >= count($this->parameters['answers'])) { + $answer->answers = null; + return false; + } + $answer->answer = array('answer' => $id); + } + return true; + } +} + +?> diff --git a/modules/survey/question.inc.php b/modules/survey/question.inc.php index f8cde84..bd206ad 100644 --- a/modules/survey/question.inc.php +++ b/modules/survey/question.inc.php @@ -47,7 +47,11 @@ class SurveyQuestion extends PlDBTableEntry public static function instanceForType(Survey $survey, $type) { - require_once dirname(__FILE__) . '/' . $type . '.inc.php'; + $file = dirname(__FILE__) . '/' . $type . '.inc.php'; + if (!file_exists($file)) { + throw new Exception("Unknown question type \"$type\""); + } + require_once $file; $class = 'SurveyQuestion' . $type; return new $class($survey); } diff --git a/modules/survey/survey.inc.php b/modules/survey/survey.inc.php index 865a148..7e715fd 100644 --- a/modules/survey/survey.inc.php +++ b/modules/survey/survey.inc.php @@ -104,6 +104,12 @@ class Survey extends PlDBTableEntry implements SurveyQuestionContainer } } + public function clearQuestions() + { + $this->fetchQuestions = true; + $this->questions = array(); + } + public function addQuestion(SurveyQuestion $question, $pos = null) { $question->parent = null; diff --git a/templates/survey/edit.questions.tpl b/templates/survey/edit.questions.tpl index df65dd1..a8a9646 100644 --- a/templates/survey/edit.questions.tpl +++ b/templates/survey/edit.questions.tpl @@ -33,8 +33,15 @@ value="{{if label}}${label}{{/if}}" />
Type de question :
{{tmpl "#q_edit_base"}} @@ -63,6 +70,23 @@
+ + {/literal} {* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *} diff --git a/templates/survey/index.tpl b/templates/survey/index.tpl index c0ade2f..6f8d914 100644 --- a/templates/survey/index.tpl +++ b/templates/survey/index.tpl @@ -46,7 +46,7 @@ {/iterate} {/if} - +