← Back
Editing: Item.php
<?php namespace App\Entity; use App\Enum\NotationType; use App\Repository\ItemRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; use Symfony\Component\Validator\Constraints as Assert; #[ORM\Table(name: 'tr_item')] #[ORM\Index(columns: ['zone_id'], name: 'IDX_1F1B251E9F2C3FAB')] #[ORM\Entity(repositoryClass: ItemRepository::class)] class Item { #[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)] #[Groups(['show_address', 'show_address_detail', 'show_user', 'supervisor_items'])] private string $nom; #[Assert\NotNull] #[ORM\ManyToOne(targetEntity: 'Zone', inversedBy: 'items')] #[ORM\JoinColumn(name: 'zone_id', referencedColumnName: 'id', nullable: false)] #[Groups(['show_address', 'show_address_detail', 'show_user'])] private ?Zone $zone = null; #[ORM\ManyToMany(targetEntity: 'Adresse', mappedBy: 'items')] private Collection $adresses; #[ORM\OneToMany(mappedBy: 'item', targetEntity: 'Note')] private Collection $notes; #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => 1])] private bool $assignToProvider = true; private bool $addToExistingAddresses; #[ORM\ManyToMany(targetEntity: ControlTemplate::class, mappedBy: 'items')] private Collection $controlTemplates; #[ORM\Column(type: 'string', length: 15, enumType: NotationType::class, options: ['default' => NotationType::STARS_5])] #[Groups(['show_address_detail'])] private NotationType $notationType = NotationType::STARS_5; /** @var Collection<int, Agency> $agencies */ #[ORM\ManyToMany(targetEntity: Agency::class, mappedBy: 'defaultAddressItems')] private Collection $agencies; public function __toString() { return $this->getNom(); } public function __construct() { $this->agencies = new ArrayCollection(); $this->adresses = new ArrayCollection(); $this->notes = new ArrayCollection(); $this->controlTemplates = 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 getZone(): ?Zone { return $this->zone; } public function setZone(?Zone $zone): self { $this->zone = $zone; return $this; } public function getNotes(): ?Collection { return $this->notes; } public function getAdresses(): ?Collection { return $this->adresses; } public function addAdress(Adresse $adress): self { if (!$this->adresses->contains($adress)) { $this->adresses[] = $adress; $adress->addItem($this); } return $this; } public function removeAdress(Adresse $adress): self { if ($this->adresses->contains($adress)) { $this->adresses->removeElement($adress); $adress->removeItem($this); } return $this; } public function addNote(Note $note): self { if (!$this->notes->contains($note)) { $this->notes[] = $note; $note->setItem($this); } return $this; } #[Groups(['supervisor_items'])] public function getNameWithZone(): string { return $this->getZone()->getNom().' : '.$this->getNom(); } public function isAddToExistingAddresses(): bool { return $this->addToExistingAddresses; } public function setAddToExistingAddresses(bool $addToExistingAddresses): void { $this->addToExistingAddresses = $addToExistingAddresses; } public function getAssignToProvider(): ?bool { return $this->assignToProvider; } public function setAssignToProvider(bool $assignToProvider): self { $this->assignToProvider = $assignToProvider; return $this; } /** * @return Collection<int, ControlTemplate> */ public function getControlTemplates(): Collection { return $this->controlTemplates; } public function addControlTemplate(ControlTemplate $controlTemplate): self { if (!$this->controlTemplates->contains($controlTemplate)) { $this->controlTemplates[] = $controlTemplate; $controlTemplate->addItem($this); } return $this; } public function removeControlTemplate(ControlTemplate $controlTemplate): self { if ($this->controlTemplates->removeElement($controlTemplate)) { $controlTemplate->removeItem($this); } return $this; } public function isAssignToProvider(): ?bool { return $this->assignToProvider; } public function getNotationType(): NotationType { return $this->notationType; } public function setNotationType(NotationType $notationType): self { $this->notationType = $notationType; return $this; } public function removeNote(Note $note): self { if ($this->notes->removeElement($note)) { // set the owning side to null (unless already changed) if ($note->getItem() === $this) { $note->setItem(null); } } return $this; } // @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->getZone()->getRoot()->getThematic()->getName(); $exclude = ['Propreté', 'Information et éclairage', 'Sécurité']; if (in_array($thematicName, $exclude, true)) { return $this->getNom(); } $zone = $this->getZone(); $zoneNames = [$zone->getNom()]; while ($parentZone = $zone->getParent()) { $zoneNames[] = $zone->getNom(); $zone = $parentZone; } return implode('>', $zoneNames).' > '.$this->getNom(); } public function getAgencies(): Collection { return $this->agencies; } public function setAgencies(Collection $agencies): self { $this->agencies = $agencies; return $this; } }
Save File
Cancel