mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
Merge branch 'master' into features/sql-vue-from-household-address-to-person
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Chill\PersonBundle\Entity\Household;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
@@ -107,6 +108,78 @@ class Household
|
||||
return $this->members;
|
||||
}
|
||||
|
||||
public function getCurrentMembers(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = $now === null ? (new \DateTimeImmutable('today')) : $now;
|
||||
|
||||
$criteria
|
||||
->where($expr->orX(
|
||||
$expr->isNull('startDate'),
|
||||
$expr->lte('startDate', $date)
|
||||
))
|
||||
->andWhere($expr->orX(
|
||||
$expr->isNull('endDate'),
|
||||
$expr->gte('endDate', $date)
|
||||
));
|
||||
|
||||
return $this->getMembers()->matching($criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the persons currently associated to the household.
|
||||
*
|
||||
* Return a list of Person, instead of a list of HouseholdMembers
|
||||
*
|
||||
* @return Person[]
|
||||
*/
|
||||
public function getCurrentPersons(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getCurrentMembers($now)
|
||||
->map(function(HouseholdMember $m) { return $m->getPerson(); });
|
||||
}
|
||||
|
||||
public function getNonCurrentMembers(\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = $now === null ? (new \DateTimeImmutable('today')) : $now;
|
||||
|
||||
$criteria
|
||||
->where(
|
||||
$expr->gt('startDate', $date)
|
||||
)
|
||||
->orWhere(
|
||||
$expr->andX(
|
||||
$expr->lt('endDate', $date),
|
||||
$expr->neq('endDate', null)
|
||||
)
|
||||
);
|
||||
|
||||
return $this->getMembers()->matching($criteria);
|
||||
}
|
||||
|
||||
public function getCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where($expr->eq('position', $position));
|
||||
|
||||
return $this->getCurrentMembers($now)->matching($criteria);
|
||||
}
|
||||
|
||||
public function getNonCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where($expr->eq('position', $position));
|
||||
|
||||
return $this->getNonCurrentMembers($now)->matching($criteria);
|
||||
}
|
||||
|
||||
public function addMember(HouseholdMember $member): self
|
||||
{
|
||||
if (!$this->members->contains($member)) {
|
||||
|
@@ -50,9 +50,9 @@ class HouseholdMember
|
||||
private ?string $comment = NULL;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @ORM\Column(type="boolean", name="sharedhousehold")
|
||||
*/
|
||||
private bool $sharedHousehold = false;
|
||||
private bool $shareHousehold = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", options={"default": false})
|
||||
@@ -98,7 +98,7 @@ class HouseholdMember
|
||||
}
|
||||
|
||||
$this->position = $position;
|
||||
$this->sharedHousehold = $position->getShareHousehold();
|
||||
$this->shareHousehold = $position->getShareHousehold();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class HouseholdMember
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
public function setEndDate(\DateTimeImmutable $endDate): self
|
||||
public function setEndDate(?\DateTimeImmutable $endDate = null): self
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
|
||||
@@ -144,7 +144,7 @@ class HouseholdMember
|
||||
*/
|
||||
public function getShareHousehold(): ?bool
|
||||
{
|
||||
return $this->sharedHousehold;
|
||||
return $this->shareHousehold;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass=PositionRepository::class)
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="chill_person_household_position")
|
||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "household_position"=Position::class
|
||||
@@ -21,34 +21,38 @@ class Position
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private $id;
|
||||
private ?int $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private $label = [];
|
||||
private array $label = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private $shareHouseHold;
|
||||
private bool $shareHouseHold = true;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private $allowHolder;
|
||||
private bool $allowHolder = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="float")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private $ordering;
|
||||
private float $ordering = 0.00;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): ?array
|
||||
public function getLabel(): array
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
@@ -60,7 +64,7 @@ class Position
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getShareHousehold(): ?bool
|
||||
public function getShareHousehold(): bool
|
||||
{
|
||||
return $this->shareHouseHold;
|
||||
}
|
||||
@@ -72,11 +76,16 @@ class Position
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAllowHolder(): ?bool
|
||||
public function getAllowHolder(): bool
|
||||
{
|
||||
return $this->allowHolder;
|
||||
}
|
||||
|
||||
public function isAllowHolder(): bool
|
||||
{
|
||||
return $this->getAllowHolder();
|
||||
}
|
||||
|
||||
public function setAllowHolder(bool $allowHolder): self
|
||||
{
|
||||
$this->allowHolder = $allowHolder;
|
||||
@@ -84,7 +93,7 @@ class Position
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrdering(): ?float
|
||||
public function getOrdering(): float
|
||||
{
|
||||
return $this->ordering;
|
||||
}
|
||||
|
Reference in New Issue
Block a user