src/Entity/Tutoring/Ressource.php line 27

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: dada
  5.  * Date: 12/07/19
  6.  * Time: 20:34
  7.  */
  8. namespace App\Entity\Tutoring;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use App\Repository\Tutoring\RessourceRepository;
  11. use App\Traits\Actions;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Doctrine\ORM\Mapping\OrderBy;
  14. use Symfony\Component\HttpFoundation\File\UploadedFile;
  15. use Doctrine\ORM\Event\LifecycleEventArgs;
  16. /**
  17.  * Ressource
  18.  *
  19.  * @ORM\HasLifecycleCallbacks()
  20.  */
  21. #[ORM\Entity(repositoryClassRessourceRepository::class)]
  22. #[ORM\Table(name'hs_tc_tutoring_ressource')]
  23. #[ApiResource]
  24. class Ressource
  25. {
  26.     use Actions;
  27.     final public const IMAGE_FOLDER='uploads/images';
  28.     #[ORM\ManyToOne(targetEntityCourse::class, inversedBy'ressources')]
  29.     #[ORM\JoinColumn(nullabletrue)]
  30.     private $course;
  31.     /**
  32.      * @var string
  33.      */
  34.     #[ORM\Column(name'name'type'string'length255nullabletrue)]
  35.     private $name;
  36.     /**
  37.      * @var string
  38.      * video, pdf , image, word, Excel
  39.      */
  40.     #[ORM\Column(name'type'type'string'length255)]
  41.     private $type;
  42.     /**
  43.      * @var string
  44.      * cours, exercice, TP,
  45.      */
  46.     #[ORM\Column(name'genre'type'string'length255)]
  47.     private $genre;
  48.     /**
  49.      * @var string
  50.      */
  51.     #[ORM\Column(name'lesson'type'string'length255)]
  52.     private $lesson;
  53.     /**
  54.      * @var string
  55.      */
  56.     #[ORM\Column(name'link'type'string'length255)]
  57.     private $link;
  58.     /**
  59.      * @var string
  60.      */
  61.     #[ORM\Column(name'file_name'type'string'length255)]
  62.     private $fileName;
  63.     private ?\Symfony\Component\HttpFoundation\File\UploadedFile $file null;
  64.     /**
  65.      * @var string
  66.      */
  67.     #[ORM\Column(name'change_files'type'string'length255nullabletrue)]
  68.     private $changeFiles;
  69.     public function __construct()
  70.     {
  71.         
  72.         $this->createAt=new \DateTime('now');
  73.         $this->published=true;
  74.     }
  75.     /**
  76.      * @return mixed
  77.      */
  78.     public function getCourse()
  79.     {
  80.         return $this->course;
  81.     }
  82.     /**
  83.      * @return Ressource
  84.      */
  85.     public function setCourse(mixed $course)
  86.     {
  87.         $this->course $course;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return string
  92.      */
  93.     public function getName()
  94.     {
  95.         return $this->name;
  96.     }
  97.     /**
  98.      * @param string $name
  99.      * @return Ressource
  100.      */
  101.     public function setName($name)
  102.     {
  103.         $this->name $name;
  104.         return $this;
  105.     }
  106.     /**
  107.      * @return string
  108.      */
  109.     public function getType()
  110.     {
  111.         return $this->type;
  112.     }
  113.     /**
  114.      * @param string $type
  115.      * @return Ressource
  116.      */
  117.     public function setType($type)
  118.     {
  119.         $this->type $type;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return string
  124.      */
  125.     public function getGenre()
  126.     {
  127.         return $this->genre;
  128.     }
  129.     /**
  130.      * @param string $genre
  131.      * @return Ressource
  132.      */
  133.     public function setGenre($genre)
  134.     {
  135.         $this->genre $genre;
  136.         return $this;
  137.     }
  138.     /**
  139.      * @return string
  140.      */
  141.     public function getLesson()
  142.     {
  143.         return $this->lesson;
  144.     }
  145.     /**
  146.      * @param string $lesson
  147.      * @return Ressource
  148.      */
  149.     public function setLesson($lesson)
  150.     {
  151.         $this->lesson $lesson;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return string
  156.      */
  157.     public function getLink()
  158.     {
  159.         return $this->link;
  160.     }
  161.     /**
  162.      * @param string $link
  163.      * @return Ressource
  164.      */
  165.     public function setLink($link)
  166.     {
  167.         $this->link $link;
  168.         return $this;
  169.     }
  170.     /**
  171.      * @return string
  172.      */
  173.     public function getFileName()
  174.     {
  175.         return $this->fileName;
  176.     }
  177.     /**
  178.      * @param string $fileName
  179.      * @return Ressource
  180.      */
  181.     public function setFileName($fileName)
  182.     {
  183.         $this->fileName $fileName;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return mixed
  188.      */
  189.     public function getFile()
  190.     {
  191.         return $this->file;
  192.     }
  193.     /**
  194.      * @param mixed $file
  195.      */
  196.     public function setFile(UploadedFile $file=null)
  197.     {
  198.         $this->file $file;
  199.     }
  200.     /**
  201.      * @ORM\PrePersist
  202.      * @ORM\PreUpdate
  203.      */
  204.     public function upload()
  205.     {
  206.         if($this->file!==null){
  207.             $name $this->file->getClientOriginalName();
  208.             $name md5(uniqid()) .'_'$name;
  209.             $this->file->move(self::IMAGE_FOLDER,$name);
  210.             $this->setFileName($name);
  211.             $this->setFile(null);
  212.         }
  213.     }
  214.     /**
  215.      * @return string
  216.      */
  217.     public function getChangeFiles()
  218.     {
  219.         return $this->changeFiles;
  220.     }
  221.     /**
  222.      * @param string $changeFiles
  223.      * @return Ressource
  224.      */
  225.     public function setChangeFiles($changeFiles)
  226.     {
  227.         $this->changeFiles $changeFiles;
  228.         return $this;
  229.     }
  230. }