container = $_container; $this->entityManager = $_container->get('doctrine.orm.entity_manager'); $this->templating = $_container->get('twig'); $this->repository = $this->entityManager->getRepository(AGridContent::class); $this->agridCacheService = $_container->get('agrid.cache_service'); } public function getAllContent(){ return $this->repository->findAll(); } /** * @param AGridContent $element * @return bool */ public function update(AGridContent $element): bool { $this->agridCacheService->invalidate($element); return $this->quickUpdate($element); } /** * @param AGridContent $element * @return bool */ public function quickUpdate(AGridContent $element): bool { try { if (!$this->entityManager->contains($element)) { if ($element) $this->entityManager->persist($element); else return false; } $this->entityManager->flush(); } catch (OptimisticLockException $e) { return false; } catch (ORMException $e) { return false; } return true; } /** * @param int $id * @return AGridContent|object|null */ public function getById(int $id) { return $this->repository->findOneBy(['id'=>$id]); } /** * @return AGridContent|null */ public function createContent(): ?AGridContent { $content = new AGridContent(); if (!$this->update($content)) return null; return $content; } /** * @param AGridContent|null $_content * @param AGridCol|null $_parentCol * @return AGridRow|null */ public function addRow(?AGridContent $_content, ?AGridCol $_parentCol): ?AGridRow { $row = $this->container->get('agrid.row_manager')->create($_content, $_parentCol); if(!$row instanceof AGridRow) return null; if($_parentCol === null && $_content instanceof AGridContent){ $_content->addRow($row); $this->update($_content); }else{ $_parentCol->addRow($row); $this->container->get('agrid.col_manager')->update($_parentCol); } // $this->makeCache($_content); return $row; } /** * @param AGridContent $_content * @param AGridRow $_row * @return AGridContentColModule|null */ public function addCol(AGridContent $_content, AGridRow $_row): ?AGridContentColModule { $col = $this->container->get('agrid.col_manager')->create($_row); if(!$col instanceof AGridCol) return null; $pageColModule = $this->container->get('agrid.content_col_module.manager')->create($_content, $col); if (!$pageColModule instanceof AGridContentColModule) return null; $_row->addCol($col); $this->container->get('agrid.row_manager')->update($_row); // $this->makeCache($_content); return $pageColModule; } }