← Back
Editing: Thematic.php
<?php namespace App\Entity; use App\Repository\ThematicRepository; use App\Solution\Annotation\SolutionAware; use App\Solution\SolutionTrait; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** * @SolutionAware(solutionFieldName="solution_id") */ #[ORM\Entity(repositoryClass: ThematicRepository::class)] class Thematic { use SolutionTrait; #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(length: 255)] private string $name; #[ORM\Column(nullable: true)] private ?int $position = null; #[ORM\OneToMany(mappedBy: 'thematic', targetEntity: Zone::class)] private Collection $zones; public function __construct() { $this->zones = new ArrayCollection(); } public function __toString(): string { return $this->name; } public function getId(): ?int { return $this->id; } public function getName(): string { return $this->name; } public function setName(string $name): static { $this->name = $name; return $this; } public function getPosition(): ?int { return $this->position; } public function setPosition(?int $position): static { $this->position = $position; return $this; } /** * @param Collection<array-key, Zone> $zones * * @return Thematic[] */ public static function getFromZones(Collection $zones): array { $arrayZones = $zones->toArray(); $thematics = array_map(fn (Zone $zone) => $zone->getRoot()->getThematic(), $arrayZones); $uniqueThematics = []; foreach ($thematics as $thematic) { $thematicIds = array_map( fn (Thematic $thematic) => $thematic->getId(), $uniqueThematics ); if (in_array($thematic->getId(), $thematicIds)) { continue; } $uniqueThematics[] = $thematic; } return $uniqueThematics; } public function getZones(): Collection { return $this->zones; } }
Save File
Cancel