コード例 #1
0
 public function postReviews(Request $request, PublicServiceRepository $gestion)
 {
     $inputData = Input::get('formData');
     parse_str($inputData, $formFields);
     $validator = Validator::make($formFields, Review_Usuario_Servicio::$rules);
     if ($validator->fails()) {
         return response()->json(array('fail' => true, 'message' => $validator->messages()->first(), 'errors' => $validator->getMessageBag()->toArray()));
     } else {
         $verifyIp = $gestion->getReviewsIpEmail($formFields['id_atraccion'], $formFields['email_reviewer']);
         if ($verifyIp == null) {
             $root_array = array();
             //Arreglo de servicios prestados que vienen del formulario
             foreach ($formFields as $key => $value) {
                 //verifica si el arreglo de parametros es un catalogo
                 if (strpos($key, 'review_score') !== false) {
                     $root_array[$key] = $value;
                 }
             }
             $save_array = array();
             $codigo = str_random(30);
             foreach ($root_array as $key1 => $value1) {
                 $save_array['calificacion'] = $value1;
                 $save_array['nombre_reviewer'] = $formFields['nombre_reviewer'];
                 $save_array['email_reviewer'] = $formFields['email_reviewer'];
                 $save_array['id_usuario_servicio'] = $formFields['id_atraccion'];
                 $save_array['id_tipo_review'] = $formFields['id_tipo_review_' . substr($key1, 13)];
                 $save_array['confirmation_rev_code'] = $codigo;
                 $save_array['ip_reviewer'] = $this->getIp();
                 $review = $gestion->storeNew($save_array);
             }
             $this->dispatch(new VerifyReview($review));
         } else {
             return response()->json(array('fail' => true, 'message' => "Usted ya ha dejado un review anteriormente", 'errors' => $validator->getMessageBag()->toArray()));
         }
         return response()->json(array('success' => true, 'message' => "Gracias por tu review, se ha enviado un correo electrónico a tu email para verificación"));
     }
 }