diff --git a/src/Bundle/ChillMainBundle/Resources/public/modules/bootstrap/bootstrap.scss b/src/Bundle/ChillMainBundle/Resources/public/modules/bootstrap/bootstrap.scss index cc9c090e2..37bf2f253 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/modules/bootstrap/bootstrap.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/modules/bootstrap/bootstrap.scss @@ -18,7 +18,7 @@ // @import "bootstrap/scss/tables"; // @import "bootstrap/scss/forms"; // @import "bootstrap/scss/buttons"; -// @import "bootstrap/scss/transitions"; +@import "bootstrap/scss/transitions"; // @import "bootstrap/scss/dropdown"; // @import "bootstrap/scss/button-group"; // @import "bootstrap/scss/input-group"; diff --git a/src/Bundle/ChillMainBundle/Resources/public/modules/bootstrap/index.js b/src/Bundle/ChillMainBundle/Resources/public/modules/bootstrap/index.js index 075823cab..e75a810c2 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/modules/bootstrap/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/modules/bootstrap/index.js @@ -4,6 +4,8 @@ // Or compile bootstrap only enabled assets require('./bootstrap.scss'); + // You can specify which plugins you need //import { Tooltip, Toast, Popover } from 'bootstrap'; import Modal from 'bootstrap/js/dist/modal'; +import Collapse from 'bootstrap/js/src/collapse'; diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php index 14ee42669..28a28f21f 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php @@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Chill\PersonBundle\Entity\Household\Household; +use Chill\PersonBundle\Entity\Household\Position; /** * @Route("/{_locale}/person/household") @@ -43,9 +44,20 @@ class HouseholdController extends AbstractController public function members(Request $request, Household $household) { // TODO ACL + $positions = $this->getDoctrine()->getManager() + ->getRepository(Position::class) + ->findAll() + ; + + // little performance improvement: + // initialize members collection, which will avoid + // some queries + $household->getMembers()->initialize(); + return $this->render('@ChillPerson/Household/members.html.twig', [ - 'household' => $household + 'household' => $household, + 'positions' => $positions ] ); } diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index f95b177f9..d1cfb6fb9 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -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 Chill\MainBundle\Entity\Address; use Chill\PersonBundle\Entity\Household\HouseholdMember; @@ -97,6 +98,66 @@ class Household return $this->members; } + public function getCurrentMembers(\DateTimeImmutable $now = null): Collection + { + $criteria = new Criteria(); + $expr = Criteria::expr(); + $date = $now === null ? (new \DateTimeImmutable('now')) : $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); + } + + public function getNonCurrentMembers(\DateTimeImmutable $now = null): Collection + { + $criteria = new Criteria(); + $expr = Criteria::expr(); + $date = $now === null ? (new \DateTimeImmutable('now')) : $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)) { diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig index bd6d54a0b..768a3321c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig @@ -7,4 +7,103 @@
Household with id {{ household.id }}
+{% for p in positions %} +{{ 'household.Those members does not share address'|trans }}
+{% endif %} + +{%- set members = household.currentMembersByPosition(p) %} +{% if members|length > 0 %} +{{ 'Any persons into this position'|trans }}
+{% endif %} + +{% set members = household.nonCurrentMembersByPosition(p) %} +{% if members|length > 0 %} + + + ++ {{ m.comment }} ++