src/Entity/Configuration/School/Formation/Formation.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Configuration\School\Formation;
  3. use App\Entity\EntityIdentifier;
  4. use App\Entity\JobConfiguration\Job;
  5. use App\Entity\User;
  6. use App\Repository\Configuration\School\Formation\FormationRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Knp\DoctrineBehaviors\Model as ORMBehaviors;
  11. /**
  12.  * @ORM\Entity(repositoryClass=FormationRepository::class)
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class Formation
  16. {
  17.     
  18.     use ORMBehaviors\Translatable\Translatable;
  19.     
  20.     use EntityIdentifier;
  21.     
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private $id;
  28.     
  29.     /**
  30.      * @ORM\OneToMany(targetEntity=FormationTranslation::class, mappedBy="translatable", cascade={"persist"})
  31.      */
  32.     protected $newTranslations;
  33.     
  34.     protected $translations;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private $link;
  39.     /**
  40.      * @ORM\ManyToMany(targetEntity=Job::class, mappedBy="formations")
  41.      */
  42.     private $jobs;
  43.     /**
  44.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="formations")
  45.      */
  46.     private $users;
  47.     public function __construct()
  48.     {
  49.         $this->jobs = new ArrayCollection();
  50.         $this->users = new ArrayCollection();
  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 \ReflectionClassFormationTranslation::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 getId(): ?int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getLink(): ?string
  78.     {
  79.         return $this->link;
  80.     }
  81.     public function setLink(?string $link): self
  82.     {
  83.         $this->link $link;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, Job>
  88.      */
  89.     public function getJobs(): Collection
  90.     {
  91.         return $this->jobs;
  92.     }
  93.     public function addJob(Job $job): self
  94.     {
  95.         if (!$this->jobs->contains($job)) {
  96.             $this->jobs[] = $job;
  97.             $job->addFormation($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeJob(Job $job): self
  102.     {
  103.         if ($this->jobs->removeElement($job)) {
  104.             $job->removeFormation($this);
  105.         }
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return Collection<int, User>
  110.      */
  111.     public function getUsers(): Collection
  112.     {
  113.         return $this->users;
  114.     }
  115.     public function addUser(User $user): self
  116.     {
  117.         if (!$this->users->contains($user)) {
  118.             $this->users[] = $user;
  119.             $user->addFormation($this);
  120.         }
  121.         return $this;
  122.     }
  123.     public function removeUser(User $user): self
  124.     {
  125.         if ($this->users->removeElement($user)) {
  126.             $user->removeFormation($this);
  127.         }
  128.         return $this;
  129.     }
  130. }