<?php
namespace App\Entity;
use App\Traits\CustomSlugify;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
use JsonSerializable;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\ProjectRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Project implements JsonSerializable, Translatable
{
use CustomSlugify;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
* @Assert\Length(min = 3, max = 50, allowEmptyString = false )
*/
private $companyName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $websiteCompany;
/**
* @ORM\Column(type="string", length=100)
* @Assert\Length(min = 3, max = 50, allowEmptyString = false )
*/
private $name;
/**
* @Gedmo\Translatable
* @ORM\Column(type="string", length=2048, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="date")
*/
private $year;
/**
* @ORM\Column(type="string", length=128, nullable=true)
* @Assert\Regex("/[A-Za-z]/")
*/
private $city;
/**
* @ORM\Column(type="string", length=25)
* @Assert\Regex("/[0-9]/")
*/
private $areaM;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(min = 4, max = 50, allowEmptyString = false )
*/
private $architect;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $websiteArchitect;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photography;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $installation;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $actif;
/**
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @var DateTime
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime", nullable=true)
*/
protected $createdAt;
/**
* @var DateTime
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime", nullable=true)
*/
protected $updatedAt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\KindProject", inversedBy="projects", fetch="EAGER")
* @ORM\JoinColumn(nullable=false)
*/
private $kindProject;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Country", inversedBy="projects")
* @ORM\JoinColumn(nullable=false)
*/
private $country;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Product", mappedBy="projects", cascade={"persist"})
* @ORM\JoinTable(name="product_project")
*/
private $products;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Attachment", mappedBy="project", cascade={"persist", "remove"}, fetch="EAGER")
*/
private $attachments;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Shape", mappedBy="projects", fetch="EAGER", cascade={"persist"})
* @ORM\JoinTable(name="shape_project")
*/
private $shapes;
public function __construct()
{
$this->products = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->shapes = new ArrayCollection();
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function __toString()
{
return $this->name.'';
}
public function jsonSerialize()
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'kindProject' => $this->kindProject,
'slug' => $this->slug,
'products' => $this->getProducts()->getValues(),
'country' => $this->country,
'attachments' => isset($this->attachmentsFile) ? $this->attachmentsFile : null,
'architect' => $this->getArchitect(),
'city' => $this->getCity(),
'areaM' => $this->getAreaM()
];
}
public function getId(): ?int
{
return $this->id;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(string $companyName): self
{
$this->companyName = $companyName;
return $this;
}
public function getWebsiteCompany(): ?string
{
return $this->websiteCompany;
}
public function setWebsiteCompany(?string $websiteCompany): self
{
$this->websiteCompany = $websiteCompany;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $description
*/
public function setDescription($description): void
{
$this->description = $description;
}
public function getYear(): ?\DateTimeInterface
{
return $this->year;
}
public function setYear(\DateTimeInterface $year): self
{
$this->year = $year;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getAreaM(): ?string
{
return $this->areaM;
}
public function setAreaM(string $areaM): self
{
$this->areaM = $areaM;
return $this;
}
public function getArchitect(): ?string
{
return $this->architect;
}
public function setArchitect(?string $architect): self
{
$this->architect = $architect;
return $this;
}
public function getWebsiteArchitect(): ?string
{
return $this->websiteArchitect;
}
public function setWebsiteArchitect(?string $websiteArchitect): self
{
$this->websiteArchitect = $websiteArchitect;
return $this;
}
public function getPhotography(): ?string
{
return $this->photography;
}
public function setPhotography(?string $photography): self
{
$this->photography = $photography;
return $this;
}
public function getInstallation(): ?string
{
return $this->installation;
}
public function setInstallation(?string $installation): self
{
$this->installation = $installation;
return $this;
}
public function getActif(): ?bool
{
return $this->actif;
}
public function setActif(?bool $actif): self
{
$this->actif = $actif;
return $this;
}
/**
* @return mixed
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param mixed $slug
* @return Project
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updateSlug()
{
$this->slug = $this->slugify($this->name);
}
/**
* @return DateTime
*/
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @param DateTime $createdAt
*/
public function setCreatedAt(DateTime $createdAt): void
{
$this->createdAt = $createdAt;
}
/**
* @return DateTime
*/
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
/**
* @param DateTime $updatedAt
*/
public function setUpdatedAt(DateTime $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
public function getKindProject(): ?KindProject
{
return $this->kindProject;
}
public function setKindProject(?KindProject $kindProject): self
{
$this->kindProject = $kindProject;
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
/**
* @return Collection|Product[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->addProject($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
$product->removeProject($this);
}
return $this;
}
/**
* @return Collection|Attachment[]
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(Attachment $attachment): self
{
if (!$this->attachments->contains($attachment)) {
$this->attachments[] = $attachment;
$attachment->setProject($this);
}
return $this;
}
/**
* @param Attachment[] $attachement
* @return $this
*/
public function addAllAttachments(array $attachements): self
{
foreach ($attachements as $attachement) {
$this->addAttachment($attachement);
}
return $this;
}
public function removeAttachment(Attachment $attachment): self
{
if ($this->attachments->contains($attachment)) {
$this->attachments->removeElement($attachment);
// set the owning side to null (unless already changed)
if ($attachment->getProject() === $this) {
$attachment->setProject(null);
}
}
return $this;
}
/**
* @return Collection|Shape[]
*/
public function getShapes(): Collection
{
return $this->shapes;
}
public function addShape(Shape $shape): self
{
if (!$this->shapes->contains($shape)) {
$this->shapes[] = $shape;
$shape->addProject($this);
}
return $this;
}
public function removeShape(Shape $shape): self
{
if ($this->shapes->contains($shape)) {
$this->shapes->removeElement($shape);
$shape->removeProject($this);
}
return $this;
}
}