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=Message::class, mappedBy="company", orphanRemoval=true)
  74.      */
  75.     private $messages;
  76.     /**
  77.      * @ORM\Column(type="string", length=255, nullable=true)
  78.      */
  79.     private $jwpLogoFilename;
  80.     public function __construct()
  81.     {
  82.         $this->users = new ArrayCollection();
  83.         $this->setStatus('activated');
  84.         $this->messages = new ArrayCollection();
  85.     }
  86.     /**
  87.      * @return mixed
  88.      */
  89.     public function getId()
  90.     {
  91.         return $this->id;
  92.     }
  93.     /**
  94.      * @param mixed $id
  95.      */
  96.     public function setId($id)
  97.     {
  98.         $this->id $id;
  99.     }
  100.     /**
  101.      * @return mixed
  102.      */
  103.     public function getName()
  104.     {
  105.         return $this->name;
  106.     }
  107.     /**
  108.      * @param mixed $name
  109.      */
  110.     public function setName($name)
  111.     {
  112.         $this->name $name;
  113.     }
  114.     /**
  115.      * @return mixed
  116.      */
  117.     public function getLogoFilename()
  118.     {
  119.         return $this->logoFilename;
  120.     }
  121.     /**
  122.      * @param mixed $logoFilename
  123.      */
  124.     public function setLogoFilename($logoFilename): void
  125.     {
  126.         $this->logoFilename $logoFilename;
  127.     }
  128.     /**
  129.      * @return mixed
  130.      */
  131.     public function getUsers()
  132.     {
  133.         return $this->users;
  134.     }
  135.     /**
  136.      * @ORM\PostRemove()
  137.      */
  138.     public function removeLogo()
  139.     {
  140.         if($this->getLogoFilename()){
  141.             $file $this->getAbsolutePath();
  142.             if ($file) {
  143.                 unlink($file);
  144.             }
  145.         }
  146.     }
  147.     protected function getAbsolutePath()
  148.     {
  149.         return __DIR__ '/../../public/img/company/logo/'.$this->logoFilename;
  150.     }
  151.     /**
  152.      * @return mixed
  153.      */
  154.     public function getSlug()
  155.     {
  156.         return $this->slug;
  157.     }
  158.     /**
  159.      * @param mixed $slug
  160.      */
  161.     public function setSlug($slug): void
  162.     {
  163.         $this->slug $slug;
  164.     }
  165.     /**
  166.      * @return mixed
  167.      */
  168.     public function getUserLimit()
  169.     {
  170.         return $this->user_limit;
  171.     }
  172.     /**
  173.      * @param mixed $user_limit
  174.      */
  175.     public function setUserLimit($user_limit): void
  176.     {
  177.         $this->user_limit $user_limit;
  178.     }
  179.     /**
  180.      * @return mixed
  181.      */
  182.     public function getStatus()
  183.     {
  184.         return $this->status;
  185.     }
  186.     /**
  187.      * @param mixed $status
  188.      */
  189.     public function setStatus($status): void
  190.     {
  191.         $this->status $status;
  192.     }
  193.     /**
  194.      * @return array|null
  195.      */
  196.     public function getFeatures()
  197.     {
  198.         return $this->features;
  199.     }
  200.     /**
  201.      * @param array $features
  202.      */
  203.     public function setFeatures(array $features): void
  204.     {
  205.         $this->features $features;
  206.     }
  207.     /**
  208.      * @ORM\PrePersist
  209.      */
  210.     public function setCreatedAtValue(): void
  211.     {
  212.         $this->created_at =new \DateTimeImmutable();
  213.         $this->updated_at =new \DateTimeImmutable();
  214.     }
  215.     /**
  216.      * @ORM\PreUpdate
  217.      */
  218.     public function setUpdatedAtValue(): void
  219.     {
  220.         $this->updated_at =new \DateTimeImmutable();
  221.     }
  222.     /**
  223.      * @return mixed
  224.      */
  225.     public function getCreatedAt()
  226.     {
  227.         return $this->created_at;
  228.     }
  229.     /**
  230.      * @param mixed $created_at
  231.      */
  232.     public function setCreatedAt($created_at): void
  233.     {
  234.         $this->created_at $created_at;
  235.     }
  236.     /**
  237.      * @return mixed
  238.      */
  239.     public function getUpdatedAt()
  240.     {
  241.         return $this->updated_at;
  242.     }
  243.     /**
  244.      * @param mixed $updated_at
  245.      */
  246.     public function setUpdatedAt($updated_at): void
  247.     {
  248.         $this->updated_at $updated_at;
  249.     }
  250.     /**
  251.      * @return array|null
  252.      */
  253.     public function getDocuments()
  254.     {
  255.         return $this->documents;
  256.     }
  257.     /**
  258.      * @param array $documents
  259.      */
  260.     public function setDocuments(array $documents): void
  261.     {
  262.         $this->documents $documents;
  263.     }
  264.     /**
  265.      * @return mixed
  266.      */
  267.     public function getExpiredAt()
  268.     {
  269.         return $this->expired_at;
  270.     }
  271.     /**
  272.      * @param mixed $expired_at
  273.      */
  274.     public function setExpiredAt($expired_at): void
  275.     {
  276.         $this->expired_at $expired_at;
  277.     }
  278.     /**
  279.      * @return mixed
  280.      */
  281.     public function getOfferName()
  282.     {
  283.         return $this->offerName;
  284.     }
  285.     /**
  286.      * @param mixed $offerName
  287.      */
  288.     public function setOfferName($offerName): void
  289.     {
  290.         $this->offerName $offerName;
  291.     }
  292.     /**
  293.      * @return Collection<int, Message>
  294.      */
  295.     public function getMessages(): Collection
  296.     {
  297.         return $this->messages;
  298.     }
  299.     public function addMessage(Message $message): self
  300.     {
  301.         if (!$this->messages->contains($message)) {
  302.             $this->messages[] = $message;
  303.             $message->setCompany($this);
  304.         }
  305.         return $this;
  306.     }
  307.     public function removeMessage(Message $message): self
  308.     {
  309.         if ($this->messages->removeElement($message)) {
  310.             // set the owning side to null (unless already changed)
  311.             if ($message->getCompany() === $this) {
  312.                 $message->setCompany(null);
  313.             }
  314.         }
  315.         return $this;
  316.     }
  317.     public function getJwpLogoFilename(): ?string
  318.     {
  319.         return $this->jwpLogoFilename;
  320.     }
  321.     public function setJwpLogoFilename(?string $jwpLogoFilename): self
  322.     {
  323.         $this->jwpLogoFilename $jwpLogoFilename;
  324.         return $this;
  325.     }
  326. }