src/Controller/User/ProfileController.php line 70

Open in your IDE?
  1. <?php
  2. namespace App\Controller\User;
  3. use App\Dictionary\ContentStatus;
  4. use App\Security\ApiUser;
  5. use App\Service\Client\ActivityFeedService;
  6. use App\Service\Client\Content\ImagesetListingService;
  7. use App\Service\Client\Content\VideoListingService;
  8. use App\Service\Client\Groups\GroupService;
  9. use App\Service\Client\GuestbookService;
  10. use App\Service\Client\Media\MemberMediaService;
  11. use App\Service\Client\User\BlogEntryService;
  12. use App\Service\Client\User\LikeService;
  13. use App\Service\Client\User\MemberBlockedService;
  14. use App\Service\Client\User\MemberService;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\RedirectResponse;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Symfony\Component\Security\Http\FirewallMapInterface;
  22. /**
  23.  * @Route("/profil")
  24.  */
  25. class ProfileController extends AbstractController
  26. {
  27.     protected MemberService $memberService;
  28.     protected ActivityFeedService $activityService;
  29.     protected VideoListingService $videoListingService;
  30.     protected ImagesetListingService $imagesetListingService;
  31.     protected GuestbookService $guestbookService;
  32.     protected MemberMediaService $memberMediaService;
  33.     protected LikeService $likeService;
  34.     protected MemberBlockedService $memberBlockedService;
  35.     protected GroupService $groupService;
  36.     public function __construct(MemberService       $memberServiceActivityFeedService $activityFeedService,
  37.                                 VideoListingService $videoListingServiceImagesetListingService $imagesetListingService,
  38.                                 MemberMediaService  $memberMediaServiceGuestbookService $guestbookService,
  39.                                 LikeService         $likeServiceMemberBlockedService $memberBlockedService,
  40.                                 GroupService        $groupService)
  41.     {
  42.         $this->memberService $memberService;
  43.         $this->activityService $activityFeedService;
  44.         $this->videoListingService $videoListingService;
  45.         $this->imagesetListingService $imagesetListingService;
  46.         $this->guestbookService $guestbookService;
  47.         $this->memberMediaService $memberMediaService;
  48.         $this->likeService $likeService;
  49.         $this->memberBlockedService $memberBlockedService;
  50.         $this->groupService $groupService;
  51.     }
  52.     /**
  53.      * @Route("/{username}/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  54.      * @Template()
  55.      * @param string $username
  56.      * @param int $page
  57.      * @return array
  58.      * @throws \Psr\Cache\InvalidArgumentException
  59.      * @throws \ReflectionException
  60.      * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
  61.      * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
  62.      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
  63.      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
  64.      */
  65.     public function detail(string $usernameint $page 1): array
  66.     {
  67.         $member $this->memberService->getMemberDetailByUsername($usernametrue);
  68.         if (!$member || !$member['is_active']) {
  69.             throw $this->createNotFoundException('Member does not exist: ' $username);
  70.         }
  71.         $memberId = (int)$member['id'];
  72.         $data = [
  73.             'member' => $member,
  74.             'profilePhotos' => $this->memberMediaService->getProfilePhotos($memberId3true),
  75.             'videos' => [],
  76.             'imagesets' => [],
  77.             'timeline' => [],
  78.         ];
  79.         if ($member['is_amateur']) {
  80.             $data['videos'] = $this->videoListingService->getRecentVideosForMember($memberId14, [ContentStatus::ACTIVE]);
  81.             $data['imagesets'] = $this->imagesetListingService->getRecentImagesetsForMember($memberId14, [ContentStatus::ACTIVE]);
  82.             $data['timeline'] = $this->activityService->getTimelineFeedForMember($memberId$page10);
  83.         }
  84.         /**
  85.          * @var $me ApiUser
  86.          */
  87.         if ($me $this->getUser()) {
  88.             if ($member['id'] != $me->getMemberId()) {
  89.                 $data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($memberId);
  90.             }
  91.         }
  92.         return $data;
  93.     }
  94.     /**
  95.      * @param string $username
  96.      * @param int $page
  97.      * @return array|RedirectResponse
  98.      * @Route("/{username}/videos/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  99.      * @Template()
  100.      */
  101.     public function videos(string $usernameint $page 1)
  102.     {
  103.         $member $this->memberService->getMemberDetailByUsername($username);
  104.         if (!$member || $member['is_active'] == false) {
  105.             throw $this->createNotFoundException('Member does not exist: ' $username);
  106.         }
  107.         if ($member['is_amateur'] === false) {
  108.             return $this->redirectToRoute('app_user_profile_detail', ['username' => $username]);
  109.         }
  110.         $data = [
  111.             'member' => $member,
  112.             'profilePhotos' => $this->memberMediaService->getProfilePhotos($member['id'], 3true),
  113.             'page' => $page,
  114.             'videos' => $this->videoListingService->getRecentVideosForMember($member['id'], $page9, [ContentStatus::ACTIVE]),
  115.         ];
  116.         if ($this->getUser()) {
  117.             $data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($member['id']);
  118.         }
  119.         return $data;
  120.     }
  121.     /**
  122.      * @param string $username
  123.      * @param int $page
  124.      * @return array|RedirectResponse
  125.      * @throws \Psr\Cache\InvalidArgumentException
  126.      * @throws \ReflectionException
  127.      * @Route("/{username}/bilder/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  128.      * @Template()
  129.      */
  130.     public function imagesets(string $usernameint $page 1)
  131.     {
  132.         $member $this->memberService->getMemberDetailByUsername($username);
  133.         if (!$member || $member['is_active'] == false) {
  134.             throw $this->createNotFoundException('Member does not exist: ' $username);
  135.         }
  136.         if ($member['is_amateur'] === false) {
  137.             return $this->redirectToRoute('app_user_profile_detail', ['username' => $username]);
  138.         }
  139.         $data = [
  140.             'member' => $member,
  141.             'profilePhotos' => $this->memberMediaService->getProfilePhotos($member['id'], 3true),
  142.             'page' => $page,
  143.             'imagesets' => $this->imagesetListingService->getRecentImagesetsForMember($member['id'], $page9, [ContentStatus::ACTIVE]),
  144.         ];
  145.         if ($this->getUser()) {
  146.             $data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($member['id']);
  147.         }
  148.         return $data;
  149.     }
  150.     /**
  151.      * @param string $username
  152.      * @param int $page
  153.      * @return array|RedirectResponse
  154.      * @throws \Psr\Cache\InvalidArgumentException
  155.      * @throws \ReflectionException
  156.      * @Route("/{username}/tagebuch/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  157.      * @Template()
  158.      */
  159.     public function blog(string $usernameint $pageBlogEntryService $blogService)
  160.     {
  161.         $member $this->memberService->getMemberDetailByUsername($username);
  162.         if (!$member || $member['is_active'] == false) {
  163.             throw $this->createNotFoundException('Member does not exist: ' $username);
  164.         }
  165.         if ($member['is_amateur'] === false) {
  166.             return $this->redirectToRoute('app_user_profile_detail', ['username' => $username]);
  167.         }
  168.         $perPage 10# col-6 in template. if changed to 12, probably also change html classes
  169.         $data = [
  170.             'member' => $member,
  171.             'profilePhotos' => $this->memberMediaService->getProfilePhotos($member['id'], 3true),
  172.             'page' => $page,
  173.             'blogEntries' => $blogService->listPublicEntries($member['id'], $page),
  174.         ];
  175.         if ($this->getUser()) {
  176.             $data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($member['id']);
  177.         }
  178.         return $data;
  179.     }
  180.     /**
  181.      * @Route("/{username}/steckbrief")
  182.      * @Template()
  183.      * @param string $username
  184.      * @return array
  185.      * @throws \Psr\Cache\InvalidArgumentException
  186.      * @throws \ReflectionException
  187.      */
  188.     public function about(string $username): array
  189.     {
  190.         $member $this->memberService->getMemberDetailByUsername($usernametrue);
  191.         if (!$member || $member['is_active'] == false) {
  192.             throw $this->createNotFoundException('Member does not exist: ' $username);
  193.         }
  194.         $data = [
  195.             'member' => $member,
  196.             'profilePhotos' => $this->memberMediaService->getProfilePhotos($member['id'], 3true),
  197.             'myGroups' => $this->groupService->getGroupsForMember($member['id']),
  198.         ];
  199.         if ($this->getUser()) {
  200.             $data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($member['id']);
  201.         }
  202.         return $data;
  203.     }
  204.     /**
  205.      * @Route("/{username}/gaestebuch/{page}", methods={"GET|POST"}, requirements={"page": "\d+"}, defaults={"page": 1})
  206.      * @param Request $request
  207.      * @param string $username
  208.      * @param GuestbookController $gbController
  209.      * @param int $page
  210.      * @return Response
  211.      * @throws \Psr\Cache\InvalidArgumentException
  212.      * @throws \ReflectionException
  213.      * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
  214.      * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
  215.      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
  216.      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
  217.      */
  218.     public function guestbook(Request $requeststring $usernameGuestbookController $gbControllerint $page 1): Response
  219.     {
  220.         return $gbController->index($request$username$page);
  221.     }
  222.     public static function getSubscribedServices()
  223.     {
  224.         $services parent::getSubscribedServices();
  225.         $services[FirewallMapInterface::class] = '?' FirewallMapInterface::class;
  226.         return $services;
  227.     }
  228. }