src/Entity/Articles/Document.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Articles;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * Image
  7.  *
  8.  * @ORM\Table("article__document")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Articles\DocumentRepository")
  10.  */
  11. class Document
  12. {
  13.     /**
  14.      * @ORM\Column(name="id", type="integer")
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue(strategy="AUTO")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\ManyToOne(targetEntity="App\Entity\Articles\Article",inversedBy="documents")
  21.      * @ORM\JoinColumn(nullable=false)
  22.      */
  23.     private $article;
  24.     /**
  25.      * @ORM\Column(name="url", type="string", length=255, nullable=true)
  26.      */
  27.     private $url;
  28.     /**
  29.      * @ORM\Column(name="date", type="datetime", nullable=true)
  30.      */
  31.     private $date;
  32.     /**
  33.      * @ORM\Column(name="extension", type="string", length=255, nullable=true)
  34.      */
  35.     private $extension;
  36.     
  37.     /**
  38.      * @ORM\Column(name="position", type="integer", nullable=true)
  39.      */
  40.     private $position;
  41.     /**
  42.      * @ORM\Column(name="affichage_web", type="boolean", nullable=true)
  43.      */
  44.     private $affichageWeb;
  45.     public function __construct()
  46.     {
  47.         $this->date = new Datetime();
  48.        
  49.     }
  50.     public function getId(): int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function setUrl(?string $url): Document
  55.     {
  56.         $this->url $url;
  57.         return $this;
  58.     }
  59.     public function getUrl(): ?string
  60.     {
  61.         return $this->url;
  62.     }
  63.     public function setDate(?DateTime $date): Document
  64.     {
  65.         $this->date $date;
  66.         return $this;
  67.     }
  68.     public function getDate(): ?DateTime
  69.     {
  70.         return $this->date;
  71.     }
  72.     public function setExtension(?string $extension): Document
  73.     {
  74.         $this->extension $extension;
  75.         return $this;
  76.     }
  77.     public function getExtension(): ?string
  78.     {
  79.         return $this->extension;
  80.     }
  81.     public function setArticle(?Article $article): Document
  82.     {
  83.         $this->article $article;
  84.         return $this;
  85.     }
  86.     public function getArticle(): ?Article
  87.     {
  88.         return $this->article;
  89.     }
  90.     
  91.      public function getUploadDir(): string
  92.      {
  93.         // On retourne le chemin relatif vers l'image pour un navigateur
  94.         //return 'uploads/articles/documents';
  95.         return 'uploads/articles/documents/'.$this->getArticle()->getDate()->format("Y").'/'.$this->getArticle()->getDate()->format("m").'/'.$this->getArticle()->getDate()->format("d");
  96.    
  97.     }
  98.     protected function getUploadRootDir() {
  99.         // On retourne le chemin relatif vers l'image pour notre code PHP
  100.         return __DIR__ '/../../../../web/' $this->getUploadDir();
  101.     }
  102.     public function setPosition(?int $position): Document
  103.     {
  104.         $this->position $position;
  105.         return $this;
  106.     }
  107.     public function getPosition(): ?int
  108.     {
  109.         return $this->position;
  110.     }
  111.     public function setAffichageWeb(?bool $affichageWeb): Document
  112.     {
  113.         $this->affichageWeb $affichageWeb;
  114.         return $this;
  115.     }
  116.     public function getAffichageWeb(): ?bool
  117.     {
  118.         return $this->affichageWeb;
  119.     }
  120. }