<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\SectorRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"sector:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"sector:write"}, "swagger_definition_name"="Write","skip_null_values" = true},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get"
* },
* attributes={
* "pagination_items_per_page"=10,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
* )
* @ORM\Entity(repositoryClass=SectorRepository::class)
*/
class Sector
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Groups({
* "directory:collaborator:search",
* "agent:read",
* "sector:read",
* "mandate:read",
* "milkiya:read"
* })
*/
private $id;
/**
* @ORM\OneToMany(targetEntity=Agent::class, mappedBy="sector")
*/
private $collaborators;
/**
* @ORM\OneToMany(targetEntity=Candidate::class, mappedBy="sector")
*/
private $candidates;
/**
* @ORM\ManyToMany(targetEntity=City::class, cascade={"persist"})
* @Groups({
* "directory:collaborator:search",
* "siege:put","siege:write",
* "candidate:read","candidate:write","candidate:put",
* "sector:read",
* "mandate:read",
* "agent:read",
* })
*/
private $cities;
/**
* @ORM\ManyToMany(targetEntity=Neighborhood::class, cascade={"persist"})
* @Groups({
* "directory:collaborator:search",
* "siege:put","siege:write",
* "candidate:read","candidate:write","candidate:put",
* "agent:read",
* "mandate:read"
* })
*/
private $neighborhoods;
/**
* @ORM\ManyToOne(targetEntity=City::class)
* @Groups({
* "directory:collaborator:search",
* "siege:put","siege:write",
* "candidate:read","candidate:write","candidate:put",
* "agent:read",
* "mandate:read",
* })
*/
private ?City $mainCity = null;
public function getId(): ?int
{
return $this->id;
}
public function __construct()
{
$this->collaborators = new ArrayCollection();
$this->candidates = new ArrayCollection();
$this->cities = new ArrayCollection();
$this->neighborhoods = new ArrayCollection();
}
/**
* @return Collection|Agent[]
*/
public function getCollaborators(): Collection
{
return $this->collaborators;
}
public function addCollaborator(Agent $collaborator): self
{
if (!$this->collaborators->contains($collaborator)) {
$this->collaborators[] = $collaborator;
$collaborator->setSector($this);
}
return $this;
}
public function removeCollaborator(Agent $collaborator): self
{
if ($this->collaborators->removeElement($collaborator)) {
// set the owning side to null (unless already changed)
if ($collaborator->getSector() === $this) {
$collaborator->setSector(null);
}
}
return $this;
}
/**
* @return Collection|Candidate[]
*/
public function getCandidates(): Collection
{
return $this->candidates;
}
public function addCandidate(Candidate $candidate): self
{
if (!$this->candidates->contains($candidate)) {
$this->candidates[] = $candidate;
$candidate->setSector($this);
}
return $this;
}
public function removeCandidate(Candidate $candidate): self
{
// set the owning side to null (unless already changed)
if ($this->candidates->removeElement($candidate) && $candidate->getSector() === $this) {
$candidate->setSector(null);
}
return $this;
}
/**
* @return Collection<int, City>
*/
public function getCities(): Collection
{
return $this->cities;
}
public function addCity(City $city): self
{
if (!$this->cities->contains($city)) {
$this->cities[] = $city;
}
return $this;
}
public function removeCity(City $city): self
{
$this->cities->removeElement($city);
return $this;
}
/**
* @return Collection<int, Neighborhood>
*/
public function getNeighborhoods(): Collection
{
return $this->neighborhoods;
}
public function addNeighborhood(Neighborhood $neighborhood): self
{
if (!$this->neighborhoods->contains($neighborhood)) {
$this->neighborhoods[] = $neighborhood;
}
return $this;
}
public function removeNeighborhood(Neighborhood $neighborhood): self
{
$this->neighborhoods->removeElement($neighborhood);
return $this;
}
public function getMainCity(): ?City
{
return $this->mainCity;
}
public function setMainCity(?City $mainCity): self
{
$this->mainCity = $mainCity;
return $this;
}
}