entityManager = $entityManager; $this->container = $container; } /** * @return array [description] */ public function list(): array { return $this->entityManager ->createQueryBuilder() ->select('sp') ->from(SocialPost::class, 'sp') ->innerJoin('sp.export','e') ->getQuery() ->getResult() ; } /** * @param int $exportId * * @return array [description] */ public function findByExportId(int $exportId): array { return $this->entityManager ->createQueryBuilder() ->select('sp') ->from(SocialPost::class, 'sp') ->innerJoin('sp.export','e') ->where('e.id = :exportId') ->andWhere('sp.deletedAt is null') ->setParameter('exportId', $exportId) ->getQuery() ->getResult() ; } /** * @param int $postId * * @return array [description] */ public function findById(int $postId): ?SocialPost { return $this->entityManager ->createQueryBuilder() ->select('sp') ->from(SocialPost::class, 'sp') ->where('sp.id = :postId') ->setParameter('postId', $postId) ->getQuery() ->getOneOrNullResult() ; } /** * @param SocialPost $post * * @return array [description] */ public function save(SocialPost $post): ?SocialPost { try { $this->entityManager->persist($post); $this->entityManager->flush(); return $post; } catch (Exception $e) { return null; } } /** * @param SocialPost $post * * @return array [description] */ public function delete(SocialPost $post): bool { try { $this->entityManager->remove($post); $this->entityManager->flush(); return true; } catch (Exception $e) { return false; } } }