| Total Complexity | 81 |
| Total Lines | 1223 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 1 |
Complex classes like ResourceController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ResourceController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 52 | class ResourceController extends AbstractResourceController implements CourseControllerInterface |
||
| 53 | { |
||
| 54 | use CourseControllerTrait; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @Route("/{tool}/{type}", name="chamilo_core_resource_index") |
||
| 58 | * |
||
| 59 | * Example: /document/files (See the 'tool' and the 'resource_type' DB tables.) |
||
| 60 | * For the tool value check the Tool entity. |
||
| 61 | * For the type value check the ResourceType entity. |
||
| 62 | */ |
||
| 63 | public function indexAction(Request $request, Grid $grid): Response |
||
| 64 | { |
||
| 65 | $tool = $request->get('tool'); |
||
| 66 | $type = $request->get('type'); |
||
| 67 | |||
| 68 | $parentResourceNode = $this->getParentResourceNode($request); |
||
| 69 | $repository = $this->getRepositoryFromRequest($request); |
||
| 70 | $settings = $repository->getResourceSettings(); |
||
| 71 | |||
| 72 | $grid = $this->getGrid($request, $repository, $grid, $parentResourceNode->getId()); |
||
| 73 | |||
| 74 | $breadcrumb = $this->getBreadCrumb(); |
||
| 75 | $breadcrumb->addChild( |
||
| 76 | $this->trans($tool), |
||
| 77 | [ |
||
| 78 | 'uri' => '#', |
||
| 79 | ] |
||
| 80 | ); |
||
| 81 | |||
| 82 | // The base resource node is the course. |
||
| 83 | $id = $parentResourceNode->getId(); |
||
| 84 | |||
| 85 | return $grid->getGridResponse( |
||
| 86 | '@ChamiloTheme/Resource/index.html.twig', |
||
| 87 | [ |
||
| 88 | 'tool' => $tool, |
||
| 89 | 'type' => $type, |
||
| 90 | 'id' => $id, |
||
| 91 | 'parent_resource_node' => $parentResourceNode, |
||
| 92 | 'resource_settings' => $settings, |
||
| 93 | ] |
||
| 94 | ); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @Route("/{tool}/{type}/{id}/list", name="chamilo_core_resource_list") |
||
| 99 | * |
||
| 100 | * If node has children show it |
||
| 101 | */ |
||
| 102 | public function listAction(Request $request, Grid $grid): Response |
||
| 103 | { |
||
| 104 | $tool = $request->get('tool'); |
||
| 105 | $type = $request->get('type'); |
||
| 106 | $resourceNodeId = $request->get('id'); |
||
| 107 | |||
| 108 | $repository = $this->getRepositoryFromRequest($request); |
||
| 109 | $settings = $repository->getResourceSettings(); |
||
| 110 | |||
| 111 | $grid = $this->getGrid($request, $repository, $grid, $resourceNodeId); |
||
| 112 | |||
| 113 | $this->setBreadCrumb($request); |
||
| 114 | $parentResourceNode = $this->getParentResourceNode($request); |
||
| 115 | |||
| 116 | return $grid->getGridResponse( |
||
| 117 | '@ChamiloTheme/Resource/index.html.twig', |
||
| 118 | [ |
||
| 119 | 'parent_id' => $resourceNodeId, |
||
| 120 | 'tool' => $tool, |
||
| 121 | 'type' => $type, |
||
| 122 | 'id' => $resourceNodeId, |
||
| 123 | 'parent_resource_node' => $parentResourceNode, |
||
| 124 | 'resource_settings' => $settings, |
||
| 125 | ] |
||
| 126 | ); |
||
| 127 | } |
||
| 128 | |||
| 129 | public function getGrid(Request $request, ResourceRepository $repository, Grid $grid, $resourceNodeId): Grid |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @Route("/{tool}/{type}/{id}/new_folder", methods={"GET", "POST"}, name="chamilo_core_resource_new_folder") |
||
| 445 | */ |
||
| 446 | public function newFolderAction(Request $request): Response |
||
| 447 | { |
||
| 448 | $this->setBreadCrumb($request); |
||
| 449 | |||
| 450 | return $this->createResource($request, 'folder'); |
||
| 451 | } |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @Route("/{tool}/{type}/{id}/new", methods={"GET", "POST"}, name="chamilo_core_resource_new") |
||
| 455 | */ |
||
| 456 | public function newAction(Request $request): Response |
||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * @Route("/{tool}/{type}/{id}/disk_space", methods={"GET", "POST"}, name="chamilo_core_resource_disk_space") |
||
| 465 | */ |
||
| 466 | public function diskSpaceAction(Request $request): Response |
||
| 467 | { |
||
| 468 | $this->setBreadCrumb($request); |
||
| 469 | |||
| 470 | $nodeId = $request->get('id'); |
||
| 471 | |||
| 472 | $repository = $this->getRepositoryFromRequest($request); |
||
| 473 | |||
| 474 | /** @var ResourceNode $resourceNode */ |
||
| 475 | $resourceNode = $repository->getResourceNodeRepository()->find($nodeId); |
||
| 476 | $size = $repository->getResourceNodeRepository()->getSize($resourceNode, $repository->getResourceType()); |
||
| 477 | |||
| 478 | $this->denyAccessUnlessGranted( |
||
| 479 | ResourceNodeVoter::VIEW, |
||
| 480 | $resourceNode, |
||
| 481 | $this->trans('Unauthorised access to resource') |
||
| 482 | ); |
||
| 483 | |||
| 484 | return $this->render( |
||
| 485 | '@ChamiloTheme/Resource/disk_space.html.twig', |
||
| 486 | [ |
||
| 487 | 'resourceNode' => $resourceNode, |
||
| 488 | 'size' => $size, |
||
| 489 | ] |
||
| 490 | ); |
||
| 491 | } |
||
| 492 | |||
| 493 | /** |
||
| 494 | * @Route("/{tool}/{type}/{id}/edit", methods={"GET", "POST"}) |
||
| 495 | */ |
||
| 496 | public function editAction(Request $request, IllustrationRepository $illustrationRepository): Response |
||
| 497 | { |
||
| 498 | $resourceNodeId = $request->get('id'); |
||
| 499 | |||
| 500 | $this->setBreadCrumb($request); |
||
| 501 | $repository = $this->getRepositoryFromRequest($request); |
||
| 502 | /** @var AbstractResource $resource */ |
||
| 503 | $resource = $repository->getRepository()->findOneBy(['resourceNode' => $resourceNodeId]); |
||
| 504 | $resourceNode = $resource->getResourceNode(); |
||
| 505 | |||
| 506 | $this->denyAccessUnlessGranted( |
||
| 507 | ResourceNodeVoter::EDIT, |
||
| 508 | $resourceNode, |
||
| 509 | $this->trans('Unauthorised access to resource') |
||
| 510 | ); |
||
| 511 | |||
| 512 | $resourceNodeParentId = $resourceNode->getId(); |
||
| 513 | |||
| 514 | $routeParams = $this->getResourceParams($request); |
||
| 515 | $routeParams['id'] = $resourceNodeParentId; |
||
| 516 | |||
| 517 | $form = $repository->getForm($this->container->get('form.factory'), $resource); |
||
| 518 | |||
| 519 | if ($resourceNode->hasEditableContent()) { |
||
| 520 | $form->add( |
||
| 521 | 'content', |
||
| 522 | CKEditorType::class, |
||
| 523 | [ |
||
| 524 | 'mapped' => false, |
||
| 525 | 'config' => [ |
||
| 526 | 'filebrowserImageBrowseRoute' => 'resources_filemanager', |
||
| 527 | 'filebrowserImageBrowseRouteParameters' => $routeParams, |
||
| 528 | ], |
||
| 529 | ] |
||
| 530 | ); |
||
| 531 | $content = $repository->getResourceNodeFileContent($resourceNode); |
||
| 532 | $form->get('content')->setData($content); |
||
| 533 | } |
||
| 534 | |||
| 535 | $form->handleRequest($request); |
||
| 536 | |||
| 537 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 538 | /** @var AbstractResource $newResource */ |
||
| 539 | $newResource = $form->getData(); |
||
| 540 | |||
| 541 | if ($form->has('content')) { |
||
| 542 | $data = $form->get('content')->getData(); |
||
| 543 | $repository->updateResourceFileContent($newResource, $data); |
||
| 544 | } |
||
| 545 | |||
| 546 | //$newResource->setTitle($form->get('title')->getData()); // already set in $form->getData() |
||
| 547 | $repository->updateNodeForResource($newResource); |
||
| 548 | |||
| 549 | if ($form->has('illustration')) { |
||
| 550 | $illustration = $form->get('illustration')->getData(); |
||
| 551 | if ($illustration) { |
||
| 552 | $file = $illustrationRepository->addIllustration($newResource, $this->getUser(), $illustration); |
||
| 553 | $em = $illustrationRepository->getEntityManager(); |
||
| 554 | $em->persist($file); |
||
| 555 | $em->flush(); |
||
| 556 | } |
||
| 557 | } |
||
| 558 | |||
| 559 | $this->addFlash('success', $this->trans('Updated')); |
||
| 560 | |||
| 561 | //if ($newResource->getResourceNode()->hasResourceFile()) { |
||
| 562 | $resourceNodeParentId = $newResource->getResourceNode()->getParent()->getId(); |
||
| 563 | //} |
||
| 564 | $routeParams['id'] = $resourceNodeParentId; |
||
| 565 | |||
| 566 | return $this->redirectToRoute('chamilo_core_resource_list', $routeParams); |
||
| 567 | } |
||
| 568 | |||
| 569 | return $this->render( |
||
| 570 | '@ChamiloTheme/Resource/edit.html.twig', |
||
| 571 | [ |
||
| 572 | 'form' => $form->createView(), |
||
| 573 | 'parent' => $resourceNodeParentId, |
||
| 574 | ] |
||
| 575 | ); |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Shows a resource information. |
||
| 580 | * |
||
| 581 | * @Route("/{tool}/{type}/{id}/info", methods={"GET"}, name="chamilo_core_resource_info") |
||
| 582 | */ |
||
| 583 | public function infoAction(Request $request, IllustrationRepository $illustrationRepository): Response |
||
| 584 | { |
||
| 585 | $this->setBreadCrumb($request); |
||
| 586 | $nodeId = $request->get('id'); |
||
| 587 | |||
| 588 | $repository = $this->getRepositoryFromRequest($request); |
||
| 589 | |||
| 590 | /** @var AbstractResource $resource */ |
||
| 591 | $resource = $repository->getRepository()->findOneBy(['resourceNode' => $nodeId]); |
||
| 592 | |||
| 593 | if (null === $resource) { |
||
| 594 | throw new NotFoundHttpException(); |
||
| 595 | } |
||
| 596 | |||
| 597 | $resourceNode = $resource->getResourceNode(); |
||
| 598 | |||
| 599 | if (null === $resourceNode) { |
||
| 600 | throw new NotFoundHttpException(); |
||
| 601 | } |
||
| 602 | |||
| 603 | $this->denyAccessUnlessGranted( |
||
| 604 | ResourceNodeVoter::VIEW, |
||
| 605 | $resourceNode, |
||
| 606 | $this->trans('Unauthorised access to resource') |
||
| 607 | ); |
||
| 608 | |||
| 609 | $tool = $request->get('tool'); |
||
| 610 | $type = $request->get('type'); |
||
| 611 | |||
| 612 | $illustration = $illustrationRepository->getIllustrationUrlFromNode($resource->getResourceNode()); |
||
| 613 | |||
| 614 | $params = [ |
||
| 615 | 'resource' => $resource, |
||
| 616 | 'illustration' => $illustration, |
||
| 617 | 'tool' => $tool, |
||
| 618 | 'type' => $type, |
||
| 619 | ]; |
||
| 620 | |||
| 621 | return $this->render('@ChamiloTheme/Resource/info.html.twig', $params); |
||
| 622 | } |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Preview a file. Mostly used when using a modal. |
||
| 626 | * |
||
| 627 | * @Route("/{tool}/{type}/{id}/preview", methods={"GET"}, name="chamilo_core_resource_preview") |
||
| 628 | */ |
||
| 629 | public function previewAction(Request $request): Response |
||
| 630 | { |
||
| 631 | $this->setBreadCrumb($request); |
||
| 632 | $nodeId = $request->get('id'); |
||
| 633 | |||
| 634 | $repository = $this->getRepositoryFromRequest($request); |
||
| 635 | |||
| 636 | /** @var AbstractResource $resource */ |
||
| 637 | $resource = $repository->getRepository()->findOneBy(['resourceNode' => $nodeId]); |
||
| 638 | |||
| 639 | if (null === $resource) { |
||
| 640 | throw new NotFoundHttpException(); |
||
| 641 | } |
||
| 642 | |||
| 643 | $resourceNode = $resource->getResourceNode(); |
||
| 644 | |||
| 645 | if (null === $resourceNode) { |
||
| 646 | throw new NotFoundHttpException(); |
||
| 647 | } |
||
| 648 | |||
| 649 | $this->denyAccessUnlessGranted( |
||
| 650 | ResourceNodeVoter::VIEW, |
||
| 651 | $resourceNode, |
||
| 652 | $this->trans('Unauthorised access to resource') |
||
| 653 | ); |
||
| 654 | |||
| 655 | $tool = $request->get('tool'); |
||
| 656 | $type = $request->get('type'); |
||
| 657 | |||
| 658 | $params = [ |
||
| 659 | 'resource' => $resource, |
||
| 660 | 'tool' => $tool, |
||
| 661 | 'type' => $type, |
||
| 662 | ]; |
||
| 663 | |||
| 664 | return $this->render('@ChamiloTheme/Resource/preview.html.twig', $params); |
||
| 665 | } |
||
| 666 | |||
| 667 | /** |
||
| 668 | * @Route("/{tool}/{type}/{id}/change_visibility", name="chamilo_core_resource_change_visibility") |
||
| 669 | */ |
||
| 670 | public function changeVisibilityAction(Request $request): Response |
||
| 671 | { |
||
| 672 | $id = $request->get('id'); |
||
| 673 | |||
| 674 | $repository = $this->getRepositoryFromRequest($request); |
||
| 675 | |||
| 676 | /** @var AbstractResource $resource */ |
||
| 677 | $resource = $repository->getRepository()->findOneBy(['resourceNode' => $id]); |
||
| 678 | |||
| 679 | if (null === $resource) { |
||
| 680 | throw new NotFoundHttpException(); |
||
| 681 | } |
||
| 682 | |||
| 683 | $resourceNode = $resource->getResourceNode(); |
||
| 684 | |||
| 685 | $this->denyAccessUnlessGranted( |
||
| 686 | ResourceNodeVoter::EDIT, |
||
| 687 | $resourceNode, |
||
| 688 | $this->trans('Unauthorised access to resource') |
||
| 689 | ); |
||
| 690 | |||
| 691 | /** @var ResourceLink $link */ |
||
| 692 | if ($this->hasCourse()) { |
||
| 693 | $link = $resource->getCourseSessionResourceLink($this->getCourse(), $this->getSession()); |
||
| 694 | } else { |
||
| 695 | $link = $resource->getFirstResourceLink(); |
||
| 696 | } |
||
| 697 | |||
| 698 | $icon = 'fa-eye'; |
||
| 699 | // Use repository to change settings easily. |
||
| 700 | if ($link && $link->getVisibility() === ResourceLink::VISIBILITY_PUBLISHED) { |
||
| 701 | $repository->setVisibilityDraft($resource); |
||
| 702 | $icon = 'fa-eye-slash'; |
||
| 703 | } else { |
||
| 704 | $repository->setVisibilityPublished($resource); |
||
| 705 | } |
||
| 706 | |||
| 707 | $result = ['icon' => $icon]; |
||
| 708 | |||
| 709 | return new JsonResponse($result); |
||
| 710 | } |
||
| 711 | |||
| 712 | /** |
||
| 713 | * @Route("/{tool}/{type}/{id}", name="chamilo_core_resource_delete") |
||
| 714 | */ |
||
| 715 | public function deleteAction(Request $request): Response |
||
| 743 | ); |
||
| 744 | } |
||
| 745 | |||
| 746 | /** |
||
| 747 | * @Route("/{tool}/{type}/{id}", methods={"DELETE"}, name="chamilo_core_resource_delete_mass") |
||
| 748 | */ |
||
| 749 | public function deleteMassAction($primaryKeys, $allPrimaryKeys, Request $request): Response |
||
| 780 | } |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Shows the associated resource file. |
||
| 784 | * |
||
| 785 | * @Route("/{tool}/{type}/{id}/view", methods={"GET"}, name="chamilo_core_resource_view") |
||
| 786 | */ |
||
| 787 | public function viewAction(Request $request, Glide $glide): Response |
||
| 788 | { |
||
| 789 | $id = $request->get('id'); |
||
| 790 | $filter = $request->get('filter'); |
||
| 791 | $mode = $request->get('mode'); |
||
| 792 | $em = $this->getDoctrine(); |
||
| 793 | $resourceNode = $em->getRepository('ChamiloCoreBundle:Resource\ResourceNode')->find($id); |
||
| 794 | |||
| 795 | if ($resourceNode === null) { |
||
| 796 | throw new FileNotFoundException('Resource not found'); |
||
| 797 | } |
||
| 798 | |||
| 799 | return $this->showFile($request, $resourceNode, $mode, $glide, $filter); |
||
| 800 | } |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Gets a document when calling route resources_document_get_file. |
||
| 804 | 1 * |
||
| 805 | * @deprecated |
||
| 806 | * |
||
| 807 | * @throws \League\Flysystem\FileNotFoundException |
||
| 808 | */ |
||
| 809 | public function getDocumentAction(Request $request, Glide $glide): Response |
||
| 810 | { |
||
| 811 | /*$file = $request->get('file'); |
||
| 812 | $mode = $request->get('mode'); |
||
| 813 | |||
| 814 | // see list of filters in config/services.yaml |
||
| 815 | $filter = $request->get('filter'); |
||
| 816 | $mode = !empty($mode) ? $mode : 'show'; |
||
| 817 | |||
| 818 | $repository = $this->getRepository('document', 'files'); |
||
| 819 | $nodeRepository = $repository->getResourceNodeRepository(); |
||
| 820 | |||
| 821 | $title = basename($file); |
||
| 822 | // @todo improve criteria to avoid giving the wrong file. |
||
| 823 | $criteria = ['slug' => $title]; |
||
| 824 | |||
| 825 | $resourceNode = $nodeRepository->findOneBy($criteria); |
||
| 826 | |||
| 827 | if (null === $resourceNode) { |
||
| 828 | throw new NotFoundHttpException(); |
||
| 829 | } |
||
| 830 | |||
| 831 | return $this->showFile($request, $resourceNode, $mode, $glide,$filter);*/ |
||
| 832 | } |
||
| 833 | |||
| 834 | /** |
||
| 835 | * @Route("/{tool}/{type}/{id}/download", methods={"GET"}, name="chamilo_core_resource_download") |
||
| 836 | */ |
||
| 837 | public function downloadAction(Request $request) |
||
| 838 | { |
||
| 839 | $resourceNodeId = (int) $request->get('id'); |
||
| 840 | $courseNode = $this->getCourse()->getResourceNode(); |
||
| 841 | |||
| 842 | $repo = $this->getRepositoryFromRequest($request); |
||
| 843 | |||
| 844 | if (empty($resourceNodeId)) { |
||
| 845 | $resourceNode = $courseNode; |
||
| 846 | } else { |
||
| 847 | $resourceNode = $repo->getResourceNodeRepository()->find($resourceNodeId); |
||
| 848 | } |
||
| 849 | |||
| 850 | $type = $repo->getResourceType(); |
||
| 851 | |||
| 852 | if (null === $resourceNode) { |
||
| 853 | throw new NotFoundHttpException(); |
||
| 854 | } |
||
| 855 | |||
| 856 | $this->denyAccessUnlessGranted( |
||
| 857 | ResourceNodeVoter::VIEW, |
||
| 858 | $resourceNode, |
||
| 859 | $this->trans('Unauthorised access to resource') |
||
| 860 | ); |
||
| 861 | |||
| 862 | // If resource node has a file just download it. Don't download the children. |
||
| 863 | if ($resourceNode->hasResourceFile()) { |
||
| 864 | // Redirect to download single file. |
||
| 865 | return $this->showFile($request, $resourceNode, 'download'); |
||
| 866 | } |
||
| 867 | |||
| 868 | $zipName = $resourceNode->getSlug().'.zip'; |
||
| 869 | $rootNodePath = $resourceNode->getPathForDisplay(); |
||
| 870 | |||
| 871 | $resourceNodeRepo = $repo->getResourceNodeRepository(); |
||
| 872 | |||
| 873 | $criteria = Criteria::create() |
||
| 874 | ->where(Criteria::expr()->neq('resourceFile', null)) // must have a file |
||
| 875 | // ->andWhere(Criteria::expr()->eq('resourceType', $type)) |
||
| 876 | ; |
||
| 877 | |||
| 878 | /** @var ArrayCollection|ResourceNode[] $children */ |
||
| 879 | /** @var QueryBuilder $children */ |
||
| 880 | $qb = $resourceNodeRepo->getChildrenQueryBuilder($resourceNode); |
||
| 881 | $qb->addCriteria($criteria); |
||
| 882 | $children = $qb->getQuery()->getResult(); |
||
| 883 | |||
| 884 | $response = new StreamedResponse(function () use ($rootNodePath, $zipName, $children, $repo) { |
||
| 885 | // Define suitable options for ZipStream Archive. |
||
| 886 | $options = new Archive(); |
||
| 887 | $options->setContentType('application/octet-stream'); |
||
| 888 | //initialise zipstream with output zip filename and options. |
||
| 889 | $zip = new ZipStream($zipName, $options); |
||
| 890 | |||
| 891 | /** @var ResourceNode $node */ |
||
| 892 | foreach ($children as $node) { |
||
| 893 | $resourceFile = $node->getResourceFile(); |
||
| 894 | $systemName = $resourceFile->getFile()->getPathname(); |
||
| 895 | $stream = $repo->getResourceNodeFileStream($node); |
||
| 896 | //error_log($node->getPathForDisplay()); |
||
| 897 | $fileToDisplay = str_replace($rootNodePath, '', $node->getPathForDisplay()); |
||
| 898 | $zip->addFileFromStream($fileToDisplay, $stream); |
||
| 899 | } |
||
| 900 | $zip->finish(); |
||
| 901 | }); |
||
| 902 | |||
| 903 | $disposition = $response->headers->makeDisposition( |
||
| 904 | ResponseHeaderBag::DISPOSITION_ATTACHMENT, |
||
| 905 | Transliterator::transliterate($zipName) |
||
| 906 | ); |
||
| 907 | $response->headers->set('Content-Disposition', $disposition); |
||
| 908 | $response->headers->set('Content-Type', 'application/octet-stream'); |
||
| 909 | |||
| 910 | return $response; |
||
| 911 | } |
||
| 912 | |||
| 913 | /** |
||
| 914 | * Upload form. |
||
| 915 | * |
||
| 916 | * @Route("/{tool}/{type}/{id}/upload", name="chamilo_core_resource_upload", methods={"GET", "POST"}, |
||
| 917 | * options={"expose"=true}) |
||
| 918 | */ |
||
| 919 | public function uploadAction(Request $request, $tool, $type, $id): Response |
||
| 940 | ); |
||
| 941 | } |
||
| 942 | |||
| 943 | public function setBreadCrumb(Request $request) |
||
| 944 | { |
||
| 945 | $tool = $request->get('tool'); |
||
| 946 | $type = $request->get('type'); |
||
| 947 | $resourceNodeId = $request->get('id'); |
||
| 948 | |||
| 949 | $routeParams = $this->getResourceParams($request); |
||
| 950 | |||
| 951 | if (!empty($resourceNodeId)) { |
||
| 952 | $breadcrumb = $this->getBreadCrumb(); |
||
| 953 | $toolParams = $routeParams; |
||
| 954 | $toolParams['id'] = null; |
||
| 955 | |||
| 956 | // Root tool link |
||
| 957 | $breadcrumb->addChild( |
||
| 958 | $this->trans($tool), |
||
| 959 | [ |
||
| 960 | 'uri' => $this->generateUrl( |
||
| 961 | 'chamilo_core_resource_index', |
||
| 962 | $toolParams |
||
| 963 | ), |
||
| 964 | ] |
||
| 965 | ); |
||
| 966 | |||
| 967 | $repo = $this->getRepositoryFromRequest($request); |
||
| 968 | |||
| 969 | /** @var AbstractResource $parent */ |
||
| 970 | $originalResource = $repo->findOneBy(['resourceNode' => $resourceNodeId]); |
||
| 971 | if ($originalResource === null) { |
||
| 972 | return; |
||
| 973 | } |
||
| 974 | $parent = $originalParent = $originalResource->getResourceNode(); |
||
| 975 | |||
| 976 | $parentList = []; |
||
| 977 | while ($parent !== null) { |
||
| 978 | if ($type !== $parent->getResourceType()->getName()) { |
||
| 979 | break; |
||
| 980 | } |
||
| 981 | $parent = $parent->getParent(); |
||
| 982 | if ($parent) { |
||
| 983 | $resource = $repo->findOneBy(['resourceNode' => $parent->getId()]); |
||
| 984 | if ($resource) { |
||
| 985 | $parentList[] = $resource; |
||
| 986 | } |
||
| 987 | } |
||
| 988 | } |
||
| 989 | |||
| 990 | $parentList = array_reverse($parentList); |
||
| 991 | /** @var AbstractResource $item */ |
||
| 992 | foreach ($parentList as $item) { |
||
| 993 | $params = $routeParams; |
||
| 994 | $params['id'] = $item->getResourceNode()->getId(); |
||
| 995 | $breadcrumb->addChild( |
||
| 996 | $item->getResourceName(), |
||
| 997 | [ |
||
| 998 | 'uri' => $this->generateUrl( |
||
| 999 | 'chamilo_core_resource_list', |
||
| 1000 | $params |
||
| 1001 | ), |
||
| 1002 | ] |
||
| 1003 | ); |
||
| 1004 | } |
||
| 1005 | |||
| 1006 | $params = $routeParams; |
||
| 1007 | $params['id'] = $originalParent->getId(); |
||
| 1008 | |||
| 1009 | $breadcrumb->addChild( |
||
| 1010 | $originalResource->getResourceName(), |
||
| 1011 | [ |
||
| 1012 | 'uri' => $this->generateUrl( |
||
| 1013 | 'chamilo_core_resource_list', |
||
| 1014 | $params |
||
| 1015 | ), |
||
| 1016 | ] |
||
| 1017 | ); |
||
| 1018 | } |
||
| 1019 | } |
||
| 1020 | |||
| 1021 | private function getParentResourceNode(Request $request): ResourceNode |
||
| 1022 | { |
||
| 1023 | $parentNodeId = $request->get('id'); |
||
| 1024 | |||
| 1025 | $parentResourceNode = null; |
||
| 1026 | |||
| 1027 | if (empty($parentNodeId)) { |
||
| 1028 | if ($this->hasCourse()) { |
||
| 1029 | $parentResourceNode = $this->getCourse()->getResourceNode(); |
||
| 1030 | } else { |
||
| 1031 | if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
||
| 1032 | /** @var User $user */ |
||
| 1033 | $parentResourceNode = $this->getUser()->getResourceNode(); |
||
| 1034 | } |
||
| 1035 | } |
||
| 1036 | } else { |
||
| 1037 | $repo = $this->getDoctrine()->getRepository('ChamiloCoreBundle:Resource\ResourceNode'); |
||
| 1038 | $parentResourceNode = $repo->find($parentNodeId); |
||
| 1039 | } |
||
| 1040 | |||
| 1041 | if (null === $parentResourceNode) { |
||
| 1042 | throw new AccessDeniedException(); |
||
| 1043 | } |
||
| 1044 | |||
| 1045 | return $parentResourceNode; |
||
| 1046 | } |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * @param string $mode |
||
| 1050 | * @param string $filter |
||
| 1051 | * |
||
| 1052 | * @return mixed|StreamedResponse |
||
| 1053 | */ |
||
| 1054 | private function showFile(Request $request, ResourceNode $resourceNode, $mode = 'show', Glide $glide = null, $filter = '') |
||
| 1118 | } |
||
| 1119 | |||
| 1120 | /** |
||
| 1121 | * @param string $fileType |
||
| 1122 | * |
||
| 1123 | * @return RedirectResponse|Response |
||
| 1124 | */ |
||
| 1125 | private function createResource(Request $request, $fileType = 'file') |
||
| 1275 | ] |
||
| 1276 | ); |
||
| 1279 |
This check looks for imports that have been defined, but are not used in the scope.