rvr-nextgen/src/Controller/HomeController.php
Pőcze Bence 49d72f1d48
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
adapt $withRelations usage to soko-web 0.7
2023-04-30 20:25:21 +02:00

46 lines
1.3 KiB
PHP

<?php namespace RVR\Controller;
use RVR\PersistentData\Model\Community;
use RVR\PersistentData\Model\User;
use RVR\Repository\CommunityMemberRepository;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Response\HtmlContent;
class HomeController implements IAuthenticationRequired
{
private CommunityMemberRepository $communityMemberRepository;
public function __construct()
{
$this->communityMemberRepository = new CommunityMemberRepository();
}
public function isAuthenticationRequired(): bool
{
return true;
}
public function getHome(): IContent
{
/**
* @var User $user
*/
$user = \Container::$request->user();
$ownCommunityMembers = $this->communityMemberRepository->getAllByUser($user, true, ['community']);
$communities = [];
foreach ($ownCommunityMembers as $ownCommunityMember) {
$communities[] = $ownCommunityMember->getCommunity();
}
usort($communities, function($a, $b) {
return strnatcmp($a->getName(), $b->getName());
});
return new HtmlContent('home', [
'communities' => $communities,
'upcomingEvents' => []
]);
}
}