$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']];
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2011 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************/
+
+class SurveyQuestionMultiple extends SurveyQuestion
+{
+ public function __construct(Survey $survey)
+ {
+ parent::__construct($survey);
+ $this->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;
+ }
+}
+
+?>
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);
}
}
}
+ public function clearQuestions()
+ {
+ $this->fetchQuestions = true;
+ $this->questions = array();
+ }
+
public function addQuestion(SurveyQuestion $question, $pos = null)
{
$question->parent = null;
value="{{if label}}${label}{{/if}}" /><br />
Type de question : <select name="q_edit[${qid}][type]">
<option value=""></option>
- <option value="text" {{if type}}{{if type == 'text'}}selected="selected"{{/if}}{{/if}}>Texte</option>
- <option value="section"{{if type}}{{if type == 'section'}}selected="selected"{{/if}}{{/if}}>Section</option>
+ <option value="section" {{if type}}{{if type == 'section'}}selected="selected"{{/if}}{{/if}}>
+ Section
+ </option>
+ <option value="text" {{if type}}{{if type == 'text'}}selected="selected"{{/if}}{{/if}}>
+ Texte
+ </option>
+ <option value="multiple" {{if type}}{{if type == 'multiple'}}selection="selected"{{/if}}{{/if}}>
+ Question à choix multiples
+ </option>
</select>
<div class="q_edit_form">
{{tmpl "#q_edit_base"}}
</div>
</div>
</script>
+
+<script id="q_edit_multiple" typex="text/x-jquery-tmpl">
+ <div id="q_edit[${qid}][answers]">
+ <div class="add_answer">
+ <a onclick="$(this).multipleAddAnswer()">
+ {/literal}{icon name="add"}{literal} Ajouter une réponse
+ </a>
+ </div>
+ <div>
+ Ajouter une case Autre ?
+ <select name="q_edit[${qid}][allow_other]">
+ <option name="1">Oui</option>
+ <option name="" selected="selected">Non</option>
+ </select>
+ </div>
+ </div>
+</script>
{/literal}
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
{/iterate}
</table>
{/if}
-
+<br />
<div class="center">
<a href="survey/edit">{icon name=page_edit} Proposer un nouveau sondage</a>
</div>