container = $_container; $this->entityManager = $_container->get('doctrine.orm.entity_manager'); //TODO a charger depuis les parameters du projet $this->langs = ['fr','en','es']; $this->resolutions = ['s','m','l','xl']; $this->repository = $this->entityManager->getRepository(AGridNews::class); } /** * @param AGridNews $element * @return AGridNews|null */ public function update(AGridNews $element) { return $this->quickUpdate($element); } /** * @param AGridNews $element * @return AGridNews|null */ public function quickUpdate(AGridNews $element) { if (!$this->entityManager->contains($element)) { try { $this->entityManager->persist($element); } catch (ORMException $e) { return null; } } try { $this->entityManager->flush(); } catch (OptimisticLockException $e) { return null; } catch (ORMException $e) { return null; } return $element; } /** * @param AGridNews $element * @return boolean */ public function delete(AGridNews $element) { try { $this->entityManager->remove($element); } catch (ORMException $e) { return false; } try { $this->entityManager->flush(); } catch (OptimisticLockException $e) { return false; } catch (ORMException $e) { return false; } return true; } public function getAll(){ return $this->repository->findAll(); } public function create_news(){ $news = new AGridNews(); $content = $this->container->get('agrid.content_manager')->createContent(); if (!$content instanceof AGridContent) return null; $news->setContent($content); if(!$this->update($news)) return null; return $news; } }