← Back
Editing: Zone.php
<?php namespace App\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; use Symfony\Component\Validator\Constraints as Assert; #[Assert\Expression( '(!this.getParent() and this.getThematic()) or this.getParent()', message: 'Thematic is required for root zones!', )] #[Gedmo\Tree(type: 'nested')] #[ORM\Table(name: 'tr_zone')] #[ORM\Index(columns: ['nom'])] #[ORM\Entity(repositoryClass: 'App\Repository\ZoneRepository')] class Zone { #[ORM\Column(name: 'id', type: 'integer', nullable: false)] #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[Groups(['show_address', 'show_address_detail', 'show_user', 'supervisor_items'])] private ?int $id = null; #[ORM\Column(name: 'nom', type: 'string', length: 255, nullable: false)] private string $nom; #[Gedmo\TreeLeft] #[ORM\Column(name: 'lft', type: Types::INTEGER, nullable: true)] private ?int $lft = null; #[Gedmo\TreeLevel] #[ORM\Column(name: 'lvl', type: Types::INTEGER, nullable: true)] private ?int $lvl = null; #[Gedmo\TreeRight] #[ORM\Column(name: 'rgt', type: Types::INTEGER, nullable: true)] private ?int $rgt = null; #[Gedmo\TreeRoot] #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'allChildren')] #[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')] private ?self $root = null; #[Gedmo\TreeParent] #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')] private ?self $parent = null; #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] #[ORM\OrderBy(['lft' => 'ASC'])] private Collection $children; #[ORM\OneToMany(mappedBy: 'root', targetEntity: self::class)] private Collection $allChildren; #[ORM\ManyToOne(targetEntity: Thematic::class, inversedBy: 'zones')] private ?Thematic $thematic = null; #[ORM\Column(type: 'boolean', options: ['default' => 0])] private bool $excludeFromPresta = false; #[ORM\OneToMany(mappedBy: 'zone', targetEntity: Item::class)] #[Groups(['supervisor_items'])] private Collection $items; public function __construct() { $this->items = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getNom(): ?string { return $this->nom; } public function setNom(string $nom): self { $this->nom = $nom; return $this; } public function __toString(): string { return $this->getNom() ?? 'Zone sans nom'; } public function getItems(): Collection { return $this->items; } public function addItem(Item $item): self { if (!$this->items->contains($item)) { $this->items[] = $item; $item->setZone($this); } return $this; } public function getExcludeFromPresta(): ?bool { return $this->excludeFromPresta; } public function setExcludeFromPresta(bool $excludeFromPresta): self { $this->excludeFromPresta = $excludeFromPresta; return $this; } public function isExcludeFromPresta(): ?bool { return $this->excludeFromPresta; } public function removeItem(Item $item): self { if ($this->items->removeElement($item)) { // set the owning side to null (unless already changed) if ($item->getZone() === $this) { $item->setZone(null); } } return $this; } public function getThematic(): ?Thematic { return $this->thematic; } public function setThematic(?Thematic $thematic): self { $this->thematic = $thematic; return $this; } public function getRoot(): ?self { return $this->root; } public function setParent(?self $parent = null): void { $this->parent = $parent; } public function getParent(): ?self { return $this->parent; } public function getAllChildren(): Collection { return $this->allChildren; } public function setAllChildren(Collection $allChildren): self { $this->allChildren = $allChildren; return $this; } public function getChildren(): Collection { return $this->children; } // @todo: remove this method and use thematic and children into app code #[SerializedName('nom')] #[Groups(['show_address', 'show_address_detail', 'show_user', 'supervisor_items'])] public function getLegacyName(): string { $thematicName = $this->getRoot()->getThematic()->getName(); if ('Propreté' === $thematicName) { return sprintf('%s - %s', mb_strtoupper($thematicName), $this->getNom()); } return mb_strtoupper($thematicName); } }
Save File
Cancel