mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-06 23:04:58 +00:00
Update Person::getLastAddress() based on feedback.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -25,6 +25,7 @@ namespace Chill\PersonBundle\Entity;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* AccompanyingPeriod
|
||||
@@ -34,111 +35,89 @@ class AccompanyingPeriod
|
||||
/** @var integer */
|
||||
private $id;
|
||||
|
||||
/** @var \DateTime */
|
||||
private $openingDate;
|
||||
private DateTimeImmutable $openingDate;
|
||||
|
||||
/** @var \DateTime */
|
||||
private $closingDate;
|
||||
private ?DateTimeImmutable $closingDate = null;
|
||||
|
||||
/** @var string */
|
||||
private $remark = '';
|
||||
|
||||
/** @var \Chill\PersonBundle\Entity\Person */
|
||||
private $person;
|
||||
|
||||
|
||||
/** @var AccompanyingPeriod\ClosingMotive */
|
||||
private $closingMotive = null;
|
||||
|
||||
|
||||
/**
|
||||
* The user making the accompanying
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \DateTime $dateOpening
|
||||
*
|
||||
* @param \DateTimeImmutable $dateOpening
|
||||
* @uses AccompanyingPeriod::setClosingDate()
|
||||
*/
|
||||
public function __construct(\DateTime $dateOpening) {
|
||||
public function __construct(\DateTimeImmutable $dateOpening) {
|
||||
$this->setOpeningDate($dateOpening);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set openingDate
|
||||
*
|
||||
* @param \DateTime $dateOpening
|
||||
* @return AccompanyingPeriod
|
||||
*/
|
||||
public function setOpeningDate($openingDate)
|
||||
public function setOpeningDate(DateTimeImmutable $openingDate): self
|
||||
{
|
||||
$this->openingDate = $openingDate;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get openingDate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getOpeningDate()
|
||||
public function getOpeningDate(): DateTimeImmutable
|
||||
{
|
||||
return $this->openingDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set closingDate
|
||||
*
|
||||
* For closing a Person file, you should use Person::setClosed instead.
|
||||
*
|
||||
* @param \DateTime $dateClosing
|
||||
* @return AccompanyingPeriod
|
||||
*
|
||||
* For closing a Person file, you should use Person::setClosed instead.
|
||||
*/
|
||||
public function setClosingDate($closingDate)
|
||||
public function setClosingDate(DateTimeImmutable $closingDate): self
|
||||
{
|
||||
$this->closingDate = $closingDate;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get closingDate
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getClosingDate()
|
||||
public function getClosingDate(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->closingDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isOpen(): bool
|
||||
public function isOpen(): bool
|
||||
{
|
||||
if ($this->getOpeningDate() > new \DateTime('now')) {
|
||||
if ($this->getOpeningDate() > new \DateTimeImmutable('now')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getClosingDate() === null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,16 +131,16 @@ class AccompanyingPeriod
|
||||
if ($remark === null) {
|
||||
$remark = '';
|
||||
}
|
||||
|
||||
|
||||
$this->remark = $remark;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get remark
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getRemark()
|
||||
{
|
||||
@@ -170,7 +149,7 @@ class AccompanyingPeriod
|
||||
|
||||
/**
|
||||
* Set person.
|
||||
*
|
||||
*
|
||||
* For consistency, you should use Person::addAccompanyingPeriod instead.
|
||||
*
|
||||
* @param \Chill\PersonBundle\Entity\Person $person
|
||||
@@ -180,20 +159,20 @@ class AccompanyingPeriod
|
||||
public function setPerson(\Chill\PersonBundle\Entity\Person $person = null)
|
||||
{
|
||||
$this->person = $person;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get person
|
||||
*
|
||||
* @return \Chill\PersonBundle\Entity\Person
|
||||
* @return \Chill\PersonBundle\Entity\Person
|
||||
*/
|
||||
public function getPerson()
|
||||
{
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
|
||||
public function getClosingMotive()
|
||||
{
|
||||
return $this->closingMotive;
|
||||
@@ -204,13 +183,13 @@ class AccompanyingPeriod
|
||||
$this->closingMotive = $closingMotive;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If the period can be reopened.
|
||||
*
|
||||
* This function test if the period is closed and if the period is the last
|
||||
*
|
||||
* This function test if the period is closed and if the period is the last
|
||||
* for the associated person
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canBeReOpened()
|
||||
@@ -218,12 +197,12 @@ class AccompanyingPeriod
|
||||
if ($this->isOpen() === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$periods = $this->getPerson()->getAccompanyingPeriodsOrdered();
|
||||
|
||||
|
||||
return end($periods) === $this;
|
||||
}
|
||||
|
||||
|
||||
public function reOpen()
|
||||
{
|
||||
$this->setClosingDate(null);
|
||||
@@ -235,29 +214,29 @@ class AccompanyingPeriod
|
||||
if ($this->isOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (! $this->isClosingAfterOpening()) {
|
||||
$context->buildViolation('The date of closing is before the date of opening')
|
||||
->atPath('dateClosing')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the closing date is after the opening date.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isClosingAfterOpening() {
|
||||
$diff = $this->getOpeningDate()->diff($this->getClosingDate());
|
||||
|
||||
|
||||
if ($diff->invert === 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
@@ -266,7 +245,7 @@ class AccompanyingPeriod
|
||||
function setUser(User $user): self
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user