entityManager = $entityManager; $this->container = $container; } public function create(Transition $transition): Transition { $this->entityManager->persist($transition); $this->entityManager->flush(); return $transition; } /** * @return mixed */ public function findByModule(string $module) { return $this->entityManager ->createQueryBuilder() ->select('t') ->from(Transition::class, 't') ->join('t.configuration', 'c') ->where('c.module = :query') ->setParameter('query', $module) ->getQuery() ->getResult() ; } public function remove(Transition $transition): bool { $this->entityManager->remove($transition); $this->entityManager->flush(); return true; } /** * @return mixed */ public function findByConfigId(int $configId) { return $this->entityManager ->createQueryBuilder() ->select('t') ->from(Transition::class, 't') ->where('t.configuration = :configId') ->setParameter('configId', $configId) ->getQuery() ->getResult(); } /** * @throws NonUniqueResultException * * @return mixed */ public function findByKey(string $key) { return $this->entityManager ->createQueryBuilder() ->select('t') ->from(Transition::class, 't') ->where('t.key = :key') ->setParameter('key', $key) ->getQuery() ->getOneOrNullResult(); } public function findByStartPlaceKey(string $key) { return $this->entityManager ->createQueryBuilder() ->select('t') ->from(Transition::class, 't') ->innerJoin('t.startPlace', 'p') ->addSelect('p') ->where('p.key = :key') ->setParameter('key', $key) ->getQuery() ->getResult(); } public function findUsersByEndPlaceKey(string $key) { return $this->entityManager ->createQueryBuilder() ->select('t') ->from(Transition::class, 't') ->innerJoin('t.endPlace', 'p') ->addSelect('p') ->where('p.key = :key') ->setParameter('key', $key) ->getQuery() ->getResult(); } public function findLastTransition(string $module, int $idConfig) { try { $connection = $this->container->get('doctrine.dbal.' . $module . '_connection'); $sql = ' SELECT t.id, keyInternal FROM workflow_transitions as t INNER JOIN workflow_configuration as c on c.id = t.configuration_id WHERE t.name NOT LIKE "%_Reject" AND c.id = "' . $idConfig . '" ORDER BY t.id DESC LIMIT 1'; $stmt = $connection->prepare($sql); $stmt->execute(); return $stmt->fetch(); } catch (Exception $exception) { return false; } } public function findFirstTransition(int $idConfig, string $module) { try { $connection = $this->container->get('doctrine.dbal.' . $module . '_connection'); $sql = ' SELECT t.keyInternal FROM workflow_transitions as t INNER JOIN workflow_configuration as c on c.id = t.configuration_id WHERE endPlace_id = startPlace_id AND c.id = "' . $idConfig . '" AND t.name NOT LIKE "%_Reject"'; $stmt = $connection->prepare($sql); $stmt->execute(); return $stmt->fetch(); } catch (Exception $exception) { return false; } } public function findSecondTransition(string $module) { try { $connection = $this->container->get('doctrine.dbal.' . $module . '_connection'); $sql = ' SELECT keyInternal FROM workflow_transitions WHERE startPlace_id = (SELECT startPlace_id FROM workflow_transitions WHERE endPlace_id = startPlace_id AND name NOT LIKE "%_Reject") AND endPlace_id != startPlace_id AND name NOT LIKE "%_Reject"'; $stmt = $connection->prepare($sql); $stmt->execute(); return $stmt->fetch(); } catch (Exception $exception) { return false; } } public function findRejectByPlace(int $place_id, string $module) { $qb = $this->entityManager->createQueryBuilder(); return $qb->select('t') ->from(Transition::class, 't') ->innerJoin('t.startPlace', 'p') ->where($qb->expr()->in('p.id', $place_id)) ->andWhere("t.name LIKE :reject") ->setParameter("reject", "%_Reject%") ->getQuery() ->getOneOrNullResult(); } }