entityManager = $entityManager; } /** * @param string $id * * @throws NonUniqueResultException * * @return int|string|null */ public function read(string $id) { $result = $this->entityManager ->createQueryBuilder() ->select('p') ->from(PageOptions::class, 'p') ->where('p.id = :id') ->andWhere('p.deletedAt is null') ->setParameter('id', $id) ->getQuery() ->getOneOrNullResult(); return $result; } /** * @param PageOptions $pageOptions * * @return PageOptions|Exception */ public function save(PageOptions $pageOptions) { try { $this->entityManager->persist($pageOptions); $this->entityManager->flush(); return $pageOptions; } catch (Exception $e) { return $e; } } /** * @param int $id * * @throws NonUniqueResultException * * @return int|string|null */ public function findByPageId(int $id) { return $this->entityManager ->createQueryBuilder() ->select('po', 'p') ->from(PageOptions::class, 'po') ->innerJoin('po.pages', 'p') ->innerJoin('p.cdf', 'c') ->where('p.id = :id') ->andWhere('po.deletedAt is null') ->setParameter('id', $id) ->getQuery() ->getOneOrNullResult(); } /** * @param int $templateId * * @return array */ public function findByTemplate(int $templateId): array { return $this->entityManager ->createQueryBuilder() ->select('po') ->from(PageOptions::class, 'po') ->where('po.template = :templateId') ->andWhere('po.deletedAt is null') ->setParameter('templateId', $templateId) ->getQuery() ->getResult(); } /** * @param PageOptions $pageOptions * * @return array */ public function diff(PageOptions $pageOptions): array { $uow = $this->entityManager->getUnitOfWork(); $uow->computeChangeSets(); return $uow->getEntityChangeSet($pageOptions); } /** * @param PageOptions $option * * @return bool|Exception */ public function delete(PageOptions $option) { try { $this->entityManager->remove($option); $this->entityManager->flush(); return true; } catch (Exception $e) { return $e; } } /** * @param string $id * * @return PageOptions|null */ public function findById(string $id): ?PageOptions { $qb = $this->entityManager->createQueryBuilder(); $qb->select('po') ->from(PageOptions::class, 'po') ->where('po.id = :id') ->andWhere('po.deletedAt is null') ->setParameter('id', $id); $result = $qb->getQuery() ->getOneOrNullResult(); return $result; } /** * @return array */ public function findCoverByExport(string $export_id) { $qb = $this->entityManager ->createQueryBuilder(); return $qb->select('o') ->from(PageOptions::class, 'o') ->innerJoin('o.pages', 'p') ->innerJoin('p.cdf', 'cdf') ->innerJoin('cdf.export', 'e') ->where("e.id = :exportId") ->andWhere('o.deletedAt is null') ->andWhere('p.deletedAt is null') ->andWhere('o.cover = true') ->setParameter("exportId", $export_id) ->getQuery() ->getResult(); } /** * {@inheritDoc} */ public function findByObjectIds(string $object, array $ids): array { $qb = $this->entityManager ->createQueryBuilder(); $qb->select('po') ->from(PageOptions::class, 'po') ->innerJoin('po.pages', 'pa') ->innerJoin('pa.cdf', 'cdf'); if ("export" === $object) { $qb->innerJoin('cdf.export', 'ex') ->where($qb->expr()->in('ex.id', $ids)) ->andWhere('ex.deleted = 0'); } else if ("project" === $object) { $qb->innerJoin('cdf.export', 'ex') ->innerJoin('ex.project', 'pr') ->where($qb->expr()->in('pr.id', $ids)) ->andWhere('pr.deleted = 0'); } else { $qb->where($qb->expr()->in('po.id', $ids)); } return $qb->andWhere('po.deletedAt is null') ->andWhere('pa.deletedAt is null') ->getQuery() ->getResult(); } }