1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace WorkflowBundle\Repository;
- use \Doctrine\ORM\EntityRepository;
- class WorkflowRepository extends EntityRepository
- {
- /**
- * Retorna los workflow habilitados (enable=true) y
- * que estén por defecto (usedByDefault=true) según la clase
- * si no encuentra, retorna los habilitados
- *
- * @param string $class
- *
- * @return array
- */
- public function findAllByClass($class)
- {
- $results = $this->createQueryBuilder('Workflow')
- ->where('Workflow.enable = :enable')->setParameter('enable', true)
- ->andWhere('Workflow.usedByDefault = :usedByDefault')
- ->setParameter('usedByDefault', true)
- ->getQuery()->getResult();
-
- foreach ($results as $key => &$result) {
- if (!in_array($class, $result->getSupport())) {
- unset($results[$key]);
- }
- }
-
- // No hay workflow enable y usedByDefault, busco los enable
- if (count($results) == 0) {
- $results = $this->createQueryBuilder('Workflow')
- ->where('Workflow.enable = :enable')->setParameter('enable', true)
- ->getQuery()->getResult();
- }
- foreach ($results as $key => &$result) {
- if (!in_array($class, $result->getSupport())) {
- unset($results[$key]);
- }
- }
-
- return $results;
- }
- /**
- * Retorna los workflow soportados por $class
- *
- * @param string $class
- *
- * @return array
- */
- public function findAllSupportedBy($class, $id = null)
- {
- $qb = $this->createQueryBuilder('Workflow')
- ->select('Workflow.id, Workflow.support');
- if ($id) {
- $qb->andWhere('Workflow.id <> :id')->setParameter('id', $id);
- }
- $results = $qb->getQuery()->getResult();
- foreach ($results as $key => &$result) {
- if (!in_array($class, $result['support'])) {
- unset($results[$key]);
- }
- }
-
- return array_map(function($result) {
- return $result['id'];
- }, $results);
- }
- }
|