<?php
namespace App\Controller\Groups;
use App\Security\ApiUser;
use App\Service\Client\Groups\GroupListingService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class IndexController
* @package App\Controller\Groups
* @Route("/gruppen")
*/
class IndexController extends AbstractController
{
/**
* @var GroupListingService
*/
protected GroupListingService $service;
const ITEMS_PER_PAGE = 15;
/**
* IndexController constructor.
* @param GroupListingService $service
*/
public function __construct(GroupListingService $service)
{
$this->service = $service;
}
/**
* @Route("/beliebte-gruppen/{category}/{page}", requirements={"category": "\d+", "page": "\d+"}, defaults={"page": 1, "category": 0})
* @Template()
* @param int $category
* @param int $page
* @return array
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function top(int $category, int $page): array
{
return [
'groups' => $this->service->getTopRatedGroups($category, $page),
'page' => $page
];
}
/**
* @Route("/oeffentliche-gruppen/{category}/{page}", requirements={"category": "\d+", "page": "\d+"}, defaults={"page": 1, "category": 0})
* @Template()
* @param int $category
* @param int $page
* @return array
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function publicindex(int $category, int $page): array
{
return [
'groups' => $this->service->getPublicGroups($category, $page),
'page' => $page
];
}
/**
* @Route("/private-gruppen/{category}/{page}", requirements={"category": "\d+", "page": "\d+"}, defaults={"page": 1, "category": 0})
* @Template()
* @param int $category
* @param int $page
* @return array
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function inviteonly(int $category, int $page): array
{
$this->denyAccessUnlessGranted('ROLE_MEMBER');
return [
'groups' => $this->service->getInviteOnlyGroups($category, $page),
'page' => $page
];
}
/**
* @Route("/meine-gruppen/{category}/{page}", requirements={"category": "\d+", "page": "\d+"}, defaults={"page": 1, "category": 0})
* @Template()
* @param int $category
* @param int $page
* @return array
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function mygroups(int $category, int $page): array
{
$this->denyAccessUnlessGranted('ROLE_MEMBER');
/**
* @var $me ApiUser
*/
$me = $this->getUser();
return [
'groups' => $this->service->getMyGroups($me->getMemberId(), $category, $page),
'page' => $page
];
}
}