src/Entity/Configuration/JobContract.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Configuration;
  3. use App\Entity\EntityIdentifier;
  4. use App\Entity\User;
  5. use App\Repository\Configuration\JobContractRepository;
  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=JobContractRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class JobContract
  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=JobContractTranslation::class, mappedBy="translatable", cascade={"persist"})
  29.      */
  30.     protected $newTranslations;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="jobContract")
  33.      */
  34.     private $users;
  35.     /**
  36.      * @ORM\Column(type="integer", nullable=true)
  37.      */
  38.     private $position;
  39.     public function __construct()
  40.     {
  41.         $this->users = new ArrayCollection();
  42.     }
  43.     
  44.     /**
  45.      * @ORM\PostLoad()
  46.      */
  47.     public function init() {
  48.                  $this->mergeNewTranslations();
  49.                  $this->currentLocale = \Locale::getDefault();
  50.              }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     /**
  56.      * @return Collection<int, User>
  57.      */
  58.     public function getUsers(): Collection
  59.     {
  60.         return $this->users;
  61.     }
  62.     public function addUser(User $user): self
  63.     {
  64.         if (!$this->users->contains($user)) {
  65.             $this->users[] = $user;
  66.             $user->setJobContract($this);
  67.         }
  68.         return $this;
  69.     }
  70.     public function removeUser(User $user): self
  71.     {
  72.         if ($this->users->removeElement($user)) {
  73.             // set the owning side to null (unless already changed)
  74.             if ($user->getJobContract() === $this) {
  75.                 $user->setJobContract(null);
  76.             }
  77.         }
  78.         return $this;
  79.     }
  80.     
  81.     public function __call($name$arguments) {
  82.                  $reflect = new \ReflectionClassJobContractTranslation::class);
  83.                  $privateProperties $reflect->getProperties(\ReflectionProperty::IS_PRIVATE);
  84.                  
  85.                  foreach ($privateProperties as $property) {
  86.                      if($property->getName() == $name) {
  87.                          return $this->translate()->{"get" ucfirst($name)}();
  88.                      }
  89.                  }
  90.                  
  91.                  return "";
  92.              }
  93.     public function getPosition(): ?int
  94.     {
  95.         return $this->position;
  96.     }
  97.     public function setPosition(?int $position): self
  98.     {
  99.         $this->position $position;
  100.         return $this;
  101.     }
  102. }