diff --git a/src/CoreBundle/Controller/CourseHomeController.php b/src/CoreBundle/Controller/CourseHomeController.php index cfd82e0de1..bab68183fb 100644 --- a/src/CoreBundle/Controller/CourseHomeController.php +++ b/src/CoreBundle/Controller/CourseHomeController.php @@ -6,6 +6,8 @@ namespace Chamilo\CoreBundle\Controller; use Career; use Chamilo\CoreBundle\Entity\Course; +use Chamilo\CoreBundle\Entity\Tool; +use Chamilo\CoreBundle\Tool\AbstractTool; use Chamilo\CoreBundle\ToolChain; use Chamilo\CourseBundle\Controller\ToolBaseController; use Chamilo\CourseBundle\Entity\CTool; @@ -219,7 +221,9 @@ class CourseHomeController extends ToolBaseController throw new NotFoundHttpException($this->trans('Tool not found')); } + /** @var AbstractTool $tool */ $tool = $toolChain->getToolFromName($tool->getTool()->getName()); + $url = $tool->getLink().'?'.$this->getCourseUrlQuery(); return $this->redirect($url); diff --git a/src/CoreBundle/Controller/ResourceController.php b/src/CoreBundle/Controller/ResourceController.php index 76a128aa6f..c66d99411e 100644 --- a/src/CoreBundle/Controller/ResourceController.php +++ b/src/CoreBundle/Controller/ResourceController.php @@ -75,7 +75,7 @@ class ResourceController extends AbstractResourceController implements CourseCon $repository = $this->getRepositoryFromRequest($request); $settings = $repository->getResourceSettings(); - $grid = $this->getGrid($request, $repository, $grid, $parentResourceNode->getId()); + $grid = $this->getGrid($request, $repository, $grid, $parentResourceNode->getId(), 'chamilo_core_resource_index'); $breadcrumb = $this->getBreadCrumb(); $breadcrumb->addChild( @@ -100,7 +100,7 @@ class ResourceController extends AbstractResourceController implements CourseCon ); } - public function getGrid(Request $request, ResourceRepository $repository, Grid $grid, int $resourceNodeId): Grid + public function getGrid(Request $request, ResourceRepository $repository, Grid $grid, int $resourceNodeId, string $routeName): Grid { $class = $repository->getRepository()->getClassName(); @@ -126,18 +126,13 @@ class ResourceController extends AbstractResourceController implements CourseCon $source->initQueryBuilder($qb); $grid->setSource($source); - /*$result = $qb->getQuery()->getResult(); - foreach ($result as $data) { - dump(get_class($data)); - }*/ - $resourceParams = $this->getResourceParams($request); if (0 === $resourceParams['id']) { $resourceParams['id'] = $resourceNodeId; } - $grid->setRouteUrl($this->generateUrl('chamilo_core_resource_list', $resourceParams)); + $grid->setRouteUrl($this->generateUrl($routeName, $resourceParams)); //$grid->hideFilters(); //$grid->setLimits(20); @@ -168,6 +163,7 @@ class ResourceController extends AbstractResourceController implements CourseCon unset($myParams[0]); $icon = $resourceNode->getIcon().'  '; + if ($resourceNode->hasResourceFile()) { // Process node that contains a file, process previews. if ($resourceNode->isResourceFileAnImage()) { @@ -270,7 +266,7 @@ class ResourceController extends AbstractResourceController implements CourseCon $myRowAction->addManipulateRender($setNodeParameters); $grid->addRowAction($myRowAction); - // Download action + // Download action. $myRowAction = new RowAction( $this->trans('Download'), 'chamilo_core_resource_download', @@ -383,7 +379,7 @@ class ResourceController extends AbstractResourceController implements CourseCon } // More action. - /*$myRowAction = new RowAction( + $myRowAction = new RowAction( $this->trans('More'), 'chamilo_core_resource_preview', false, @@ -392,7 +388,7 @@ class ResourceController extends AbstractResourceController implements CourseCon ); $myRowAction->addManipulateRender($setNodeParameters); - $grid->addRowAction($myRowAction);*/ + $grid->addRowAction($myRowAction); // Delete action. $myRowAction = new RowAction( @@ -434,7 +430,7 @@ class ResourceController extends AbstractResourceController implements CourseCon $repository = $this->getRepositoryFromRequest($request); $settings = $repository->getResourceSettings(); - $grid = $this->getGrid($request, $repository, $grid, $resourceNodeId); + $grid = $this->getGrid($request, $repository, $grid, $resourceNodeId, 'chamilo_core_resource_list'); $this->setBreadCrumb($request); $parentResourceNode = $this->getParentResourceNode($request); @@ -655,7 +651,7 @@ class ResourceController extends AbstractResourceController implements CourseCon $tool = $request->get('tool'); $type = $request->get('type'); - $illustration = $illustrationRepository->getIllustrationUrlFromNode($resource->getResourceNode()); + $illustration = $illustrationRepository->getIllustrationUrlFromNode($resourceNode); $form = $this->createForm(ResourceCommentType::class, null); @@ -666,7 +662,6 @@ class ResourceController extends AbstractResourceController implements CourseCon 'type' => $type, 'comment_form' => $form->createView(), ]; - return $this->render( $repository->getTemplates()->getFromAction(__FUNCTION__, $request->isXmlHttpRequest()), $params @@ -753,7 +748,7 @@ class ResourceController extends AbstractResourceController implements CourseCon } /** - * @Route("/{tool}/{type}/{id}", name="chamilo_core_resource_delete") + * @Route("/{tool}/{type}/{id}/delete", name="chamilo_core_resource_delete") */ public function deleteAction(Request $request): Response { @@ -789,7 +784,7 @@ class ResourceController extends AbstractResourceController implements CourseCon } /** - * @Route("/{tool}/{type}/{id}", methods={"DELETE"}, name="chamilo_core_resource_delete_mass") + * @Route("/{tool}/{type}/{id}/delete_mass", methods={"DELETE"}, name="chamilo_core_resource_delete_mass") */ public function deleteMassAction($primaryKeys, $allPrimaryKeys, Request $request): Response { diff --git a/src/CoreBundle/Entity/Resource/ResourceFile.php b/src/CoreBundle/Entity/Resource/ResourceFile.php index 8809706dfe..693ab644c9 100644 --- a/src/CoreBundle/Entity/Resource/ResourceFile.php +++ b/src/CoreBundle/Entity/Resource/ResourceFile.php @@ -122,7 +122,7 @@ class ResourceFile /** * @var ResourceNode * - * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="resourceFile") + * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="resourceFile", fetch="EAGER") */ protected $resourceNode; diff --git a/src/CoreBundle/Entity/Resource/ResourceNode.php b/src/CoreBundle/Entity/Resource/ResourceNode.php index 2800f51200..581a925ed4 100644 --- a/src/CoreBundle/Entity/Resource/ResourceNode.php +++ b/src/CoreBundle/Entity/Resource/ResourceNode.php @@ -82,7 +82,7 @@ class ResourceNode * @var ResourceFile * @Groups({"list"}) * - * @ORM\OneToOne(targetEntity="ResourceFile", inversedBy="resourceNode", orphanRemoval=true) + * @ORM\OneToOne(targetEntity="ResourceFile", inversedBy="resourceNode", orphanRemoval=true, fetch="EAGER") * @ORM\JoinColumn(name="resource_file_id", referencedColumnName="id", onDelete="CASCADE") */ protected $resourceFile; diff --git a/src/CoreBundle/Repository/IllustrationRepository.php b/src/CoreBundle/Repository/IllustrationRepository.php index 33003b27c5..6f022f4ffe 100644 --- a/src/CoreBundle/Repository/IllustrationRepository.php +++ b/src/CoreBundle/Repository/IllustrationRepository.php @@ -34,28 +34,13 @@ final class IllustrationRepository extends ResourceRepository implements GridInt ->select('resource') ->from($className, 'resource') ->innerJoin( - ResourceNode::class, - 'node', - Join::WITH, - 'resource.resourceNode = node.id' + 'resource.resourceNode', + 'node' ) - //->innerJoin('node.resourceLinks', 'links') - //->where('node.resourceType = :type') - //->setParameter('type',$type) ; - /*$qb - ->andWhere('links.visibility = :visibility') - ->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED) - ;*/ - - if (null !== $parentNode) { -// $qb->andWhere('node.parent = :parentNode'); - // $qb->setParameter('parentNode', $parentNode); - } $qb->andWhere('node.creator = :creator'); $qb->setParameter('creator', $user); - //var_dump($qb->getQuery()->getSQL(), $parentNode->getId());exit; return $qb; } @@ -130,12 +115,19 @@ final class IllustrationRepository extends ResourceRepository implements GridInt public function getIllustrationNodeFromParent(ResourceNode $resourceNode): ?ResourceNode { $nodeRepo = $this->getResourceNodeRepository(); - $resourceType = $this->getResourceType(); + $name = $this->getResourceTypeName(); + + $qb = $nodeRepo->getEntityManager()->createQueryBuilder() + ->select('node') + ->from(ResourceNode::class, 'node') + ->innerJoin('node.resourceType', 'type') + ->innerJoin('node.resourceFile', 'file') + ->where('node.parent = :parent') + ->andWhere('type.name = :name') + ->setParameters(['parent' => $resourceNode, 'name' => $name]) + ; - /** @var ResourceNode $node */ - return $nodeRepo->findOneBy( - ['parent' => $resourceNode, 'resourceType' => $resourceType] - ); + return $qb->getQuery()->getFirstResult(); } public function deleteIllustration(AbstractResource $resource) @@ -151,7 +143,7 @@ final class IllustrationRepository extends ResourceRepository implements GridInt /** * @param string $filter See: services.yaml parameter "glide_media_filters" to see the list of filters. */ - public function getIllustrationUrl(AbstractResource $resource, $filter = ''): string + public function getIllustrationUrl(AbstractResource $resource, string $filter = ''): string { return $this->getIllustrationUrlFromNode($resource->getResourceNode(), $filter); } diff --git a/src/CoreBundle/Repository/ResourceRepository.php b/src/CoreBundle/Repository/ResourceRepository.php index 72c8c66b03..c98694955b 100644 --- a/src/CoreBundle/Repository/ResourceRepository.php +++ b/src/CoreBundle/Repository/ResourceRepository.php @@ -27,7 +27,6 @@ use Cocur\Slugify\SlugifyInterface; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository as BaseEntityRepository; -use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use League\Flysystem\FilesystemInterface; use Symfony\Component\Filesystem\Exception\FileNotFoundException; @@ -605,7 +604,6 @@ class ResourceRepository extends BaseEntityRepository $qb->andWhere('node.creator = :creator'); $qb->setParameter('creator', $user); - //var_dump($qb->getQuery()->getSQL(), $parentNode->getId());exit; return $qb; } @@ -670,6 +668,23 @@ class ResourceRepository extends BaseEntityRepository public function getResourceFromResourceNode(int $resourceNodeId): ?AbstractResource { + /*$repo = $this->getRepository(); + $className = $repo->getClassName(); + $qb = $repo->getEntityManager()->createQueryBuilder() + ->select('resource') + ->from($className, 'resource') + ->innerJoin( + 'resource.resourceNode', + 'node' + ) + ->innerJoin('node.resourceLinks', 'links') + ->leftJoin('node.resourceFile', 'file') + ->where('node = :id') + ->setParameters(['id' => $resourceNodeId]) + ; + + return $qb->getQuery()->getFirstResult();*/ + return $this->getRepository()->findOneBy(['resourceNode' => $resourceNodeId]); } diff --git a/src/CourseBundle/EventListener/CourseListener.php b/src/CourseBundle/EventListener/CourseListener.php index fa5a956fc6..7f6c0e294c 100644 --- a/src/CourseBundle/EventListener/CourseListener.php +++ b/src/CourseBundle/EventListener/CourseListener.php @@ -57,19 +57,28 @@ class CourseListener } $sessionHandler = $request->getSession(); - $container = $this->container; $translator = $container->get('translator'); $course = null; // Check if URL has cid value. Using Symfony request. - $courseId = $request->get('cid'); + $courseId = (int) $request->get('cid'); + $checker = $container->get('security.authorization_checker'); if (!empty($courseId)) { - /** @var EntityManager $em */ - $em = $container->get('doctrine')->getManager(); - $checker = $container->get('security.authorization_checker'); - $course = $em->getRepository('ChamiloCoreBundle:Course')->find($courseId); + if ($sessionHandler->has('course')) { + /** @var Course $courseFromSession */ + $courseFromSession = $sessionHandler->get('course'); + if ($courseId === $courseFromSession->getId()) { + $course = $courseFromSession; + } + } + + if (null === $course) { + /** @var EntityManager $em */ + $em = $container->get('doctrine')->getManager(); + $course = $em->getRepository('ChamiloCoreBundle:Course')->find($courseId); + } if (null === $course) { throw new NotFoundHttpException($translator->trans('Course does not exist')); @@ -165,27 +174,6 @@ class CourseListener $courseParams = $this->generateCourseUrl($course, $sessionId, $groupId, $origin); $sessionHandler->set('course_url_params', $courseParams); $container->get('twig')->addGlobal('course_url_params', $courseParams); - - /*if (!$alreadyVisited || - isset($alreadyVisited) && $alreadyVisited != $courseCode - ) { - // Course access events - $dispatcher = $this->container->get('event_dispatcher'); - if (empty($sessionId)) { - $dispatcher->dispatch('chamilo_course.course.access', new CourseAccess($user, $course)); - } else { - $dispatcher->dispatch( - 'chamilo_course.course.access', - new SessionAccess($user, $course, $session) - ); - } - $coursesAlreadyVisited[$course->getCode()] = 1; - $sessionHandler->set('course_already_visited', $courseCode); - }*/ - -// Container::setRequest($request); -// Container::setContainer($container); -// Container::setLegacyServices($container); } } @@ -237,7 +225,6 @@ class CourseListener //|| $controllerList[0] instanceof LegacyController ) ) { - //var_dump($courseId); if (!empty($courseId)) { $controller = $controllerList[0]; $session = $sessionHandler->get('session'); @@ -266,17 +253,6 @@ class CourseListener //$controllerActionParts = explode(':', $controllerAction); //$controllerNameParts = explode('.', $controllerActionParts[0]); //$controllerName = $controllerActionParts[0]; - } else { - /*$ignore = [ - 'fos_js_routing.controller:indexAction', - 'web_profiler.controller.profiler:toolbarAction', - ]; - - $controllerAction = $request->get('_controller'); - if (!in_array($controllerAction, $ignore)) { - //error_log('remove'); - //$this->removeCourseFromSession($request); - }*/ } } diff --git a/src/ThemeBundle/EventListener/TwigListener.php b/src/ThemeBundle/EventListener/TwigListener.php index 2f0a4d08a5..e19be267b9 100644 --- a/src/ThemeBundle/EventListener/TwigListener.php +++ b/src/ThemeBundle/EventListener/TwigListener.php @@ -134,59 +134,62 @@ class TwigListener implements EventSubscriberInterface } } - // Plugins - Region list - $pluginConfiguration = api_get_settings('Plugins', 'list', 1); - $pluginRegionList = []; - foreach ($pluginConfiguration as $plugin) { - if ('region' === $plugin['type']) { - $pluginRegionList[$plugin['variable']][] = $plugin['subkey']; - } - } - $appPlugin = new \AppPlugin(); $installedPlugins = $appPlugin->getInstalledPluginListName(); - $pluginRegions = $appPlugin->getPluginRegions(); - $courseInfo = api_get_course_info(); - $regionListContent = []; - foreach ($installedPlugins as $pluginName) { - foreach ($pluginRegions as $region) { - if (!isset($pluginRegionList[$region])) { - continue; + if (!empty($installedPlugins)) { + // Plugins - Region list + $pluginConfiguration = api_get_settings('Plugins', 'list', 1); + $pluginRegionList = []; + foreach ($pluginConfiguration as $plugin) { + if ('region' === $plugin['type']) { + $pluginRegionList[$plugin['variable']][] = $plugin['subkey']; } + } - if ('course_tool_plugin' === $region) { - $courseRegions = $appPlugin->getPluginRegions(); - $pluginInfo = $appPlugin->getPluginInfo($pluginName, true); + $pluginRegions = $appPlugin->getPluginRegions(); + $courseInfo = api_get_course_info(); + $regionListContent = []; - if (empty($courseInfo)) { + foreach ($installedPlugins as $pluginName) { + foreach ($pluginRegions as $region) { + if (!isset($pluginRegionList[$region])) { continue; } - foreach ($courseRegions as $subRegion) { - if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof \Plugin) { - /** @var \Plugin $plugin */ - $plugin = $pluginInfo['obj']; - $regionListContent[$subRegion][] = $plugin->renderRegion($subRegion); + + if ('course_tool_plugin' === $region) { + $courseRegions = $appPlugin->getPluginRegions(); + $pluginInfo = $appPlugin->getPluginInfo($pluginName, true); + + if (empty($courseInfo)) { + continue; + } + foreach ($courseRegions as $subRegion) { + if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof \Plugin) { + /** @var \Plugin $plugin */ + $plugin = $pluginInfo['obj']; + $regionListContent[$subRegion][] = $plugin->renderRegion($subRegion); + } + } + } else { + if (in_array($pluginName, $pluginRegionList[$region])) { + $regionListContent[$region][] = $appPlugin->loadRegion( + $pluginName, + $region, + $twig, + true //$this->force_plugin_load + ); } - } - } else { - if (in_array($pluginName, $pluginRegionList[$region])) { - $regionListContent[$region][] = $appPlugin->loadRegion( - $pluginName, - $region, - $twig, - true //$this->force_plugin_load - ); } } } - } - foreach ($regionListContent as $region => $contentList) { - $contentToString = ''; - foreach ($contentList as $content) { - $contentToString .= $content; + foreach ($regionListContent as $region => $contentList) { + $contentToString = ''; + foreach ($contentList as $content) { + $contentToString .= $content; + } + $twig->addGlobal("plugin_$region", $contentToString); } - $twig->addGlobal("plugin_$region", $contentToString); } /*$userInfo = api_get_user_info(); diff --git a/src/ThemeBundle/Resources/views/Breadcrumb/breadcrumb.html.twig b/src/ThemeBundle/Resources/views/Breadcrumb/breadcrumb.html.twig deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/ThemeBundle/Resources/views/Resource/grid_theme.html.twig b/src/ThemeBundle/Resources/views/Resource/grid_theme.html.twig index 55626636e3..7060f0ceb3 100644 --- a/src/ThemeBundle/Resources/views/Resource/grid_theme.html.twig +++ b/src/ThemeBundle/Resources/views/Resource/grid_theme.html.twig @@ -93,6 +93,84 @@ {% endblock grid_column_actions_cell %} + + +{% block grid_scripts %} + {{ parent }} + + +{% endblock %} + {% block grid %}
@@ -106,7 +184,7 @@
- +
{% if grid.isTitleSectionVisible %} {{ grid_titles(grid) }} {% endif %} @@ -189,6 +267,9 @@ {% endblock grid_column_filter_type_input %} + + + {# ---------------------------------------------------- grid_pager_selectpage -------------------------------------------------- #} {#{% block grid_pager_selectpage %}#} {# {{ 'Page'|trans }}#} diff --git a/src/ThemeBundle/Resources/views/Resource/index.html.twig b/src/ThemeBundle/Resources/views/Resource/index.html.twig index e1bcfec4d7..ddfaa7bea7 100644 --- a/src/ThemeBundle/Resources/views/Resource/index.html.twig +++ b/src/ThemeBundle/Resources/views/Resource/index.html.twig @@ -2,77 +2,7 @@ {% block content %}