From 224cdc0eda861866517bd4fbefc1556bd3d6535e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 26 May 2023 16:36:51 +0200 Subject: [PATCH 01/13] RVRNEXT-11 add migrations for events --- .../structure/20230526_1551_events.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 database/migrations/structure/20230526_1551_events.sql diff --git a/database/migrations/structure/20230526_1551_events.sql b/database/migrations/structure/20230526_1551_events.sql new file mode 100644 index 0000000..aae1234 --- /dev/null +++ b/database/migrations/structure/20230526_1551_events.sql @@ -0,0 +1,18 @@ +CREATE TABLE `events` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `slug` varchar(255) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, + `community_id` int(10) unsigned NOT NULL, + `start` timestamp NOT NULL DEFAULT current_timestamp(), + `end` timestamp NOT NULL DEFAULT current_timestamp(), + `title` varchar(255) NOT NULL, + `description` text NOT NULL, + PRIMARY KEY (`id`), + KEY `community_id` (`community_id`), + UNIQUE KEY `slug` (`slug`), + CONSTRAINT `events_community_id` FOREIGN KEY (`community_id`) REFERENCES `communities` (`id`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; + +ALTER TABLE `transactions` +ADD `event_id` int(10) unsigned NULL, +ADD KEY `event_id` (`event_id`) AFTER `community_id`, +ADD CONSTRAINT `transactions_event_id` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`); From 63ca6e7557dcdc3246d8bc6a103a17117fb9b717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 03:42:13 +0200 Subject: [PATCH 02/13] RVRNEXT-11 add model and repository for events --- src/PersistentData/Model/Event.php | 107 +++++++++++++++++++++++++++++ src/Repository/EventRepository.php | 89 ++++++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 src/PersistentData/Model/Event.php create mode 100644 src/Repository/EventRepository.php diff --git a/src/PersistentData/Model/Event.php b/src/PersistentData/Model/Event.php new file mode 100644 index 0000000..0812971 --- /dev/null +++ b/src/PersistentData/Model/Event.php @@ -0,0 +1,107 @@ + Community::class]; + + protected static string $slugSource = 'title'; + + private ?Community $community = null; + + private int $communityId; + + private DateTime $start; + + private DateTime $end; + + private string $title = ''; + + private string $description = ''; + + public function setCommunity(Community $community): void + { + $this->community = $community; + } + + public function setCommunityId(int $communityId): void + { + $this->communityId = $communityId; + } + + public function setStartDate(DateTime $start): void + { + $this->start = $start; + } + + public function setStart(string $start): void + { + $this->start = new DateTime($start); + } + + public function setEndDate(DateTime $end): void + { + $this->end = $end; + } + + public function setEnd(string $end): void + { + $this->end = new DateTime($end); + } + + public function setTitle(string $title): void + { + $this->title = $title; + } + + public function setDescription(string $description): void + { + $this->description = $description; + } + + public function getCommunity(): ?Community + { + return $this->community; + } + + public function getCommunityId(): int + { + return $this->communityId; + } + + public function getStartDate(): DateTime + { + return $this->start; + } + + public function getStart(): string + { + return $this->start->format('Y-m-d H:i:s'); + } + + public function getEndDate(): DateTime + { + return $this->end; + } + + public function getEnd(): string + { + return $this->end->format('Y-m-d H:i:s'); + } + + public function getTitle(): string + { + return $this->title; + } + + public function getDescription(): string + { + return $this->description; + } +} diff --git a/src/Repository/EventRepository.php b/src/Repository/EventRepository.php new file mode 100644 index 0000000..9e568e4 --- /dev/null +++ b/src/Repository/EventRepository.php @@ -0,0 +1,89 @@ +selectFromDbById($id, Event::class); + } + + public function getBySlug(string $slug): ?Event + { + return \Container::$persistentDataManager->selectFromDbBySlug($slug, Event::class); + } + + public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator + { + $select = $this->selectAllByCommunity($community); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); + } + + public function countAllByCommunity(Community $community): int + { + return $this->selectAllByCommunity($community)->count(); + } + + public function getUpcomingByCommunity(Community $community, DateTime $from, 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'); + $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 + { + $select = $this->selectAllByUser($user); + $select->where('end', '>', $from->format('Y-m-d H:i:s')); + $select->orderBy('start', 'ASC'); + $select->limit($limit, 0); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); + } + + public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator + { + $select = $this->selectAllByCommunity($community); + $select->orderBy('start', 'DESC'); + $select->limit($limit, $start); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); + } + + public function searchByTitle(Community $community, string $title): Generator + { + $select = $this->selectAllByCommunity($community); + $select->where('title', 'LIKE', '%' . $title . '%'); + $select->orderBy('start', 'DESC'); + $select->limit(10); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class); + } + + private function selectAllByCommunity(Community $community) + { + $select = new Select(Container::$dbConnection, Event::getTable()); + $select->where('community_id', '=', $community->getId()); + return $select; + } + + private function selectAllByUser(User $user) + { + $select = new Select(Container::$dbConnection, Event::getTable()); + $select->innerJoin('communities', ['communities', 'id'], '=', ['events', 'community_id']); + $select->innerJoin('community_members', ['communities', 'id'], '=', ['community_members', 'community_id']); + $select->where(['community_members', 'user_id'], '=', $user->getId()); + return $select; + } +} From 2fc5812eba4d8c61db4cf24aa80696b026cada50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 03:43:26 +0200 Subject: [PATCH 03/13] RVRNEXT-11 add new endpoints for events --- web.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/web.php b/web.php index 81aac81..3ad14df 100644 --- a/web.php +++ b/web.php @@ -13,6 +13,7 @@ use RVR\Controller\UserController; use RVR\Controller\UserSearchController; use RVR\Controller\CommunityController; use RVR\Controller\TransactionController; +use RVR\Controller\EventController; use RVR\Repository\UserRepository; require 'app.php'; @@ -91,6 +92,18 @@ Container::$routeCollection->group('communities', function (RouteCollection $rou $routeCollection->post('community.transactions.edit-action', '{transactionId}', [TransactionController::class, 'saveTransaction']); $routeCollection->post('community.transactions.delete-action', '{transactionId}/delete', [TransactionController::class, 'deleteTransaction']); }); + $routeCollection->group('events', function (RouteCollection $routeCollection) { + $routeCollection->get('community.events', '', [EventController::class, 'getEvents']); + $routeCollection->get('community.events.new', 'new', [EventController::class, 'getEventEdit']); + $routeCollection->post('community.events.new-action', 'new', [EventController::class, 'saveEvent']); + $routeCollection->get('community.events.search', 'search', [EventController::class, 'searchEvent']); + $routeCollection->group('{eventSlug}', function (RouteCollection $routeCollection) { + $routeCollection->get('community.event', '', [EventController::class, 'getEvent']); + $routeCollection->get('community.event.edit', 'edit', [EventController::class, 'getEventEdit']); + $routeCollection->post('community.event.edit-action', 'edit', [EventController::class, 'saveEvent']); + $routeCollection->post('community.event.delete-action', 'delete', [EventController::class, 'deleteEvent']); + }); + }); }); }); From 2bcaf13ee31e754786d2a0a7dd7dd96feaf48f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 03:44:01 +0200 Subject: [PATCH 04/13] RVRNEXT-11 add controller for events --- src/Controller/EventController.php | 181 +++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/Controller/EventController.php diff --git a/src/Controller/EventController.php b/src/Controller/EventController.php new file mode 100644 index 0000000..be72ca1 --- /dev/null +++ b/src/Controller/EventController.php @@ -0,0 +1,181 @@ +communityRepository = new CommunityRepository(); + $this->communityMemberRepository = new CommunityMemberRepository(); + $this->eventRepository = new EventRepository(); + $this->transactionRepository = new TransactionRepository(); + } + + public function isAuthenticationRequired(): bool + { + return true; + } + + public function authorize(): bool + { + $communitySlug = \Container::$request->query('communitySlug'); + $this->community = $this->communityRepository->getBySlug($communitySlug); + if ($this->community === null) { + return false; + } + + /** + * @var User $user + */ + $user = \Container::$request->user(); + $this->ownCommunityMember = $this->communityMemberRepository->getByCommunityAndUser($this->community, $user); + if ($this->ownCommunityMember === null) { + return false; + } + + return true; + } + + public function getEvents(): IContent + { + $itemsPerPage = 10; + $numberOfEvents = $this->eventRepository->countAllByCommunity($this->community); + $pages = ceil($numberOfEvents / $itemsPerPage); + $currentPage = Container::$request->query('page') ?: 0; + $events = $this->eventRepository->getPagedByCommunity( + $this->community, + $currentPage * $itemsPerPage, + $itemsPerPage + ); + + return new HtmlContent('events/events', [ + 'community' => $this->community, + 'pages' => $pages, + 'currentPage' => $currentPage, + 'numberOfEvents' => $numberOfEvents, + 'events' => $events + ]); + } + + public function searchEvent(): IContent + { + $events = iterator_to_array($this->eventRepository->searchByTitle($this->community, Container::$request->query('q'))); + $results = []; + foreach ($events as $event) { + $results[] = ['value' => $event->getId(), 'label' => $event->getTitle()]; + } + + return new JsonContent([ + 'results' => $results + ]); + } + + public function getEvent(): ?IContent + { + $event = $this->eventRepository->getBySlug(Container::$request->query('eventSlug')); + if (!$event) { + return null; + } + Container::$persistentDataManager->loadRelationsFromDb($this->community, true, ['main_currency']); + + return new HtmlContent('events/event', [ + 'community' => $this->community, + 'event' => $event, + 'totalCost' => $this->sumTransactions($event) + ]); + } + + public function getEventEdit(): ?IContent + { + $eventSlug = Container::$request->query('eventSlug'); + if ($eventSlug) { + $event = $this->eventRepository->getBySlug($eventSlug); + if ($event === null) { + return null; + } + } else { + $event = null; + } + + return new HtmlContent('events/event_edit', [ + 'community' => $this->community, + 'event' => $event + ]); + } + + public function saveEvent(): ?IContent + { + $eventSlug = Container::$request->query('eventSlug'); + if ($eventSlug) { + $event = $this->eventRepository->getBySlug($eventSlug); + } else { + $event = new Event(); + $event->setCommunity($this->community); + } + + $event->setTitle(Container::$request->post('title')); + $event->setDescription(Container::$request->post('description')); + $event->setStartDate(new DateTime(Container::$request->post('start'))); + $event->setEndDate(new DateTime(Container::$request->post('end'))); + Container::$persistentDataManager->saveToDb($event); + + return new JsonContent([ + 'redirect' => ['target' => \Container::$routeCollection->getRoute('community.event')->generateLink(['communitySlug' => $this->community->getSlug(), 'eventSlug' => $event->getSlug()])] + ]); + } + + public function deleteEvent(): IContent + { + $event = $this->eventRepository->getBySlug(Container::$request->query('eventSlug')); + + foreach ($this->transactionRepository->getAllByEvent($event) as $transaction) { + $transaction->setEventId(null); + Container::$persistentDataManager->saveToDb($transaction); + } + + Container::$persistentDataManager->deleteFromDb($event); + + return new JsonContent(['success' => true]); + } + + private function sumTransactions(Event $event): float + { + $exchangeRateCalculator = new ExchangeRateCalculator($this->community->getMainCurrency()); + $transactions = $this->transactionRepository->getAllByEvent($event, true, ['currency']); + $sum = 0.0; + + foreach ($transactions as $transaction) { + $sum += $exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate()); + } + + return $sum; + } +} From 49f3a371e56160849eb309adb012e6012f7997e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 03:44:19 +0200 Subject: [PATCH 05/13] RVRNEXT-11 add views for events --- views/events/event.php | 27 +++++++++++++++++ views/events/event_edit.php | 40 +++++++++++++++++++++++++ views/events/events.php | 60 +++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 views/events/event.php create mode 100644 views/events/event_edit.php create mode 100644 views/events/events.php diff --git a/views/events/event.php b/views/events/event.php new file mode 100644 index 0000000..9c95adf --- /dev/null +++ b/views/events/event.php @@ -0,0 +1,27 @@ +@extends(templates/layout_normal) + +@section(main) +

+ getName() ?> » + Events » + getTitle() ?> + [edit] +

+ +
+
+ getMainCurrency()->getCode(); + $mainCurrencyRoundDigits = $community->getMainCurrency()->getRoundDigits(); + ?> +

Finances

+

Transactions | New transaction

+ + + + + +
Total cost
+
+
+@endsection diff --git a/views/events/event_edit.php b/views/events/event_edit.php new file mode 100644 index 0000000..2326572 --- /dev/null +++ b/views/events/event_edit.php @@ -0,0 +1,40 @@ +@extends(templates/layout_normal) + +@section(main) +

+ getName() ?> » + Events » + + getTitle() ?> » Edit event + + New event + +

+
+ getRoute('community.event.edit-action')->generateLink(['communitySlug' => $community->getSlug(), 'eventSlug' => $event->getSlug()]) : + Container::$routeCollection->getRoute('community.events.new-action')->generateLink(['communitySlug' => $community->getSlug()]); + ?> +
+

Title

+ +

Description

+ +

Start

+ +

End

+ +

+
+ + + + +
+
+ +
+ +
+@endsection diff --git a/views/events/events.php b/views/events/events.php new file mode 100644 index 0000000..a3cf74b --- /dev/null +++ b/views/events/events.php @@ -0,0 +1,60 @@ +@extends(templates/layout_normal) + +@section(main) +

+ getName() ?> » + Events +

+ +

New event

+ + 0): ?> + 1): ?> +

+ « + + + + + + + + + + » +

+ + + + +
+

getTitle() ?>

+

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

+

getDescription() ?>

+
+
+ + + 1): ?> +

+ « + + + + + + + + + + » +

+ + +

New event

+ +
+

There are no events yet.

+
+ +@endsection From 532dbfd8d6be67f5a37fa18151900d20c412efa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 03:45:36 +0200 Subject: [PATCH 06/13] RVRNEXT-11 add event for transactions --- public/static/js/communities/transaction.js | 30 +++++++++++ src/Controller/TransactionController.php | 58 ++++++++++++++++----- src/PersistentData/Model/Transaction.php | 27 +++++++++- src/Repository/TransactionRepository.php | 32 +++++++++++- views/communities/transaction_edit.php | 25 ++++++++- views/communities/transactions.php | 11 +++- 6 files changed, 163 insertions(+), 20 deletions(-) create mode 100644 public/static/js/communities/transaction.js diff --git a/public/static/js/communities/transaction.js b/public/static/js/communities/transaction.js new file mode 100644 index 0000000..0abaf6c --- /dev/null +++ b/public/static/js/communities/transaction.js @@ -0,0 +1,30 @@ +(function () { + const element = document.getElementById('transactionForm').elements['event_id']; + const select = new TomSelect(element, { + valueField: 'value', + labelField: 'label', + searchField: 'label', + loadThrottle: 300, + load: function (query, callback) { + var self = this; + RVR.httpRequest('GET', searchEventUrl.replace('QUERY', encodeURIComponent(query)), function () { + self.clearOptions(); + callback(this.response.results); + }); + }, + }); + + select.on('change', function (value) { + this.clearOptions(); + }); + + select.on('blur', function (value) { + this.clearOptions(); + }); + + select.on('type', function (value) { + if (value === '') { + this.clearOptions(); + } + }); +})(); diff --git a/src/Controller/TransactionController.php b/src/Controller/TransactionController.php index aafbea0..2a08ff5 100644 --- a/src/Controller/TransactionController.php +++ b/src/Controller/TransactionController.php @@ -11,6 +11,7 @@ use RVR\Repository\CommunityMemberRepository; use RVR\Repository\CommunityRepository; use RVR\Repository\CurrencyRepository; use RVR\Repository\TransactionRepository; +use RVR\Repository\EventRepository; use SokoWeb\Interfaces\Authentication\IAuthenticationRequired; use SokoWeb\Interfaces\Authorization\ISecured; use SokoWeb\Interfaces\Response\IContent; @@ -27,9 +28,11 @@ class TransactionController implements IAuthenticationRequired, ISecured private TransactionRepository $transactionRepository; - private Community $community; + private EventRepository $eventRepository; - private CommunityMember $ownCommunityMember; + private ?Community $community; + + private ?CommunityMember $ownCommunityMember; public function __construct() { @@ -37,6 +40,7 @@ class TransactionController implements IAuthenticationRequired, ISecured $this->communityMemberRepository = new CommunityMemberRepository(); $this->currencyRepository = new CurrencyRepository(); $this->transactionRepository = new TransactionRepository(); + $this->eventRepository = new EventRepository(); } public function isAuthenticationRequired(): bool @@ -69,20 +73,38 @@ class TransactionController implements IAuthenticationRequired, ISecured Container::$persistentDataManager->loadRelationsFromDb($this->community, true, ['main_currency']); $exchangeRateCalculator = new ExchangeRateCalculator($this->community->getMainCurrency()); + $eventSlug = Container::$request->query('event'); + if ($eventSlug) { + $event = $this->eventRepository->getBySlug($eventSlug); + } else { + $event = null; + } + $itemsPerPage = 50; - $numberOfTransactions = $this->transactionRepository->countAllByCommunity($this->community); + $numberOfTransactions = $event ? + $this->transactionRepository->countAllByEvent($event) : + $this->transactionRepository->countAllByCommunity($this->community); $pages = ceil($numberOfTransactions / $itemsPerPage); $currentPage = Container::$request->query('page') ?: 0; - $transactions = $this->transactionRepository->getPagedByCommunity( - $this->community, - $currentPage * $itemsPerPage, - $itemsPerPage, - true, - ['currency', 'payer_user', 'payee_user'] - ); + $transactions = $event ? + $this->transactionRepository->getPagedByEvent( + $event, + $currentPage * $itemsPerPage, + $itemsPerPage, + true, + ['currency', 'payer_user', 'payee_user'] + ) : + $this->transactionRepository->getPagedByCommunity( + $this->community, + $currentPage * $itemsPerPage, + $itemsPerPage, + true, + ['event', 'currency', 'payer_user', 'payee_user'] + ); return new HtmlContent('communities/transactions', [ 'community' => $this->community, + 'event' => $event, 'exchangeRateCalculator' => $exchangeRateCalculator, 'pages' => $pages, 'currentPage' => $currentPage, @@ -99,13 +121,22 @@ class TransactionController implements IAuthenticationRequired, ISecured if ($transaction === null) { return null; } + Container::$persistentDataManager->loadRelationsFromDb($transaction, false, ['event']); + $event = $transaction->getEvent(); } else { $transaction = null; + $eventSlug = Container::$request->query('event'); + if ($eventSlug) { + $event = $this->eventRepository->getBySlug($eventSlug); + } else { + $event = null; + } } return new HtmlContent('communities/transaction_edit', [ 'community' => $this->community, 'transaction' => $transaction, + 'event' => $event, 'members' => $this->getMembers($this->community), 'currencies' => $this->getCurrencies($this->community) ]); @@ -121,6 +152,7 @@ class TransactionController implements IAuthenticationRequired, ISecured $transaction->setCommunity($this->community); } + $transaction->setEventId(Container::$request->post('event_id') ?: null); $transaction->setCurrencyId(Container::$request->post('currency_id')); $transaction->setPayerUserId(Container::$request->post('payer_user_id')); $transaction->setPayeeUserId(Container::$request->post('payee_user_id') ?: null); @@ -143,7 +175,7 @@ class TransactionController implements IAuthenticationRequired, ISecured private function getMembers(Community $community): array { $members = iterator_to_array($this->communityMemberRepository->getAllByCommunity($community, true, ['user'])); - usort($members, function($a, $b) { + usort($members, function ($a, $b) { return strnatcmp($a->getUser()->getDisplayName(), $b->getUser()->getDisplayName()); }); return $members; @@ -152,10 +184,10 @@ class TransactionController implements IAuthenticationRequired, ISecured private function getCurrencies(Community $community): array { $currencies = iterator_to_array($this->currencyRepository->getAllByCommunity($community)); - usort($currencies, function($a, $b) { + usort($currencies, function ($a, $b) { return strnatcmp($a->getCode(), $b->getCode()); }); - usort($currencies, function($a, $b) use ($community) { + usort($currencies, function ($a, $b) use ($community) { return (int)($b->getId() === $community->getMainCurrencyId()) - (int)($a->getId() === $community->getMainCurrencyId()); }); return $currencies; diff --git a/src/PersistentData/Model/Transaction.php b/src/PersistentData/Model/Transaction.php index a4a9b48..fe73d49 100644 --- a/src/PersistentData/Model/Transaction.php +++ b/src/PersistentData/Model/Transaction.php @@ -7,10 +7,11 @@ class Transaction extends Model { protected static string $table = 'transactions'; - protected static array $fields = ['community_id', 'currency_id', 'payer_user_id', 'payee_user_id', 'description', 'sum', 'time']; + protected static array $fields = ['community_id', 'event_id', 'currency_id', 'payer_user_id', 'payee_user_id', 'description', 'sum', 'time']; protected static array $relations = [ 'community' => Community::class, + 'event' => Event::class, 'currency' => Currency::class, 'payer_user' => User::class, 'payee_user' => User::class @@ -20,6 +21,10 @@ class Transaction extends Model private int $communityId; + private ?Event $event = null; + + private ?int $eventId = null; + private ?Currency $currency = null; private int $currencyId; @@ -48,6 +53,16 @@ class Transaction extends Model $this->communityId = $communityId; } + public function setEvent(?Event $event): void + { + $this->event = $event; + } + + public function setEventId(?int $eventId): void + { + $this->eventId = $eventId; + } + public function setCurrency(Currency $currency): void { $this->currency = $currency; @@ -108,6 +123,16 @@ class Transaction extends Model return $this->communityId; } + public function getEvent(): ?Event + { + return $this->event; + } + + public function getEventId(): ?int + { + return $this->eventId; + } + public function getCurrency(): ?Currency { return $this->currency; diff --git a/src/Repository/TransactionRepository.php b/src/Repository/TransactionRepository.php index 4535e74..8d2c5b0 100644 --- a/src/Repository/TransactionRepository.php +++ b/src/Repository/TransactionRepository.php @@ -4,6 +4,7 @@ use Container; use Generator; use RVR\PersistentData\Model\Community; use RVR\PersistentData\Model\Currency; +use RVR\PersistentData\Model\Event; use RVR\PersistentData\Model\Transaction; use RVR\PersistentData\Model\User; use SokoWeb\Database\Query\Select; @@ -22,11 +23,23 @@ class TransactionRepository yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations); } + public function getAllByEvent(Event $event, bool $useRelations = false, array $withRelations = []): Generator + { + $select = $this->selectAllByEvent($event); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations); + } + public function countAllByCommunity(Community $community): int { return $this->selectAllByCommunity($community)->count(); } + public function countAllByEvent(Event $event): int + { + return $this->selectAllByEvent($event)->count(); + } + public function isAnyForUser(User $user): bool { $select = new Select(Container::$dbConnection, Transaction::getTable()); @@ -55,8 +68,16 @@ class TransactionRepository public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator { - $select = new Select(Container::$dbConnection); - $select->where('community_id', '=', $community->getId()); + $select = $this->selectAllByCommunity($community); + $select->orderBy('time', 'DESC'); + $select->limit($limit, $start); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations); + } + + public function getPagedByEvent(Event $event, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator + { + $select = $this->selectAllByEvent($event); $select->orderBy('time', 'DESC'); $select->limit($limit, $start); @@ -69,4 +90,11 @@ class TransactionRepository $select->where('community_id', '=', $community->getId()); return $select; } + + private function selectAllByEvent(Event $event) + { + $select = new Select(Container::$dbConnection, Transaction::getTable()); + $select->where('event_id', '=', $event->getId()); + return $select; + } } diff --git a/views/communities/transaction_edit.php b/views/communities/transaction_edit.php index 76c3392..2d98c7f 100644 --- a/views/communities/transaction_edit.php +++ b/views/communities/transaction_edit.php @@ -1,9 +1,17 @@ +@css(/static/node_modules/tom-select/dist/css/tom-select.min.css) +@js(/static/node_modules/tom-select/dist/js/tom-select.base.min.js) +@js(js/communities/transaction.js) + @extends(templates/layout_normal) @section(main)

getName() ?> » Transactions » + + Events » + getTitle() ?> » + Edit transaction @@ -16,8 +24,15 @@ Container::$routeCollection->getRoute('community.transactions.edit-action')->generateLink(['communitySlug' => $community->getSlug(), 'transactionId' => $transaction->getId()]) : Container::$routeCollection->getRoute('community.transactions.new-action')->generateLink(['communitySlug' => $community->getSlug()]); ?> -
-

Payer

+ +

Event

+ +

Payer

+ From f370ccba883bb4c648eed5bbc6e33eae7a0b528a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 04:05:53 +0200 Subject: [PATCH 11/13] RVRNEXT-11 add upcoming events for user --- src/Controller/HomeController.php | 7 ++++++- views/home.php | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index d3a4960..a5af7ff 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -1,8 +1,10 @@ communityMemberRepository = new CommunityMemberRepository(); + $this->eventRepository = new EventRepository(); } public function isAuthenticationRequired(): bool @@ -39,7 +44,7 @@ class HomeController implements IAuthenticationRequired return new HtmlContent('home', [ 'communities' => $communities, - 'upcomingEvents' => [] + 'upcomingEvents' => iterator_to_array($this->eventRepository->getUpcomingByUser($user, new DateTime(), 3, true, ['community'])) ]); } } diff --git a/views/home.php b/views/home.php index 67a997d..f7db5c3 100644 --- a/views/home.php +++ b/views/home.php @@ -19,7 +19,13 @@

Upcoming events

0): ?> - +

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

There is no upcoming event.

From 0ae7040804a65f6fd20752777bd72d100ea104b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 16:00:51 +0200 Subject: [PATCH 12/13] RVRNEXT-11 update soko-web to 0.12.1 --- composer.json | 2 +- composer.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index b62335d..f6fae7b 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "esoko/soko-web": "0.11", + "esoko/soko-web": "0.12.1", "firebase/php-jwt": "^6.4" }, "require-dev": { diff --git a/composer.lock b/composer.lock index d10597a..d7a56cf 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": "c17dd5eb82ff8f509a17404bd4c471b8", + "content-hash": "a6f50b31b14027eec094629b13cc4097", "packages": [ { "name": "cocur/slugify", @@ -82,11 +82,11 @@ }, { "name": "esoko/soko-web", - "version": "v0.11", + "version": "v0.12.1", "source": { "type": "git", "url": "https://git.esoko.eu/esoko/soko-web.git", - "reference": "78f891fbff0dc8e5de5607529f4c8282f1dff40f" + "reference": "bda12177ebc201f04fdad5493b93039676a983ca" }, "require": { "cocur/slugify": "^4.3", @@ -108,7 +108,7 @@ "GNU GPL 3.0" ], "description": "Lightweight web framework", - "time": "2023-05-06T23:52:34+00:00" + "time": "2023-05-28T13:56:14+00:00" }, { "name": "firebase/php-jwt", From ede5c24a5d3ce769c8fd2ca4432246877d26dfee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 16:39:38 +0200 Subject: [PATCH 13/13] RVRNEXT-11 fix archive in pipeline --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e88d4e6..e3e225c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,7 +35,7 @@ pipeline { sh 'vendor/bin/phpunit --log-junit unit_test_results.xml --testdox tests' } post { - success { + always { archiveArtifacts 'unit_test_results.xml' } } @@ -53,7 +53,7 @@ pipeline { sh 'php vendor/bin/phpstan analyse -c phpstan.neon --error-format=prettyJson > static_code_analysis_results.json' } post { - success { + always { archiveArtifacts 'static_code_analysis_results.json' } }