diff --git a/module/Decision/src/Mapper/Member.php b/module/Decision/src/Mapper/Member.php index 3071ba2795..313c1dff2c 100644 --- a/module/Decision/src/Mapper/Member.php +++ b/module/Decision/src/Mapper/Member.php @@ -5,6 +5,7 @@ namespace Decision\Mapper; use Application\Mapper\BaseMapper; +use DateTime; use Decision\Model\Member as MemberModel; use Decision\Model\Organ as OrganModel; use Decision\Model\OrganMember as OrganMemberModel; @@ -128,9 +129,13 @@ public function findOrgans(MemberModel $member): array ->join('o.members', 'om') ->join('om.member', 'm') ->where('m.lidnr = :lidnr') - ->andWhere('om.dischargeDate IS NULL'); + ->andWhere($qb->expr()->orX( + $qb->expr()->isNull('om.dischargeDate'), + $qb->expr()->gt('om.dischargeDate', ':now'), + )); - $qb->setParameter('lidnr', $member->getLidnr()); + $qb->setParameter('lidnr', $member->getLidnr()) + ->setParameter('now', new DateTime()); return $qb->getQuery()->getResult(); } @@ -147,10 +152,14 @@ public function findCurrentInstallations(MemberModel $member): array ->from(OrganMemberModel::class, 'om') ->leftJoin('om.organ', 'o') ->where('om.member = :member') - ->andWhere('om.installDate <= CURRENT_TIMESTAMP()') - ->andWhere('om.dischargeDate IS NULL OR om.dischargeDate > CURRENT_TIMESTAMP()'); + ->andWhere('om.installDate <= :now') + ->andWhere($qb->expr()->orX( + $qb->expr()->isNull('om.dischargeDate'), + $qb->expr()->gt('om.dischargeDate', ':now'), + )); - $qb->setParameter('member', $member); + $qb->setParameter('member', $member) + ->setParameter('now', new DateTime()); return $qb->getQuery()->getResult(); } @@ -167,10 +176,13 @@ public function findHistoricalInstallations(MemberModel $member): array ->from(OrganMemberModel::class, 'om') ->leftJoin('om.organ', 'o') ->where('om.member = :member') - ->andWhere('om.dischargeDate IS NOT NULL') - ->andWhere('om.dischargeDate <= CURRENT_TIMESTAMP()'); + ->andWhere($qb->expr()->andX( + $qb->expr()->isNotNull('om.dischargeDate'), + $qb->expr()->lte('om.dischargeDate', ':now'), + )); - $qb->setParameter('member', $member); + $qb->setParameter('member', $member) + ->setParameter('now', new DateTime()); return $qb->getQuery()->getResult(); } diff --git a/module/Decision/src/Mapper/Organ.php b/module/Decision/src/Mapper/Organ.php index 5d4b6b9be7..9809f59ff0 100644 --- a/module/Decision/src/Mapper/Organ.php +++ b/module/Decision/src/Mapper/Organ.php @@ -5,6 +5,7 @@ namespace Decision\Mapper; use Application\Mapper\BaseMapper; +use DateTime; use Decision\Model\Enums\OrganTypes; use Decision\Model\Organ as OrganModel; use Doctrine\ORM\NonUniqueResultException; @@ -26,15 +27,19 @@ class Organ extends BaseMapper */ public function findActive(?OrganTypes $type = null): array { - $criteria = [ - 'abrogationDate' => null, - ]; + $qb = $this->getRepository()->createQueryBuilder('o'); + $qb->where($qb->expr()->orX( + $qb->expr()->isNull('o.abrogationDate'), + $qb->expr()->gt('o.abrogationDate', ':now'), + )) + ->setParameter('now', new DateTime()); if (null !== $type) { - $criteria['type'] = $type; + $qb->andWhere('o.type = :type') + ->setParameter('type', $type); } - return $this->getRepository()->findBy($criteria); + return $qb->getQuery()->getResult(); } /** @@ -42,12 +47,17 @@ public function findActive(?OrganTypes $type = null): array */ public function findActiveById(int $id): ?OrganModel { - return $this->getRepository()->findOneBy( - [ - 'id' => $id, - 'abrogationDate' => null, - ], - ); + $qb = $this->getRepository()->createQueryBuilder('o'); + $qb->where('o.id = :id') + ->andWhere($qb->expr()->orX( + $qb->expr()->isNull('o.abrogationDate'), + $qb->expr()->gt('o.abrogationDate', ':now'), + )); + + $qb->setParameter('id', $id) + ->setParameter('now', new DateTime()); + + return $qb->getQuery()->getOneOrNullResult(); } /** @@ -58,7 +68,11 @@ public function findActiveById(int $id): ?OrganModel public function findAbrogated(?OrganTypes $type = null): array { $qb = $this->getRepository()->createQueryBuilder('o'); - $qb->where('o.abrogationDate IS NOT NULL') + $qb->where($qb->expr()->andX( + $qb->expr()->isNotNull('o.abrogationDate'), + $qb->expr()->lte('o.abrogationDate', ':now'), + )) + ->setParameter('now', new DateTime()) ->orderBy('o.abrogationDate', 'DESC'); if (null !== $type) { diff --git a/module/Decision/src/Model/Member.php b/module/Decision/src/Model/Member.php index a53733a161..50350be289 100644 --- a/module/Decision/src/Model/Member.php +++ b/module/Decision/src/Model/Member.php @@ -668,7 +668,7 @@ static function (BoardMember $boardMember) use ($today) { $dischargeDate = $boardMember->getDischargeDate(); // Keep installation if not discharged or discharged in the future - return null === $dischargeDate || $dischargeDate >= $today; + return null === $dischargeDate || $dischargeDate > $today; }, ); @@ -855,12 +855,12 @@ protected function isCurrentBoard(BoardMember $boardMember): bool // Installation was (before) today. if ( null === $releaseDate - || $releaseDate >= $now + || $releaseDate > $now ) { // Not yet released or the release is the in the future. if ( null === $dischargeDate - || $dischargeDate >= $now + || $dischargeDate > $now ) { // Not yet discharged or the discharge is in the future. return true; diff --git a/module/User/src/Permissions/Assertion/IsOrganMember.php b/module/User/src/Permissions/Assertion/IsOrganMember.php index 8a791f894c..057b14fb67 100644 --- a/module/User/src/Permissions/Assertion/IsOrganMember.php +++ b/module/User/src/Permissions/Assertion/IsOrganMember.php @@ -68,6 +68,6 @@ protected function isCurrentMember(OrganMember $organMember): bool $now = new DateTime(); return $organMember->getInstallDate() <= $now && - (null === $organMember->getDischargeDate() || $organMember->getDischargeDate() >= $now); + (null === $organMember->getDischargeDate() || $organMember->getDischargeDate() > $now); } }