<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 2019-03-19
* Time: 22:20
*/
namespace App\Controller;
use App\Entity\Location\City;
use App\Entity\Profile\Profile;
use App\Entity\ServiceGroups;
use App\Event\Profile\ProfileViewEvent;
use App\Repository\ServiceRepository;
use App\Service\ModerationService;
use App\Service\NearestProfiles;
use App\Service\ProfileList;
use App\Specification\ElasticSearch\Spec;
use Carbon\CarbonImmutable;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\GoneHttpException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
#[Cache(maxage: 600, public: true)]
class ProfilePreviewController extends AbstractController
{
use ProfileCommentsTrait;
#[ParamConverter("city", converter:"city_converter")]
#[Entity("profile", expr:"repository.ofUriIdentityWithinCity(profile, city)")]
public function page(
ServiceRepository $serviceRepository, City $city, Profile $profile, ModerationService $moderationService,
ParameterBagInterface $parameterBag, EventDispatcherInterface $eventDispatcher, NearestProfiles $nearestProfiles,
): Response
{
$showHttp200FromDate = CarbonImmutable::createFromTimeString($parameterBag->get('app.profile.page.deleted_profile_http_200_starting_from'));
if($profile->isDeleted() && $profile->getDeletedAt() < $showHttp200FromDate) {
throw new GoneHttpException();
}
//$entityManager->getFilters()->enable('not_deleted_profile_filter');
if($profile->isModerationRejected()) {
//показываем
} else if (false == $moderationService->isProfileEligibleToShowByModeration($profile)) {
throw $this->createNotFoundException();
}
$services = $serviceRepository->allIndexedByGroup();
//вынесено d ProfileCtrController для ajax
//$eventDispatcher->dispatch(new ProfileViewEvent($profile->getId()), ProfileViewEvent::NAME);
$parameters = [
'profile' => $profile,
'services' => $services,
'masseurExcludeServiceGroups' => [
ServiceGroups::SEX, ServiceGroups::EXTREME, ServiceGroups::BDSM, ServiceGroups::MISC,
],
'recommendationSpec' => Spec::andX(),
'rating' => $this->countAverageRating($profile),
'nearest_profiles' => $nearestProfiles->getNearestProfiles($profile, 6),
];
return $this->render('ProfilePreview/page.html.twig', $parameters);
}
}