find('ChamiloCoreBundle:Course', api_get_course_int_id()); /** @var Session $session */ $session = $em->find('ChamiloCoreBundle:Session', api_get_session_id()); $action = isset($_GET['action']) ? $_GET['action'] : 'list'; $cidreq = api_get_cidreq(); $baseUrl = api_get_self().'?'.($cidreq ? $cidreq.'&' : ''); $allowEdit = $currentUserId == $user->getId(); if (isset($_GET['preview'])) { $allowEdit = false; } $toolName = get_lang('Portfolio'); $actions = []; $content = ''; /** * Check if the portfolio item or category is valid for the current user. * * @param $item * * @return bool */ $isValid = function ($item) use ($user, $course, $session) { if (!$item) { return false; } if (get_class($item) == Portfolio::class) { if ($session && $item->getSession()->getId() != $session->getId()) { return false; } if ($course && $item->getCourse()->getId() != $course->getId()) { return false; } } if ($item->getUser()->getId() != $user->getId()) { return false; } return true; }; switch ($action) { case 'add_category': require 'add_category.php'; break; case 'edit_category': $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; if (!$id) { break; } /** @var PortfolioCategory $category */ $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); if (!$isValid($category)) { api_not_allowed(true); } require 'edit_category.php'; break; case 'hide_category': case 'show_category': $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; if (!$id) { break; } /** @var PortfolioCategory $category */ $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); if (!$isValid($category)) { api_not_allowed(true); } $category->setIsVisible(!$category->isVisible()); $em->persist($category); $em->flush(); Display::addFlash( Display::return_message(get_lang('VisibilityChanged'), 'success') ); header("Location: $baseUrl"); exit; case 'delete_category': $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; if (!$id) { break; } /** @var PortfolioCategory $category */ $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); if (!$isValid($category)) { api_not_allowed(true); } $em->remove($category); $em->flush(); Display::addFlash( Display::return_message(get_lang('CategoryDeleted'), 'success') ); header("Location: $baseUrl"); exit; case 'add_item': require 'add_item.php'; break; case 'edit_item': $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; if (!$id) { break; } /** @var CPortfolio $item */ $item = $em->find('ChamiloCoreBundle:Portfolio', $id); if (!$isValid($item)) { api_not_allowed(true); } require 'edit_item.php'; break; case 'hide_item': case 'show_item': $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; if (!$id) { break; } /** @var Portfolio $item */ $item = $em->find('ChamiloCoreBundle:Portfolio', $id); if (!$isValid($item)) { api_not_allowed(true); } $item->setIsVisible(!$item->isVisible()); $em->persist($item); $em->flush(); Display::addFlash( Display::return_message(get_lang('VisibilityChanged'), 'success') ); header("Location: $baseUrl"); exit; case 'delete_item': $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; if (!$id) { break; } /** @var Portfolio $item */ $item = $em->find('ChamiloCoreBundle:Portfolio', $id); if (!$isValid($item)) { api_not_allowed(true); } $em->remove($item); $em->flush(); Display::addFlash( Display::return_message(get_lang('ItemDeleted'), 'success') ); header("Location: $baseUrl"); exit; case 'list': default: require 'list.php'; } /* * View */ $this_section = $course ? SECTION_COURSES : SECTION_SOCIAL; $actions = implode(PHP_EOL, $actions); Display::display_header($toolName); Display::display_introduction_section(TOOL_PORTFOLIO); echo $actions ? Display::toolbarAction('portfolio-toolbar', [$actions]) : ''; echo Display::page_header($toolName); echo $content; Display::display_footer();