Created
June 10, 2013 16:27
-
-
Save thyseus/5750112 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function actionCreate() | |
| { | |
| $model=new Survey; | |
| // Uncomment the following line if AJAX validation is needed | |
| // $this->performAjaxValidation($model); | |
| if(isset($_POST['Survey'])) | |
| { | |
| $model->attributes=$_POST['Survey']; | |
| if($model->save()) { | |
| $model->processQuestions($_POST); | |
| $this->redirect(array('view','id'=>$model->id)); | |
| } | |
| } | |
| if(!$model->questions) | |
| $model->addDefaultQuestions(); | |
| $this->render('create',array( | |
| 'model'=>$model, | |
| )); | |
| } | |
| public function processAnswers($answers) { | |
| foreach($answers as $key => $value) | |
| if(substr($key, 0, 6) == 'answer') { | |
| $question = explode('_', $key); | |
| $question = $question[1]; | |
| $answer = new Answer(); | |
| $answer->attend_id = $_POST['Answer']['attend_id']; | |
| $answer->question_id = $question; | |
| $answer->answer = $value; | |
| $answer->save(); | |
| } | |
| } | |
| ? $questions = $model->questions; ?> | |
| <table id="questions" class="table table-striped"> | |
| <tr> <th> Frage </th> <th> Typ </th> <th> Optionen </th> </tr> | |
| <? for($i = 0; $i <= 20; $i++) { ?> | |
| <tr> <td style="width:70%"> | |
| <?= CHtml::textField('question_'.$i, | |
| isset($questions[$i]) ? $questions[$i]->title : '', array( | |
| 'class'=>'span12', | |
| 'maxlength'=>255)); ?> | |
| </td> <td> | |
| <?= CHtml::dropDownList('type_'.$i, | |
| isset($questions[$i]) ? $questions[$i]->type : '', array( | |
| 0 => 'Ja/Nein', | |
| 1 => 'Freitexteingabe', | |
| 2 => 'Wertigkeit')); ?> | |
| </td> <td> | |
| <?= CHtml::textField('options_'.$i, | |
| isset($questions[$i]) ? $questions[$i]->option : '', array( | |
| 'class'=>'span12', | |
| 'maxlength'=>255)); ?> | |
| </td></tr> | |
| <? } ?> | |
| </table> | |
thyseus
commented
Jun 10, 2013
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment