Skip to content

Instantly share code, notes, and snippets.

@goshmx
Last active July 6, 2016 04:04
Show Gist options
  • Save goshmx/2082cd7fb841da37b8839ae9054e8358 to your computer and use it in GitHub Desktop.
Save goshmx/2082cd7fb841da37b8839ae9054e8358 to your computer and use it in GitHub Desktop.
Coding Refactoring
<?php
class PresentacionController extends Controller {
/**
* Cofirmación de Servicio
*
* @author gosh
* @version 1.1
* @return json Código de error generado
* @param string service_id ID de servicio
* @param string driver_id ID de conductor
* @todo Agregar pwd al actualizar Service
*
* Catalogo de Estados de respuesta
* 1. Driver id igual a NULL y status del servicio igual a 1
* 2. Estado del servicio igual a 6
* 3. No se encontro el registro del Servicio.
* 4. Ocurrio un error al enviar la notificación.
* 5. El parametro Id es necesario.
* 6. El parametro driver_id es necesario.
*
*/
public function postConfirm(){
$id = Input::get('service_id');
if($id){
$servicio = Service::find($id);
if ($servicio){
if ($servicio->status_id == '6'){
return Response::json(array('error' => '2');
}
if ($servicio->driver_id == NULL && $servicio->status_id == '1'){
$driverId = Input::get('driver_id');
if($driverId){
$driver = Driver::find(Input::get('driver_id'));
$driver->available = '0';
$driver->save();
$servicio->driver_id = Input::get('driver_id');
$servicio->status_id = '2';
$servicio->car_id = $driver->card_id;
$servicio->save();
$pushMessage = 'Tu servicio ha sido confirmado';
$push = Push::make();
if ($servicio->user->uuid == ''){
return Response::json(array('error' => '0'));
}
if($servicio->user->type == '1'){
$result = $push->ios($servicio->user->uuid, $pushMessage, 1, 'honk.wav', 'Open', array('serviceId' => $servicio->id));
}
else{
$result = $push->android2($servicio->user->uuid, $pushMessage, 1, 'default', 'Open', array('serviceId' => $servicio->id));
}
if($result){
return Response::json(array('error' => '0'));
}
else{
return Response::json(array('error' => '4'));
}
}
else{
return Response::json(array('error' => '6'));
}
}
else{
return Response::json(array('error' => '1'));
}
}
else{
return Response::json(array('error' => '3'));
}
}
else{
return Response::json(array('error' => '5'));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment