mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge branch 'master' into 'fix-accompanying-period-opening'
# Conflicts: # src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php
This commit is contained in:
@@ -22,25 +22,34 @@
|
||||
|
||||
namespace Chill\PersonBundle\Entity;
|
||||
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||
|
||||
/**
|
||||
* AccompanyingPeriod Class
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\AccompanyingPeriodRepository")
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="chill_person_accompanying_period")
|
||||
* @DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "accompanying_period"=AccompanyingPeriod::class
|
||||
* })
|
||||
*/
|
||||
class AccompanyingPeriod
|
||||
class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
{
|
||||
/**
|
||||
* Mark an accompanying period as "occasional"
|
||||
@@ -80,6 +89,7 @@ class AccompanyingPeriod
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
@@ -87,6 +97,7 @@ class AccompanyingPeriod
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(type="date")
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $openingDate;
|
||||
|
||||
@@ -94,6 +105,7 @@ class AccompanyingPeriod
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(type="date", nullable=true)
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $closingDate = null;
|
||||
|
||||
@@ -101,6 +113,7 @@ class AccompanyingPeriod
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="text")
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $remark = '';
|
||||
|
||||
@@ -108,17 +121,28 @@ class AccompanyingPeriod
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Comment",
|
||||
* mappedBy="accompanyingPeriod"
|
||||
* mappedBy="accompanyingPeriod",
|
||||
* cascade={"persist", "remove"},
|
||||
* orphanRemoval=true
|
||||
* )
|
||||
*/
|
||||
private $comments;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(
|
||||
* targetEntity=Comment::class
|
||||
* )
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private ?Comment $initialComment = null;
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
|
||||
* mappedBy="accompanyingPeriod",
|
||||
* cascade={"persist", "refresh", "remove", "merge", "detach"})
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private $participations;
|
||||
|
||||
@@ -128,36 +152,42 @@ class AccompanyingPeriod
|
||||
* @ORM\ManyToOne(
|
||||
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive")
|
||||
* @ORM\JoinColumn(nullable=true)
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $closingMotive = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=User::class)
|
||||
* @ORM\JoinColumn(nullable=true)
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=User::class)
|
||||
* @ORM\JoinColumn(nullable=true)
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private $createdBy;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=32, nullable=true)
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private $step = self::STEP_DRAFT;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Origin::class)
|
||||
* @ORM\JoinColumn(nullable=true)
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $origin;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $intensity;
|
||||
|
||||
@@ -172,6 +202,7 @@ class AccompanyingPeriod
|
||||
* joinColumns={@ORM\JoinColumn(name="accompanying_period_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
|
||||
* )
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private $scopes;
|
||||
|
||||
@@ -189,19 +220,22 @@ class AccompanyingPeriod
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
* @ORM\Column(type="boolean", options={"default": false} )
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $requestorAnonymous = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
* @ORM\Column(type="boolean", options={"default": false} )
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $emergency = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
* @ORM\Column(type="boolean", options={"default": false} )
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $confidential = false;
|
||||
|
||||
@@ -210,21 +244,54 @@ class AccompanyingPeriod
|
||||
*
|
||||
* @ORM\OneToMany(
|
||||
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Resource",
|
||||
* mappedBy="accompanyingPeriod"
|
||||
* mappedBy="accompanyingPeriod",
|
||||
* cascade={"persist", "remove"},
|
||||
* orphanRemoval=true
|
||||
* )
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private $resources;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity=SocialIssue::class
|
||||
* )
|
||||
* @ORM\JoinTable(
|
||||
* name="chill_person_accompanying_period_social_issues"
|
||||
* )
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private Collection $socialIssues;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
|
||||
*/
|
||||
private \DateTimeInterface $createdAt;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(
|
||||
* targetEntity=User::class
|
||||
* )
|
||||
*/
|
||||
private User $updatedBy;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
|
||||
*/
|
||||
private \DateTimeInterface $updatedAt;
|
||||
|
||||
/**
|
||||
* AccompanyingPeriod constructor.
|
||||
*
|
||||
* @param \DateTime $dateOpening
|
||||
* @uses AccompanyingPeriod::setClosingDate()
|
||||
*/
|
||||
public function __construct(\DateTime $dateOpening) {
|
||||
$this->setOpeningDate($dateOpening);
|
||||
public function __construct(\DateTime $dateOpening = null) {
|
||||
$this->setOpeningDate($dateOpening ?? new \DateTime('now'));
|
||||
$this->participations = new ArrayCollection();
|
||||
$this->scopes = new ArrayCollection();
|
||||
$this->socialIssues = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,23 +385,55 @@ class AccompanyingPeriod
|
||||
return $this->remark;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
public function getComments(): Collection
|
||||
{
|
||||
return $this->comments;
|
||||
return $this->comments->filter(function (Comment $c) {
|
||||
return $c !== $this->initialComment;
|
||||
});
|
||||
}
|
||||
|
||||
public function addComment(Comment $comment): self
|
||||
{
|
||||
$this->comments[] = $comment;
|
||||
$comment->setAccompanyingPeriod($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeComment(Comment $comment): void
|
||||
{
|
||||
$comment->setAccompanyingPeriod(null);
|
||||
$this->comments->removeElement($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
public function setInitialComment(?Comment $comment = null): self
|
||||
{
|
||||
if (NULL !== $this->initialComment) {
|
||||
$this->removeComment($this->initialComment);
|
||||
}
|
||||
if ($comment instanceof Comment) {
|
||||
$this->addComment($comment);
|
||||
}
|
||||
|
||||
$this->initialComment = $comment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
public function getInitialComment(): ?Comment
|
||||
{
|
||||
return $this->initialComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Participations Collection
|
||||
*/
|
||||
@@ -458,7 +557,7 @@ class AccompanyingPeriod
|
||||
return false;
|
||||
}
|
||||
|
||||
$participation = $this->participationsContainsPerson($person);
|
||||
$participation = $this->getParticipationsContainsPerson($person);
|
||||
if (!null === $participation)
|
||||
{
|
||||
$person = $participation->getPerson();
|
||||
@@ -540,9 +639,9 @@ class AccompanyingPeriod
|
||||
return $this->requestorPerson;
|
||||
}
|
||||
|
||||
public function setRequestorPerson(Person $requestorPerson): self
|
||||
private function setRequestorPerson(Person $requestorPerson = null): self
|
||||
{
|
||||
$this->requestorPerson = ($this->requestorThirdParty === null) ? $requestorPerson : null;
|
||||
$this->requestorPerson = $requestorPerson;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -552,21 +651,53 @@ class AccompanyingPeriod
|
||||
return $this->requestorThirdParty;
|
||||
}
|
||||
|
||||
public function setRequestorThirdParty(ThirdParty $requestorThirdParty): self
|
||||
private function setRequestorThirdParty(ThirdParty $requestorThirdParty = null): self
|
||||
{
|
||||
$this->requestorThirdParty = ($this->requestorPerson === null) ? $requestorThirdParty : null;
|
||||
$this->requestorThirdParty = $requestorThirdParty;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Person|ThirdParty
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
public function getRequestor()
|
||||
{
|
||||
return $this->requestorPerson ?? $this->requestorThirdParty;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a requestor
|
||||
*
|
||||
* The requestor is either an instance of ThirdParty, or an
|
||||
* instance of Person
|
||||
*
|
||||
* @param $requestor Person|ThirdParty
|
||||
* @return self
|
||||
* @throw UnexpectedValueException if the requestor is not a Person or ThirdParty
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
public function setRequestor($requestor): self
|
||||
{
|
||||
if ($requestor instanceof Person) {
|
||||
$this->setRequestorThirdParty(NULL);
|
||||
$this->setRequestorPerson($requestor);
|
||||
} elseif ($requestor instanceof ThirdParty) {
|
||||
$this->setRequestorThirdParty($requestor);
|
||||
$this->setRequestorPerson(NULL);
|
||||
} elseif (NULL === $requestor) {
|
||||
$this->setRequestorPerson(NULL);
|
||||
$this->setRequestorThirdParty(NULL);
|
||||
} else {
|
||||
throw new \UnexpectedValueException("requestor is not an instance of Person or ThirdParty");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function isRequestorAnonymous(): bool
|
||||
{
|
||||
return $this->requestorAnonymous;
|
||||
@@ -663,6 +794,7 @@ class AccompanyingPeriod
|
||||
|
||||
public function addResource(Resource $resource): self
|
||||
{
|
||||
$resource->setAccompanyingPeriod($this);
|
||||
$this->resources[] = $resource;
|
||||
|
||||
return $this;
|
||||
@@ -670,9 +802,27 @@ class AccompanyingPeriod
|
||||
|
||||
public function removeResource(Resource $resource): void
|
||||
{
|
||||
$resource->setAccompanyingPeriod(null);
|
||||
$this->resources->removeElement($resource);
|
||||
}
|
||||
|
||||
public function getSocialIssues(): Collection
|
||||
{
|
||||
return $this->socialIssues;
|
||||
}
|
||||
|
||||
public function addSocialIssue(SocialIssue $socialIssue): self
|
||||
{
|
||||
$this->socialIssues[] = $socialIssue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeSocialIssue(SocialIssue $socialIssue): void
|
||||
{
|
||||
$this->socialIssues->removeElement($socialIssue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all persons which are participating to this course
|
||||
*/
|
||||
@@ -684,4 +834,25 @@ class AccompanyingPeriod
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTimeInterface $datetime): self
|
||||
{
|
||||
$this->createdAt = $datetime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setUpdatedBy(User $user): self
|
||||
{
|
||||
$this->updatedBy = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setUpdatedAt(\DateTimeInterface $datetime): self
|
||||
{
|
||||
$this->updatedAt = $datetime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user