src/Entity/Company.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\CompanyRepository")
  9.  * @ORM\HasLifecycleCallbacks
  10.  * @UniqueEntity(
  11.  *     fields={"name"},
  12.  *     message="Le nom est déjà utilisé."
  13.  * )
  14.  */
  15. class Company
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string")
  25.      */
  26.     private $name;
  27.     /**
  28.      * @ORM\Column(type="string", nullable=true)
  29.      */
  30.     private $slug;
  31.     /**
  32.      * @ORM\Column(type="string", nullable=true)
  33.      */
  34.     private $logoFilename;
  35.     /**
  36.      * @ORM\Column(type="string",nullable=true)
  37.      */
  38.     private $offerName;
  39.     /**
  40.      * @ORM\Column(type="date", nullable=true)
  41.      */
  42.     private $expired_at;
  43.     /**
  44.      * @ORM\Column(type="integer", nullable=true)
  45.      */
  46.     private $user_limit;
  47.     /**
  48.      * @ORM\Column(type="string", length=255,options={"default"="activated"})
  49.      */
  50.     private $status;
  51.     /**
  52.      * @ORM\Column(type="json", nullable=true)
  53.      */
  54.     private $features = [];
  55.     /**
  56.      * @ORM\Column(type="json", nullable=true)
  57.      */
  58.     private $documents = [];
  59.     /**
  60.      * @ORM\Column(type="datetime_immutable", options={"default"="CURRENT_TIMESTAMP"})
  61.      */
  62.     private $created_at;
  63.     /**
  64.      * @ORM\Column(type="datetime_immutable",  options={"default"="CURRENT_TIMESTAMP"})
  65.      */
  66.     private $updated_at;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity="User", mappedBy="company", fetch="LAZY", cascade={"remove"})
  69.      *
  70.      */
  71.     private $users;
  72.     /**
  73.      * @ORM\OneToMany(targetEntity=Job::class, mappedBy="company",cascade={"remove"})
  74.      */
  75.     private $jobs;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=Department::class, mappedBy="company",cascade={"remove"})
  78.      */
  79.     private $departments;
  80.     /**
  81.      * @ORM\OneToMany(targetEntity=Message::class, mappedBy="company", orphanRemoval=true)
  82.      */
  83.     private $messages;
  84.     /**
  85.      * @ORM\Column(type="string", length=255, nullable=true)
  86.      */
  87.     private $jwpLogoFilename;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity=Site::class, mappedBy="company")
  90.      */
  91.     private $sites;
  92.     public function __construct()
  93.     {
  94.         $this->jobs = new ArrayCollection();
  95.         $this->departments = new ArrayCollection();
  96.         $this->users = new ArrayCollection();
  97.         $this->setStatus('activated');
  98.         $this->messages = new ArrayCollection();
  99.         $this->sites = new ArrayCollection();
  100.     }
  101.     /**
  102.      * @return mixed
  103.      */
  104.     public function getId()
  105.     {
  106.         return $this->id;
  107.     }
  108.     /**
  109.      * @param mixed $id
  110.      */
  111.     public function setId($id)
  112.     {
  113.         $this->id $id;
  114.     }
  115.     /**
  116.      * @return mixed
  117.      */
  118.     public function getName()
  119.     {
  120.         return $this->name;
  121.     }
  122.     /**
  123.      * @param mixed $name
  124.      */
  125.     public function setName($name)
  126.     {
  127.         $this->name $name;
  128.     }
  129.     /**
  130.      * @return mixed
  131.      */
  132.     public function getLogoFilename()
  133.     {
  134.         return $this->logoFilename;
  135.     }
  136.     /**
  137.      * @param mixed $logoFilename
  138.      */
  139.     public function setLogoFilename($logoFilename): void
  140.     {
  141.         $this->logoFilename $logoFilename;
  142.     }
  143.     /**
  144.      * @return mixed
  145.      */
  146.     public function getUsers()
  147.     {
  148.         return $this->users;
  149.     }
  150.     /**
  151.      * @ORM\PostRemove()
  152.      */
  153.     public function removeLogo()
  154.     {
  155.         if($this->getLogoFilename()){
  156.             $file $this->getAbsolutePath();
  157.             if ($file) {
  158.                 unlink($file);
  159.             }
  160.         }
  161.     }
  162.     protected function getAbsolutePath()
  163.     {
  164.         return __DIR__ '/../../public/img/company/logo/'.$this->logoFilename;
  165.     }
  166.     /**
  167.      * @return mixed
  168.      */
  169.     public function getSlug()
  170.     {
  171.         return $this->slug;
  172.     }
  173.     /**
  174.      * @param mixed $slug
  175.      */
  176.     public function setSlug($slug): void
  177.     {
  178.         $this->slug $slug;
  179.     }
  180.     /**
  181.      * @return Collection|Job[]
  182.      */
  183.     public function getJobs(): Collection
  184.     {
  185.         return $this->jobs;
  186.     }
  187.     public function addJob(Job $job): self
  188.     {
  189.         if (!$this->jobs->contains($job)) {
  190.             $this->jobs[] = $job;
  191.             $job->setCompany($this);
  192.         }
  193.         return $this;
  194.     }
  195.     public function removeJob(Job $job): self
  196.     {
  197.         if ($this->jobs->removeElement($job)) {
  198.             // set the owning side to null (unless already changed)
  199.             if ($job->getCompany() === $this) {
  200.                 $job->setCompany(null);
  201.             }
  202.         }
  203.         return $this;
  204.     }
  205.     /**
  206.      * @return Collection|Department[]
  207.      */
  208.     public function getDepartments(): Collection
  209.     {
  210.         return $this->departments;
  211.     }
  212.     public function addDepartment(Department $department): self
  213.     {
  214.         if (!$this->departments->contains($department)) {
  215.             $this->departments[] = $department;
  216.             $department->setCompany($this);
  217.         }
  218.         return $this;
  219.     }
  220.     public function removeDepartment(Department $department): self
  221.     {
  222.         if ($this->departments->removeElement($department)) {
  223.             // set the owning side to null (unless already changed)
  224.             if ($department->getCompany() === $this) {
  225.                 $department->setCompany(null);
  226.             }
  227.         }
  228.         return $this;
  229.     }
  230.     /**
  231.      * @return mixed
  232.      */
  233.     public function getUserLimit()
  234.     {
  235.         return $this->user_limit;
  236.     }
  237.     /**
  238.      * @param mixed $user_limit
  239.      */
  240.     public function setUserLimit($user_limit): void
  241.     {
  242.         $this->user_limit $user_limit;
  243.     }
  244.     /**
  245.      * @return mixed
  246.      */
  247.     public function getStatus()
  248.     {
  249.         return $this->status;
  250.     }
  251.     /**
  252.      * @param mixed $status
  253.      */
  254.     public function setStatus($status): void
  255.     {
  256.         $this->status $status;
  257.     }
  258.     /**
  259.      * @return array|null
  260.      */
  261.     public function getFeatures()
  262.     {
  263.         return $this->features;
  264.     }
  265.     /**
  266.      * @param array $features
  267.      */
  268.     public function setFeatures(array $features): void
  269.     {
  270.         $this->features $features;
  271.     }
  272.     /**
  273.      * @ORM\PrePersist
  274.      */
  275.     public function setCreatedAtValue(): void
  276.     {
  277.         $this->created_at =new \DateTimeImmutable();
  278.         $this->updated_at =new \DateTimeImmutable();
  279.     }
  280.     /**
  281.      * @ORM\PreUpdate
  282.      */
  283.     public function setUpdatedAtValue(): void
  284.     {
  285.         $this->updated_at =new \DateTimeImmutable();
  286.     }
  287.     /**
  288.      * @return mixed
  289.      */
  290.     public function getCreatedAt()
  291.     {
  292.         return $this->created_at;
  293.     }
  294.     /**
  295.      * @param mixed $created_at
  296.      */
  297.     public function setCreatedAt($created_at): void
  298.     {
  299.         $this->created_at $created_at;
  300.     }
  301.     /**
  302.      * @return mixed
  303.      */
  304.     public function getUpdatedAt()
  305.     {
  306.         return $this->updated_at;
  307.     }
  308.     /**
  309.      * @param mixed $updated_at
  310.      */
  311.     public function setUpdatedAt($updated_at): void
  312.     {
  313.         $this->updated_at $updated_at;
  314.     }
  315.     /**
  316.      * @return array|null
  317.      */
  318.     public function getDocuments()
  319.     {
  320.         return $this->documents;
  321.     }
  322.     /**
  323.      * @param array $documents
  324.      */
  325.     public function setDocuments(array $documents): void
  326.     {
  327.         $this->documents $documents;
  328.     }
  329.     /**
  330.      * @return mixed
  331.      */
  332.     public function getExpiredAt()
  333.     {
  334.         return $this->expired_at;
  335.     }
  336.     /**
  337.      * @param mixed $expired_at
  338.      */
  339.     public function setExpiredAt($expired_at): void
  340.     {
  341.         $this->expired_at $expired_at;
  342.     }
  343.     /**
  344.      * @return mixed
  345.      */
  346.     public function getOfferName()
  347.     {
  348.         return $this->offerName;
  349.     }
  350.     /**
  351.      * @param mixed $offerName
  352.      */
  353.     public function setOfferName($offerName): void
  354.     {
  355.         $this->offerName $offerName;
  356.     }
  357.     /**
  358.      * @return Collection<int, Message>
  359.      */
  360.     public function getMessages(): Collection
  361.     {
  362.         return $this->messages;
  363.     }
  364.     public function addMessage(Message $message): self
  365.     {
  366.         if (!$this->messages->contains($message)) {
  367.             $this->messages[] = $message;
  368.             $message->setCompany($this);
  369.         }
  370.         return $this;
  371.     }
  372.     public function removeMessage(Message $message): self
  373.     {
  374.         if ($this->messages->removeElement($message)) {
  375.             // set the owning side to null (unless already changed)
  376.             if ($message->getCompany() === $this) {
  377.                 $message->setCompany(null);
  378.             }
  379.         }
  380.         return $this;
  381.     }
  382.     public function getJwpLogoFilename(): ?string
  383.     {
  384.         return $this->jwpLogoFilename;
  385.     }
  386.     public function setJwpLogoFilename(?string $jwpLogoFilename): self
  387.     {
  388.         $this->jwpLogoFilename $jwpLogoFilename;
  389.         return $this;
  390.     }
  391.     /**
  392.      * @return Collection<int, Site>
  393.      */
  394.     public function getSites(): Collection
  395.     {
  396.         return $this->sites;
  397.     }
  398.     public function addSite(Site $site): self
  399.     {
  400.         if (!$this->sites->contains($site)) {
  401.             $this->sites[] = $site;
  402.             $site->setCompany($this);
  403.         }
  404.         return $this;
  405.     }
  406.     public function removeSite(Site $site): self
  407.     {
  408.         if ($this->sites->removeElement($site)) {
  409.             // set the owning side to null (unless already changed)
  410.             if ($site->getCompany() === $this) {
  411.                 $site->setCompany(null);
  412.             }
  413.         }
  414.         return $this;
  415.     }
  416. }