load->model('Question_Management_Model'); } public function listAllQuestions_get() { $page = 0;$limit = 0;$sort = 'ASC'; if($this->get('page')) { $page = $this->get('page'); } if($this->get('limit')){ $limit = $this->get('limit'); } if($this->get('sort')) { $sort = $this->get('sort'); } $result = $this->Question_Management_Model->listAllQuestions($page,$limit,$sort); if($result['data_status']) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result['data']; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $this->response($data,REST_Controller::HTTP_NO_CONTENT); } } public function saveNewQuestion_post()// Save single question and it's answers { $records = $this->post('records'); $count = 0; $answers = array(); if(array_key_exists('answers',$records)) { $answers = $records['answers']; unset($records['ansewrs']); } $question_id = $this->Question_Management_Model->saveRecords($records,QUESTIONS); if($question_id != '' || $question_id != null) { //$count++; foreach($answers as $answer) { $temp_answers = array('fk_question_id' => $question_id, 'answer' =>$answer['answer'] , 'createdon' =>$records['createdon'] , 'fk_createdby' =>$records['fk_createdby']); $child_id = $this->db->saveRecords($temp_answers,QUESTIONANSWERS); } } if($question_id != '' || $question_id != null) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['record'] = $question_id; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $this->response($data,REST_Controller::HTTP_OK); } } public function saveExistQuestion_post() { $records = $this->post('records'); $answers = array(); if(array_key_exists('answers',$records)) { $answers = $records['answers']; unset($records['ansewrs']); } $where_condtion_array = array('question_id'=>$records['question_id']); $affected_rows = $this->db->updateRecords($records,QUESTIONS,$where_condtion_array); $affected_rows_child = 0; foreach($answers as $answer) { $where_condtion_array = array('question_answer_id'=>$answer['question_answer_id']); $affected_rows_child = $this->db->updateRecords($answer,QUESTIONANSWERS,$where_condtion_array); } if($affected_rows == 1) //&& (count($answers) == $affected_rows_child)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['record'] = $affected_rows; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $this->response($data,REST_Controller::HTTP_OK); } } }