src/Entity/OSEntity.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\ORM\Mapping\MappedSuperclass;
  5. use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use OlaSoft\Common;
  10. /**
  11.  * @ORM\MappedSuperclass()
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class OSEntity implements \Serializable
  15. {
  16.     /**
  17.     * @ORM\Column(name="id", type="integer")
  18.     * @ORM\Id
  19.     * @ORM\GeneratedValue(strategy="AUTO")
  20.     */
  21.     protected $id;
  22.     /**
  23.     * @ORM\Column(name="title", type="string", length=255,nullable=true)
  24.     */
  25.     protected $title;
  26.     /**
  27.     * @ORM\Column(name="description", type="text", nullable=true)
  28.     */
  29.     protected $description;
  30.     /**
  31.     * @ORM\Column(name="content", type="text",nullable=true)
  32.     */
  33.     protected $content;
  34.     /**
  35.     * @ORM\OneToOne(targetEntity="App\Entity\Picture", cascade={"persist","remove"}, orphanRemoval=true, fetch="EAGER")
  36.     * @ORM\JoinColumn(nullable=true)
  37.     */
  38.     protected $banner;
  39.     /**
  40.     * @ORM\Column(name="slug", type="string", length=255,nullable=true)
  41.     */
  42.     protected $slug;
  43.     /**
  44.     * @ORM\ManyToMany(targetEntity=Tags::class)
  45.     */
  46.     protected $tags;
  47.     /**
  48.     * @ORM\ManyToOne(targetEntity=Sectors::class)
  49.     * @ORM\JoinColumn(nullable=true)
  50.     */
  51.     protected $sector;
  52.     /**
  53.      * @ORM\Column(type="datetime", nullable=true)
  54.      */
  55.     protected $date;
  56.     /**
  57.     * @ORM\Column(name="createdAt", type="datetime", nullable=true)
  58.     */
  59.     protected $createdAt;
  60.     /**
  61.     * @ORM\ManyToOne(targetEntity="App\Entity\Users", fetch="EAGER")
  62.     * @ORM\JoinColumn(nullable=true)
  63.     */
  64.     protected $user;
  65.     /**
  66.      * @ORM\Column(name="lastUpdate", type="datetime", nullable=true)
  67.      */
  68.     protected $lastUpdate;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity="App\Entity\Users")
  71.      * @ORM\JoinColumn(name="updatedBy",nullable=true)
  72.      */
  73.     protected $updatedBy;
  74.     /**
  75.     * @ORM\Column(name="isEnabled", type="boolean", nullable=true)
  76.     */
  77.     protected $isEnabled;
  78.     public function __construct()
  79.     {
  80.         $this->isEnabled false;
  81.         $this->createdAt = new \DateTime;
  82.         $this->date = new \DateTime;
  83.         $this->tags = new ArrayCollection();
  84.     }
  85.     public function getId(): ?int
  86.     {
  87.         return $this->id;
  88.     }
  89.     public function __toString(){
  90.         return $this->getTitle() ?? "";
  91.     }
  92.     public function serialize()
  93.     {
  94.         return serialize(array(
  95.             $this->id,
  96.             $this->title,
  97.             $this->content,
  98.         ));
  99.     }
  100.     public function unserialize($serialized)
  101.     {
  102.         list (
  103.             $this->id,
  104.             $this->title,
  105.             $this->content,
  106.         ) = unserialize($serialized);
  107.     }
  108.     public function getTitle(): ?string
  109.     {
  110.         return $this->title;
  111.     }
  112.     public function setTitle(?string $title): self
  113.     {
  114.         $this->title $title;
  115.         return $this;
  116.     }
  117.     public function getDescription(): ?string
  118.     {
  119.         return $this->description;
  120.     }
  121.     public function setDescription(?string $description): self
  122.     {
  123.         $this->description $description;
  124.         return $this;
  125.     }
  126.     public function getContent(): ?string
  127.     {
  128.         return $this->content;
  129.     }
  130.     public function setContent(?string $content): self
  131.     {
  132.         $this->content $content;
  133.         return $this;
  134.     }
  135.     public function getSlug(): ?string
  136.     {
  137.         return $this->slug;
  138.     }
  139.     public function setSlug(?string $slug): self
  140.     {
  141.         $this->slug $slug;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @ORM\PrePersist()
  146.      */
  147.     public  function setSlugOnPersist(){
  148.         $this->setSlug(Common::slug($this->getTitle()));
  149.     }
  150.     /**
  151.      * @ORM\PreUpdate()
  152.      */
  153.     public  function setSlugOnUpdate(){
  154.         $this->setSlug(Common::slug($this->getTitle()));
  155.     }
  156.     public function getDate(): ?\DateTimeInterface
  157.     {
  158.         return $this->date;
  159.     }
  160.     public function setDate(?\DateTimeInterface $date): self
  161.     {
  162.         $this->date $date;
  163.         return $this;
  164.     }
  165.     public function getCreatedAt(): ?\DateTimeInterface
  166.     {
  167.         return $this->createdAt;
  168.     }
  169.     public function setCreatedAt(\DateTimeInterface $date): self
  170.     {
  171.         $this->createdAt $date;
  172.         return $this;
  173.     }
  174.     public function isEnabled(): ?bool
  175.     {
  176.         return $this->isEnabled;
  177.     }
  178.     public function getIsEnabled(): ?bool
  179.     {
  180.         return $this->isEnabled;
  181.     }
  182.     public function setIsEnabled(?bool $isEnabled): self
  183.     {
  184.         $this->isEnabled $isEnabled;
  185.         return $this;
  186.     }
  187.     public function getBanner(): ?Picture
  188.     {
  189.         return $this->banner;
  190.     }
  191.     public function setBanner(?Picture $banner): self
  192.     {
  193.         if($banner->getTarget()){
  194.             $this->banner $banner;
  195.             $this->banner->setDir('upload/images/banners/');
  196.             $this->banner->setThumbnailDir('upload/thumbnails/banners/');
  197.         }
  198.         return $this;
  199.     }
  200.     public function getUser(): ?Users
  201.     {
  202.         return $this->user;
  203.     }
  204.     public function setUser(?Users $user): self
  205.     {
  206.         $this->user $user;
  207.         return $this;
  208.     }
  209.     public function getLastUpdate(): ?\DateTimeInterface
  210.     {
  211.         return $this->lastUpdate;
  212.     }
  213.     public function setLastUpdate(\DateTimeInterface $lastUpdate): self
  214.     {
  215.         $this->lastUpdate $lastUpdate;
  216.         return $this;
  217.     }
  218.     public function getUpdatedBy(): ?Users
  219.     {
  220.         return $this->updatedBy;
  221.     }
  222.     public function setUpdatedBy(?Users $updatedBy): self
  223.     {
  224.         $this->updatedBy $updatedBy;
  225.         return $this;
  226.     }
  227.     public function getTags(): Collection
  228.     {
  229.         return $this->tags;
  230.     }
  231.     public function addTag(Tags $tag): self
  232.     {
  233.         if (!$this->tags->contains($tag)) {
  234.             $this->tags[] = $tag;
  235.         }
  236.         return $this;
  237.     }
  238.     public function removeTag(Tags $tag): self
  239.     {
  240.         $this->tags->removeElement($tag);
  241.         return $this;
  242.     }
  243.     public function getSector(): ?Sectors
  244.     {
  245.         return $this->sector;
  246.     }
  247.     public function setSector(?Sectors $sector): self
  248.     {
  249.         $this->sector $sector;
  250.         return $this;
  251.     }
  252. }