Compare commits

..
Author SHA1 Message Date
bence 6146641eed Merge pull request 'fix selectUpcomingAndRecent when used with other selects' (!67) from bugfix/upcoming-events-are-multiplicated into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #67
2023-08-06 22:09:33 +02:00
bence 7cb406cc49 fix selectUpcomingAndRecent when used with other selects
rvr-nextgen/pipeline/pr-master This commit looks good
2023-08-06 22:06:42 +02:00
bence 2d2cf9c6f0 Merge pull request 'make short new transaction url even shorter' (!66) from feature/change-short-new-transaction-url into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #66
2023-07-24 21:43:39 +02:00
bence ca069d0795 make short new transaction url even shorter
rvr-nextgen/pipeline/pr-master This commit looks good
2023-07-24 21:42:27 +02:00
bence 17d9437a50 Merge pull request 'fix select to avoid getting all events as upcoming/recent' (!65) from bugfix/fix-select-for-upcoming-and-recent-events into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #65
2023-07-24 02:12:15 +02:00
bence aed4548c7b fix select to avoid getting all events as upcoming/recent
rvr-nextgen/pipeline/pr-master This commit looks good
2023-07-24 02:11:27 +02:00
bence 0d6d152b82 Merge pull request 'create endpoints to get current event and current event new transaction' (!64) from feature/create-endpoint-for-currect-event-redirection into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #64
2023-07-24 02:08:11 +02:00
bence 7beec510a1 create endpoints to get current event and current event new transaction
rvr-nextgen/pipeline/pr-master This commit looks good
2023-07-24 02:00:59 +02:00
bence 22b849a1c8 Merge pull request 'select current user as payer by default for new transaction' (!63) from feature/default-payer-is-current-user into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #63
2023-07-24 01:31:22 +02:00
bence 492aa9fcef select current user as payer by default for new transaction
rvr-nextgen/pipeline/pr-master This commit looks good
2023-07-24 01:29:53 +02:00
5 changed files with 124 additions and 15 deletions

No files matched your search

