Example #1
0
 function save($id = NULL)
 {
     /*echo '<pre>';
     		print_r($_POST);
     		echo '</pre>';
     		exit();*/
     $topic = new Topic($id);
     $topic->title = $_POST['title'];
     $topic->detail = $_POST['detail'];
     $topic->status = $_POST['status'];
     if (!$id) {
         $topic->user_id = $this->session->userdata('id');
     }
     $topic->save();
     foreach ($_POST['question_id'] as $key => $value) {
         if (@$_POST['question'][$key]) {
             $question = new Questionaire($value);
             $question->question = $_POST['question'][$key];
             $question->type = $_POST['type'][$key];
             if (@$_POST['min'][$key]) {
                 $question->min = $_POST['min'][$key];
             }
             if (@$_POST['max'][$key]) {
                 $question->max = $_POST['max'][$key];
             }
             if (@$_POST['range'][$key]) {
                 $question->range = $_POST['range'][$key];
             }
             if (@$_POST['other'][$key]) {
                 $question->other = $_POST['other'][$key];
             }
             if (@$_POST['optional'][$key]) {
                 $question->optional = json_encode($_POST['optional'][$key]);
             }
             $question->topic_id = $topic->id;
             $question->sequence = $key;
             $question->save();
         }
         if (@$_POST['choice'][$key]) {
             foreach ($_POST['choice'][$key] as $index => $data) {
                 if ($data) {
                     $choice = new Choice(@$_POST['choice_id'][$key][$index]);
                     $choice->name = $data;
                     $choice->questionaire_id = $question->id;
                     $choice->save();
                 }
             }
         }
     }
     set_notify('success', 'บันทึกข้อมูลเรียบร้อยแล้วค่ะ');
     redirect('docs/index');
 }
 public function postCreate2()
 {
     $nb_choice = Input::get('nb_choice');
     for ($i = 0; $i < $nb_choice; $i++) {
         $choice = new Choice();
         $choice->question_id = Input::get('question_id');
         $choice->content = Input::get("content{$i}");
         $choice->status = Input::get("status{$i}");
         $choice->save();
     }
     Session::flash('message_success', 'Le QCM a été ajouté');
     return Redirect::to('/teacher/questions');
 }