<?php
/**
* Created by PhpStorm.
* User: dada
* Date: 12/07/19
* Time: 20:34
*/
namespace App\Entity\Tutoring;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\Tutoring\RessourceRepository;
use App\Traits\Actions;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OrderBy;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Doctrine\ORM\Event\LifecycleEventArgs;
/**
* Ressource
*
* @ORM\HasLifecycleCallbacks()
*/
#[ORM\Entity(repositoryClass: RessourceRepository::class)]
#[ORM\Table(name: 'hs_tc_tutoring_ressource')]
#[ApiResource]
class Ressource
{
use Actions;
final public const IMAGE_FOLDER='uploads/images';
#[ORM\ManyToOne(targetEntity: Course::class, inversedBy: 'ressources')]
#[ORM\JoinColumn(nullable: true)]
private $course;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', length: 255, nullable: true)]
private $name;
/**
* @var string
* video, pdf , image, word, Excel
*/
#[ORM\Column(name: 'type', type: 'string', length: 255)]
private $type;
/**
* @var string
* cours, exercice, TP,
*/
#[ORM\Column(name: 'genre', type: 'string', length: 255)]
private $genre;
/**
* @var string
*/
#[ORM\Column(name: 'lesson', type: 'string', length: 255)]
private $lesson;
/**
* @var string
*/
#[ORM\Column(name: 'link', type: 'string', length: 255)]
private $link;
/**
* @var string
*/
#[ORM\Column(name: 'file_name', type: 'string', length: 255)]
private $fileName;
private ?\Symfony\Component\HttpFoundation\File\UploadedFile $file = null;
/**
* @var string
*/
#[ORM\Column(name: 'change_files', type: 'string', length: 255, nullable: true)]
private $changeFiles;
public function __construct()
{
$this->createAt=new \DateTime('now');
$this->published=true;
}
/**
* @return mixed
*/
public function getCourse()
{
return $this->course;
}
/**
* @return Ressource
*/
public function setCourse(mixed $course)
{
$this->course = $course;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
* @return Ressource
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type
* @return Ressource
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* @return string
*/
public function getGenre()
{
return $this->genre;
}
/**
* @param string $genre
* @return Ressource
*/
public function setGenre($genre)
{
$this->genre = $genre;
return $this;
}
/**
* @return string
*/
public function getLesson()
{
return $this->lesson;
}
/**
* @param string $lesson
* @return Ressource
*/
public function setLesson($lesson)
{
$this->lesson = $lesson;
return $this;
}
/**
* @return string
*/
public function getLink()
{
return $this->link;
}
/**
* @param string $link
* @return Ressource
*/
public function setLink($link)
{
$this->link = $link;
return $this;
}
/**
* @return string
*/
public function getFileName()
{
return $this->fileName;
}
/**
* @param string $fileName
* @return Ressource
*/
public function setFileName($fileName)
{
$this->fileName = $fileName;
return $this;
}
/**
* @return mixed
*/
public function getFile()
{
return $this->file;
}
/**
* @param mixed $file
*/
public function setFile(UploadedFile $file=null)
{
$this->file = $file;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function upload()
{
if($this->file!==null){
$name = $this->file->getClientOriginalName();
$name = md5(uniqid()) .'_'. $name;
$this->file->move(self::IMAGE_FOLDER,$name);
$this->setFileName($name);
$this->setFile(null);
}
}
/**
* @return string
*/
public function getChangeFiles()
{
return $this->changeFiles;
}
/**
* @param string $changeFiles
* @return Ressource
*/
public function setChangeFiles($changeFiles)
{
$this->changeFiles = $changeFiles;
return $this;
}
}