first impl

This commit is contained in:
2021-05-20 17:41:37 +02:00
parent 6bd7a0105d
commit 6a62b46dec
19 changed files with 729 additions and 17 deletions

View File

@@ -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
* @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
*/
@@ -515,9 +614,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;
}
@@ -527,21 +626,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;
@@ -638,6 +769,7 @@ class AccompanyingPeriod
public function addResource(Resource $resource): self
{
$resource->setAccompanyingPeriod($this);
$this->resources[] = $resource;
return $this;
@@ -645,9 +777,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
*/
@@ -659,4 +809,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;
}
}

View File

@@ -417,6 +417,31 @@ class Person implements HasCenterInterface
return $this->accompanyingPeriodParticipations;
}
/**
* Return a collection of participation, where the participation
* is still opened, not a draft, and the period is still opened
*/
public function getOpenedParticipations(): Collection
{
// create a criteria for filtering easily
$criteria = Criteria::create();
$criteria
->andWhere(Criteria::expr()->eq('endDate', NULL))
->orWhere(Criteria::expr()->gt('endDate', new \DateTime('now')))
;
return $this->getAccompanyingPeriodParticipations()
->matching($criteria)
->filter(function (AccompanyingPeriodParticipation $app) {
$period = $app->getAccompanyingPeriod();
return (
NULL === $period->getClosingDate()
|| new \DateTime('now') < $period->getClosingDate()
)
&& AccompanyingPeriod::STEP_DRAFT !== $period->getStep();
});
}
/**
* Get the accompanying periods of a give person with the chronological order.
*/