src/Controller/Frontend/MarketPlaceController.php line 46
<?phpnamespace App\Controller\Frontend;use App\Services\CategoryService;use App\Services\Mooc\MoocService;use App\Services\Product\FakeData;use App\Services\Product\ProductService;use App\Services\ReviewService;use App\Services\TokenVerifier;use App\Services\User\AuthUserService;use Knp\Component\Pager\PaginatorInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\Security\Core\Exception\AuthenticationException;class MarketPlaceController extends AbstractController{private ProductService $productService;private CategoryService $categoryService;private PaginatorInterface $paginator;private ReviewService $reviewService;private AuthUserService $authUserService;/*** @param ProductService $productService* @param CategoryService $categoryService* @param PaginatorInterface $paginator* @param ReviewService $reviewService* @param AuthUserService $authUserService*/public function __construct(ProductService $productService, CategoryService $categoryService, PaginatorInterface $paginator,ReviewService $reviewService, AuthUserService $authUserService){$this->productService = $productService;$this->categoryService = $categoryService;$this->paginator = $paginator;$this->reviewService = $reviewService;$this->authUserService = $authUserService;}#[Route('/market-place', name: 'app_market_search')]public function index(Request $request, string $marketplaceEnabled): Response{if (!$marketplaceEnabled) {throw $this->createNotFoundException();}try {$client_id = null;$client = $this->authUserService->getAllAboutMe();if ($client !== null) {$client_id = $client->id;}} catch (AuthenticationException $exception) {$client_id = null;}$products = $this->paginator->paginate($this->productService->getProducts(null, true, false, $client_id),$request->query->getInt('page', 1),limit: 9);$categories = json_decode($this->categoryService->getCategories()->getContent(), true);return $this->render('frontend/market/index.html.twig', ['products' => $products,'categories' => $categories,]);}#[Route('market/products/{id}', name: 'app_market_detail_products')]public function details($id, string $marketplaceEnabled): Response{if (!$marketplaceEnabled) {throw $this->createNotFoundException();}$my_product = $this->productService->getProduct($id);$my_product = json_decode($my_product->getContent(), true);$products = $this->productService->getProductsByCategory($my_product['id']);$products = json_decode($products->getContent(), true);$reviews = $this->reviewService->getReview($my_product['id']);$productsArray=[];$i = 0;foreach ($products as $product){if ($i < 3){$productsArray[] = $product;}$i = $i + 1;}return $this->render("frontend/market/detail-product.html.twig",['product' => $my_product,'products' => $productsArray,'reviews' => $reviews]);}#[Route('/market-place/category/{id}', name: 'app_market_search_by_category')]public function productByCategory(Request $request, $id, string $marketplaceEnabled): Response{if (!$marketplaceEnabled) {throw $this->createNotFoundException();}$products = $this->productService->getProductsByCategory((int) $id);$products = json_decode($products->getContent(), true);$products = $this->paginator->paginate($products,$request->query->getInt('page', 1),limit: 9);$categories = json_decode($this->categoryService->getCategories()->getContent(), true);return $this->render('frontend/market/product-by-category.html.twig', ['products' => $products,'categories' => $categories]);}}