<?php
namespace App\Entity;
use App\Repository\ActivityRepository;
use App\Traits\DateTrait;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=ActivityRepository::class)
*
* @ORM\HasLifecycleCallbacks
*
* @Serializer\ExclusionPolicy("ALL")
* @Vich\Uploadable
*/
class Activity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose
* @Groups({"activity"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Expose
* @Groups({"activity"})
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Expose
* @Groups({"activity"})
*/
private $path;
// Vich Uploader
/**
* @Vich\UploadableField(mapping="activity_images", fileNameProperty="path")
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="boolean", nullable=true)
*
* @Expose
* @Groups({"activity"})
*/
private $mainActivity;
/**
* @ORM\OneToMany(targetEntity=Devis::class, mappedBy="mainActivity")
* @ORM\JoinColumn(nullable=true)
*
*/
private $mainDevis;
/**
* @ORM\OneToMany(targetEntity=Devis::class, mappedBy="secondaryActivity")
* @ORM\JoinColumn(nullable=true)
*/
private $secondaryDevis;
/**
* @ORM\Column(type="boolean", nullable=true)
*
* @Expose
* @Groups({"activity"})
*/
private $enabled;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $slug;
use DateTrait;
public function __construct()
{
$this->mainDevis = new ArrayCollection();
$this->secondaryDevis = new ArrayCollection();
}
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param File|UploadedFile|null $imageFile
*/
public function setImageFile( File $imageFile )
{
$this->imageFile = $imageFile;
if ( NULL !== $imageFile ) {
// 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
$this->updatedAt = new DateTimeImmutable();
}
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName( string $name ): self
{
$this->name = $name;
return $this;
}
public function getPath(): ?string
{
return $this->path;
}
public function setPath( string $path ): self
{
$this->path = $path;
return $this;
}
/**
* @return Collection|Devis[]
*/
public function getMainDevis(): Collection
{
return $this->mainDevis;
}
public function addMainDevi( Devis $mainDevi ): self
{
if ( !$this->mainDevis->contains( $mainDevi ) ) {
$this->mainDevis[] = $mainDevi;
$mainDevi->setMainActivity( $this );
}
return $this;
}
public function removeMainDevi( Devis $mainDevi ): self
{
if ( $this->mainDevis->removeElement( $mainDevi ) ) {
// set the owning side to null (unless already changed)
if ( $mainDevi->getMainActivity() === $this ) {
$mainDevi->setMainActivity( NULL );
}
}
return $this;
}
public function getMainActivity(): ?bool
{
return $this->mainActivity;
}
public function setMainActivity( ?bool $mainActivity ): self
{
$this->mainActivity = $mainActivity;
return $this;
}
/**
* @return Collection|Devis[]
*/
public function getSecondaryDevis(): Collection
{
return $this->secondaryDevis;
}
public function addSecondaryDevi( Devis $secondaryDevi ): self
{
if ( !$this->secondaryDevis->contains( $secondaryDevi ) ) {
$this->secondaryDevis[] = $secondaryDevi;
$secondaryDevi->setSecondaryActivity( $this );
}
return $this;
}
public function removeSecondaryDevi( Devis $secondaryDevi ): self
{
if ( $this->secondaryDevis->removeElement( $secondaryDevi ) ) {
// set the owning side to null (unless already changed)
if ( $secondaryDevi->getSecondaryActivity() === $this ) {
$secondaryDevi->setSecondaryActivity( NULL );
}
}
return $this;
}
public function getEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled( ?bool $enabled ): self
{
$this->enabled = $enabled;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug( ?string $slug ): self
{
$this->slug = $slug;
return $this;
}
}