src/Entity/JobConfiguration/JobSubCategory.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\JobConfiguration;
  3. use App\Entity\EntityIdentifier;
  4. use App\Entity\User;
  5. use App\Repository\JobConfiguration\JobSubCategoryRepository;
  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=JobSubCategoryRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class JobSubCategory
  15. {
  16.     use ORMBehaviors\Translatable\Translatable;
  17.     
  18.     use EntityIdentifier;
  19.     
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.     
  27.     /**
  28.      * @ORM\OneToMany(targetEntity=JobSubCategoryTranslation::class, mappedBy="translatable", cascade={"persist"})
  29.      */
  30.     protected $newTranslations;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity=JobCategory::class, inversedBy="jobSubCategories")
  33.      */
  34.     private $jobCategory;
  35.     /**
  36.      * @var Job[] $jobs
  37.      * @ORM\OneToMany(targetEntity=Job::class, mappedBy="jobSubCategory")
  38.      */
  39.     private $jobs;
  40.     /**
  41.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="studentFormations")
  42.      */
  43.     private $students;
  44.     public function __construct()
  45.     {
  46.         $this->jobs = new ArrayCollection();
  47.         $this->students = new ArrayCollection();
  48.     }
  49.     
  50.     /**
  51.      * @ORM\PostLoad()
  52.      */
  53.     public function init() {
  54.                                       $this->mergeNewTranslations();
  55.                                       $this->currentLocale = \Locale::getDefault();
  56.                                   }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getJobCategory(): ?JobCategory
  62.     {
  63.         return $this->jobCategory;
  64.     }
  65.     public function setJobCategory(?JobCategory $jobCategory): self
  66.     {
  67.         $this->jobCategory $jobCategory;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return Collection<int, Job>
  72.      */
  73.     public function getJobs(): Collection
  74.     {
  75.         return $this->jobs;
  76.     }
  77.     public function addJob(Job $job): self
  78.     {
  79.         if (!$this->jobs->contains($job)) {
  80.             $this->jobs[] = $job;
  81.             $job->setJobSubCategory($this);
  82.         }
  83.         return $this;
  84.     }
  85.     public function removeJob(Job $job): self
  86.     {
  87.         if ($this->jobs->removeElement($job)) {
  88.             // set the owning side to null (unless already changed)
  89.             if ($job->getJobSubCategory() === $this) {
  90.                 $job->setJobSubCategory(null);
  91.             }
  92.         }
  93.         return $this;
  94.     }
  95.     
  96.     public function __call($name$arguments) {
  97.                                       $reflect = new \ReflectionClassJobSubCategoryTranslation::class);
  98.                                       $privateProperties $reflect->getProperties(\ReflectionProperty::IS_PRIVATE);
  99.                                       
  100.                                       foreach ($privateProperties as $property) {
  101.                                           if($property->getName() == $name) {
  102.                                               return $this->translate()->{"get" ucfirst($name)}();
  103.                                           }
  104.                                       }
  105.                                       
  106.                                       return "";
  107.                                   }
  108.     /**
  109.      * @return Collection<int, User>
  110.      */
  111.     public function getStudents(): Collection
  112.     {
  113.         return $this->students;
  114.     }
  115.     public function addStudent(User $student): self
  116.     {
  117.         if (!$this->students->contains($student)) {
  118.             $this->students[] = $student;
  119.             $student->addUserFormation($this);
  120.         }
  121.         return $this;
  122.     }
  123.     public function removeStudent(User $student): self
  124.     {
  125.         if ($this->students->removeElement($student)) {
  126.             $student->removeUserFormation($this);
  127.         }
  128.         return $this;
  129.     }
  130. }