Beispiel #1
0
 public function save()
 {
     $this->load->table('question');
     $this->load->module_table('maze', 'response');
     $question = new Question_delegate();
     $question->bind($_POST);
     $question->store();
     $responses = $this->input->post('response');
     $response_ids = array();
     foreach ($responses as $response) {
         $resp = new Response_delegate();
         $resp->bind($response);
         $resp->question_id = $question->id;
         $resp->store();
         if (false === empty($resp->id)) {
             $response_ids[] = $resp->id;
         }
     }
     if (0 < sizeof($response_ids)) {
         $query = 'DELETE FROM ' . $this->db->protect_identifiers('responses') . ' WHERE question_id = ? AND id NOT IN (' . implode(',', $response_ids) . ')';
         $this->db->query($query, array($question->id));
     }
     redirect('admin/questions');
 }