|
@@ -20,7 +20,6 @@ use Voryx\RESTGeneratorBundle\Controller\VoryxController;
|
|
|
|
|
|
abstract class RESTController extends VoryxController
|
|
abstract class RESTController extends VoryxController
|
|
{
|
|
{
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* @return string Retorna el nombre de la Entity de trabajo.
|
|
* @return string Retorna el nombre de la Entity de trabajo.
|
|
*/
|
|
*/
|
|
@@ -37,7 +36,7 @@ abstract class RESTController extends VoryxController
|
|
{
|
|
{
|
|
return get_class(new ClientType());
|
|
return get_class(new ClientType());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Get all entities.
|
|
* Get all entities.
|
|
*
|
|
*
|
|
@@ -57,6 +56,8 @@ abstract class RESTController extends VoryxController
|
|
public function cgetAction(ParamFetcherInterface $paramFetcher)
|
|
public function cgetAction(ParamFetcherInterface $paramFetcher)
|
|
{
|
|
{
|
|
$em = $this->getDoctrine()->getManager();
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
+
|
|
|
|
+ $disableTenancy = false;
|
|
$filters = !is_null($paramFetcher->get('filters')) ? $paramFetcher->get('filters') : array();
|
|
$filters = !is_null($paramFetcher->get('filters')) ? $paramFetcher->get('filters') : array();
|
|
if (isset($filters['tenancyId'])) {
|
|
if (isset($filters['tenancyId'])) {
|
|
// tengo que buscar por tenencia.
|
|
// tengo que buscar por tenencia.
|
|
@@ -64,53 +65,58 @@ abstract class RESTController extends VoryxController
|
|
$tenancyService->setTenancy($filters['tenancyId']);
|
|
$tenancyService->setTenancy($filters['tenancyId']);
|
|
unset($filters['tenancyId']);
|
|
unset($filters['tenancyId']);
|
|
}
|
|
}
|
|
- if (isset($filters['qb-criteria'])) {
|
|
|
|
|
|
+ if (isset($filters['disableTenancy'])) {
|
|
|
|
+ $disableTenancy = true;
|
|
|
|
+ // tengo que buscar por tenencia.
|
|
|
|
+ $tenancyService = $this->container->get('base_tenancy.tenancy_service');
|
|
|
|
+ $tenancyService->disableFilter();
|
|
|
|
+ unset($filters['disableTenancy']);
|
|
|
|
+ }
|
|
|
|
+ if(isset($filters['qb-criteria'])) {
|
|
try {
|
|
try {
|
|
|
|
|
|
unset($filters['qb-criteria']);
|
|
unset($filters['qb-criteria']);
|
|
$criteria = new \Doctrine\Common\Collections\Criteria();
|
|
$criteria = new \Doctrine\Common\Collections\Criteria();
|
|
|
|
|
|
- foreach ($filters as $field => $value) {
|
|
|
|
|
|
+ foreach($filters as $field => $value) {
|
|
$criteria->andWhere($criteria->expr()->contains("$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'));
|
|
$criteria->setFirstResult($paramFetcher->get('offset'));
|
|
}
|
|
}
|
|
|
|
|
|
- if (!is_null($paramFetcher->get('limit'))) {
|
|
|
|
|
|
+ if(!is_null($paramFetcher->get('limit'))) {
|
|
$criteria->setMaxResults($paramFetcher->get('limit'));
|
|
$criteria->setMaxResults($paramFetcher->get('limit'));
|
|
}
|
|
}
|
|
|
|
|
|
- if ($paramFetcher->get('order_by')) {
|
|
|
|
|
|
+ if($paramFetcher->get('order_by')) {
|
|
$order_by = $paramFetcher->get('order_by');
|
|
$order_by = $paramFetcher->get('order_by');
|
|
$orderBy = array();
|
|
$orderBy = array();
|
|
- foreach ($order_by as $field => $order) {
|
|
|
|
|
|
+ foreach($order_by as $field => $order) {
|
|
$orderBy[$field] = $order;
|
|
$orderBy[$field] = $order;
|
|
}
|
|
}
|
|
$criteria->orderBy($orderBy);
|
|
$criteria->orderBy($orderBy);
|
|
}
|
|
}
|
|
|
|
|
|
- $repo = $em->getRepository($this->getRepository());
|
|
|
|
|
|
+ $repo = $em->getRepository($this->repository);
|
|
$entities = $repo->matching($criteria)->toArray();
|
|
$entities = $repo->matching($criteria)->toArray();
|
|
|
|
|
|
if($disableTenancy) $tenancyService->enableFilter();
|
|
if($disableTenancy) $tenancyService->enableFilter();
|
|
-
|
|
|
|
if ($entities) {
|
|
if ($entities) {
|
|
return $entities;
|
|
return $entities;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
|
|
return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
try {
|
|
try {
|
|
$offset = $paramFetcher->get('offset');
|
|
$offset = $paramFetcher->get('offset');
|
|
$limit = $paramFetcher->get('limit');
|
|
$limit = $paramFetcher->get('limit');
|
|
$order_by = $paramFetcher->get('order_by');
|
|
$order_by = $paramFetcher->get('order_by');
|
|
- $entities = $em->getRepository($this->getRepository())->findBy($filters, $order_by, $limit, $offset);
|
|
|
|
-
|
|
|
|
|
|
+ $entities = $em->getRepository($this->repository)->findBy($filters, $order_by, $limit, $offset);
|
|
if($disableTenancy) $tenancyService->enableFilter();
|
|
if($disableTenancy) $tenancyService->enableFilter();
|
|
|
|
|
|
if ($entities) {
|
|
if ($entities) {
|
|
@@ -123,9 +129,8 @@ abstract class RESTController extends VoryxController
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- return array();
|
|
|
|
|
|
+ return array();
|
|
}
|
|
}
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* @return object Retorna el nombre de la Entity de trabajo.
|
|
* @return object Retorna el nombre de la Entity de trabajo.
|
|
*/
|
|
*/
|
|
@@ -246,6 +251,5 @@ abstract class RESTController extends VoryxController
|
|
{
|
|
{
|
|
return $entity;
|
|
return $entity;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|