src/Hona/ApiBundle/Controller/AddressController.php line 217

Open in your IDE?
  1. <?php
  2. namespace Hona\ApiBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Hona\ApiBundle\Library\Utils;
  8. class AddressController extends EntityController
  9. {
  10.     protected $required = array("street""residential");
  11.     protected function _validateAfterGET(Request $request$entity$uuid, &$data$clean){
  12.         if($entity == "access_history" || $entity == "invitation"){
  13.             $this->_changeIdForEntity("user"$data$clean);
  14.             if(!empty($data["image_code_path"])){
  15.                 $data["image_code_path"] = Utils::addMediaDomainToPath($data["image_code_path"]);
  16.             }
  17.         }else if($entity == "event"){
  18.             $this->_changeIdForEntity("user"$data$clean);
  19.         }else if($entity == "address"){
  20.             $this->_changeIdForEntity("residential"$data$clean);
  21.         }
  22.     }
  23.     protected function _validateAfterPUT(Request $request$entity$uuid, &$data$clean){
  24.         $this->_changeIdForEntity("residential"$data$clean);
  25.     }
  26.     protected function _validateAfterPOST(Request $request$entity$uuid, &$data$clean){
  27.         $this->_changeIdForEntity("residential"$data$clean);
  28.     }
  29.     protected function _validateBeforePOST(Request $request$entity, &$data){
  30.         $this->_changeUuidForId("residential"$data);
  31.         if(!isset($data["status"])){
  32.             $data["status"] = Utils::ACTIVE;
  33.         }
  34.     }
  35.     protected function _validateBeforePUT(Request $request$entity$uuid, &$data){
  36.         $this->_changeUuidForId("residential"$data);
  37.     }
  38.     /**
  39.      * @Route("/address/{uuid}/news/{size}/{page}", name="address_get_uuid_news", methods={"GET"})
  40.      * @param $request
  41.      */
  42.     public function addressNewsGETAction(Request $request$uuid$size 10$page 0)
  43.     {
  44.         $user $this->getUser();
  45.         $userHasAddress Utils::checkUserAddressExists($this->getDoctrine()->getManager(), $uuid$user);
  46.         if($userHasAddress){
  47.             $address $this->_entityGET($request"address"$uuidnulltrue);
  48.             if(is_array($address)){
  49.                 return $this->forward('HonaApiBundle:Residential:residentialNewsGET', [
  50.                     'request' => $request,
  51.                     'uuid' => $address["residential"]["uuid"],
  52.                     'type' => 1,
  53.                     'size' => $size,
  54.                     'page' => $page
  55.                 ]);
  56.             }
  57.             return $address;
  58.         }else{
  59.             $data = [
  60.                 'message' => "user with no address",
  61.                 'code' => 20
  62.             ];
  63.             
  64.             return new JsonResponse($data400);
  65.         }
  66.     }
  67.     /**
  68.      * @Route("/address/{uuid}/user/{user_uuid}/history/{size}/{page}", name="address_get_uuid_user_uuid_history", methods={"GET"})
  69.      * @param $request
  70.      */
  71.     public function addressUserHistoryGETAction(Request $request$uuid$user_uuid$size 10$page 0)
  72.     {
  73.         $user $this->getUser();
  74.         $userHasAddress Utils::checkUserAddressExists($this->getDoctrine()->getManager(), $uuid$user);
  75.         if($userHasAddress){
  76.             $address $this->_entityGET($request"address"$uuidnulltruefalse);
  77.             if(is_array($address)){
  78.                 $user $this->_entityGET($request"user"$user_uuidnulltruefalse);
  79.                 if(is_array($user)){
  80.                     return $this->_listEntitiesByFunction($request"access_history""address_id_user_id_and_status", array(
  81.                         "address_id" => $address["id"],
  82.                         "user_id" => $user["id"],
  83.                         "status" => Utils::ACTIVE
  84.                     ), array("date_entry" => "DESC"), $size$page);
  85.                 }else{
  86.                     return $address;
  87.                 }
  88.             }else{
  89.                 return $address;
  90.             }
  91.         }else{
  92.             $data = [
  93.                 'message' => "user with no address",
  94.                 'code' => 20
  95.             ];
  96.             
  97.             return new JsonResponse($data400);
  98.         }
  99.     }
  100.     /**
  101.      * @Route("/address/{uuid}/user/{user_uuid}/invitation/{size}/{page}", name="address_get_uuid_user_uuid_invitation", methods={"GET"})
  102.      * @param $request
  103.      */
  104.     public function addressUserInvitationGETAction(Request $request$uuid$user_uuid$size 10$page 0)
  105.     {
  106.         $user $this->getUser();
  107.         $userHasAddress Utils::checkUserAddressExists($this->getDoctrine()->getManager(), $uuid$user);
  108.         if($userHasAddress){
  109.             $order $request->query->get('order');
  110.             if(isset($order)){
  111.                 $order strtoupper($order);
  112.             }else{
  113.                 $order "ASC";
  114.             }
  115.             $address $this->_entityGET($request"address"$uuidnulltruefalse);
  116.             if(is_array($address)){
  117.                 $user $this->_entityGET($request"user"$user_uuidnulltruefalse);
  118.                 if(is_array($user)){
  119.                     return $this->_listEntitiesByFunction($request"invitation""address_id_user_id_and_status", array(
  120.                         "address_id" => $address["id"],
  121.                         "user_id" => $user["id"],
  122.                         "status" => Utils::ACTIVE
  123.                     ), array("date_invitation" => $order), $size$page);
  124.                 }else{
  125.                     return $user;
  126.                 }
  127.             }else{
  128.                 return $address;
  129.             }
  130.         }else{
  131.             $data = [
  132.                 'message' => "user with no address",
  133.                 'code' => 20
  134.             ];
  135.             
  136.             return new JsonResponse($data400);
  137.         }
  138.     }
  139.     /**
  140.      * @Route("/address/{uuid}/user/{user_uuid}/event/history/{size}/{page}", name="address_get_uuid_user_uuid_event_history", methods={"GET"})
  141.      * @param $request
  142.      */
  143.     public function addressUserEventHistoryGETAction(Request $request$uuid$user_uuid$size 10$page 0)
  144.     {
  145.         $address $this->_entityGET($request"address"$uuidnulltruefalse);
  146.         if(is_array($address)){
  147.             $user $this->_entityGET($request"user"$user_uuidnulltruefalse);
  148.             if(is_array($user)){
  149.                 return $this->_listEntitiesByFunction($request"event""history_address_id_user_id_and_status", array(
  150.                     "address_id" => $address["id"],
  151.                     "user_id" => $user["id"],
  152.                     "status" => Utils::ACTIVE
  153.                 ), array("date_event" => "DESC"), $size$page);
  154.             }else{
  155.                 return $address;
  156.             }
  157.         }else{
  158.             return $address;
  159.         }
  160.     }
  161.     /**
  162.      * @Route("/address/{uuid}/user/{user_uuid}/event/{size}/{page}", name="address_get_uuid_user_uuid_event", methods={"GET"})
  163.      * @param $request
  164.      */
  165.     public function addressUserEventGETAction(Request $request$uuid$user_uuid$size 10$page 0)
  166.     {
  167.         $address $this->_entityGET($request"address"$uuidnulltruefalse);
  168.         if(is_array($address)){
  169.             $user $this->_entityGET($request"user"$user_uuidnulltruefalse);
  170.             if(is_array($user)){
  171.                 return $this->_listEntitiesByFunction($request"event""address_id_user_id_and_status", array(
  172.                     "address_id" => $address["id"],
  173.                     "user_id" => $user["id"],
  174.                     "status" => Utils::ACTIVE
  175.                 ), array("date_event" => "ASC"), $size$page);
  176.             }else{
  177.                 return $user;
  178.             }
  179.         }else{
  180.             return $address;
  181.         }
  182.     }
  183.     /**
  184.      * @Route("/address/{uuid}/user/{size}/{page}", name="address_get_uuid_user", methods={"GET"})
  185.      * @param $request
  186.      */
  187.     public function addressUserGETAction(Request $request$uuid$size 10$page 0)
  188.     {
  189.         $user $this->getUser();
  190.         $userHasAddress Utils::checkUserAddressExists($this->getDoctrine()->getManager(), $uuid$user);
  191.         if($userHasAddress){
  192.             $address $this->_entityGET($request"address"$uuidnulltruefalse);
  193.             if(is_array($address)){
  194.                 return $this->_listEntitiesByFunction($request"user""address_id_and_status", array(
  195.                         "address_id" => $address["id"],
  196.                         "status" => Utils::ACTIVE
  197.                     ), array(), $size$page);
  198.             }else{
  199.                 return $address;
  200.             }
  201.         }else{
  202.             $data = [
  203.                 'message' => "user with no address",
  204.                 'code' => 20
  205.             ];
  206.             
  207.             return new JsonResponse($data400);
  208.         }
  209.         
  210.     }
  211.     /**
  212.      * @Route("/address/{uuid}/history/{size}/{page}", name="address_get_uuid_history", methods={"GET"})
  213.      * @param $request
  214.      */
  215.     public function addressHistoryGETAction(Request $request$uuid$size 10$page 0)
  216.     {
  217.         $user $this->getUser();
  218.         $userHasAddress Utils::checkUserAddressExists($this->getDoctrine()->getManager(), $uuid$user);
  219.         if($userHasAddress){
  220.             $address $this->_entityGET($request"address"$uuidnulltruefalse);
  221.             if(is_array($address)){
  222.                 return $this->_listEntitiesByFunction($request"access_history""address_id_and_status", array(
  223.                         "address_id" => $address["id"],
  224.                         "status" => Utils::ACTIVE
  225.                     ), array("date_entry" => "DESC"), $size$page);
  226.             }else{
  227.                 return $address;
  228.             }
  229.         }else{
  230.             $data = [
  231.                 'message' => "user with no address",
  232.                 'code' => 20
  233.             ];
  234.             
  235.             return new JsonResponse($data400);
  236.         }
  237.     }
  238.     /**
  239.      * @Route("/address/{uuid}/invitation/{size}/{page}", name="address_get_uuid_invitation", methods={"GET"})
  240.      * @param $request
  241.      */
  242.     public function addressInvitationGETAction(Request $request$uuid$size 10$page 0)
  243.     {
  244.         $user $this->getUser();
  245.         $userHasAddress Utils::checkUserAddressExists($this->getDoctrine()->getManager(), $uuid$user);
  246.         if($userHasAddress){
  247.             $order $request->query->get('order');
  248.             if(isset($order)){
  249.                 $order strtoupper($order);
  250.             }else{
  251.                 $order "ASC";
  252.             }
  253.             $address $this->_entityGET($request"address"$uuidnulltruefalse);
  254.             if(is_array($address)){
  255.                 return $this->_listEntitiesByFunction($request"invitation""address_id_and_status", array(
  256.                     "address_id" => $address["id"],
  257.                     "status" => Utils::ACTIVE
  258.                 ), array("date_invitation" => $order), $size$page);
  259.             }else{
  260.                 return $address;
  261.             }
  262.         }else{
  263.             $data = [
  264.                 'message' => "user with no address",
  265.                 'code' => 20
  266.             ];
  267.             
  268.             return new JsonResponse($data400);
  269.         }
  270.     }
  271.     /**
  272.      * @Route("/address/{uuid}/event/history/{size}/{page}", name="address_get_uuid_historic_event", methods={"GET"})
  273.      * @param $request
  274.      */
  275.     public function addressEventHistoryGETAction(Request $request$uuid$size 10$page 0)
  276.     {
  277.         $address $this->_entityGET($request"address"$uuidnulltruefalse);
  278.         if(is_array($address)){
  279.             return $this->_listEntitiesByFunction($request"event""history_address_id_and_status", array(
  280.                 "address_id" => $address["id"],
  281.                 "status" => Utils::ACTIVE
  282.             ), array("date_event" => "ASC"), $size$page);
  283.         }else{
  284.             return $address;
  285.         }
  286.     }
  287.     /**
  288.      * @Route("/address/{uuid}/event/{size}/{page}", name="address_get_uuid_event", methods={"GET"})
  289.      * @param $request
  290.      */
  291.     public function addressEventGETAction(Request $request$uuid$size 10$page 0)
  292.     {
  293.         $address $this->_entityGET($request"address"$uuidnulltruefalse);
  294.         if(is_array($address)){
  295.             return $this->_listEntitiesByFunction($request"event""address_id_and_status", array(
  296.                 "address_id" => $address["id"],
  297.                 "status" => Utils::ACTIVE
  298.             ), array("date_event" => "ASC"), $size$page);
  299.         }else{
  300.             return $address;
  301.         }
  302.     }
  303.     /**
  304.      * @Route("/address/{uuid}", name="address_get_uuid", methods={"GET"})
  305.      * @param $request
  306.      */
  307.     public function addressGETAction(Request $request$uuid)
  308.     {
  309.         return $this->_entityGET($request"address"$uuid);
  310.     }
  311.     /**
  312.      * @Route("/address", name="address_post_uuid", methods={"POST"})
  313.      * @param $request
  314.      */
  315.     public function addressPOSTAction(Request $request)
  316.     {
  317.         return $this->_entityPOST($request"address");
  318.     }
  319.     /**
  320.      * @Route("/address/{uuid}", name="address_put_uuid", methods={"PUT"})
  321.      * @param $request
  322.      */
  323.     public function addressPUTAction(Request $request$uuid)
  324.     {
  325.         return $this->_entityPUT($request"address"$uuid);
  326.     }
  327.     /**
  328.      * @Route("/address/{uuid}", name="address_delete_uuid", methods={"DELETE"})
  329.      * @param $request
  330.      */
  331.     public function addressDELETEAction(Request $request$uuid)
  332.     {
  333.         return $this->_entityDELETE($request"address"$uuid);
  334.     }
  335. }