src/Entity/Profil/ProfilPositiveDescription.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Profil;
  3. use App\Entity\EntityIdentifier;
  4. use App\Entity\User;
  5. use App\Repository\Profil\ProfilPositiveDescriptionRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Knp\DoctrineBehaviors\Model as ORMBehaviors;
  10. /**
  11.  * @ORM\Entity(repositoryClass=ProfilPositiveDescriptionRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class ProfilPositiveDescription
  15. {
  16.     
  17.     use ORMBehaviors\Translatable\Translatable;
  18.     
  19.     use EntityIdentifier;
  20.     
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     
  28.     /**
  29.      * @ORM\OneToMany(targetEntity=ProfilPositiveDescriptionTranslation::class, mappedBy="translatable", cascade={"persist"})
  30.      */
  31.     protected $newTranslations;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=Profil::class, inversedBy="profilPositiveDescriptions")
  34.      */
  35.     private $profil;
  36.     /**
  37.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="positiveDescriptionChoices")
  38.      */
  39.     private $users;
  40.     /**
  41.      * @ORM\Column(type="integer", nullable=true)
  42.      */
  43.     private $position;
  44.     public function __construct()
  45.     {
  46.         $this->users = new ArrayCollection();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     
  53.     /**
  54.      * @ORM\PostLoad()
  55.      */
  56.     public function init() {
  57.                                                      $this->mergeNewTranslations();
  58.                                                      $this->currentLocale = \Locale::getDefault();
  59.                                                  }
  60.     
  61.     public function __call($name$arguments) {
  62.                                                      $reflect = new \ReflectionClass(ProfilPositiveDescriptionTranslation::class);
  63.                                                      $privateProperties $reflect->getProperties(\ReflectionProperty::IS_PRIVATE);
  64.                                                      
  65.                                                      foreach ($privateProperties as $property) {
  66.                                                          if($property->getName() == $name) {
  67.                                                              return $this->translate()->{"get" ucfirst($name)}();
  68.                                                          }
  69.                                                      }
  70.                                                      
  71.                                                      return "";
  72.                                                  }
  73.     public function getProfil(): ?Profil
  74.     {
  75.         return $this->profil;
  76.     }
  77.     public function setProfil(?Profil $profil): self
  78.     {
  79.         $this->profil $profil;
  80.         return $this;
  81.     }
  82.     /**
  83.      * @return Collection<int, User>
  84.      */
  85.     public function getUsers(): Collection
  86.     {
  87.         return $this->users;
  88.     }
  89.     public function addUser(User $user): self
  90.     {
  91.         if (!$this->users->contains($user)) {
  92.             $this->users[] = $user;
  93.             $user->addPositiveDescriptionChoice($this);
  94.         }
  95.         return $this;
  96.     }
  97.     public function removeUser(User $user): self
  98.     {
  99.         if ($this->users->removeElement($user)) {
  100.             $user->removePositiveDescriptionChoice($this);
  101.         }
  102.         return $this;
  103.     }
  104.     public function getPosition(): ?int
  105.     {
  106.         return $this->position;
  107.     }
  108.     public function setPosition(?int $position): self
  109.     {
  110.         $this->position $position;
  111.         return $this;
  112.     }
  113. }