Преглед изворни кода

Agregado del filtro por tenencia

gabriel пре 7 година
родитељ
комит
1979d5d391
1 измењених фајлова са 17 додато и 12 уклоњено
  1. 17 12
      Controller/RESTController.php

+ 17 - 12
Controller/RESTController.php

@@ -19,7 +19,7 @@ use Voryx\RESTGeneratorBundle\Controller\VoryxController;
 class RESTController extends VoryxController
 {
     var $repository = 'ClientBundle:Client';
-    
+
     /**
      * Get all entities.
      *
@@ -39,30 +39,35 @@ class RESTController extends VoryxController
     public function cgetAction(ParamFetcherInterface $paramFetcher)
     {
         $em = $this->getDoctrine()->getManager();
-        
         $filters = !is_null($paramFetcher->get('filters')) ? $paramFetcher->get('filters') : array();
-        if(isset($filters['qb-criteria'])) {
+        if (isset($filters['tenancy_id'])) {
+            // tengo que buscar por tenencia.
+            $tenancyService = $this->container->get('base_tenancy.tenancy_service');
+            $tenancyService->setTenancy($filters['tenancy_id']);
+            unset($filters['tenancy_id']);
+        }
+        if (isset($filters['qb-criteria'])) {
             try {
 
                 unset($filters['qb-criteria']);
                 $criteria = new \Doctrine\Common\Collections\Criteria();
 
-                foreach($filters as $field => $value) {
+                foreach ($filters as $field => $value) {
                     $criteria->andWhere($criteria->expr()->contains("$field", "$value"));
                 }
 
-                if(!is_null($paramFetcher->get('offset'))) {
+                if (!is_null($paramFetcher->get('offset'))) {
                     $criteria->setFirstResult($paramFetcher->get('offset'));
                 }
 
-                if(!is_null($paramFetcher->get('limit'))) {
+                if (!is_null($paramFetcher->get('limit'))) {
                     $criteria->setMaxResults($paramFetcher->get('limit'));
                 }
 
-                if($paramFetcher->get('order_by')) {
+                if ($paramFetcher->get('order_by')) {
                     $order_by = $paramFetcher->get('order_by');
                     $orderBy = array();
-                    foreach($order_by as $field => $order) {
+                    foreach ($order_by as $field => $order) {
                         $orderBy[$field] = $order;
                     }
                     $criteria->orderBy($orderBy);
@@ -74,11 +79,11 @@ class RESTController extends VoryxController
                 if ($entities) {
                     return $entities;
                 }
-            
+
             } catch (\Exception $e) {
                 return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
             }
-            
+
         } else {
             try {
                 $offset = $paramFetcher->get('offset');
@@ -96,7 +101,7 @@ class RESTController extends VoryxController
 
         }
 
-         return array();
+        return array();
     }
-    
+
 }