From 7a51e7aeffd72798fcd8cfaa1f27535b5e959b07 Mon Sep 17 00:00:00 2001 From: devega Date: Tue, 24 Mar 2020 12:36:46 +0100 Subject: Updated Symfony 3.x to 4.x - Reorganizado los Repositorios de Symfony - Registrado los commandos como Servicio - Actualizado la configuraiĆ³n de Doctrine - Modificado el fichero update e installer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/OrganizationalUnitRepository.php | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Repository/OrganizationalUnitRepository.php (limited to 'admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Repository/OrganizationalUnitRepository.php') diff --git a/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Repository/OrganizationalUnitRepository.php b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Repository/OrganizationalUnitRepository.php new file mode 100644 index 00000000..c63ee2a8 --- /dev/null +++ b/admin/WebConsole3/backend/src/Opengnsys/ServerBundle/Repository/OrganizationalUnitRepository.php @@ -0,0 +1,121 @@ + + * Copyright (c) 2015 Opengnsys. All rights reserved. + * + */ + +namespace Opengnsys\ServerBundle\Repository; + +use Opengnsys\CoreBundle\Repository\BaseRepository; + +/** + * OrganizationalUnitRepository + * + * This class was generated by the Doctrine ORM. Add your own custom + * repository methods below. + */ +class OrganizationalUnitRepository extends BaseRepository +{ + + + public function findByObservable($term = "", $limit = null, $offset = null, $ordered = array(), $selects = array(), $searchs = array(), $matching = array()) + { + $qb = $this->createQueryBuilder('o'); + + if(count($selects) > 0){ + $qb = $this->createSelect($qb, $selects); + }else{ + $qb->select("DISTINCT o.createdAt, o.updatedAt, o.notes, o.name, o.description, o.comments, o.id"); + } + + if($term != ""){ + if(count($searchs) > 0){ + $qb = $this->createSearch($qb, $term, $searchs); + }else{ + $qb->andWhere("o.createdAt LIKE :term OR o.updatedAt LIKE :term OR o.notes LIKE :term OR o.name LIKE :term OR o.description LIKE :term OR o.comments LIKE :term OR o.id LIKE :term ")->setParameter('term', '%' . $term . '%'); + } + } + + $qb = $this->createMaching($qb, $matching); + + $qb = $this->createOrdered($qb, $ordered); + + if($limit != null){ + $qb->setMaxResults($limit); + } + + if($offset){ + $qb->setFirstResult($offset); + } + + $entities = $qb->getQuery()->getScalarResult(); + return $entities; + } + + public function countFiltered($term = "", $searchs = array(), $matching = array()) + { + $qb = $this->createQueryBuilder('o'); + + $qb->select("count(DISTINCT o.id)"); + + if($term != ""){ + if(count($searchs) > 0){ + $qb = $this->createSearch($qb, $term, $searchs); + }else{ + $qb->andWhere("o.createdAt LIKE :term OR o.updatedAt LIKE :term OR o.notes LIKE :term OR o.name LIKE :term OR o.description LIKE :term OR o.comments LIKE :term OR o.id LIKE :term ")->setParameter('term', '%' . $term . '%'); + } + } + + $qb = $this->createMaching($qb, $matching); + + $count = $qb->getQuery()->getSingleScalarResult(); + return $count; + } + + + /* + public function allBy($limit , $offset, $hierarchical, $leaf) + { + + $qb = $this->createQueryBuilder('o'); + + + + if($limit != null){ + $qb->setMaxResults($limit); + } + if($offset != null){ + $qb->setFirstResult($offset); + } + + try { + $objects = $qb->getQuery()->getResult(); + } catch (NoResultException $e) { + $message = sprintf('Unable to find an objects'); + throw new NotFoundHttpException($message, null, 0, $e); + } + return $objects; + } + */ + + + protected function createMaching($qb, $matching) + { + + if($matching['hierarchical']){ + $qb->andWhere("o.parent is null"); + }else if($matching['leaf']){ + $qb->andWhere("o.children is empty"); + } + + unset($matching['hierarchical']); + unset($matching['leaf']); + $qb = parent::createMaching($qb, $matching); + + return $qb; + } +} -- cgit v1.2.3-18-g5258