rvr-nextgen/src/Controller/HomeController.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2023-04-08 00:42:55 +02:00
<?php namespace RVR\Controller;
2023-04-16 03:31:40 +02:00
use RVR\PersistentData\Model\User;
use RVR\Repository\CommunityMemberRepository;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
2023-04-08 00:42:55 +02:00
use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Response\HtmlContent;
class HomeController implements IAuthenticationRequired
2023-04-08 00:42:55 +02:00
{
2023-04-16 03:31:40 +02:00
private CommunityMemberRepository $communityMemberRepository;
2023-04-19 23:19:22 +02:00
public function __construct()
2023-04-08 00:42:55 +02:00
{
2023-04-16 03:31:40 +02:00
$this->communityMemberRepository = new CommunityMemberRepository();
2023-04-08 00:42:55 +02:00
}
public function isAuthenticationRequired(): bool
2023-04-08 00:42:55 +02:00
{
return true;
2023-04-08 00:42:55 +02:00
}
2023-04-16 03:31:40 +02:00
public function getHome(): IContent
2023-04-08 00:42:55 +02:00
{
2023-04-16 03:31:40 +02:00
/**
* @var User $user
*/
2023-04-19 23:19:22 +02:00
$user = \Container::$request->user();
2023-04-16 03:31:40 +02:00
$ownCommunityMembers = $this->communityMemberRepository->getAllByUser($user, true);
$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' => []
]);
2023-04-08 00:42:55 +02:00
}
}