<?php
namespace App\Entity;
use App\Repository\RessourcesRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use phpDocumentor\Reflection\Types\Null_;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: RessourcesRepository::class)]
#[Vich\Uploadable]
class Ressources
{
public const STATUS_ARRAY = [
'WAITING' => 'en cours',
'VALIDATED' => 'validé',
'REFUSED' => 'refusé',
];
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $Categorie;
#[ORM\Column(type: 'string', length: 255)]
private $titre;
#[ORM\Column(type: 'string', length: 255)]
private $auteur;
#[ORM\Column(type: Types::TEXT, length: 10000)]
private $description;
#[ORM\Column(type: 'boolean')]
private $isPublic = false;
#[ORM\Column(type: 'date'),
Assert\NotBlank()
]
private $date_debut;
#[ORM\Column(type: 'date', nullable:true),
]
private $date_expiration;
#[ORM\Column(type:'string', length:255)]
private $image;
#[ORM\Column(type:'string', length:255)]
private $ressource;
#[Vich\UploadableField(mapping:'post_thumbnails', fileNameProperty:'image')]
private $ressourceFile;
#[ORM\Column(type: 'string', nullable:false, options:[ 'default' => self::STATUS_ARRAY['WAITING'] ])]
private $status = self::STATUS_ARRAY['WAITING'] ;
#[ORM\ManyToOne(inversedBy: 'ressources')]
private ?User $user = null;
public function getId(): ?int
{
return $this->id;
}
public function getCategorie(): ?string
{
return $this->Categorie;
}
public function setCategorie(string $Categorie): self
{
$this->Categorie = $Categorie;
return $this;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function isIsPublic(): ?bool
{
return $this->isPublic;
}
public function setIsPublic(bool $isPublic): self
{
$this->isPublic = $isPublic;
return $this;
}
public function getAuteur(): ?string
{
return $this->auteur;
}
public function setAuteur(string $auteur): self
{
$this->auteur = $auteur;
return $this;
}
public function getDateDebut(): ?\DateTimeInterface
{
return $this->date_debut;
}
public function setDateDebut(\DateTimeInterface $date_debut): self
{
$this->date_debut = $date_debut;
return $this;
}
public function getDateExpiration()
{
return $this->date_expiration;
}
public function setDateExpiration($date_expiration): self
{
$this->date_expiration = $date_expiration;
return $this;
}
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
// if ($image) {
// if 'updatedAt' is not defined in your entity, use another property
// $this->updatedAt = new \DateTime('now');
// }
}
public function getImageFile()
{
return $this->imageFile;
}
public function setImage($image)
{
$this->image = $image;
}
public function getImage()
{
return $this->image;
}
public function setRessource($ressource)
{
$this->ressource = $ressource;
}
public function getRessource()
{
return $this->ressource;
}
public function setRessourceFile(File $image = null)
{
$this->imageFile = $image;
// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
// if ($image) {
// if 'updatedAt' is not defined in your entity, use another property
// $this->updatedAt = new \DateTime('now');
// }
}
public function getRessourceFile()
{
return $this->imageFile;
}
public function getStatus()
{
return $this->status;
}
public function setStatus($status): self
{
$current_status = strtolower(array_search($this->status, self::STATUS_ARRAY));
if ($status) {
$this->status = self::STATUS_ARRAY[ strtoupper($status) ];
} else {
$this->status = self::STATUS_ARRAY[ strtoupper($current_status) ] ;
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}