|
|
@ -2,6 +2,7 @@ |
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
|
|
|
|
|
|
|
use ChamiloSession as Session; |
|
|
|
use ChamiloSession as Session; |
|
|
|
|
|
|
|
use Chamilo\CourseBundle\Entity\CTool; |
|
|
|
|
|
|
|
|
|
|
|
// @todo refactor this script, create a class that manage the jqgrid requests |
|
|
|
// @todo refactor this script, create a class that manage the jqgrid requests |
|
|
|
/** |
|
|
|
/** |
|
|
@ -13,63 +14,125 @@ switch ($action) { |
|
|
|
case 'set_visibility': |
|
|
|
case 'set_visibility': |
|
|
|
require_once __DIR__.'/../global.inc.php'; |
|
|
|
require_once __DIR__.'/../global.inc.php'; |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
$sessionId = api_get_session_id(); |
|
|
|
|
|
|
|
// Allow tool visibility in sessions. |
|
|
|
|
|
|
|
$allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session'); |
|
|
|
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
|
|
|
$repository = $em->getRepository('ChamiloCourseBundle:CTool'); |
|
|
|
if (api_is_allowed_to_edit(null, true)) { |
|
|
|
if (api_is_allowed_to_edit(null, true)) { |
|
|
|
$tool_table = Database::get_course_table(TABLE_TOOL_LIST); |
|
|
|
$criteria = [ |
|
|
|
$tool_info = api_get_tool_information($_GET['id']); |
|
|
|
'cId' => $course_id, |
|
|
|
$tool_visibility = $tool_info['visibility']; |
|
|
|
'sessionId' => 0, |
|
|
|
$tool_image = $tool_info['image']; |
|
|
|
'id' => (int) $_GET['id'] |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
/** @var CTool $tool */ |
|
|
|
|
|
|
|
$tool = $repository->findOneBy($criteria); |
|
|
|
|
|
|
|
$visibility = $tool->getVisibility(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($allowEditionInSession && !empty($sessionId)) { |
|
|
|
|
|
|
|
$criteria = [ |
|
|
|
|
|
|
|
'cId' => $course_id, |
|
|
|
|
|
|
|
'sessionId' => $sessionId, |
|
|
|
|
|
|
|
'name' => $tool->getName() |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @var CTool $tool */ |
|
|
|
|
|
|
|
$toolInSession = $repository->findOneBy($criteria); |
|
|
|
|
|
|
|
if ($toolInSession) { |
|
|
|
|
|
|
|
// Use the session |
|
|
|
|
|
|
|
$tool = $toolInSession; |
|
|
|
|
|
|
|
$visibility = $toolInSession->getVisibility(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Creates new row in c_tool |
|
|
|
|
|
|
|
$toolInSession = clone $tool; |
|
|
|
|
|
|
|
$toolInSession->setIid(0); |
|
|
|
|
|
|
|
$toolInSession->setId(0); |
|
|
|
|
|
|
|
$toolInSession->setVisibility(0); |
|
|
|
|
|
|
|
$toolInSession->setSessionId($session_id); |
|
|
|
|
|
|
|
$em->persist($toolInSession); |
|
|
|
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
// Update id with iid |
|
|
|
|
|
|
|
$toolInSession->setId($toolInSession->getIid()); |
|
|
|
|
|
|
|
$em->persist($toolInSession); |
|
|
|
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
// $tool will be updated later |
|
|
|
|
|
|
|
$tool = $toolInSession; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$toolImage = $tool->getImage(); |
|
|
|
|
|
|
|
$customIcon = $tool->getCustomIcon(); |
|
|
|
|
|
|
|
|
|
|
|
if (api_get_setting('homepage_view') != 'activity_big') { |
|
|
|
if (api_get_setting('homepage_view') != 'activity_big') { |
|
|
|
$tool_image = Display::return_icon( |
|
|
|
$toolImage = Display::return_icon( |
|
|
|
$tool_image, |
|
|
|
$toolImage, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
true |
|
|
|
true |
|
|
|
); |
|
|
|
); |
|
|
|
$na_image = str_replace('.gif', '_na.gif', $tool_image); |
|
|
|
$inactiveImage = str_replace('.gif', '_na.gif', $toolImage); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Display::return_icon() also checks in the app/Resources/public/css/themes/{theme}/icons folder |
|
|
|
// Display::return_icon() also checks in the app/Resources/public/css/themes/{theme}/icons folder |
|
|
|
$tool_image = (substr($tool_image, 0, strpos($tool_image, '.'))).'.png'; |
|
|
|
$toolImage = (substr($toolImage, 0, strpos($toolImage, '.'))).'.png'; |
|
|
|
$tool_image = Display::return_icon( |
|
|
|
$toolImage = Display::return_icon( |
|
|
|
$tool_image, |
|
|
|
$toolImage, |
|
|
|
get_lang(ucfirst($tool_info['name'])), |
|
|
|
get_lang(ucfirst($tool->getName())), |
|
|
|
null, |
|
|
|
null, |
|
|
|
ICON_SIZE_BIG, |
|
|
|
ICON_SIZE_BIG, |
|
|
|
null, |
|
|
|
null, |
|
|
|
true |
|
|
|
true |
|
|
|
); |
|
|
|
); |
|
|
|
$na_image = str_replace('.png', '_na.png', $tool_image); |
|
|
|
$inactiveImage = str_replace('.png', '_na.png', $toolImage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($tool_info['custom_icon']) && !empty($tool_info['custom_icon'])) { |
|
|
|
if (isset($customIcon) && !empty($customIcon)) { |
|
|
|
$tool_image = CourseHome::getCustomWebIconPath().$tool_info['custom_icon']; |
|
|
|
$toolImage = CourseHome::getCustomWebIconPath().$customIcon; |
|
|
|
$na_image = CourseHome::getCustomWebIconPath().CourseHome::getDisableIcon($tool_info['custom_icon']); |
|
|
|
$inactiveImage = CourseHome::getCustomWebIconPath().CourseHome::getDisableIcon($customIcon); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$requested_image = $tool_visibility == 0 ? $tool_image : $na_image; |
|
|
|
$requested_image = $visibility == 0 ? $toolImage : $inactiveImage; |
|
|
|
$requested_class = $tool_visibility == 0 ? '' : 'text-muted'; |
|
|
|
$requested_class = $visibility == 0 ? '' : 'text-muted'; |
|
|
|
$requested_message = $tool_visibility == 0 ? 'is_active' : 'is_inactive'; |
|
|
|
$requested_message = $visibility == 0 ? 'is_active' : 'is_inactive'; |
|
|
|
$requested_view = $tool_visibility == 0 ? 'visible.png' : 'invisible.png'; |
|
|
|
$requested_view = $visibility == 0 ? 'visible.png' : 'invisible.png'; |
|
|
|
$requested_visible = $tool_visibility == 0 ? 1 : 0; |
|
|
|
$requestedVisible = $visibility == 0 ? 1 : 0; |
|
|
|
$requested_view = $tool_visibility == 0 ? 'visible.png' : 'invisible.png'; |
|
|
|
$requested_view = $visibility == 0 ? 'visible.png' : 'invisible.png'; |
|
|
|
$requested_visible = $tool_visibility == 0 ? 1 : 0; |
|
|
|
$requestedVisible = $visibility == 0 ? 1 : 0; |
|
|
|
|
|
|
|
|
|
|
|
// HIDE AND REACTIVATE TOOL |
|
|
|
// HIDE AND REACTIVATE TOOL |
|
|
|
if ($_GET["id"] == strval(intval($_GET["id"]))) { |
|
|
|
if ($_GET['id'] == strval(intval($_GET['id']))) { |
|
|
|
$sql = "UPDATE $tool_table SET |
|
|
|
$tool->setVisibility($requestedVisible); |
|
|
|
visibility = $requested_visible |
|
|
|
$em->persist($tool); |
|
|
|
WHERE c_id = $course_id AND id='".intval($_GET['id'])."'"; |
|
|
|
$em->flush(); |
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
|
|
// Also hide the tool in all sessions |
|
|
|
|
|
|
|
if ($allowEditionInSession && $requestedVisible == 0 && empty($sessionId)) { |
|
|
|
|
|
|
|
$criteria = [ |
|
|
|
|
|
|
|
'cId' => $course_id, |
|
|
|
|
|
|
|
'name' => $tool->getName() |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @var CTool $toolItem */ |
|
|
|
|
|
|
|
$tools = $repository->findBy($criteria); |
|
|
|
|
|
|
|
foreach ($tools as $toolItem) { |
|
|
|
|
|
|
|
$toolSessionId = $toolItem->getSessionId(); |
|
|
|
|
|
|
|
if (!empty($toolSessionId)) { |
|
|
|
|
|
|
|
$toolItem->setVisibility(0); |
|
|
|
|
|
|
|
$em->persist($toolItem); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$response_data = array( |
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = array( |
|
|
|
'image' => $requested_image, |
|
|
|
'image' => $requested_image, |
|
|
|
'tclass' => $requested_class, |
|
|
|
'tclass' => $requested_class, |
|
|
|
'message' => $requested_message, |
|
|
|
'message' => $requested_message, |
|
|
|
'view' => $requested_view |
|
|
|
'view' => $requested_view |
|
|
|
); |
|
|
|
); |
|
|
|
echo json_encode($response_data); |
|
|
|
echo json_encode($response); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'show_course_information': |
|
|
|
case 'show_course_information': |
|
|
|