'API', self::EXPORT_CDF => 'CDF', self::EXPORT_CSV => 'CSV', self::EXPORT_EXCEL => 'EXCEL', self::EXPORT_HTML => 'HTML', self::EXPORT_MARKETING => 'Marketing', self::EXPORT_XML => 'XML', self::EXPORT_SOCIAL => 'SOCIAL', self::EXPORT_BOOKLET => 'BOOKLET', self::EXPORT_JSON => 'JSON', ]; /** @var EntityManagerInterface */ private $entityManager; /** @var ContainerInterface */ private $container; public function __construct( ContainerInterface $container, EntityManagerInterface $entityManager, ManagerRegistry $registry ) { parent::__construct($registry, Exports::class); $this->entityManager = $entityManager; $this->container = $container; } public function listExportType(): array { return self::EXPORT_TYPE; } /** * @param int $id [description] * * @return array [description] */ public function list(int $id): array { return $this->entityManager ->createQueryBuilder() ->select('e') ->from(Exports::class, 'e') ->where('e.project = :id') ->andWhere('e.deleted = false') ->andWhere('e.archived = false') ->setParameter('id', $id) ->getQuery() ->getResult(); } /** * @return array [description] */ public function listAll(): array { return $this->entityManager ->createQueryBuilder() ->select('e') ->from(Exports::class, 'e') ->andWhere('e.deleted = false') ->andWhere('e.archived = false') ->getQuery() ->getResult(); } /** * @param int $id [description] * * @return array [description] */ public function listExportWorkflow(int $id): array { $qb = $this->entityManager->createQueryBuilder(); return $qb->select('e') ->from(Exports::class, 'e') ->where('e.project = :id') ->andWhere('e.deleted = false') ->andWhere('e.archived = false') ->andWhere($qb->expr()->in('e.exportType', [self::EXPORT_CDF, self::EXPORT_HTML, self::EXPORT_MARKETING, self::EXPORT_BOOKLET])) ->setParameter('id', $id) ->getQuery() ->getResult(); } /** * @param Exports $export [description] * * @return Exports|bool [description] */ public function save(Exports $export) { try { $this->entityManager->persist($export); $this->entityManager->flush(); return $export; } catch (Exception $exception) { return false; } } /** * @param EntityManagerInterface $entityManager [description] * @param Exports $export [description] * * @return EntityManagerInterface|bool [description] */ public function saveWithoutFlush(EntityManagerInterface $entityManager, Exports $export) { try { $entityManager->persist($export); return $entityManager; } catch (Exception $exception) { return false; } } /** * @param Exports $export * * @return bool */ public function delete(Exports $export): bool { $this->entityManager->remove($export); $this->entityManager->flush(); return true; } /** * @param int $id [description] * * @throws NonUniqueResultException * * @return Exports|null [description] */ public function findById(int $id): ?Exports { return $this->entityManager ->createQueryBuilder() ->select('e') ->from(Exports::class, 'e') ->where('e.id = :id') ->setParameter('id', $id) ->getQuery() ->getOneOrNullResult(); } /** * @param int $id [description] * * @return array [description] */ /** * ATTENTION ! Cette requette renvoi tous les produits lié au projet et non pas a l'export !!!! * Requette utilisé dans une route (ListElementAction) a voir si elle est appelée côté front. * La requette en dessous (getElementExportById) elle a le bon comportement. */ public function getElementsById(int $id): array { return $this->entityManager ->createQueryBuilder() ->select('et.elementsPIM') ->from(Exports::class, 'e') ->leftJoin('e.project', 'p') ->leftJoin('p.elementTypes', 'et') ->where('e.id = :id') ->andWhere('et.deletedAt is null') ->setParameter('id', $id) ->getQuery() ->getResult(); } /** * @param int $id [description] * * @return array [description] */ public function getElementsExportById(int $id): array { return $this->entityManager ->createQueryBuilder() ->select('et.elementsPIM') ->from(Exports::class, 'e') ->leftJoin('e.templates', 'et') ->where('e.id = :id') ->andWhere('et.deletedAt is null') ->setParameter('id', $id) ->getQuery() ->getResult(); } /** * @param int $exportId [description] * @param int $projectId [description] * * @throws NonUniqueResultException * * @return Exports|null [description] */ public function findExportByIdProject(int $exportId, int $projectId): ?Exports { $qb = $this->entityManager ->createQueryBuilder() ->select('ex') ->from(Exports::class, 'ex') ->where('ex.id = :exportId') ->andWhere('ex.project = :projectId') ->setParameters([':exportId' => $exportId, ':projectId' => $projectId]); return $qb->getQuery()->getOneOrNullResult(); } /** * @param int $export_id [description] * * @throws NonUniqueResultException * * @return int [description] */ public function nbProduct(int $export_id): int { $elementsPIM = $this->entityManager ->createQueryBuilder() ->select('exT.elementsPIM') ->from(Exports::class, 'ex') ->leftJoin('ex.templates', 'exT') ->where('ex.id = :export_id') ->setParameter('export_id', $export_id) ->getQuery() ->getResult(); $nbElements = 0; if (!empty($elementsPIM)) { foreach ($elementsPIM as $elements) { if ($elements['elementsPIM']) { $nbElements += count($elements['elementsPIM']); } } } return $nbElements; /* $qb = $this->entityManager->createQueryBuilder(); $qb->select('COUNT(exT.elementsPIM)') ->from(Exports::class, 'ex') ->leftJoin('ex.templates', 'exT') ->where('ex.id = :export_id') ->setParameter('export_id', $export_id); $result = (int) $qb->getQuery() ->getSingleScalarResult(); return $result;*/ } /** * @param int $export_id [description] * @param int $workflow_id [description] * * @return bool [description] */ public function setWorkflow(int $export_id, int $workflow_id): bool { try { $connection = $this->container->get('doctrine.dbal.projects_connection'); $sql = ' UPDATE exports SET workflow_id= "' . $workflow_id . '" WHERE id = ' . $export_id; $stmt = $connection->prepare($sql); $stmt->execute(); return true; } catch (Exception $exception) { return false; } } /** * @param int $export_id [description] * @param int $workflow_id [description] * * @return bool [description] */ public function setWorkflowProject(int $export_id, string $workflow_id): bool { try { $connection = $this->container->get('doctrine.dbal.projects_connection'); $sql = ' UPDATE exports SET workflow_projects= ' . $workflow_id . ' WHERE id = ' . $export_id; $stmt = $connection->prepare($sql); $stmt->execute(); return true; } catch (Exception $exception) { return false; } } /** * @param int $export_id [description] * * @throws NonUniqueResultException * * @return array|null [description] */ public function findWorkflowById(int $export_id): ?array { return $this->entityManager ->createQueryBuilder() ->select('wp.workflow, wp.page') ->from(Exports::class, 'ex') ->join('ex.workflowProjects', 'wp') ->where('ex.id = :export_id') ->setParameter('export_id', $export_id) ->getQuery() ->getOneOrNullResult(); } /** * @param int $export_id [description] * * @throws NonUniqueResultException * * @return array|null [description] */ public function findWorkflowProgressionById(int $export_id): ?array { return $this->entityManager ->createQueryBuilder() ->select('wp.workflow, wp.page') ->from(Exports::class, 'ex') ->join('ex.workflowProjects', 'wp') ->where('ex.id = :export_id') ->setParameter('export_id', $export_id) ->getQuery() ->getOneOrNullResult(); } /** * @param string $exportIds [description] * * @throws DBALException * * @return bool [description] */ public function deleteMultipleExport(string $exportIds): bool { $connection = $this->container->get('doctrine.dbal.projects_connection'); $sql = ' DELETE FROM exports WHERE id IN (' . $exportIds . ')'; $stmt = $connection->prepare($sql); $stmt->execute(); return $stmt->rowCount() > 0; } /** * @param string $workflowProject_ids [description] * * @return bool [description] */ public function detachWorkflow(string $workflowProject_ids): bool { try { $connection = $this->container->get('doctrine.dbal.projects_connection'); $sql = ' UPDATE export SET export_workflow= NULL WHERE export_workflow IN (' . $workflowProject_ids . ')'; $stmt = $connection->prepare($sql); $stmt->execute(); return true; } catch (Exception $exception) { return false; } } /** * @return array [description] */ public function listIds(): array { $qb = $this->entityManager->createQueryBuilder(); $qb->select('e.id as id') ->from(Exports::class, 'e'); $result = $qb->getQuery() ->getResult(); return $result; } /** * @param int $projectId * * @return array */ public function listIdsByProjectId(int $projectId): array { return $this->entityManager ->createQueryBuilder() ->select('e.id') ->from(Exports::class, 'e') ->where('e.project = :id') ->andWhere('e.deleted = false') ->andWhere('e.archived = false') ->setParameter('id', $projectId) ->getQuery() ->getArrayResult(); } /** * @param int $exportId * * @return int */ public function getIdProjectFromIdExport(int $exportId): int { return $this->entityManager ->createQueryBuilder() ->select('p.id') ->from(Exports::class, 'e') ->leftJoin('e.project', 'p') ->where('e.id = :id') ->andWhere('e.deleted = false') ->andWhere('e.archived = false') ->setParameter('id', $exportId) ->getQuery() ->getOneOrNullResult()['id']; } }