mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Add new methods to RegroupmentRepository and fix association
Regroupment/Center
This commit is contained in:
@@ -48,12 +48,19 @@ class Center implements HasCenterInterface
|
||||
*/
|
||||
private string $name = '';
|
||||
|
||||
/**
|
||||
* @var Collection<Regroupment>
|
||||
* @ORM\ManyToMany(targetEntity=Regroupment::class, mappedBy="centers")
|
||||
*/
|
||||
private Collection $regroupments;
|
||||
|
||||
/**
|
||||
* Center constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->groupCenters = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
$this->groupCenters = new ArrayCollection();
|
||||
$this->regroupments = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,6 +113,14 @@ class Center implements HasCenterInterface
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<Regroupment>
|
||||
*/
|
||||
public function getRegroupments(): Collection
|
||||
{
|
||||
return $this->regroupments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
|
@@ -22,11 +22,12 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
class Regroupment
|
||||
{
|
||||
/**
|
||||
* @var Center
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity=Center::class
|
||||
* targetEntity=Center::class,
|
||||
* inversedBy="regroupments"
|
||||
* )
|
||||
* @ORM\Id
|
||||
* @var Collection<Center>
|
||||
*/
|
||||
private Collection $centers;
|
||||
|
||||
@@ -52,6 +53,26 @@ class Regroupment
|
||||
$this->centers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function addCenter(Center $center): self
|
||||
{
|
||||
if (!$this->centers->contains($center)) {
|
||||
$this->centers->add($center);
|
||||
$center->getRegroupments()->add($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeCenter(Center $center): self
|
||||
{
|
||||
if ($this->centers->contains($center)) {
|
||||
$this->centers->removeElement($center);
|
||||
$center->getRegroupments()->removeElement($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCenters(): Collection
|
||||
{
|
||||
return $this->centers;
|
||||
|
Reference in New Issue
Block a user