diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index 46ae02ce0..2669aed32 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -245,6 +245,16 @@ class Household $members->getIterator() ->uasort( function (HouseholdMember $a, HouseholdMember $b) { + if ($a->getPosition() === NULL) { + if ($b->getPosition() === NULL) { + return 0; + } else { + return -1; + } + } elseif ($b->getPosition() === NULL) { + return 1; + } + if ($a->getPosition()->getOrdering() < $b->getPosition()->getOrdering()) { return -1; } @@ -334,6 +344,26 @@ class Household return $this->getNonCurrentMembers($now)->matching($criteria); } + public function getCurrentMembersWithoutPosition(\DateTimeInterface $now = null) + { + $criteria = new Criteria(); + $expr = Criteria::expr(); + + $criteria->where($expr->isNull('position')); + + return $this->getCurrentMembers($now)->matching($criteria); + } + + public function getNonCurrentMembersWithoutPosition(\DateTimeInterface $now = null) + { + $criteria = new Criteria(); + $expr = Criteria::expr(); + + $criteria->where($expr->isNull('position')); + + return $this->getNonCurrentMembers($now)->matching($criteria); + } + public function addMember(HouseholdMember $member): self { if (!$this->members->contains($member)) { diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php index 985084623..89ec4feb5 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php @@ -29,7 +29,7 @@ class HouseholdMember /** * @ORM\ManyToOne(targetEntity=Position::class) * @Serializer\Groups({"read"}) - * @Assert\NotNull(groups={"household_memberships"}) + * @Assert\NotNull(groups={"household_memberships_created"}) */ private ?Position $position = null; diff --git a/src/Bundle/ChillPersonBundle/Household/MembersEditor.php b/src/Bundle/ChillPersonBundle/Household/MembersEditor.php index 2fd322bb4..f718bb8a9 100644 --- a/src/Bundle/ChillPersonBundle/Household/MembersEditor.php +++ b/src/Bundle/ChillPersonBundle/Household/MembersEditor.php @@ -19,15 +19,17 @@ class MembersEditor private array $persistables = []; private array $membershipsAffected = []; + private array $oldMembershipsHashes = []; - public const VALIDATION_GROUP = 'household_memberships'; + public const VALIDATION_GROUP_CREATED = 'household_memberships_created'; + public const VALIDATION_GROUP_AFFECTED = 'household_memberships'; public function __construct(ValidatorInterface $validator, ?Household $household) { $this->validator = $validator; $this->household = $household; } - + public function addMovement(\DateTimeImmutable $date, Person $person, Position $position, ?bool $holder = false, ?string $comment = null): self { if (NULL === $this->household) { @@ -56,6 +58,7 @@ class MembersEditor if ($participation->getEndDate() === NULL || $participation->getEndDate() > $date) { $participation->setEndDate($date); $this->membershipsAffected[] = $participation; + $this->oldMembershipsHashes[] = \spl_object_hash($participation); } } } @@ -97,13 +100,18 @@ class MembersEditor { if ($this->hasHousehold()) { $list = $this->validator - ->validate($this->getHousehold(), null, [ self::VALIDATION_GROUP ]); + ->validate($this->getHousehold(), null, [ self::VALIDATION_GROUP_AFFECTED ]); } else { $list = new ConstraintViolationList(); } foreach ($this->membershipsAffected as $m) { - $list->addAll($this->validator->validate($m, null, [ self::VALIDATION_GROUP ])); + if (\in_array(\spl_object_hash($m), $this->oldMembershipsHashes)) { + $list->addAll($this->validator->validate($m, null, [ self::VALIDATION_GROUP_AFFECTED ])); + } else { + $list->addAll($this->validator->validate($m, null, [ self::VALIDATION_GROUP_CREATED, + self::VALIDATION_GROUP_AFFECTED ])); + } } return $list; diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig index 990a7cdd3..50822794c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig @@ -22,8 +22,11 @@ {%- for m in members -%} + class="badge-member{%- if m.holder %} holder{% endif -%}" + {% if m.position is not null %} + title="{{ m.position.label.fr }}" + {% endif %} + > {%- if m.holder %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/summary.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/summary.html.twig index e99c1dc1a..3567d1f7e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/summary.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/summary.html.twig @@ -106,81 +106,95 @@

{{ 'household.Household members'|trans }}

- {% for p in positions %} -
-

{{ p.label|localize_translatable_string }} - {% if false == p.shareHousehold %} - - {% endif %} -

+ {% for p in positions|merge([ '_none' ]) %} - {%- set members = household.currentMembersByPosition(p) %} + {% if p == '_none' %} + {% set members = household.currentMembersWithoutPosition %} + {% set old_members = household.nonCurrentMembersWithoutPosition %} + {% else %} + {%- set members = household.currentMembersByPosition(p) %} + {% set old_members = household.nonCurrentMembersByPosition(p) %} + {% endif %} - {% macro customButtons(member, household) %} -
  • - -
  • -
  • - -
  • - {% endmacro %} + {% if not (p == '_none' and members|length == 0 and old_members|length == 0) %} +
    + {% if p != '_none' %} +

    {{ p.label|localize_translatable_string }} + {% if false == p.shareHousehold %} + + {% endif %} +

    + {% else %} +

    {{ 'household.Members without position'|trans }}

    + {% endif %} - {% if members|length > 0 %} -
    - {% for m in members %} - {% include '@ChillPerson/Household/_render_member.html.twig' with { - 'member': m, - 'customButtons': { 'after': _self.customButtons(m, household) } - } %} - {% endfor %} -
    - {% else %} -

    {{ 'household.Any persons into this position'|trans }}

    - {% endif %} - {% set members = household.nonCurrentMembersByPosition(p) %} - {% if members|length > 0 %} + {% macro customButtons(member, household) %} +
  • + +
  • +
  • + +
  • + {% endmacro %} - -
    -
    -

    - -

    -
    -
    - {% for m in members %} - {% include '@ChillPerson/Household/_render_member.html.twig' with { 'member': m } %} - {% endfor %} + {% if members|length > 0 %} +
    + {% for m in members %} + {% include '@ChillPerson/Household/_render_member.html.twig' with { + 'member': m, + 'customButtons': { 'after': _self.customButtons(m, household) } + } %} + {% endfor %} +
    + {% else %} +

    {{ 'household.Any persons into this position'|trans }}

    + {% endif %} + + {% if old_members|length > 0 %} + +
    +
    +

    + +

    +
    +
    + {% for m in old_members %} + {% include '@ChillPerson/Household/_render_member.html.twig' with { 'member': m } %} + {% endfor %} +
    +
    -
    -
    - {% endif %} + {% endif %} -
    +
    + {% endif %} {% endfor %} + +