mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
In between commit implementing reciever
This commit is contained in:
54
application/src/Entity/Attribut/MembersAttribut.php
Normal file
54
application/src/Entity/Attribut/MembersAttribut.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
trait MembersAttribut
|
||||
{
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
protected $members;
|
||||
|
||||
public function getMembers(): Collection
|
||||
{
|
||||
return $this->members;
|
||||
}
|
||||
|
||||
public function setMembers(Collection $members): void
|
||||
{
|
||||
$this->members = $members;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $dimension The dimensions start with 1 for the members of the actuall dimension and NULL for all members
|
||||
* @param Collection $members A reference to a members list, to which new members should be add
|
||||
*
|
||||
* @return Collection|MembersAttributInterface[] Returns all members till the defined dimension
|
||||
*/
|
||||
public function getMembersInclusiveChildren(int $dimension = null, Collection &$members = null): Collection
|
||||
{
|
||||
// Subtract minus one, so that following members start on a other dimension:
|
||||
--$dimension;
|
||||
|
||||
//Define members if no members are passed
|
||||
if (!$members) {
|
||||
$members = new ArrayCollection();
|
||||
}
|
||||
foreach ($this->members as $member) {
|
||||
if (!$members->contains($member)) {
|
||||
$members->add($member);
|
||||
if ($dimension > 0 || null === $dimension) {
|
||||
$member->getMembersInclusiveChildren($dimension, $members);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $members;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user