src/Controller/ProfilePreviewController.php line 47

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-19
  5.  * Time: 22:20
  6.  */
  7. namespace App\Controller;
  8. use App\Entity\Location\City;
  9. use App\Entity\Profile\Profile;
  10. use App\Entity\ServiceGroups;
  11. use App\Repository\ServiceRepository;
  12. use App\Serializer\Normalizer\ProfileNormalizer;
  13. use App\Service\ModerationService;
  14. use App\Service\NearestProfiles;
  15. use App\Service\ProfileList;
  16. use App\Specification\ElasticSearch\Spec;
  17. use Carbon\CarbonImmutable;
  18. use Nelmio\ApiDocBundle\Attribute\Model;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  23. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use Symfony\Component\HttpKernel\Exception\GoneHttpException;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. use OpenApi\Attributes as OA;
  29. #[Cache(maxage600, public: true)]
  30. class ProfilePreviewController extends AbstractController
  31. {
  32.     use ProfileCommentsTrait;
  33.     use ResponseTrait;
  34.     #[ParamConverter("city"converter"city_converter")]
  35.     #[Entity("profile"expr"repository.ofUriIdentityWithinCity(profile, city)")]
  36.     #[Route("/api/profiles/city/{city}/preview/{profile}"name"api.profiles.preview"methods"GET"format"json")]
  37.     #[OA\Tag(name"Preview")]
  38.     #[OA\Response(
  39.         response200,
  40.         description'Полная информация анкеты',
  41.         content: new OA\JsonContent(ref: new Model(typeProfile::class, groups: ['preview''comments']))
  42.     )]
  43.     public function page(
  44.         Request               $request,
  45.         ServiceRepository     $serviceRepository,
  46.         City                  $city,
  47.         Profile               $profile,
  48.         ModerationService     $moderationService,
  49.         ParameterBagInterface $parameterBag,
  50.         NearestProfiles       $nearestProfiles,
  51.     ): Response
  52.     {
  53.         //  DMCA hard delete — всегда 404
  54.         if ($profile->isHardDeleted()) {
  55.             throw $this->createNotFoundException();
  56.         }
  57.         $showHttp200FromDate $this->createDateFromParameter(
  58.             $parameterBag->get('app.profile.page.deleted_profile_http_200_starting_from')
  59.         );
  60.         if ($profile->isDeleted() && $profile->getDeletedAt() < $showHttp200FromDate) {
  61.             throw new GoneHttpException();
  62.         }
  63.         //$entityManager->getFilters()->enable('not_deleted_profile_filter');
  64.         if ($profile->isModerationRejected()) {
  65.             //показываем
  66.         } else if (false == $moderationService->isProfileEligibleToShowByModeration($profile)) {
  67.             throw $this->createNotFoundException();
  68.         }
  69.         if ($this->isApiRequest($request)) {
  70.             return $this->json($profilecontext: ['groups' => ['preview''comments']]);
  71.         }
  72.         $services $serviceRepository->allIndexedByGroup();
  73.         $parameters = [
  74.             'profile' => $profile,
  75.             'profile_saloon' => $profile->getSaloon(),
  76.             'services' => $services,
  77.             'masseurExcludeServiceGroups' => [
  78.                 ServiceGroups::SEXServiceGroups::EXTREMEServiceGroups::BDSMServiceGroups::MISC,
  79.             ],
  80.             'recommendationSpec' => Spec::andX(),
  81.             'rating' => $this->countAverageRating($profile),
  82.             'nearest_profiles' => $nearestProfiles->getNearestProfiles($profile6),
  83.         ];
  84.         return $this->render('ProfilePreview/page.html.twig'$parameters);
  85.     }
  86.     private function createDateFromParameter(string $value): CarbonImmutable
  87.     {
  88.         $value trim(html_entity_decode($valueENT_QUOTES), '"\' ');
  89.         $value preg_replace('/([+-]\d{2}:\d{2})([+-]\d{2}:\d{2})$/''$1'$value);
  90.         return CarbonImmutable::createFromTimeString($value);
  91.     }
  92. }