em = $em; $this->paymentModeRepository = $this->em->getRepository(PaymentMode::class); } /** * @param PaymentMode $element * @return PaymentMode|null */ public function quickUpdate(PaymentMode $element) { if (!$this->em->contains($element)) { try { $this->em->persist($element); } catch (ORMException $e) { return null; } } try { $this->em->flush(); } catch (OptimisticLockException $e) { return null; } catch (ORMException $e) { return null; } return $element; } /** * @param $publicKey * @return PaymentMode|object|null */ public function getByPublicKey(string $publicKey){ return $this->paymentModeRepository->findOneBy(['publicKey'=>$publicKey]); } public function getAll(){ return $this->paymentModeRepository->findBy(['deleted'=>false]); } /** * @param $_name * @return object|PaymentMode|null */ public function getPaymentByName($_name){ return $this->paymentModeRepository->findOneBy(['name'=>$_name]); } /** * @param array $dataElement * @return PaymentMode */ public function create(array $dataElement){ $paymentMode = new PaymentMode(); $paymentMode->hydrate($dataElement); if (!$this->quickUpdate($paymentMode)) return null; return $paymentMode; } /** * @param PaymentMode $element * @param array $dataElement * @return PaymentMode|null */ public function update(PaymentMode $element, array $dataElement) { $element->hydrate($dataElement); return $this->quickUpdate($element); } /** * @param string $publicKey * @return boolean */ public function delete(string $publicKey) { $element = $this->getByPublicKey($publicKey); $element->setDeleted(true); if (!$this->quickUpdate($element)) return null; return true; } }