feature/RVRNEXT-45-show-recent-events-as-well #60
@ -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,
 | 
			
		||||
 | 
			
		||||
@ -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']))
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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'));
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -12,16 +12,16 @@
 | 
			
		||||
 | 
			
		||||
    <div class="gridContainer marginTop">
 | 
			
		||||
        <div>
 | 
			
		||||
            <h3 class="marginBottom">Upcoming events</h3>
 | 
			
		||||
            <?php if (count($upcomingEvents) > 0): ?>
 | 
			
		||||
                <?php foreach ($upcomingEvents as $event): ?>
 | 
			
		||||
            <h3 class="marginBottom">Upcoming and recent events</h3>
 | 
			
		||||
            <?php if (count($upcomingAndRecentEvents) > 0): ?>
 | 
			
		||||
                <?php foreach ($upcomingAndRecentEvents as $event): ?>
 | 
			
		||||
                    <p>
 | 
			
		||||
                        <a href="<?= Container::$routeCollection->getRoute('community.event')->generateLink(['communitySlug' => $community->getSlug(), 'eventSlug' => $event->getSlug()]) ?>"><?= $event->getTitle() ?></a>
 | 
			
		||||
                        <span class="small"><?= $event->getStartDate()->format('Y-m-d') ?> – <?= $event->getEndDate()->format('Y-m-d') ?></span>
 | 
			
		||||
                    </p>
 | 
			
		||||
                <?php endforeach; ?>
 | 
			
		||||
            <?php else: ?>
 | 
			
		||||
                <p>There is no upcoming event.</p>
 | 
			
		||||
                <p>There is no event to show.</p>
 | 
			
		||||
            <?php endif; ?>
 | 
			
		||||
            <p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug()]) ?>">All events</a> | <a href="<?= Container::$routeCollection->getRoute('community.events.new')->generateLink(['communitySlug' => $community->getSlug()]) ?>">New event</a></p>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
@ -16,9 +16,9 @@
 | 
			
		||||
            <?php endif; ?>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div>
 | 
			
		||||
            <h3 class="marginBottom">Upcoming events</h3>
 | 
			
		||||
            <?php if (count($upcomingEvents) > 0): ?>
 | 
			
		||||
                <?php foreach ($upcomingEvents as $event): ?>
 | 
			
		||||
            <h3 class="marginBottom">Upcoming and recent events</h3>
 | 
			
		||||
            <?php if (count($upcomingAndRecentEvents) > 0): ?>
 | 
			
		||||
                <?php foreach ($upcomingAndRecentEvents as $event): ?>
 | 
			
		||||
                    <p>
 | 
			
		||||
                        <a href="<?= Container::$routeCollection->getRoute('community.event')->generateLink(['communitySlug' => $event->getCommunity()->getSlug(), 'eventSlug' => $event->getSlug()]) ?>"><?= $event->getTitle() ?></a>
 | 
			
		||||
                        <span class="small">
 | 
			
		||||
@ -28,7 +28,7 @@
 | 
			
		||||
                    </p>
 | 
			
		||||
                <?php endforeach; ?>
 | 
			
		||||
            <?php else: ?>
 | 
			
		||||
                <p>There is no upcoming event.</p>
 | 
			
		||||
                <p>There is no event to show.</p>
 | 
			
		||||
            <?php endif; ?>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user