rvr-nextgen/src/Controller/HomeController.php

49 lines
1.3 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;
2023-04-08 00:42:55 +02:00
use SokoWeb\Interfaces\Authorization\ISecured;
use SokoWeb\Interfaces\Request\IRequest;
use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Response\HtmlContent;
class HomeController implements ISecured
{
private IRequest $request;
2023-04-16 03:31:40 +02:00
private CommunityMemberRepository $communityMemberRepository;
2023-04-08 00:42:55 +02:00
public function __construct(IRequest $request)
{
$this->request = $request;
2023-04-16 03:31:40 +02:00
$this->communityMemberRepository = new CommunityMemberRepository();
2023-04-08 00:42:55 +02:00
}
public function authorize(): bool
{
return $this->request->user() !== null;
}
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
*/
$user = $this->request->user();
$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
}
}