src/Entity/JobConfiguration/Job/JobAssignment.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\JobConfiguration\Job;
  3. use App\Entity\EntityIdentifier;
  4. use App\Entity\JobConfiguration\Job;
  5. use App\Repository\JobConfiguration\Job\JobAssignmentRepository;
  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=JobAssignmentRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class JobAssignment
  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=JobAssignmentTranslation::class, mappedBy="translatable", cascade={"persist"})
  30.      */
  31.     protected $newTranslations;
  32.     
  33.     protected $translations;
  34.     /**
  35.      * @ORM\ManyToMany(targetEntity=Job::class, mappedBy="jobAssignments")
  36.      */
  37.     private $jobs;
  38.     public function __construct()
  39.     {
  40.         $this->jobs = new ArrayCollection();
  41.     }
  42.     
  43.     /**
  44.      * @ORM\PostLoad()
  45.      */
  46.     public function init() {
  47.                     $this->mergeNewTranslations();
  48.                     $this->currentLocale = \Locale::getDefault();
  49.                 }
  50.     
  51.     public function __call($name$arguments) {
  52.                     $reflect = new \ReflectionClassJobAssignmentTranslation::class);
  53.                     $privateProperties $reflect->getProperties(\ReflectionProperty::IS_PRIVATE);
  54.                     
  55.                     foreach ($privateProperties as $property) {
  56.                         if($property->getName() == $name) {
  57.                             return $this->translate()->{"get" ucfirst($name)}();
  58.                         }
  59.                     }
  60.                     
  61.                     return "";
  62.                 }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     /**
  68.      * @return Collection<int, Job>
  69.      */
  70.     public function getJobs(): Collection
  71.     {
  72.         return $this->jobs;
  73.     }
  74.     public function addJob(Job $job): self
  75.     {
  76.         if (!$this->jobs->contains($job)) {
  77.             $this->jobs[] = $job;
  78.             $job->addJobAssignment($this);
  79.         }
  80.         return $this;
  81.     }
  82.     public function removeJob(Job $job): self
  83.     {
  84.         if ($this->jobs->removeElement($job)) {
  85.             $job->removeJobAssignment($this);
  86.         }
  87.         return $this;
  88.     }
  89.     
  90. }