Exemplo n.º 1
0
 public function getQuestions()
 {
     $validator = Validator::make(Input::all(), array('token' => 'required', 'doctor' => ''));
     if ($validator->passes()) {
         $post = Input::all();
         if ($post['token'] == Config::get('doktornarabote.secret_string')) {
             $questions = array();
             if (Input::has('doctor')) {
                 $doctor_type = Input::get('doctor');
                 $doctors_types = Config::get('doktornarabote.doctor_types');
                 $doctor_type_id = 0;
                 foreach ($doctors_types as $index => $name) {
                     if (is_numeric($doctor_type)) {
                         if ($index == (int) $doctor_type) {
                             $doctor_type_id = $index;
                             break;
                         }
                     } elseif (is_string($doctor_type)) {
                         if (mb_strtolower(trim($name)) == mb_strtolower(trim($doctor_type))) {
                             $doctor_type_id = $index;
                             break;
                         }
                     }
                 }
                 $questions_list = Questions::orderBy('order')->where('doctor_type', $doctor_type_id)->get();
             } else {
                 $questions_list = Questions::orderBy('order')->get();
             }
             foreach ($questions_list as $question) {
                 $questions[] = array('question' => trim($question->question), 'doctor_type' => $question->doctor_type, 'is_true' => $question->is_true, 'answer' => trim($question->answer), 'is_branding' => $question->is_branding);
             }
             $this->json_request['data'] = $questions;
             $this->json_request['error'] = 0;
         } else {
             $this->json_request['message'] = 'Неверный токен';
         }
     }
     return Response::make(Input::get('callback') . '(' . json_encode($this->json_request) . ')', 200);
 }
 public function index()
 {
     $questions = Questions::orderBy('order')->get();
     return View::make($this->module['tpl'] . 'questions.index', compact('questions'));
 }