create endpoints to get current event and current event new transaction
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
This commit is contained in:
parent
b6da70e015
commit
7beec510a1
70
src/Controller/EventRedirectController.php
Normal file
70
src/Controller/EventRedirectController.php
Normal file
@ -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']);
|
||||||
|
}
|
||||||
|
}
|
@ -53,6 +53,16 @@ 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 = $this->selectAllByUser($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 = $this->selectAllByCommunity($community);
|
||||||
|
8
views/event_redirect/no_event.php
Normal file
8
views/event_redirect/no_event.php
Normal 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
web.php
5
web.php
@ -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', 'transactions/new', [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']);
|
||||||
|
Loading…
Reference in New Issue
Block a user