container = $_container; $this->entityManager = $_container->get('doctrine.orm.entity_manager'); $this->repository = $this->entityManager->getRepository(AGridNewsFeed::class); } /** * @param AGridNewsFeed $element * @return AGridNewsFeed|null */ public function update(AGridNewsFeed $element) { return $this->quickUpdate($element); } /** * @param AGridNewsFeed $element * @return AGridNewsFeed|null */ public function quickUpdate(AGridNewsFeed $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 AGridNewsFeed $element * @return boolean */ public function delete(AGridNewsFeed $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 getOneById(int $id){ return $this->repository->findOneBy(['id'=>$id]); } public function create(string $feed_name){ $feed = new AGridNewsFeed(); $feed->setDefault($feed_name); if (!$this->quickUpdate($feed)) return null; return $feed; } }