create endpoints to get current event and current event new transaction
rvr-nextgen/pipeline/pr-master This commit looks good
rvr-nextgen/pipeline/pr-master This commit looks good
This commit is contained in:
4 files changed
+93
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']);
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,16 @@ class EventRepository
|
||||
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
|
||||
{
|
||||
$select = $this->selectAllByCommunity($community);
|
||||
|
||||
Reference in new issue
Block a user