mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-23 02:34:24 +00:00
233 lines
4.2 KiB
PHP
233 lines
4.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Chill is a software for social workers.
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* ClosingMotive give an explanation why we closed the Accompanying period.
|
|
*
|
|
* @ORM\Entity
|
|
* @ORM\Table(name="chill_person_accompanying_period_closingmotive")
|
|
*/
|
|
class ClosingMotive
|
|
{
|
|
/**
|
|
* @var bool
|
|
*
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
private $active = true;
|
|
|
|
/**
|
|
* Child Accompanying periods.
|
|
*
|
|
* @var Collection
|
|
*
|
|
* @ORM\OneToMany(
|
|
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
|
|
* mappedBy="parent")
|
|
*/
|
|
private $children;
|
|
|
|
/**
|
|
* @var int
|
|
*
|
|
* @ORM\Id
|
|
* @ORM\Column(name="id", type="integer")
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @var array
|
|
*
|
|
* @ORM\Column(type="json")
|
|
*/
|
|
private $name;
|
|
|
|
/**
|
|
* @var float
|
|
*
|
|
* @ORM\Column(type="float")
|
|
*/
|
|
private $ordering = 0.0;
|
|
|
|
/**
|
|
* @var self
|
|
*
|
|
* @ORM\ManyToOne(
|
|
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
|
|
* inversedBy="children")
|
|
*/
|
|
private $parent;
|
|
|
|
/**
|
|
* ClosingMotive constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->children = new ArrayCollection();
|
|
}
|
|
|
|
public function addChildren(ClosingMotive $child): ClosingMotive
|
|
{
|
|
if ($this->children->contains($child)) {
|
|
return $this;
|
|
}
|
|
|
|
$this->children->add($child);
|
|
$child->setParent($this);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getChildren(): Collection
|
|
{
|
|
return $this->children;
|
|
}
|
|
|
|
/**
|
|
* Get id.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getId()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Get name.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getName()
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function getOrdering(): float
|
|
{
|
|
return $this->ordering;
|
|
}
|
|
|
|
/**
|
|
* @return ClosingMotive
|
|
*/
|
|
public function getParent()
|
|
{
|
|
return $this->parent;
|
|
}
|
|
|
|
public function hasParent(): bool
|
|
{
|
|
return null !== $this->parent;
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return $this->active;
|
|
}
|
|
|
|
public function isChild(): bool
|
|
{
|
|
return null !== $this->parent;
|
|
}
|
|
|
|
public function isLeaf(): bool
|
|
{
|
|
return $this->children->count() === 0;
|
|
}
|
|
|
|
public function isParent(): bool
|
|
{
|
|
return $this->children->count() > 0;
|
|
}
|
|
|
|
public function removeChildren(ClosingMotive $child): ClosingMotive
|
|
{
|
|
if ($this->children->removeElement($child)) {
|
|
$child->setParent(null);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function setActive(bool $active)
|
|
{
|
|
$this->active = $active;
|
|
|
|
if (false === $this->active) {
|
|
foreach ($this->getChildren() as $child) {
|
|
$child->setActive(false);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setChildren(Collection $children): ClosingMotive
|
|
{
|
|
$this->children = $children;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set name.
|
|
*
|
|
* @param array $name
|
|
*
|
|
* @return ClosingMotive
|
|
*/
|
|
public function setName($name)
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function setOrdering(float $ordering)
|
|
{
|
|
$this->ordering = $ordering;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setParent(?ClosingMotive $parent): ClosingMotive
|
|
{
|
|
$this->parent = $parent;
|
|
|
|
if (null !== $parent) {
|
|
//$parent->addChildren($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|