src/Entity/Project.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\CustomSlugify;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Gedmo\Translatable\Translatable;
  10. use JsonSerializable;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\ProjectRepository")
  14.  * @ORM\HasLifecycleCallbacks()
  15.  */
  16. class Project implements JsonSerializableTranslatable
  17. {
  18.     use CustomSlugify;
  19.     /**
  20.      * @ORM\Id()
  21.      * @ORM\GeneratedValue()
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=128)
  27.      * @Assert\Length(min = 3, max = 50, allowEmptyString = false )
  28.      */
  29.     private $companyName;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $websiteCompany;
  34.     /**
  35.      * @ORM\Column(type="string", length=100)
  36.      * @Assert\Length(min = 3, max = 50, allowEmptyString = false )
  37.      */
  38.     private $name;
  39.     /**
  40.      * @Gedmo\Translatable
  41.      * @ORM\Column(type="string", length=2048, nullable=true)
  42.      */
  43.     private $description;
  44.     /**
  45.      * @ORM\Column(type="date")
  46.      */
  47.     private $year;
  48.     /**
  49.      * @ORM\Column(type="string", length=128, nullable=true)
  50.      * @Assert\Regex("/[A-Za-z]/")
  51.      */
  52.     private $city;
  53.     /**
  54.      * @ORM\Column(type="string", length=25)
  55.      * @Assert\Regex("/[0-9]/")
  56.      */
  57.     private $areaM;
  58.     /**
  59.      * @ORM\Column(type="string", length=255, nullable=true)
  60.      * @Assert\Length(min = 4, max = 50, allowEmptyString = false )
  61.      */
  62.     private $architect;
  63.     /**
  64.      * @ORM\Column(type="string", length=255, nullable=true)
  65.      */
  66.     private $websiteArchitect;
  67.     /**
  68.      * @ORM\Column(type="string", length=255, nullable=true)
  69.      */
  70.     private $photography;
  71.     /**
  72.      * @ORM\Column(type="string", length=255, nullable=true)
  73.      */
  74.     private $installation;
  75.     /**
  76.      * @ORM\Column(type="boolean", nullable=true)
  77.      */
  78.     private $actif;
  79.     /**
  80.      * @ORM\Column(length=128, unique=true)
  81.      */
  82.     private $slug;
  83.     /**
  84.      * @var DateTime
  85.      * @Gedmo\Timestampable(on="create")
  86.      * @ORM\Column(type="datetime", nullable=true)
  87.      */
  88.     protected $createdAt;
  89.     /**
  90.      * @var DateTime
  91.      * @Gedmo\Timestampable(on="update")
  92.      * @ORM\Column(type="datetime", nullable=true)
  93.      */
  94.     protected $updatedAt;
  95.     /**
  96.      * @ORM\ManyToOne(targetEntity="App\Entity\KindProject", inversedBy="projects", fetch="EAGER")
  97.      * @ORM\JoinColumn(nullable=false)
  98.      */
  99.     private $kindProject;
  100.     /**
  101.      * @ORM\ManyToOne(targetEntity="App\Entity\Country", inversedBy="projects")
  102.      * @ORM\JoinColumn(nullable=false)
  103.      */
  104.     private $country;
  105.     /**
  106.      * @ORM\ManyToMany(targetEntity="App\Entity\Product", mappedBy="projects", cascade={"persist"})
  107.      * @ORM\JoinTable(name="product_project")
  108.      */
  109.     private $products;
  110.     /**
  111.      * @ORM\OneToMany(targetEntity="App\Entity\Attachment", mappedBy="project", cascade={"persist", "remove"}, fetch="EAGER")
  112.      */
  113.     private $attachments;
  114.     /**
  115.      * @ORM\ManyToMany(targetEntity="App\Entity\Shape", mappedBy="projects", fetch="EAGER", cascade={"persist"})
  116.      * @ORM\JoinTable(name="shape_project")
  117.      */
  118.     private $shapes;
  119.     public function __construct()
  120.     {
  121.         $this->products = new ArrayCollection();
  122.         $this->attachments = new ArrayCollection();
  123.         $this->shapes = new ArrayCollection();
  124.     }
  125.     public function setTranslatableLocale($locale)
  126.     {
  127.         $this->locale $locale;
  128.     }
  129.     public function __toString()
  130.     {
  131.         return $this->name.'';
  132.     }
  133.     public function jsonSerialize()
  134.     {
  135.         return [
  136.             'id' => $this->id,
  137.             'name' => $this->name,
  138.             'description' => $this->description,
  139.             'kindProject' => $this->kindProject,
  140.             'slug' => $this->slug,
  141.             'products' => $this->getProducts()->getValues(),
  142.             'country' => $this->country,
  143.             'attachments' => isset($this->attachmentsFile) ? $this->attachmentsFile null,
  144.             'architect' => $this->getArchitect(),
  145.             'city' => $this->getCity(),
  146.             'areaM' => $this->getAreaM()
  147.         ];
  148.     }
  149.     public function getId(): ?int
  150.     {
  151.         return $this->id;
  152.     }
  153.     public function getCompanyName(): ?string
  154.     {
  155.         return $this->companyName;
  156.     }
  157.     public function setCompanyName(string $companyName): self
  158.     {
  159.         $this->companyName $companyName;
  160.         return $this;
  161.     }
  162.     public function getWebsiteCompany(): ?string
  163.     {
  164.         return $this->websiteCompany;
  165.     }
  166.     public function setWebsiteCompany(?string $websiteCompany): self
  167.     {
  168.         $this->websiteCompany $websiteCompany;
  169.         return $this;
  170.     }
  171.     public function getName(): ?string
  172.     {
  173.         return $this->name;
  174.     }
  175.     public function setName(string $name): self
  176.     {
  177.         $this->name $name;
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return mixed
  182.      */
  183.     public function getDescription()
  184.     {
  185.         return $this->description;
  186.     }
  187.     /**
  188.      * @param mixed $description
  189.      */
  190.     public function setDescription($description): void
  191.     {
  192.         $this->description $description;
  193.     }
  194.     public function getYear(): ?\DateTimeInterface
  195.     {
  196.         return $this->year;
  197.     }
  198.     public function setYear(\DateTimeInterface $year): self
  199.     {
  200.         $this->year $year;
  201.         return $this;
  202.     }
  203.     public function getCity(): ?string
  204.     {
  205.         return $this->city;
  206.     }
  207.     public function setCity(?string $city): self
  208.     {
  209.         $this->city $city;
  210.         return $this;
  211.     }
  212.     public function getAreaM(): ?string
  213.     {
  214.         return $this->areaM;
  215.     }
  216.     public function setAreaM(string $areaM): self
  217.     {
  218.         $this->areaM $areaM;
  219.         return $this;
  220.     }
  221.     public function getArchitect(): ?string
  222.     {
  223.         return $this->architect;
  224.     }
  225.     public function setArchitect(?string $architect): self
  226.     {
  227.         $this->architect $architect;
  228.         return $this;
  229.     }
  230.     public function getWebsiteArchitect(): ?string
  231.     {
  232.         return $this->websiteArchitect;
  233.     }
  234.     public function setWebsiteArchitect(?string $websiteArchitect): self
  235.     {
  236.         $this->websiteArchitect $websiteArchitect;
  237.         return $this;
  238.     }
  239.     public function getPhotography(): ?string
  240.     {
  241.         return $this->photography;
  242.     }
  243.     public function setPhotography(?string $photography): self
  244.     {
  245.         $this->photography $photography;
  246.         return $this;
  247.     }
  248.     public function getInstallation(): ?string
  249.     {
  250.         return $this->installation;
  251.     }
  252.     public function setInstallation(?string $installation): self
  253.     {
  254.         $this->installation $installation;
  255.         return $this;
  256.     }
  257.     public function getActif(): ?bool
  258.     {
  259.         return $this->actif;
  260.     }
  261.     public function setActif(?bool $actif): self
  262.     {
  263.         $this->actif $actif;
  264.         return $this;
  265.     }
  266.     /**
  267.      * @return mixed
  268.      */
  269.     public function getSlug()
  270.     {
  271.         return $this->slug;
  272.     }
  273.     /**
  274.      * @param mixed $slug
  275.      * @return Project
  276.      */
  277.     public function setSlug($slug)
  278.     {
  279.         $this->slug $slug;
  280.         return $this;
  281.     }
  282.     /**
  283.      * @ORM\PrePersist
  284.      * @ORM\PreUpdate
  285.      */
  286.     public function updateSlug()
  287.     {
  288.         $this->slug $this->slugify($this->name);
  289.     }
  290.     /**
  291.      * @return DateTime
  292.      */
  293.     public function getCreatedAt(): DateTime
  294.     {
  295.         return $this->createdAt;
  296.     }
  297.     /**
  298.      * @param DateTime $createdAt
  299.      */
  300.     public function setCreatedAt(DateTime $createdAt): void
  301.     {
  302.         $this->createdAt $createdAt;
  303.     }
  304.     /**
  305.      * @return DateTime
  306.      */
  307.     public function getUpdatedAt(): DateTime
  308.     {
  309.         return $this->updatedAt;
  310.     }
  311.     /**
  312.      * @param DateTime $updatedAt
  313.      */
  314.     public function setUpdatedAt(DateTime $updatedAt): void
  315.     {
  316.         $this->updatedAt $updatedAt;
  317.     }
  318.     public function getKindProject(): ?KindProject
  319.     {
  320.         return $this->kindProject;
  321.     }
  322.     public function setKindProject(?KindProject $kindProject): self
  323.     {
  324.         $this->kindProject $kindProject;
  325.         return $this;
  326.     }
  327.     public function getCountry(): ?Country
  328.     {
  329.         return $this->country;
  330.     }
  331.     public function setCountry(?Country $country): self
  332.     {
  333.         $this->country $country;
  334.         return $this;
  335.     }
  336.     /**
  337.      * @return Collection|Product[]
  338.      */
  339.     public function getProducts(): Collection
  340.     {
  341.         return $this->products;
  342.     }
  343.     public function addProduct(Product $product): self
  344.     {
  345.         if (!$this->products->contains($product)) {
  346.             $this->products[] = $product;
  347.             $product->addProject($this);
  348.         }
  349.         return $this;
  350.     }
  351.     public function removeProduct(Product $product): self
  352.     {
  353.         if ($this->products->contains($product)) {
  354.             $this->products->removeElement($product);
  355.             $product->removeProject($this);
  356.         }
  357.         return $this;
  358.     }
  359.     /**
  360.      * @return Collection|Attachment[]
  361.      */
  362.     public function getAttachments(): Collection
  363.     {
  364.         return $this->attachments;
  365.     }
  366.     public function addAttachment(Attachment $attachment): self
  367.     {
  368.         if (!$this->attachments->contains($attachment)) {
  369.             $this->attachments[] = $attachment;
  370.             $attachment->setProject($this);
  371.         }
  372.         return $this;
  373.     }
  374.     /**
  375.      * @param Attachment[] $attachement
  376.      * @return $this
  377.      */
  378.     public function addAllAttachments(array $attachements): self
  379.     {
  380.         foreach ($attachements as $attachement) {
  381.             $this->addAttachment($attachement);
  382.         }
  383.         return $this;
  384.     }
  385.     public function removeAttachment(Attachment $attachment): self
  386.     {
  387.         if ($this->attachments->contains($attachment)) {
  388.             $this->attachments->removeElement($attachment);
  389.             // set the owning side to null (unless already changed)
  390.             if ($attachment->getProject() === $this) {
  391.                 $attachment->setProject(null);
  392.             }
  393.         }
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection|Shape[]
  398.      */
  399.     public function getShapes(): Collection
  400.     {
  401.         return $this->shapes;
  402.     }
  403.     public function addShape(Shape $shape): self
  404.     {
  405.         if (!$this->shapes->contains($shape)) {
  406.             $this->shapes[] = $shape;
  407.             $shape->addProject($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removeShape(Shape $shape): self
  412.     {
  413.         if ($this->shapes->contains($shape)) {
  414.             $this->shapes->removeElement($shape);
  415.             $shape->removeProject($this);
  416.         }
  417.         return $this;
  418.     }
  419. }