src/Entity/Customer.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CustomerRepository;
  4. use App\Service\RoleService;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=CustomerRepository::class)
  10.  * @method self setStatus(bool $status)
  11.  */
  12. class Customer extends User
  13. {
  14.     /**
  15.      * @ORM\OneToMany(targetEntity=Praying::class, mappedBy="customer")
  16.      */
  17.     private $prayings;
  18.     public function __construct()
  19.     {
  20.         parent::__construct();
  21.         $this->setRoles([RoleService::ROLE_CUSTOMER]);
  22.         $this->prayings = new ArrayCollection();
  23.     }
  24.     public function __toString(): string
  25.     {
  26.         return $this->getFullName();
  27.     }
  28.     /**
  29.      * @return Collection<int, Praying>
  30.      */
  31.     public function getPrayings(): Collection
  32.     {
  33.         return $this->prayings;
  34.     }
  35.     public function addPraying(Praying $praying): self
  36.     {
  37.         if (!$this->prayings->contains($praying)) {
  38.             $this->prayings[] = $praying;
  39.             $praying->setCustomer($this);
  40.         }
  41.         return $this;
  42.     }
  43.     public function removePraying(Praying $praying): self
  44.     {
  45.         if ($this->prayings->removeElement($praying)) {
  46.             // set the owning side to null (unless already changed)
  47.             if ($praying->getCustomer() === $this) {
  48.                 $praying->setCustomer(null);
  49.             }
  50.         }
  51.         return $this;
  52.     }
  53.     /**
  54.      * @return Collection<int, Prayer|null>
  55.      */
  56.     public function getParticipatedPrayers(): Collection
  57.     {
  58.         return $this->getPrayings()->map(function (Praying $praying) {
  59.             return $praying->getPrayer();
  60.         });
  61.     }
  62. }