|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Users\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Controller\BaseController; |
|
6
|
|
|
use App\Movies\Repository\MovieRecommendationRepository; |
|
7
|
|
|
use App\Movies\Transformer\UserRecommendationTransformer; |
|
8
|
|
|
use App\Pagination\CustomPaginatedCollection; |
|
9
|
|
|
use App\Users\Entity\User; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
|
|
14
|
|
|
class RecommendationsController extends BaseController |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @Route("/api/users/{id<\d+>}/recommendations", methods={"GET"}) |
|
18
|
|
|
* |
|
19
|
|
|
* @param User $profileOwner |
|
20
|
|
|
* @param Request $request |
|
21
|
|
|
* @param MovieRecommendationRepository $repository |
|
22
|
|
|
* |
|
23
|
|
|
* @throws |
|
24
|
|
|
* |
|
25
|
|
|
* @return JsonResponse |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function getUserRecommendations(User $profileOwner, Request $request, MovieRecommendationRepository $repository) |
|
28
|
|
|
{ |
|
29
|
2 |
|
$offset = (int) $request->get('offset', 0); |
|
30
|
2 |
|
$limit = $request->get('limit', null); |
|
31
|
2 |
|
$minRating = (int) $request->get('minRating', 7); |
|
32
|
|
|
|
|
33
|
2 |
|
[$items, $ids, $count] = $repository->findAllByUser($profileOwner->getId(), abs($minRating), $this->getUser()); |
|
|
|
|
|
|
34
|
2 |
|
$collection = new CustomPaginatedCollection($items, $ids, $count, $offset, $limit); |
|
35
|
|
|
|
|
36
|
2 |
|
return $this->items($collection, UserRecommendationTransformer::list($collection->getItemsIds())); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.