Add config 'allow_edit_tool_visibility_in_session' see BT#12631

- Course tools visibility edition in sessions
remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 7ee764c997
commit a5ba257b2b
  1. 121
      main/inc/ajax/course_home.ajax.php
  2. 14
      main/inc/lib/api.lib.php
  3. 60
      main/inc/lib/course_home.lib.php
  4. 2
      main/install/configuration.dist.php
  5. 19
      src/Chamilo/CourseBundle/Entity/CTool.php

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
use Chamilo\CourseBundle\Entity\CTool;
// @todo refactor this script, create a class that manage the jqgrid requests
/**
@ -13,63 +14,125 @@ switch ($action) {
case 'set_visibility':
require_once __DIR__.'/../global.inc.php';
$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)) {
$tool_table = Database::get_course_table(TABLE_TOOL_LIST);
$tool_info = api_get_tool_information($_GET['id']);
$tool_visibility = $tool_info['visibility'];
$tool_image = $tool_info['image'];
$criteria = [
'cId' => $course_id,
'sessionId' => 0,
'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') {
$tool_image = Display::return_icon(
$tool_image,
$toolImage = Display::return_icon(
$toolImage,
null,
null,
null,
null,
true
);
$na_image = str_replace('.gif', '_na.gif', $tool_image);
$inactiveImage = str_replace('.gif', '_na.gif', $toolImage);
} else {
// 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';
$tool_image = Display::return_icon(
$tool_image,
get_lang(ucfirst($tool_info['name'])),
$toolImage = (substr($toolImage, 0, strpos($toolImage, '.'))).'.png';
$toolImage = Display::return_icon(
$toolImage,
get_lang(ucfirst($tool->getName())),
null,
ICON_SIZE_BIG,
null,
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'])) {
$tool_image = CourseHome::getCustomWebIconPath().$tool_info['custom_icon'];
$na_image = CourseHome::getCustomWebIconPath().CourseHome::getDisableIcon($tool_info['custom_icon']);
if (isset($customIcon) && !empty($customIcon)) {
$toolImage = CourseHome::getCustomWebIconPath().$customIcon;
$inactiveImage = CourseHome::getCustomWebIconPath().CourseHome::getDisableIcon($customIcon);
}
$requested_image = $tool_visibility == 0 ? $tool_image : $na_image;
$requested_class = $tool_visibility == 0 ? '' : 'text-muted';
$requested_message = $tool_visibility == 0 ? 'is_active' : 'is_inactive';
$requested_view = $tool_visibility == 0 ? 'visible.png' : 'invisible.png';
$requested_visible = $tool_visibility == 0 ? 1 : 0;
$requested_view = $tool_visibility == 0 ? 'visible.png' : 'invisible.png';
$requested_visible = $tool_visibility == 0 ? 1 : 0;
$requested_image = $visibility == 0 ? $toolImage : $inactiveImage;
$requested_class = $visibility == 0 ? '' : 'text-muted';
$requested_message = $visibility == 0 ? 'is_active' : 'is_inactive';
$requested_view = $visibility == 0 ? 'visible.png' : 'invisible.png';
$requestedVisible = $visibility == 0 ? 1 : 0;
$requested_view = $visibility == 0 ? 'visible.png' : 'invisible.png';
$requestedVisible = $visibility == 0 ? 1 : 0;
// HIDE AND REACTIVATE TOOL
if ($_GET["id"] == strval(intval($_GET["id"]))) {
$sql = "UPDATE $tool_table SET
visibility = $requested_visible
WHERE c_id = $course_id AND id='".intval($_GET['id'])."'";
Database::query($sql);
if ($_GET['id'] == strval(intval($_GET['id']))) {
$tool->setVisibility($requestedVisible);
$em->persist($tool);
$em->flush();
// 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,
'tclass' => $requested_class,
'message' => $requested_message,
'view' => $requested_view
);
echo json_encode($response_data);
echo json_encode($response);
}
break;
case 'show_course_information':

@ -6012,20 +6012,6 @@ function api_check_term_condition($user_id)
return false;
}
/**
* Gets all information of a tool into course
* @param int The tool id
* @return array
*/
function api_get_tool_information($tool_id)
{
$t_tool = Database::get_course_table(TABLE_TOOL_LIST);
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM $t_tool WHERE c_id = $course_id AND id = ".intval($tool_id);
$rs = Database::query($sql);
return Database::fetch_array($rs);
}
/**
* Gets all information of a tool into course
* @param int The tool id

@ -459,7 +459,12 @@ class CourseHome
// Condition for the session
$session_id = $sessionId ?: api_get_session_id();
$course_id = $courseId ?: api_get_course_int_id();
$condition_session = api_get_session_condition($session_id, true, true, 't.session_id');
$condition_session = api_get_session_condition(
$session_id,
true,
true,
't.session_id'
);
switch ($course_tool_category) {
case TOOL_STUDENT_VIEW:
@ -698,11 +703,15 @@ class CourseHome
$web_code_path = api_get_path(WEB_CODE_PATH);
$session_id = api_get_session_id();
$is_platform_admin = api_is_platform_admin();
$allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
if ($session_id == 0) {
$is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
} else {
$is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
if ($allowEditionInSession) {
$is_allowed_to_edit = api_is_allowed_to_edit(null,true) && api_is_coach($session_id, api_get_course_int_id());
}
}
$i = 0;
@ -711,12 +720,10 @@ class CourseHome
if (isset($all_tools_list)) {
$lnk = '';
foreach ($all_tools_list as & $tool) {
$item = array();
$studentview = false;
$tool['original_link'] = $tool['link'];
if ($tool['image'] == 'scormbuilder.gif') {
// check if the published learnpath is visible for student
$published_lp_id = self::get_published_lp_id_from_link($tool['link']);
@ -772,6 +779,51 @@ class CourseHome
$lnk[] = $link;
}
}
} elseif ($allowEditionInSession) {
$criteria = [
'cId' => api_get_course_int_id(),
'name' => $tool['name'],
'sessionId' => $session_id
];
/** @var \Chamilo\CourseBundle\Entity\CTool $tool */
$toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
if ($toolObj) {
$visibility = $toolObj->getVisibility();
switch ($visibility) {
case '0':
$link['name'] = Display::return_icon(
'invisible.png',
get_lang('Activate'),
array('id' => 'linktool_'.$tool['id']),
ICON_SIZE_SMALL,
false
);
$link['cmd'] = 'restore=yes';
$lnk[] = $link;
break;
case '1':
$link['name'] = Display::return_icon(
'visible.png',
get_lang('Deactivate'),
array('id' => 'linktool_'.$tool['id']),
ICON_SIZE_SMALL,
false
);
$link['cmd'] = 'hide=yes';
$lnk[] = $link;
break;
}
} else {
$link['name'] = Display::return_icon(
'visible.png',
get_lang('Deactivate'),
array('id' => 'linktool_'.$tool['id']),
ICON_SIZE_SMALL,
false
);
$link['cmd'] = 'hide=yes';
$lnk[] = $link;
}
}
if (!empty($tool['adminlink'])) {
$item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
@ -789,7 +841,7 @@ class CourseHome
if (isset($lnk) && is_array($lnk)) {
foreach ($lnk as $this_link) {
if (empty($tool['adminlink'])) {
$item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.
$item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['id'].'&'.$this_link['cmd'].'">'.
$this_link['name'].'</a>';
}
}

@ -373,3 +373,5 @@ $_configuration['agenda_legend'] = [
//$_configuration['session_admins_access_all_content'] = false;
// Adds roles to the system announcements (requires DB change BT#12476)
//$_configuration['system_announce_extra_roles'] = false;
// Course tools visibility edition in sessions
//$_configuration['allow_edit_tool_visibility_in_session'] = false;

@ -126,6 +126,25 @@ class CTool
*/
private $customIcon;
/**
* @return int
*/
public function getIid()
{
return $this->iid;
}
/**
* @param int $iid
* @return CTool
*/
public function setIid($iid)
{
$this->iid = $iid;
return $this;
}
/**
* Set name
*

Loading…
Cancel
Save