src/Entity/Jobs.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Embedded\DateAndTime;
  4. use App\Entity\File\Biblios;
  5. use App\Entity\File\Picture;
  6. use App\Entity\Trait\EnabledDisabledTrait;
  7. use App\Entity\Trait\TimestampTrait;
  8. use App\Features\Core\Itranslatable;
  9. use App\Form\JobsType;
  10. use App\Repository\JobsRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use OSAdmin\Annotation\EntityConfig;
  15. use OSAdmin\Annotation\EntityFormConfig;
  16. use OSAdmin\Annotation\EntityToRoute;
  17. use OSAdmin\Util\EntityExportableInterface;
  18. use Symfony\Component\Validator\Constraints\IsTrue;
  19. use Symfony\Component\Validator\Constraints\Valid;
  20. #[ORM\Entity(repositoryClassJobsRepository::class)]
  21. #[ORM\HasLifecycleCallbacks]
  22. #[EntityToRoute(
  23.     config: new EntityConfig(
  24.         title"Gestion des offres d'emploi",
  25.         editSubtitle"Edition d'une offre d'emploi",
  26.         listSubtitle"Liste des offres d'emploi",
  27.     ),
  28.     formConfig: new EntityFormConfig(
  29.         formClassJobsType::class,
  30.     )
  31. )]
  32. class Jobs implements EntityExportableInterfaceItranslatable
  33. {
  34.     use TimestampTrait;
  35.     use EnabledDisabledTrait;
  36.     #[ORM\Id]
  37.     #[ORM\GeneratedValue]
  38.     #[ORM\Column(type'integer')]
  39.     private readonly ?int $id;
  40.     #[ORM\Column(type'string'length255nullabletrue)]
  41.     private ?string $title;
  42.     public function getTranslateTitle(): ?string
  43.     {
  44.         if($this->currentLocal){
  45.             if($this->currentLocal === 'fr'){
  46.                 return $this->title;
  47.             }
  48.             if($this->currentLocal === 'en' && $this->titleEn){
  49.                 return $this->titleEn;
  50.             }
  51.         }
  52.         return $this->title;
  53.     }
  54.     #[ORM\Column(type'text'nullabletrue)]
  55.     private ?string $content;
  56.     public function getTranslateContent(): ?string
  57.     {
  58.         if($this->currentLocal){
  59.             if($this->currentLocal === 'fr'){
  60.                 return $this->content;
  61.             }
  62.             if($this->currentLocal === 'en' && $this->contentEn){
  63.                 return $this->contentEn;
  64.             }
  65.         }
  66.         return $this->content;
  67.     }
  68.     #[ORM\Column(type'integer'nullabletrue)]
  69.     private ?int $experienceYear;
  70.     #[ORM\Column(type'text'nullabletrue)]
  71.     private ?string $qualifications;
  72.     public function getTranslateQualifications(): ?string
  73.     {
  74.         if($this->currentLocal){
  75.             if($this->currentLocal === 'fr'){
  76.                 return $this->qualifications;
  77.             }
  78.             if($this->currentLocal === 'en' && $this->qualificationsEn){
  79.                 return $this->qualificationsEn;
  80.             }
  81.         }
  82.         return $this->qualifications;
  83.     }
  84.     #[ORM\Embedded(class: DateAndTime::class)]
  85.     #[Valid]
  86.     private ?DateAndTime $startAt;
  87.     #[ORM\Embedded(class: DateAndTime::class)]
  88.     #[Valid]
  89.     private ?DateAndTime $endAt;
  90.     #[ORM\ManyToMany(targetEntityStudyLevel::class)]
  91.     private Collection $studyLevel;
  92.     #[ORM\ManyToOne(targetEntityEmploymentContract::class, fetch"EAGER")]
  93.     private ?EmploymentContract $employmentContract;
  94.     #[ORM\ManyToMany(targetEntityActivitySector::class)]
  95.     private Collection $sectors;
  96.     #[ORM\OneToOne(targetEntityBiblios::class, cascade: ['persist''remove'])]
  97.     private ?Biblios $biblio;
  98.     #[ORM\OneToOne(targetEntityPicture::class, cascade: ['persist''remove'])]
  99.     private ?Picture $banner;
  100.     #[ORM\OneToMany(mappedBy'job'targetEntityJobsApplications::class, orphanRemovaltrue)]
  101.     private Collection $applications;
  102.     #[ORM\Column(type'text'nullabletrue)]
  103.     private ?string $description;
  104.     public function getTranslateDescription(): ?string
  105.     {
  106.         if($this->currentLocal){
  107.             if($this->currentLocal === 'fr'){
  108.                 return $this->description;
  109.             }
  110.             if($this->currentLocal === 'en' && $this->descriptionEn){
  111.                 return $this->descriptionEn;
  112.             }
  113.         }
  114.         return $this->description;
  115.     }
  116.     #[ORM\Column(type'string'length255nullabletrue)]
  117.     private string $uuid;
  118.     #[ORM\Column(type'date_immutable'nullabletrue)]
  119.     private ?\DateTimeImmutable $createdDate;
  120.     public function __construct()
  121.     {
  122.         $this->studyLevel = new ArrayCollection();
  123.         $this->sectors = new ArrayCollection();
  124.         $this->isEnabledtrue;
  125.         $this->createdAt = new \DateTimeImmutable();
  126.         $this->createdDate = new \DateTimeImmutable();
  127.         $this->applications = new ArrayCollection();
  128.         $this->uuiduniqid(''true);
  129.     }
  130.     public function getId(): ?int
  131.     {
  132.         return $this->id;
  133.     }
  134.     public function getTitle(): ?string
  135.     {
  136.         return $this->getTranslateTitle();
  137.     }
  138.     public function getContent(): ?string
  139.     {
  140.         return $this->getTranslateContent();
  141.     }
  142.     public function getExperienceYear(): ?int
  143.     {
  144.         return $this->experienceYear;
  145.     }
  146.     public function setExperienceYear(?int $experienceYear): self
  147.     {
  148.         $this->experienceYear $experienceYear;
  149.         return $this;
  150.     }
  151.     public function getQualifications(): ?string
  152.     {
  153.         return $this->getTranslateQualifications();
  154.     }
  155.     /**
  156.      * @return DateAndTime|null
  157.      */
  158.     public function getStartAt(): ?DateAndTime
  159.     {
  160.         return $this->startAt;
  161.     }
  162.     /**
  163.      * @param DateAndTime|null $startAt
  164.      */
  165.     public function setStartAt(?DateAndTime $startAt): void
  166.     {
  167.         $this->startAt $startAt;
  168.     }
  169.     /**
  170.      * @return DateAndTime|null
  171.      */
  172.     public function getEndAt(): ?DateAndTime
  173.     {
  174.         return $this->endAt;
  175.     }
  176.     /**
  177.      * @param DateAndTime|null $endAt
  178.      */
  179.     public function setEndAt(?DateAndTime $endAt): void
  180.     {
  181.         $this->endAt $endAt;
  182.     }
  183.     /**
  184.      * @return Collection<int, StudyLevel>
  185.      */
  186.     public function getStudyLevel(): Collection
  187.     {
  188.         return $this->studyLevel;
  189.     }
  190.     public function addStudyLevel(StudyLevel $studyLevel): self
  191.     {
  192.         if (!$this->studyLevel->contains($studyLevel)) {
  193.             $this->studyLevel[] = $studyLevel;
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeStudyLevel(StudyLevel $studyLevel): self
  198.     {
  199.         $this->studyLevel->removeElement($studyLevel);
  200.         return $this;
  201.     }
  202.     public function getEmploymentContract(): ?EmploymentContract
  203.     {
  204.         return $this->employmentContract;
  205.     }
  206.     public function setEmploymentContract(?EmploymentContract $employmentContract): self
  207.     {
  208.         $this->employmentContract $employmentContract;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return Collection<int, ActivitySector>
  213.      */
  214.     public function getSectors(): Collection
  215.     {
  216.         return $this->sectors;
  217.     }
  218.     public function addSector(ActivitySector $sector): self
  219.     {
  220.         if (!$this->sectors->contains($sector)) {
  221.             $this->sectors[] = $sector;
  222.         }
  223.         return $this;
  224.     }
  225.     public function removeSector(ActivitySector $sector): self
  226.     {
  227.         $this->sectors->removeElement($sector);
  228.         return $this;
  229.     }
  230.     public function getBiblio(): ?Biblios
  231.     {
  232.         return $this->biblio;
  233.     }
  234.     public function setBiblio(?Biblios $biblio): self
  235.     {
  236.         $this->biblio $biblio;
  237.         return $this;
  238.     }
  239.     public function getBanner(): ?Picture
  240.     {
  241.         return $this->banner;
  242.     }
  243.     public function setBanner(?Picture $banner): self
  244.     {
  245.         $this->banner $banner;
  246.         return $this;
  247.     }
  248.     /**
  249.      * @return Collection<int, JobsApplications>
  250.      */
  251.     public function getApplications(): Collection
  252.     {
  253.         return $this->applications->filter(function (JobsApplications $applications) {
  254.             return $applications->getConfirmedAt() !== null;
  255.         });
  256.     }
  257.     public function addApplication(JobsApplications $application): self
  258.     {
  259.         if (!$this->applications->contains($application)) {
  260.             $this->applications[] = $application;
  261.             $application->setJob($this);
  262.         }
  263.         return $this;
  264.     }
  265.     public function removeApplication(JobsApplications $application): self
  266.     {
  267.         if ($this->applications->removeElement($application)) {
  268.             // set the owning side to null (unless already changed)
  269.             if ($application->getJob() === $this) {
  270.                 $application->setJob(null);
  271.             }
  272.         }
  273.         return $this;
  274.     }
  275.     public function getNbAcceptedRequest(): int
  276.     {
  277.         if($this->applications->isEmpty()) {
  278.             return 0;
  279.         }
  280.         return $this->applications->filter(function (JobsApplications $request) {
  281.             return $request->getConfirmedAt() != null && $request->getStatus() === "accepted";
  282.         })->count();
  283.     }
  284.     public function getNbRejectedRequest(): int
  285.     {
  286.         if($this->applications->isEmpty()) {
  287.             return 0;
  288.         }
  289.         return $this->applications->filter(function (JobsApplications $request) {
  290.             return $request->getConfirmedAt() != null && $request->getStatus() === "rejected";
  291.         })->count();
  292.     }
  293.     public function getNbWaitingRequest(): int
  294.     {
  295.         if($this->applications->isEmpty()) {
  296.             return 0;
  297.         }
  298.         return $this->applications->filter(function (JobsApplications $request) {
  299.             return $request->getConfirmedAt() != null && (!$request->getStatus() || $request->getStatus() === "registered");
  300.         })->count();
  301.     }
  302.     public function getNbRequest(): ?int
  303.     {
  304.         return $this->applications->filter(function (JobsApplications $application){
  305.             return $application->getConfirmedAt() != null;
  306.         })->count();
  307.     }
  308.     public function getDescription(): ?string
  309.     {
  310.         return $this->getTranslateDescription();
  311.     }
  312.     public function getUuid(): ?string
  313.     {
  314.         return $this->uuid;
  315.     }
  316.     public function setUuid(?string $uuid): self
  317.     {
  318.         $this->uuid $uuid;
  319.         return $this;
  320.     }
  321.     public function getCreatedDate(): ?\DateTimeImmutable
  322.     {
  323.         return $this->createdDate;
  324.     }
  325.     public function setCreatedDate(?\DateTimeImmutable $createdDate): self
  326.     {
  327.         $this->createdDate $createdDate;
  328.         return $this;
  329.     }
  330.     #[IsTrue(message"La date de début doit être antérieure à la date de fin")]
  331.     public function isDateValid(): bool
  332.     {
  333.         return $this->endAt->asDate() > $this->startAt->asDate();
  334.     }
  335.     public function getExportData(): array
  336.     {
  337.         return [
  338.             'ID' => function (Jobs $item) {
  339.                 return $item->getId();
  340.             },
  341.             'Titre' => function (Jobs $item) {
  342.                 return $item->getTitle();
  343.             },
  344.             'Contenu' => function (Jobs $item) {
  345.                 return $item->getContent();
  346.             },
  347.             'experienceYear' => function (Jobs $item) {
  348.                 return $item->getExperienceYear();
  349.             }
  350.         ];
  351.     }
  352.     private string $currentLocal "fr";
  353.     #[ORM\Column(type'string'length255nullabletrue)]
  354.     private string|null $titleEn;
  355.     /**
  356.      * @param array|null $titleTran
  357.      */
  358.     public function setTitleTrans(array|null $titleTran): void
  359.     {
  360.         if($titleTran) {
  361.             $this->title$titleTran['fr'] ?? null;
  362.             $this->titleEn $titleTran['en'] ?? null;
  363.         }
  364.     }
  365.     /**
  366.      * @return array|null
  367.      */
  368.     public function getTitleTrans(): array|null
  369.     {
  370.         return [
  371.             'fr' => $this->title,
  372.             'en' => $this->titleEn
  373.         ];
  374.     }
  375.     #[ORM\Column(type'text'nullabletrue)]
  376.     private string|null $contentEn;
  377.     /**
  378.      * @param array|null $contentTrans
  379.      */
  380.     public function setContentTrans(array|null $contentTrans): void
  381.     {
  382.         if($contentTrans) {
  383.             $this->content $contentTrans['fr'] ?? null;
  384.             $this->contentEn $contentTrans['en'] ?? null;
  385.         }
  386.     }
  387.     /**
  388.      * @return array|null
  389.      */
  390.     public function getContentTrans(): array|null
  391.     {
  392.         return [
  393.             'fr' => $this->content,
  394.             'en' => $this->contentEn
  395.         ];
  396.     }
  397.     #[ORM\Column(type'text'nullabletrue)]
  398.     private string|null $qualificationsEn;
  399.     /**
  400.      * @param array|null $qualificationsTrans
  401.      */
  402.     public function setQualificationsTrans(array|null $qualificationsTrans): void
  403.     {
  404.         if($qualificationsTrans) {
  405.             $this->qualifications $qualificationsTrans['fr'] ?? null;
  406.             $this->qualificationsEn $qualificationsTrans['en'] ?? null;
  407.         }
  408.     }
  409.     /**
  410.      * @return array|null
  411.      */
  412.     public function getQualificationsTrans(): array|null
  413.     {
  414.         return [
  415.             'fr' => $this->qualifications,
  416.             'en' => $this->qualificationsEn
  417.         ];
  418.     }
  419.     #[ORM\Column(type'text'nullabletrue)]
  420.     private string|null $descriptionEn;
  421.     /**
  422.      * @param array|null $descriptionTrans
  423.      */
  424.     public function setDescriptionTrans(array|null $descriptionTrans): void
  425.     {
  426.         if($descriptionTrans) {
  427.             $this->description $descriptionTrans['fr'] ?? null;
  428.             $this->descriptionEn $descriptionTrans['en'] ?? null;
  429.         }
  430.     }
  431.     /**
  432.      * @return array|null
  433.      */
  434.     public function getDescriptionTrans(): array|null
  435.     {
  436.         return [
  437.             'fr' => $this->description,
  438.             'en' => $this->descriptionEn
  439.         ];
  440.     }
  441.     public function setCurrentLocal(string $locale): Itranslatable
  442.     {
  443.         $this->currentLocal $locale;
  444.         return $this;
  445.     }
  446.     public function getCurrentLocal(): string
  447.     {
  448.         return $this->currentLocal;
  449.     }
  450.     public function getTitleEn(): ?string
  451.     {
  452.         return $this->titleEn;
  453.     }
  454.     public function setTitleEn(?string $titleEn): self
  455.     {
  456.         $this->titleEn $titleEn;
  457.         return $this;
  458.     }
  459.     public function getContentEn(): ?string
  460.     {
  461.         return $this->contentEn;
  462.     }
  463.     public function setContentEn(string $contentEn): self
  464.     {
  465.         $this->contentEn $contentEn;
  466.         return $this;
  467.     }
  468.     public function getQualificationsEn(): ?string
  469.     {
  470.         return $this->qualificationsEn;
  471.     }
  472.     public function setQualificationsEn(?string $qualificationsEn): self
  473.     {
  474.         $this->qualificationsEn $qualificationsEn;
  475.         return $this;
  476.     }
  477.     public function getDescriptionEn(): ?string
  478.     {
  479.         return $this->descriptionEn;
  480.     }
  481.     public function setDescriptionEn(?string $descriptionEn): self
  482.     {
  483.         $this->descriptionEn $descriptionEn;
  484.         return $this;
  485.     }
  486. }