mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
210 lines
4.8 KiB
PHP
210 lines
4.8 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);
|
|
|
|
namespace Chill\PersonBundle\Entity\Person;
|
|
|
|
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
|
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
|
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
|
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
|
|
/**
|
|
* @ORM\Entity
|
|
* @ORM\Table(name="chill_person_resource")
|
|
* @DiscriminatorMap(typeProperty="type", mapping={
|
|
* "personResource": personResource::class
|
|
* })
|
|
*/
|
|
class PersonResource implements TrackCreationInterface, TrackUpdateInterface
|
|
{
|
|
use TrackCreationTrait;
|
|
|
|
use TrackUpdateTrait;
|
|
|
|
/**
|
|
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_")
|
|
* @Groups({"read"})
|
|
*/
|
|
private CommentEmbeddable $comment;
|
|
|
|
/**
|
|
* @ORM\Column(type="text", nullable=true)
|
|
* @Groups({"read"})
|
|
*/
|
|
private ?string $freeText = null;
|
|
|
|
/**
|
|
* @ORM\Id
|
|
* @ORM\GeneratedValue
|
|
* @ORM\Column(type="integer")
|
|
*/
|
|
private ?int $id;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity=PersonResourceKind::class, inversedBy="personResources")
|
|
* @ORM\JoinColumn(nullable=true)
|
|
* @Groups({"read"})
|
|
*/
|
|
private $kind;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="personResources")
|
|
* @ORM\JoinColumn(nullable=true)
|
|
* @Groups({"read"})
|
|
*/
|
|
private ?Person $person = null;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity=Person::class)
|
|
* @ORM\JoinColumn(nullable=false)
|
|
* @Groups({"read"})
|
|
*/
|
|
private ?Person $personOwner = null;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity=ThirdParty::class, inversedBy="personResources")
|
|
* @ORM\JoinColumn(nullable=true)
|
|
* @Groups({"read"})
|
|
*/
|
|
private ?ThirdParty $thirdParty = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->comment = new CommentEmbeddable();
|
|
}
|
|
|
|
public function getComment(): CommentEmbeddable
|
|
{
|
|
return $this->comment;
|
|
}
|
|
|
|
public function getFreeText(): ?string
|
|
{
|
|
return $this->freeText;
|
|
}
|
|
|
|
/**
|
|
* GETTERS.
|
|
*/
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getKind(): ?PersonResourceKind
|
|
{
|
|
return $this->kind;
|
|
}
|
|
|
|
public function getPerson(): ?Person
|
|
{
|
|
return $this->person;
|
|
}
|
|
|
|
public function getPersonOwner(): ?Person
|
|
{
|
|
return $this->personOwner;
|
|
}
|
|
|
|
public function getThirdParty(): ?ThirdParty
|
|
{
|
|
return $this->thirdParty;
|
|
}
|
|
|
|
public function setComment(?CommentEmbeddable $comment): self
|
|
{
|
|
if (null === $comment) {
|
|
$this->comment->setComment('');
|
|
|
|
return $this;
|
|
}
|
|
|
|
$this->comment = $comment;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFreeText(?string $freeText): self
|
|
{
|
|
$this->freeText = $freeText;
|
|
|
|
if ('' !== $freeText && null !== $freeText) {
|
|
$this->setPerson(null);
|
|
$this->setThirdParty(null);
|
|
}
|
|
|
|
if ('' === $freeText) {
|
|
$this->freeText = null;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setKind(?PersonResourceKind $kind): self
|
|
{
|
|
$this->kind = $kind;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setPerson(?Person $person): self
|
|
{
|
|
$this->person = $person;
|
|
|
|
if (null !== $person) {
|
|
$this->setFreeText('');
|
|
$this->setThirdParty(null);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setPersonOwner(?Person $personOwner): self
|
|
{
|
|
$this->personOwner = $personOwner;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setThirdParty(?ThirdParty $thirdParty): self
|
|
{
|
|
$this->thirdParty = $thirdParty;
|
|
|
|
if (null !== $thirdParty) {
|
|
$this->setFreeText('');
|
|
$this->setPerson(null);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @Assert\Callback
|
|
*
|
|
* @param mixed $payload
|
|
*/
|
|
public function validate(ExecutionContextInterface $context, $payload)
|
|
{
|
|
if (null === $this->person && null === $this->thirdParty && (null === $this->freeText || '' === $this->freeText)) {
|
|
$context->buildViolation('You must associate at least one entity')
|
|
->addViolation();
|
|
}
|
|
}
|
|
}
|