entityManager = $entityManager; } /** * @return array [description] */ public function list(): array { return $this->entityManager ->createQueryBuilder() ->select('t') ->from(Template::class, 't') ->where('t.deletedAt IS NULL') ->orderBy('t.createdAt', 'DESC') ->getQuery() ->getResult(); } /** * @param int $id [description] * * @return Template|null [description] */ public function findById(int $id): ?Template { return $this->entityManager ->createQueryBuilder() ->select('t') ->from(Template::class, 't') ->where('t.id = :id') ->setParameter('id', $id) ->getQuery() ->getOneOrNullResult(); } /** * @param Template $template * * @return Template */ public function save(Template $template): Template { $this->entityManager->persist($template); $this->entityManager->flush(); return $template; } /** * @param Template $template * * @return void */ public function delete(Template $template): void { $this->entityManager->remove($template); $this->entityManager->flush(); } /** * @param int $id [description] * * @return array [description] */ public function listByTwigsExport(int $id): array { return $this->entityManager ->createQueryBuilder() ->select('t') ->from(Template::class, 't') ->innerJoin('t.twig', 'twig') ->where('twig.deletedAt IS NULL') ->andWhere('twig.exportType = :idExport') ->andWhere('t.deletedAt IS NULL') ->setParameter('idExport', $id) ->getQuery() ->getResult(); } /** * @param array $ids [description] * * @return mixed [description] */ public function listByExportsIds(array $ids): array { $qb = $this->entityManager ->createQueryBuilder(); return $qb->select('t') ->from(Template::class, 't') ->innerJoin('t.twig', 'twig') ->where('twig.deletedAt IS NULL') ->andWhere($qb->expr()->in('twig.exportType', $ids)) ->andWhere('t.deletedAt IS NULL') ->getQuery() ->getResult(); } /** * @param array $templates * * @return array */ public function nameCdf(array $templates): array { $qb = $this->entityManager->createQueryBuilder(); $qb->select('t') ->from(Template::class, 't') ->where($qb->expr()->in('t.id', $templates)); return $qb->getQuery() ->getResult(); } /** * @param string $templateIds [description] * * @return array [description] */ public function findByIds(string $templateIds): array { $qb = $this->entityManager ->createQueryBuilder(); return $qb->select('t') ->from(Template::class, 't') ->where($qb->expr()->in('t.id', $templateIds)) ->andWhere('t.deletedAt IS NULL') ->getQuery() ->getResult(); } /** * @param string $templateName [description] * * @return Template|null [description] */ public function findByName(string $templateName): ?Template { return $this->entityManager->createQueryBuilder() ->select('t') ->from(Template::class, 't') ->where('t.name = :templateName') ->setParameter('templateName', $templateName) ->getQuery() ->getOneOrNullResult(); } /** * @param string $templateName [description] * @param int $templateId [description] * * @return Template|null [description] */ public function findDuplicateByName(string $templateName, int $templateId): ?Template { return $this->entityManager->createQueryBuilder() ->select('t') ->from(Template::class, 't') ->where('t.name = :templateName') ->andWhere('t.id != :templateId') ->setParameters(['templateName' => $templateName, 'templateId' => $templateId]) ->getQuery() ->getOneOrNullResult(); } /** * {@inheritDoc} */ public function findGenerationData(int $templateId, string $fileTypeName = null, string $fileTypeExtension = null): ?array { $qb = $this->entityManager ->createQueryBuilder() ->select('t.name AS templateName', 't.fontPath', 'tw.content AS twigContent', 't.nbElement AS elementNumber'); if ($fileTypeName && $fileTypeExtension) { $qb->addSelect('df.originalName AS fileOriginalName'); } $qb->from(Template::class, 't'); if ($fileTypeName && $fileTypeExtension) { $qb->join('t.dedicatedFiles', 'df') ->join('df.fileType', 'ft'); } $qb->join('t.twig', 'tw') ->where('t.id = :id'); if ($fileTypeName && $fileTypeExtension) { $qb->andWhere('df.deletedAt IS NULL') ->andWhere('df.archivedAt IS NULL') ->andWhere('ft.name = :fileTypeName') ->andWhere('ft.extension = :fileTypeExtension') ->andWhere('ft.deletedAt IS NULL') ->setParameters(['id' => $templateId, 'fileTypeName' => $fileTypeName, 'fileTypeExtension' => $fileTypeExtension]); } $qb->setParameter('id', $templateId); return $qb->getQuery() ->getOneOrNullResult(); } /** * @param array $ids * @param int $nbPage * @param int $nbProduct * * @return array */ public function findByIdsAndNumberPageProduct(array $ids, int $nbPage, int $nbProduct): array { $qb = $this->entityManager ->createQueryBuilder(); $qb->select('t') ->from(Template::class, 't') ->where($qb->expr()->in('t.id', $ids)) ->andWhere('t.deletedAt IS NULL') ->andWhere('t.nbPage = :nbPage') ->andWhere('t.nbElement = :nbProduct') ->setParameters(['nbPage' => $nbPage, 'nbProduct' => $nbProduct]); return $qb->getQuery()->getResult(); } /** * @param Template $template [description] * * @return string|array [description] */ public function diff(Template $template) { $uow = $this->entityManager->getUnitOfWork(); $uow->computeChangeSets(); $result = $uow->getEntityChangeSet($template); return $result; } /** * @param int $templateId [description] * * @return array [description] */ public function getProjectNameByTemplate(int $templateId) { $qb = $this->entityManager ->createQueryBuilder(); return $qb->select('DISTINCT p.name') ->from(Template::class, 't') ->innerJoin("t.pageOptions", 'po') ->innerJoin("po.pages","pg") ->innerJoin("pg.cdf","cdf") ->innerjoin("cdf.export",'e') ->innerJoin("e.project", "p") ->where("t.id = :templateId") ->setParameter("templateId", $templateId) ->getQuery()->getResult(); } public function findTemplateByVariableProjectUse(array $variables) { $qb = $this->entityManager->createQueryBuilder(); return $qb->select('t') ->from(Template::class,'t') ->innerJoin('t.twig', 'tw') ->innerJoin('tw.variables','v') ->innerJoin('v.variableProject','vp') ->where($qb->expr()->in('vp.id', $variables)) ->andWhere('t.deletedAt is null') ->getQuery()->getResult(); } }