<?php
namespace App\Controller\User;
use App\Dictionary\ContentStatus;
use App\Security\ApiUser;
use App\Service\Client\ActivityFeedService;
use App\Service\Client\Content\ImagesetListingService;
use App\Service\Client\Content\VideoListingService;
use App\Service\Client\Groups\GroupService;
use App\Service\Client\GuestbookService;
use App\Service\Client\Media\MemberMediaService;
use App\Service\Client\User\BlogEntryService;
use App\Service\Client\User\LikeService;
use App\Service\Client\User\MemberBlockedService;
use App\Service\Client\User\MemberService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\FirewallMapInterface;
/**
* @Route("/profil")
*/
class ProfileController extends AbstractController
{
protected MemberService $memberService;
protected ActivityFeedService $activityService;
protected VideoListingService $videoListingService;
protected ImagesetListingService $imagesetListingService;
protected GuestbookService $guestbookService;
protected MemberMediaService $memberMediaService;
protected LikeService $likeService;
protected MemberBlockedService $memberBlockedService;
protected GroupService $groupService;
public function __construct(MemberService $memberService, ActivityFeedService $activityFeedService,
VideoListingService $videoListingService, ImagesetListingService $imagesetListingService,
MemberMediaService $memberMediaService, GuestbookService $guestbookService,
LikeService $likeService, MemberBlockedService $memberBlockedService,
GroupService $groupService)
{
$this->memberService = $memberService;
$this->activityService = $activityFeedService;
$this->videoListingService = $videoListingService;
$this->imagesetListingService = $imagesetListingService;
$this->guestbookService = $guestbookService;
$this->memberMediaService = $memberMediaService;
$this->likeService = $likeService;
$this->memberBlockedService = $memberBlockedService;
$this->groupService = $groupService;
}
/**
* @Route("/{username}/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
* @param string $username
* @param int $page
* @return array
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
*/
public function detail(string $username, int $page = 1): array
{
$member = $this->memberService->getMemberDetailByUsername($username, true);
if (!$member || !$member['is_active']) {
throw $this->createNotFoundException('Member does not exist: ' . $username);
}
$memberId = (int)$member['id'];
$data = [
'member' => $member,
'profilePhotos' => $this->memberMediaService->getProfilePhotos($memberId, 3, true),
'videos' => [],
'imagesets' => [],
'timeline' => [],
];
if ($member['is_amateur']) {
$data['videos'] = $this->videoListingService->getRecentVideosForMember($memberId, 1, 4, [ContentStatus::ACTIVE]);
$data['imagesets'] = $this->imagesetListingService->getRecentImagesetsForMember($memberId, 1, 4, [ContentStatus::ACTIVE]);
$data['timeline'] = $this->activityService->getTimelineFeedForMember($memberId, $page, 10);
}
/**
* @var $me ApiUser
*/
if ($me = $this->getUser()) {
if ($member['id'] != $me->getMemberId()) {
$data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($memberId);
}
}
return $data;
}
/**
* @param string $username
* @param int $page
* @return array|RedirectResponse
* @Route("/{username}/videos/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
*/
public function videos(string $username, int $page = 1)
{
$member = $this->memberService->getMemberDetailByUsername($username);
if (!$member || $member['is_active'] == false) {
throw $this->createNotFoundException('Member does not exist: ' . $username);
}
if ($member['is_amateur'] === false) {
return $this->redirectToRoute('app_user_profile_detail', ['username' => $username]);
}
$data = [
'member' => $member,
'profilePhotos' => $this->memberMediaService->getProfilePhotos($member['id'], 3, true),
'page' => $page,
'videos' => $this->videoListingService->getRecentVideosForMember($member['id'], $page, 9, [ContentStatus::ACTIVE]),
];
if ($this->getUser()) {
$data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($member['id']);
}
return $data;
}
/**
* @param string $username
* @param int $page
* @return array|RedirectResponse
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
* @Route("/{username}/bilder/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
*/
public function imagesets(string $username, int $page = 1)
{
$member = $this->memberService->getMemberDetailByUsername($username);
if (!$member || $member['is_active'] == false) {
throw $this->createNotFoundException('Member does not exist: ' . $username);
}
if ($member['is_amateur'] === false) {
return $this->redirectToRoute('app_user_profile_detail', ['username' => $username]);
}
$data = [
'member' => $member,
'profilePhotos' => $this->memberMediaService->getProfilePhotos($member['id'], 3, true),
'page' => $page,
'imagesets' => $this->imagesetListingService->getRecentImagesetsForMember($member['id'], $page, 9, [ContentStatus::ACTIVE]),
];
if ($this->getUser()) {
$data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($member['id']);
}
return $data;
}
/**
* @param string $username
* @param int $page
* @return array|RedirectResponse
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
* @Route("/{username}/tagebuch/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
* @Template()
*/
public function blog(string $username, int $page, BlogEntryService $blogService)
{
$member = $this->memberService->getMemberDetailByUsername($username);
if (!$member || $member['is_active'] == false) {
throw $this->createNotFoundException('Member does not exist: ' . $username);
}
if ($member['is_amateur'] === false) {
return $this->redirectToRoute('app_user_profile_detail', ['username' => $username]);
}
$perPage = 10; # col-6 in template. if changed to 12, probably also change html classes
$data = [
'member' => $member,
'profilePhotos' => $this->memberMediaService->getProfilePhotos($member['id'], 3, true),
'page' => $page,
'blogEntries' => $blogService->listPublicEntries($member['id'], $page),
];
if ($this->getUser()) {
$data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($member['id']);
}
return $data;
}
/**
* @Route("/{username}/steckbrief")
* @Template()
* @param string $username
* @return array
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
*/
public function about(string $username): array
{
$member = $this->memberService->getMemberDetailByUsername($username, true);
if (!$member || $member['is_active'] == false) {
throw $this->createNotFoundException('Member does not exist: ' . $username);
}
$data = [
'member' => $member,
'profilePhotos' => $this->memberMediaService->getProfilePhotos($member['id'], 3, true),
'myGroups' => $this->groupService->getGroupsForMember($member['id']),
];
if ($this->getUser()) {
$data['existingLike'] = $this->likeService->getExistingMemberLikeForIssuer($member['id']);
}
return $data;
}
/**
* @Route("/{username}/gaestebuch/{page}", methods={"GET|POST"}, requirements={"page": "\d+"}, defaults={"page": 1})
* @param Request $request
* @param string $username
* @param GuestbookController $gbController
* @param int $page
* @return Response
* @throws \Psr\Cache\InvalidArgumentException
* @throws \ReflectionException
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
*/
public function guestbook(Request $request, string $username, GuestbookController $gbController, int $page = 1): Response
{
return $gbController->index($request, $username, $page);
}
public static function getSubscribedServices()
{
$services = parent::getSubscribedServices();
$services[FirewallMapInterface::class] = '?' . FirewallMapInterface::class;
return $services;
}
}