src/Controller/Library/LibraryCategoryController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Library;
  3. use App\Entity\LibraryCategory;
  4. use App\EntityManager\LibraryManager;
  5. use App\Form\Library\LibraryDocumentSearchType;
  6. use App\Model\SearchLibraryDocument;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route("/library")
  13.  */
  14. class LibraryCategoryController extends AbstractController
  15. {
  16.     protected $libraryManager;
  17.     public function __construct(LibraryManager $libraryManager)
  18.     {
  19.         $this->libraryManager $libraryManager;
  20.     }
  21.     /**
  22.      * @Route("/{id<\d+>?}", name="library_category_view")
  23.      * @Template()
  24.      */
  25.     public function view(Request $requestLibraryCategory $category null)
  26.     {
  27.         $searchObject = new SearchLibraryDocument();
  28.         $searchForm   $this->createForm(
  29.             LibraryDocumentSearchType::class,
  30.             $searchObject,
  31.             ['method' => Request::METHOD_GET]
  32.         );
  33.         $searchForm->handleRequest($request);
  34.         $documents $this->libraryManager->getCategoryList($category$searchObject);
  35.         $comments  $this->libraryManager->getComments($category$searchObject);
  36.         return [
  37.             'category'   => $category ?? new LibraryCategory(),
  38.             'documents'  => $documents,
  39.             'comments'   => $comments,
  40.             'sort'       => $request->query->get('sort'),
  41.             'searchForm' => $searchForm->createView(),
  42.         ];
  43.     }
  44.     /**
  45.      * @Route("/best", name="library_category_best")
  46.      * @Template()
  47.      */
  48.     public function best(Request $request)
  49.     {
  50.         $documents $this->libraryManager->getBestDocuments();
  51.         return [
  52.             'documents' => $documents,
  53.         ];
  54.     }
  55.     /**
  56.      * @Route("/favorite", name="library_category_favorite")
  57.      * @Template()
  58.      */
  59.     public function favorite(Request $request)
  60.     {
  61.         $documents $this->libraryManager->getFavorites();
  62.         return [
  63.             'documents' => $documents,
  64.         ];
  65.     }
  66. }