src/Service/Client/Groups/GroupListingService.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Service\Client\Groups;
  3. use App\Controller\Groups\IndexController;
  4. use App\Service\Client\AbstractClient;
  5. use Knp\Component\Pager\Pagination\PaginationInterface;
  6. use Symfony\Contracts\Cache\ItemInterface;
  7. class GroupListingService extends AbstractClient
  8. {
  9.     /**
  10.      * @param int $category
  11.      * @param int $page
  12.      * @param int $perPage
  13.      * @return PaginationInterface
  14.      * @throws \Psr\Cache\InvalidArgumentException
  15.      */
  16.     public function getTopRatedGroups(int $categoryint $pageint $perPage IndexController::ITEMS_PER_PAGE): PaginationInterface
  17.     {
  18.         $key = (new \ReflectionClass($this))->getShortName() . '_' __FUNCTION__ .
  19.             '_' $category '_' $page '_' $perPage;
  20.         return $this->getCacheService()->get($key, function(ItemInterface $item)use ($category$page$perPage) {
  21.             $item->expiresAfter(600);
  22.             $path 'api/public/group/index/top/' $category '/' $page;
  23.             $response $this->requestJSON('GET'$path, [
  24.                 'query' => [
  25.                     'limit' => $perPage,
  26.                 ]
  27.             ]);
  28.             return $this->getDefaultPagination($response$page$perPage);
  29.         });
  30.     }
  31.     /**
  32.      * @param int $member
  33.      * @param int $category
  34.      * @param int $page
  35.      * @param int $perPage
  36.      * @return PaginationInterface
  37.      * @throws \Psr\Cache\InvalidArgumentException
  38.      * @throws \ReflectionException
  39.      */
  40.     public function getMyGroups(int $memberint $categoryint $pageint $perPage IndexController::ITEMS_PER_PAGE): PaginationInterface
  41.     {
  42.         $key $this->getMyGroupsCacheKey($member$category$page$perPage);
  43.         return $this->getCacheService()->get($key, function(ItemInterface $item)use ($member$category$page$perPage) {
  44.             $item->expiresAfter(600);
  45.             $path 'api/group/member/' $member '/' $category '/' $page;
  46.             $response $this->requestJSON('GET'$path, [
  47.                 'query' => [
  48.                     'limit' => $perPage,
  49.                 ]
  50.             ]);
  51.             return $this->getDefaultPagination($response$page$perPage);
  52.         });
  53.     }
  54.     /**
  55.      * @param int $member
  56.      * @param int $category
  57.      * @param int $page
  58.      * @param int $perPage
  59.      * @return string
  60.      * @throws \ReflectionException
  61.      */
  62.     public static function getMyGroupsCacheKey(int $memberint $categoryint $pageint $perPage IndexController::ITEMS_PER_PAGE): string
  63.     {
  64.         return (new \ReflectionClass(self::class))->getShortName() . '_getMyGroups_'  .
  65.             '_' $member '_' $category '_' $page '_' $perPage;
  66.     }
  67.     /**
  68.      * @param int $category
  69.      * @param int $page
  70.      * @param int $perPage
  71.      * @return PaginationInterface
  72.      * @throws \Psr\Cache\InvalidArgumentException
  73.      * @throws \ReflectionException
  74.      */
  75.     public function getPublicGroups(int $categoryint $pageint $perPage IndexController::ITEMS_PER_PAGE): PaginationInterface
  76.     {
  77.         $key = (new \ReflectionClass($this))->getShortName() . '_' __FUNCTION__ .
  78.             '_' $category '_' $page '_' $perPage;
  79.         return $this->getCacheService()->get($key, function(ItemInterface $item) use ($category$page$perPage) {
  80.             $item->expiresAfter(600);
  81.             $path 'api/public/group/index/public/' $category '/' $page;
  82.             $response $this->requestJSON('GET'$path, [
  83.                 'query' => [
  84.                     'limit' => $perPage,
  85.                 ]
  86.             ]);
  87.             return $this->getDefaultPagination($response$page$perPage);
  88.         });
  89.     }
  90.     /**
  91.      * @param int $category
  92.      * @param int $page
  93.      * @param int $perPage
  94.      * @return PaginationInterface
  95.      * @throws \Psr\Cache\InvalidArgumentException
  96.      * @throws \ReflectionException
  97.      */
  98.     public function getInviteOnlyGroups(int $categoryint $pageint $perPage IndexController::ITEMS_PER_PAGE): PaginationInterface
  99.     {
  100.         $key = (new \ReflectionClass($this))->getShortName() . '_' __FUNCTION__ .
  101.             '_' $category '_' $page '_' $perPage;
  102.         return $this->getCacheService()->get($key, function(ItemInterface $item) use ($category$page$perPage) {
  103.             $item->expiresAfter(600);
  104.             $path 'api/public/group/index/inviteonly/' $category '/' $page;
  105.             $response $this->requestJSON('GET'$path, [
  106.                 'query' => [
  107.                     'limit' => $perPage,
  108.                 ]
  109.             ]);
  110.             return $this->getDefaultPagination($response$page$perPage);
  111.         });
  112.     }
  113. }