entityManager = $entityManager; } /** * @param $id * * @throws NonUniqueResultException * * @return mixed */ public function read(int $id) { $result = $this->entityManager ->createQueryBuilder() ->select('c') ->from(Cdf::class, 'c') ->where('c.id = :id') ->setParameters(['id' => $id]) ->getQuery() ->getOneOrNullResult(); return $result; } public function getCdfByIdExport(int $id) { return $this->entityManager ->createQueryBuilder() ->select('c') ->from(Cdf::class, 'c') ->innerJoin('c.export','e') ->where('e.id = :id') ->setParameters(['id' => $id]) ->getQuery() ->getOneOrNullResult(); } public function save(Cdf $cdf) { try { $this->entityManager->persist($cdf); $this->entityManager->flush(); $result = $cdf; } catch (Exception $e) { $result = $e; } return $result; } public function readNbPage(int $export_id) { return $this->entityManager ->createQueryBuilder() ->select('SUM(po.nbPages)') ->from(Cdf::class, 'cdf') ->innerJoin('cdf.cdfPage', 'p') ->innerJoin('p.option', 'po') ->innerJoin('cdf.export', 'e') ->where('e.id = :export_id') ->andWhere('po.deletedAt is null') ->andWhere('p.deletedAt is null') ->setParameter('export_id', $export_id) ->getQuery() ->getSingleScalarResult(); } public function readNbPageMax(int $export_id): ?array { return $this->entityManager ->createQueryBuilder() ->select('cdf.nbPage as max') ->from(Cdf::class, 'cdf') ->innerJoin('cdf.export', 'e') ->where('e.id = :export_id') ->setParameter('export_id', $export_id) ->groupBy('cdf') ->getQuery() ->getOneOrNullResult(); } /** * @param array $exportIds * * @return array */ public function getCdfByExportIds(array $exportIds): array { $qb = $this->entityManager ->createQueryBuilder(); $qb->select('c') ->from(Cdf::class, 'c') ->where($qb->expr()->in('c.idExport', $exportIds)) ->andWhere('c.deletedAt is null'); $result = $qb->getQuery() ->getResult(); return $result; } /** * @param array $flatplans * @param bool $andFlush * * @return bool */ public function deleteMultiple(array $flatplans, bool $andFlush = true): bool { foreach ($flatplans as $flatplan) { $this->entityManager->remove($flatplan); } if ($andFlush) { $this->entityManager->flush(); } return true; } }