Guest User

Untitled

a guest
Jan 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2. public function confirm(){
  3. $id = Input::get('service_id');
  4. $driver = Driver::find(Input::get('driver_id'));
  5. $servicio = Service::find($id);
  6. $response = $this->validate($servicio);
  7. if ($response !== true) {
  8. return $response;
  9. }
  10. Service::update($id,array('driver_id'=>$driver->id,'status_id','2','car_id'=>$driver->car_id));
  11. Driver::update($driver->id,array('available'=>'0'));
  12. $this->pushMessage($servicio);
  13. }
  14. public function validate($servicio){
  15. (!$servicio) ? $error = 3 : '';
  16. ($servicio->status_id == '6') ? $error = 2 : '';
  17. ($servicio->driver_id !== null) ? $error = 1 : '';
  18. ($servicio->status_id != '1') ? $error = 1: '';
  19. ($servicio->user->uuid == '') ? $error = 0 : '';
  20. if (!empty($error)) {
  21. return Response::json(array("error"=>$error));
  22. }
  23. return true;
  24. }
  25. public function pushMessage($servicio){
  26. $pushMessage =" Tu servicio ha sido confirmado";
  27. $push = Push::make();
  28. $iPhone = $this->isiPhone($servicio->user->type);
  29. if ($iPhone) {
  30. $push->ios($servicio->user->uuid,$pushMessage,1,$iPhone,'Open',array("serviceId"=>$servicio->id));
  31. }else{
  32. $push->android2($servicio->user->uuid,$pushMessage,1,"default",'Open',array("serviceId"=>$servicio->id));
  33. }
  34. }
  35. public function isiPhone($type){
  36. if ($type == 1) {
  37. return "honk.wav";
  38. }
  39. return false;
  40. }
  41. }
  42.  
  43.  
  44. ?>
Add Comment
Please, Sign In to add comment