entityManager = $_container->get('doctrine.orm.entity_manager'); $this->templating = $_container->get('twig'); $this->repository = $this->entityManager->getRepository(AGridRow::class); $this->agridCacheService = $_container->get('agrid.cache_service'); $this->container = $_container; } public function create(?AGridContent $parent, ?AGridCol $parentCol){ $row = new AGridRow($parent, $parentCol); if($parent instanceof AGridPage) $row->setOrdered(count($parent->getRows())); else if($parentCol instanceof AGridCol) $row->setOrdered(count($parentCol->getRows())); if(!$this->update($row)) return null; return $row; } public function update(AGridRow $element) { $this->agridCacheService->invalidate($element->getParentContainer()); return $this->quickUpdate($element); } public function quickUpdate(AGridRow $element) { 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; } public function getById(int $id) { return $this->repository->findOneBy(['id'=>$id]); } public function getByCol(AGridCol $col){ return $this->repository->findOneByCol($col); } public function changeOrder(int $row_id, int $order): bool { $row = $this->getById($row_id); if($row instanceof AGridRow){ $row->setOrdered($order); $this->update($row); return true; } return false; } public function delete(AGridRow $row){ try { $container = $row->getParentContainer(); foreach ($row->getCols() as $col){ $this->container->get('agrid.col_manager')->delete($col); } $this->entityManager->remove($row); $this->entityManager->flush(); } catch (OptimisticLockException $e) { return false; } catch (ORMException $e) { return false; } $this->agridCacheService->invalidate($container); return true; } }