<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Table(name="article")
* @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
* @Vich\Uploadable
* @ORM\HasLifecycleCallbacks()
*/
class Article
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
* @Assert\NotBlank(
* message="Champ obligatoire"
* )
*/
private $title;
/**
* @var string
*
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(type="string", unique=true)
*/
private $slug;
/**
* @var \DateTime
*
* @ORM\Column(name="create_at", type="datetime", nullable=false)
*/
private $createAt;
/**
* @var string
*
* @ORM\Column(name="content", type="text")
* @Assert\NotBlank(
* message="Champ obligatoire"
* )
*/
private $content;
/**
* @var Admin
*
* @ORM\ManyToOne(targetEntity="App\Entity\Admin")
* @ORM\JoinColumn(nullable=false, name="user_id")
*/
private $author;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $logo;
/**
* @Vich\UploadableField(mapping="marque_upload", fileNameProperty="logo")
* @var File
*/
public $logoFile;
/**
* @var ArrayCollection
* @ORM\ManyToMany(targetEntity="App\Entity\Tag", cascade={"persist"})
*/
private $tags;
public function __construct()
{
$this->tags = new ArrayCollection();
}
public function __toString()
{
return $this->getTitle();
}
public function getId(): ?int
{
return $this->id;
}
public function setTitle(?string $title): Article
{
$this->title = $title;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
/**
* @ORM\PrePersist
*/
public function setCreateAt(): self
{
$this->createAt = new \DateTime();
return $this;
}
public function getCreateAt(): ?\DateTime
{
return $this->createAt;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function getAuthor(): ?Admin
{
return $this->author;
}
public function setAuthor(Admin $author): self
{
$this->author = $author;
return $this;
}
public function addTag(Tag ...$tags): void
{
foreach ($tags as $tag) {
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
}
}
}
public function removeTag(Tag $tag): void
{
$this->tags->removeElement($tag);
}
public function getTags(): ?Collection
{
return $this->tags;
}
public function getSlug(): string
{
return $this->slug;
}
public function setSlug($slug): string
{
$this->slug = $slug;
return $this;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
}