@@ -0,0 +1,70 @@
<?php namespace RVR\Controller;
use DateTime;
use Container;
use RVR\PersistentData\Model\Event;
use RVR\PersistentData\Model\User;
use RVR\Repository\EventRepository;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Response\IRedirect;
use SokoWeb\Response\HtmlContent;
use SokoWeb\Response\Redirect;
class EventRedirectController implements IAuthenticationRequired
{
private EventRepository $eventRepository;
public function __construct()
{
$this->eventRepository = new EventRepository();
}
public function isAuthenticationRequired(): bool
{
return true;
}
public function getEvent()
{
$currentEvent = $this->getCurrentEvent();
if ($currentEvent === null) {
return new HtmlContent('event_redirect/no_event');
}
return new Redirect(
\Container::$routeCollection->getRoute('community.event')
->generateLink([
'communitySlug' => $currentEvent->getCommunity()->getSlug(),
'eventSlug' => $currentEvent->getSlug()
]),
IRedirect::TEMPORARY
);
}
public function getEventNewTransaction()
{
$currentEvent = $this->getCurrentEvent();
if ($currentEvent === null) {
return new HtmlContent('event_redirect/no_event');
}
return new Redirect(
\Container::$routeCollection->getRoute('community.transactions.new')
->generateLink([
'communitySlug' => $currentEvent->getCommunity()->getSlug(),
'event' => $currentEvent->getSlug()
]),
IRedirect::TEMPORARY
);
}
private function getCurrentEvent(): ?Event
{
/**
* @var User $user
*/
$user = Container::$request->user();
return $this->eventRepository->getCurrentByUser($user, new DateTime(), 30, true, ['community']);
}
}
+35 -14
View File
@@ -23,19 +23,24 @@ class EventRepository
public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator
{ {
$select = $this->selectAllByCommunity($community); $select = new Select(Container::$dbConnection, Event::getTable());
$this->selectAllByCommunity($select, $community);
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
} }
public function countAllByCommunity(Community $community): int public function countAllByCommunity(Community $community): int
{ {
return $this->selectAllByCommunity($community)->count(); $select = new Select(Container::$dbConnection, Event::getTable());
$this->selectAllByCommunity($select, $community);
return $select->count();
} }
public function getUpcomingAndRecentByCommunity(Community $community, DateTime $from, int $days, 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 = new Select(Container::$dbConnection, Event::getTable());
$this->selectAllByCommunity($select, $community);
$this->selectUpcomingAndRecent($select, $from, $days); $this->selectUpcomingAndRecent($select, $from, $days);
$select->orderBy('start', 'DESC'); $select->orderBy('start', 'DESC');
$select->limit($limit, 0); $select->limit($limit, 0);
@@ -45,7 +50,8 @@ class EventRepository
public function getUpcomingAndRecentByUser(User $user, DateTime $from, int $days, 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 = new Select(Container::$dbConnection, Event::getTable());
$this->selectAllByUser($select, $user);
$this->selectUpcomingAndRecent($select, $from, $days); $this->selectUpcomingAndRecent($select, $from, $days);
$select->orderBy('start', 'DESC'); $select->orderBy('start', 'DESC');
$select->limit($limit, 0); $select->limit($limit, 0);
@@ -53,9 +59,21 @@ class EventRepository
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
} }
public function getCurrentByUser(User $user, DateTime $from, int $days, bool $useRelations = false, array $withRelations = []): ?Event
{
$select = new Select(Container::$dbConnection, Event::getTable());
$this->selectAllByUser($select, $user);
$this->selectUpcomingAndRecent($select, $from, $days);
$select->orderBy('start', 'DESC');
$select->limit(1, 0);
return Container::$persistentDataManager->selectFromDb($select, Event::class, $useRelations, $withRelations);
}
public function getPagedByCommunity(Community $community, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator public function getPagedByCommunity(Community $community, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
{ {
$select = $this->selectAllByCommunity($community); $select = new Select(Container::$dbConnection, Event::getTable());
$this->selectAllByCommunity($select, $community);
$select->orderBy('start', 'DESC'); $select->orderBy('start', 'DESC');
$select->paginate($page, $itemsPerPage); $select->paginate($page, $itemsPerPage);
@@ -64,7 +82,8 @@ class EventRepository
public function searchByTitle(Community $community, string $title): Generator public function searchByTitle(Community $community, string $title): Generator
{ {
$select = $this->selectAllByCommunity($community); $select = new Select(Container::$dbConnection, Event::getTable());
$this->selectAllByCommunity($select, $community);
$select->where('title', 'LIKE', '%' . $title . '%'); $select->where('title', 'LIKE', '%' . $title . '%');
$select->orderBy('start', 'DESC'); $select->orderBy('start', 'DESC');
$select->limit(10); $select->limit(10);
@@ -72,27 +91,29 @@ class EventRepository
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class); yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class);
} }
private function selectAllByCommunity(Community $community) private function selectAllByCommunity(Select $select, Community $community): void
{ {
$select = new Select(Container::$dbConnection, Event::getTable());
$select->where('community_id', '=', $community->getId()); $select->where('community_id', '=', $community->getId());
return $select;
} }
private function selectAllByUser(User $user) private function selectAllByUser(Select $select, User $user): void
{ {
$select = new Select(Container::$dbConnection, Event::getTable());
$select->innerJoin('communities', ['communities', 'id'], '=', ['events', 'community_id']); $select->innerJoin('communities', ['communities', 'id'], '=', ['events', 'community_id']);
$select->innerJoin('community_members', ['communities', 'id'], '=', ['community_members', 'community_id']); $select->innerJoin('community_members', ['communities', 'id'], '=', ['community_members', 'community_id']);
$select->where(['community_members', 'user_id'], '=', $user->getId()); $select->where(['community_members', 'user_id'], '=', $user->getId());
return $select;
} }
private function selectUpcomingAndRecent(Select $select, DateTime $from, int $days) private function selectUpcomingAndRecent(Select $select, DateTime $from, int $days): void
{ {
$select->where(function (Select $select) use ($from, $days) {
$select->where(function (Select $select) use ($from, $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->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')); $select->where('end', '>', $from->format('Y-m-d H:i:s'));
});
$select->orWhere(function (Select $select) use ($from, $days) {
$select->where('end', '>', (clone $from)->sub(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s'));
$select->where('start', '<', $from->format('Y-m-d H:i:s'));
});
}); });
} }
} }
+6 -1
View File
@@ -36,7 +36,12 @@
<select class="big fullWidth" name="payer_user_id" required> <select class="big fullWidth" name="payer_user_id" required>
<option value="" hidden></option> <option value="" hidden></option>
<?php foreach ($members as $member): ?> <?php foreach ($members as $member): ?>
<option value="<?= $member->getUser()->getId() ?>" <?= isset($transaction) && $transaction->getPayerUserId() === $member->getUser()->getId() ? 'selected' : '' ?>><?= $member->getUser()->getDisplayName() ?></option> <option value="<?= $member->getUser()->getId() ?>"
<?= isset($transaction) ?
($transaction->getPayerUserId() === $member->getUser()->getId() ? 'selected' : '') :
(Container::$request->user()->getUniqueId() == $member->getUser()->getId() ? 'selected' : '') ?>>
<?= $member->getUser()->getDisplayName() ?>
</option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<p class="formLabel marginTop">Payee(s)</p> <p class="formLabel marginTop">Payee(s)</p>
+8
View File
@@ -0,0 +1,8 @@
@extends(templates/layout_normal)
@section(main)
<h2>No event found</h2>
<div class="box compactBox">
<p class="error justify">No upcoming or recent event was found. <a href="<?= Container::$routeCollection->getRoute('home')->generateLink() ?>" title="<?= $_ENV['APP_NAME'] ?>">Back to start.</a></p>
</div>
@endsection
+5
View File
@@ -13,6 +13,7 @@ use RVR\Controller\UserController;
use RVR\Controller\UserSearchController; use RVR\Controller\UserSearchController;
use RVR\Controller\CommunityController; use RVR\Controller\CommunityController;
use RVR\Controller\TransactionController; use RVR\Controller\TransactionController;
use RVR\Controller\EventRedirectController;
use RVR\Controller\EventController; use RVR\Controller\EventController;
use RVR\Repository\UserRepository; use RVR\Repository\UserRepository;
@@ -62,6 +63,10 @@ Container::$routeCollection->group('account', function (RouteCollection $routeCo
$routeCollection->get('account.googleAuthenticate-action', 'googleAuthenticate/code', [UserController::class, 'authenticateWithGoogle']); $routeCollection->get('account.googleAuthenticate-action', 'googleAuthenticate/code', [UserController::class, 'authenticateWithGoogle']);
}); });
Container::$routeCollection->get('searchUser', 'searchUser', [UserSearchController::class, 'searchUser']); Container::$routeCollection->get('searchUser', 'searchUser', [UserSearchController::class, 'searchUser']);
Container::$routeCollection->group('now', function (RouteCollection $routeCollection) {
$routeCollection->get('now.event', '', [EventRedirectController::class, 'getEvent']);
$routeCollection->get('now.transactions.new', 'transaction', [EventRedirectController::class, 'getEventNewTransaction']);
});
Container::$routeCollection->group('communities', function (RouteCollection $routeCollection) { Container::$routeCollection->group('communities', function (RouteCollection $routeCollection) {
$routeCollection->get('community.new', 'new', [CommunityController::class, 'getCommunityNew']); $routeCollection->get('community.new', 'new', [CommunityController::class, 'getCommunityNew']);
$routeCollection->post('community.new-action', 'new', [CommunityController::class, 'saveCommunity']); $routeCollection->post('community.new-action', 'new', [CommunityController::class, 'saveCommunity']);