* @Route("/") */ class HomeController extends ToolBaseController { /** * @Route("/", name="course_home") * @Route("/index.php", methods={"GET"}) * * @param Request $request * * @return Response */ public function indexAction(Request $request) { $sessionId = api_get_session_id(); $course = $this->getCourse(); $courseCode = $course->getId(); $result = $this->autoLaunch(); $showAutoLaunchLpWarning = $result['show_autolaunch_lp_warning']; $showAutoLaunchExerciseWarning = $result['show_autolaunch_exercise_warning']; if ($showAutoLaunchLpWarning) { $this->addFlash( 'warning', $this->trans('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP') ); } if ($showAutoLaunchExerciseWarning) { $this->addFlash( 'warning', $this->trans('TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise') ); } if (true) { $editIcons = Display::url( Display::return_icon('edit.png'), $this->generateUrl( 'chamilo_course_home_home_iconlist', [ 'course' => api_get_course_id(), ] ) ); } $isSpecialCourse = \CourseManager::isSpecialCourse($courseCode); if ($isSpecialCourse) { $user = $this->getUser(); if (!empty($user)) { $userId = $this->getUser()->getId(); $autoreg = $request->get('autoreg'); if ($autoreg == 1) { \CourseManager::subscribe_user( $userId, $courseCode, STUDENT ); } } } $homeView = api_get_setting('course.homepage_view'); if ($homeView == 'activity' || $homeView == 'activity_big') { $blocks = $this->renderActivityView(); } elseif ($homeView == '2column') { $result = $this->render2ColumnView(); } elseif ($homeView == '3column') { $result = $this->render3ColumnView(); } elseif ($homeView == 'vertical_activity') { $result = $this->renderVerticalActivityView(); } $toolList = $result['tool_list']; $introduction = Display::return_introduction_section( TOOL_COURSE_HOMEPAGE, $toolList ); $sessionInfo = null; if (api_get_setting('session.show_session_data') == 'true' && $sessionId) { $sessionInfo = CourseHome::show_session_data($sessionId); } return $this->render( 'ChamiloCourseBundle:Home:index.html.twig', [ 'course' => $course, 'session_info' => $sessionInfo, 'icons' => $result['content'], 'blocks' => $blocks, 'edit_icons' => $editIcons, 'introduction_text' => $introduction, 'exercise_warning' => null, 'lp_warning' => null, ] ); } /** * @param string $courseCode * @param string $fileName * * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ public function getFileAction($courseCode, $fileName) { $courseInfo = api_get_course_info($courseCode); $sessionId = $this->getRequest()->get('id_session'); $docId = \DocumentManager::get_document_id($courseInfo, "/".$fileName); $filePath = null; if ($docId) { $isVisible = \DocumentManager::is_visible_by_id($docId, $courseInfo, $sessionId, api_get_user_id()); $documentData = \DocumentManager::get_document_data_by_id($docId, $courseCode); $filePath = $documentData['absolute_path']; event_download($filePath); } if (!api_is_allowed_to_edit() && !$isVisible) { $this->abort(500); } return $this->sendFile($filePath); } /** * @Route("/show/{iconId}", methods={"GET"}) * * @param $iconId * * @return string|null */ public function showIconAction($iconId) { $entityManager = $this->getDoctrine()->getManager(); $criteria = ['cId' => api_get_course_int_id(), 'id' => $iconId]; $tool = $this->getRepository( 'Chamilo\CourseBundle\Entity\CTool' )->findOneBy($criteria); if ($tool) { $tool->setVisibility(1); } $entityManager->persist($tool); //$entityManager->flush(); return Display::return_message(get_lang('Visible'), 'confirmation'); } /** * @Route("/hide/{iconId}", methods={"GET"}) * * @param $iconId * * @return string|null */ public function hideIconAction($iconId) { if (!$this->isCourseTeacher()) { return $this->abort(404); } $entityManager = $this->getDoctrine()->getManager(); $criteria = ['cId' => api_get_course_int_id(), 'id' => $iconId]; $tool = $this->getRepository( 'Chamilo\CourseBundle\Entity\CTool' )->findOneBy($criteria); if ($tool) { $tool->setVisibility(0); } $entityManager->persist($tool); //$entityManager->flush(); return Display::return_message(get_lang('ToolIsNowHidden'), 'confirmation'); } /** * @Route("/delete/{iconId}", methods={"GET"}) * * @param $iconId * * @return string|null */ public function deleteIcon($iconId) { if (!$this->isCourseTeacher()) { return $this->abort(404); } $entityManager = $this->getDoctrine()->getManager(); $criteria = ['cId' => api_get_course_int_id(), 'id' => $iconId, 'added_tool' => 1]; $tool = $this->getRepository( 'Chamilo\CourseBundle\Entity\CTool' )->findOneBy($criteria); $entityManager->remove($tool); //$entityManager->flush(); return Display::return_message(get_lang('Deleted'), 'confirmation'); } /** * @Route("/icon_list", methods={"GET"}) * * @param Request $request */ public function iconListAction(Request $request) { $em = $this->getDoctrine()->getManager(); $repo = $this->getDoctrine()->getRepository('ChamiloCourseBundle:CTool'); $sessionId = intval($request->get('id_session')); $itemsFromSession = []; if (!empty($sessionId)) { $query = $repo->createQueryBuilder('a'); $query->select('s'); $query->from('Chamilo\CourseBundle\Entity\CTool', 's'); $query->where('s.cId = :courseId AND s.sessionId = :sessionId') ->setParameters( [ 'course' => $this->getCourse()->getId(), 'sessionId' => $sessionId, ] ); $itemsFromSession = $query->getQuery()->getResult(); $itemNameList = []; foreach ($itemsFromSession as $item) { $itemNameList[] = $item->getName(); } //$itemsFromSession = $this->getRepository()->findBy($criteria); $query = $repo->createQueryBuilder('a'); $query->select('s'); $query->from('Chamilo\CourseBundle\Entity\CTool', 's'); $query->where('s.cId = :courseId AND s.sessionId = 0') ->setParameters( [ 'courseId' => $this->getCourse()->getId(), ] ); if (!empty($itemNameList)) { $query->andWhere($query->expr()->notIn('s.name', $itemNameList)); } $itemsFromCourse = $query->getQuery()->getResult(); } else { $criteria = ['cId' => $this->getCourse()->getId(), 'sessionId' => 0]; $itemsFromCourse = $repo->findBy($criteria); } return $this->render( '@ChamiloCourse/Home/list.html.twig', [ 'items_from_course' => $itemsFromCourse, 'items_from_session' => $itemsFromSession, 'links' => '', ] ); } /** * @Route("/{itemName}/add", methods={"GET", "POST"}) * * @param $itemName * * @return mixed */ public function addIconAction($itemName) { if (!$this->isCourseTeacher()) { return $this->abort(404); } $sessionId = intval($this->getRequest()->get('id_session')); if (empty($sessionId)) { return $this->abort(500); } $criteria = ['cId' => $this->getCourse()->getId(), 'sessionId' => 0, 'name' => $itemName]; $itemFromDatabase = $this->getRepository()->findOneBy($criteria); if (!$itemFromDatabase) { $this->createNotFoundException(); } /** @var CTool $item */ $item = clone $itemFromDatabase; $item->setId(null); $item->setSessionId($sessionId); $form = $this->createForm($this->getFormType(), $item); $form->handleRequest($this->getRequest()); if ($form->isValid()) { $query = $this->getDoctrine()->getManager()->createQueryBuilder('a'); $query->select('MAX(s.id) as id'); $query->from('Chamilo\CourseBundle\Entity\CTool', 's'); $query->where('s.cId = :courseId')->setParameter('courseId', $this->getCourse()->getId()); $result = $query->getQuery()->getArrayResult(); $maxId = $result[0]['id'] + 1; $item->setId($maxId); $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($item); $entityManager->flush(); $customIcon = $item->getCustomIcon(); if (!empty($customIcon)) { $item->createGrayIcon($this->get('imagine')); } $this->get('session')->getFlashBag()->add('success', "Added"); $url = $this->generateUrl('course_home.controller:iconListAction', ['id_session' => $sessionId]); return $this->redirect($url); } $this->getTemplate()->assign('item', $item); $this->getTemplate()->assign('form', $form->createView()); $this->getTemplate()->assign('links', $this->generateLinks()); return $this->render('@ChamiloCourse/Home/add.html.twig'); } /** * @Route("/{itemId}/edit", methods={"GET"}) */ public function editIconAction($itemId) { if (!$this->isCourseTeacher()) { return $this->abort(404); } $sessionId = intval($this->getRequest()->get('id_session')); $criteria = ['cId' => $this->getCourse()->getId(), 'id' => $itemId]; /** @var CTool $item */ $item = $this->getRepository()->findOneBy($criteria); $form = $this->createForm($this->getFormType(), $item); $form->handleRequest($this->getRequest()); if ($form->isValid()) { $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($item); $entityManager->flush(); $customIcon = $item->getCustomIcon(); if (!empty($customIcon)) { $item->createGrayIcon($this->get('imagine')); } $this->get('session')->getFlashBag()->add('success', "Updated"); $url = $this->generateUrl('course_home.controller:iconListAction', ['id_session' => $sessionId]); return $this->redirect($url); } $this->getTemplate()->assign('item', $item); $this->getTemplate()->assign('form', $form->createView()); $this->getTemplate()->assign('links', $this->generateLinks()); return $this->render('@ChamiloCourse/Home/edit.html.twig'); } /** * @Route("/{itemId}/delete", methods={"GET"}) */ public function deleteIconAction($itemId) { if (!$this->isCourseTeacher()) { return $this->abort(404); } $criteria = ['cId' => $this->getCourse()->getId(), 'id' => $itemId]; /** @var CTool $item */ $item = $this->getRepository()->findOneBy($criteria); $entityManager = $this->getDoctrine()->getManager(); $sessionId = $item->getSessionId(); if (!empty($sessionId)) { $entityManager->remove($item); } else { $item->setCustomIcon(null); $entityManager->persist($item); } $entityManager->flush(); $this->get('session')->getFlashBag()->add('success', "Deleted"); $this->getTemplate()->assign('links', $this->generateLinks()); $url = $this->generateUrl('course_home.controller:iconListAction'); return $this->redirect($url); } /** * @param string $title * @param string $content * @param string $class * * @return string */ private function return_block($title, $content, $class = null) { $html = '