From 5ebce653dc0a9666de29ea570ccc42d6d9f9e7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 8 Jul 2023 13:52:24 +0200 Subject: [PATCH 1/2] RVRNEXT-45 show recent events as well with upcoming events --- src/Controller/CommunityController.php | 2 +- src/Controller/HomeController.php | 2 +- src/Repository/EventRepository.php | 21 +++++++++++++++------ views/communities/community.php | 8 ++++---- views/home.php | 8 ++++---- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/Controller/CommunityController.php b/src/Controller/CommunityController.php index 74ee8f1..159dbde 100644 --- a/src/Controller/CommunityController.php +++ b/src/Controller/CommunityController.php @@ -79,7 +79,7 @@ class CommunityController implements IAuthenticationRequired return new HtmlContent('communities/community', [ 'community' => $community, - 'upcomingEvents' => iterator_to_array($this->eventRepository->getUpcomingByCommunity($community, new DateTime(), 3)), + 'upcomingAndRecentEvents' => iterator_to_array($this->eventRepository->getUpcomingAndRecentByCommunity($community, new DateTime(), 30, 3)), 'debtItems' => $debtItems, 'debtBalance' => $debtBalance, 'outstandingItems' => $outstandingItems, diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index a5af7ff..b66f6e2 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -44,7 +44,7 @@ class HomeController implements IAuthenticationRequired return new HtmlContent('home', [ 'communities' => $communities, - 'upcomingEvents' => iterator_to_array($this->eventRepository->getUpcomingByUser($user, new DateTime(), 3, true, ['community'])) + 'upcomingAndRecentEvents' => iterator_to_array($this->eventRepository->getUpcomingAndRecentByUser($user, new DateTime(), 30, 3, true, ['community'])) ]); } } diff --git a/src/Repository/EventRepository.php b/src/Repository/EventRepository.php index 3767c67..e40e083 100644 --- a/src/Repository/EventRepository.php +++ b/src/Repository/EventRepository.php @@ -2,6 +2,7 @@ use Container; use DateTime; +use DateInterval; use Generator; use RVR\PersistentData\Model\Community; use RVR\PersistentData\Model\Event; @@ -32,21 +33,21 @@ class EventRepository return $this->selectAllByCommunity($community)->count(); } - public function getUpcomingByCommunity(Community $community, DateTime $from, int $limit, bool $useRelations = false, array $withRelations = []): Generator + public function getUpcomingAndRecentByCommunity(Community $community, DateTime $from, int $days, int $limit, bool $useRelations = false, array $withRelations = []): Generator { $select = $this->selectAllByCommunity($community); - $select->where('end', '>', $from->format('Y-m-d H:i:s')); - $select->orderBy('start', 'ASC'); + $this->selectUpcomingAndRecent($select, $from, $days); + $select->orderBy('start', 'DESC'); $select->limit($limit, 0); yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); } - public function getUpcomingByUser(User $user, DateTime $from, int $limit, bool $useRelations = false, array $withRelations = []): Generator + public function getUpcomingAndRecentByUser(User $user, DateTime $from, int $days, int $limit, bool $useRelations = false, array $withRelations = []): Generator { $select = $this->selectAllByUser($user); - $select->where('end', '>', $from->format('Y-m-d H:i:s')); - $select->orderBy('start', 'ASC'); + $this->selectUpcomingAndRecent($select, $from, $days); + $select->orderBy('start', 'DESC'); $select->limit($limit, 0); yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); @@ -86,4 +87,12 @@ class EventRepository $select->where(['community_members', 'user_id'], '=', $user->getId()); return $select; } + + private function selectUpcomingAndRecent(Select $select, DateTime $from, int $days) + { + $select->where(function (Select $select) use ($from, $days) { + $select->where('start', '<', (clone $from)->add(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s')); + $select->orWhere('end', '>', (clone $from)->sub(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s')); + }); + } } diff --git a/views/communities/community.php b/views/communities/community.php index 78406ec..722d540 100644 --- a/views/communities/community.php +++ b/views/communities/community.php @@ -12,16 +12,16 @@
-

Upcoming events

- 0): ?> - +

Upcoming and recent events

+ 0): ?> +

getTitle() ?> getStartDate()->format('Y-m-d') ?> – getEndDate()->format('Y-m-d') ?>

-

There is no upcoming event.

+

There is no event to show.

All events | New event

diff --git a/views/home.php b/views/home.php index f7db5c3..d180a2c 100644 --- a/views/home.php +++ b/views/home.php @@ -16,9 +16,9 @@
-

Upcoming events

- 0): ?> - +

Upcoming and recent events

+ 0): ?> +

getTitle() ?> @@ -28,7 +28,7 @@

-

There is no upcoming event.

+

There is no event to show.

-- 2.45.2 From e0fe6a86227c22dc9afaa2d2a083f0d8d3d4f96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 8 Jul 2023 14:42:09 +0200 Subject: [PATCH 2/2] RVRNEXT-45 update soko-web to 0.13.1 --- composer.json | 2 +- composer.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 62f3eb7..2a5b307 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "esoko/soko-web": "0.13", + "esoko/soko-web": "0.13.1", "firebase/php-jwt": "^6.4" }, "require-dev": { diff --git a/composer.lock b/composer.lock index ccb3e71..ed3b648 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "707bad5bd796500db300c5384f2ce378", + "content-hash": "59130fbd82b1c81275666b16adb0c1a1", "packages": [ { "name": "cocur/slugify", @@ -82,11 +82,11 @@ }, { "name": "esoko/soko-web", - "version": "v0.13", + "version": "v0.13.1", "source": { "type": "git", "url": "https://git.esoko.eu/esoko/soko-web.git", - "reference": "4283bc9bb15d17914393b4ba3463d83717487c53" + "reference": "8bf495c89b4ce1456da1133adc285003e544dd48" }, "require": { "cocur/slugify": "^4.3", @@ -108,7 +108,7 @@ "GNU GPL 3.0" ], "description": "Lightweight web framework", - "time": "2023-06-17T12:32:56+00:00" + "time": "2023-07-08T12:38:40+00:00" }, { "name": "firebase/php-jwt", -- 2.45.2