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 */ /* 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':

@ -6012,20 +6012,6 @@ function api_check_term_condition($user_id)
return false; 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 * Gets all information of a tool into course
* @param int The tool id * @param int The tool id

@ -459,7 +459,12 @@ class CourseHome
// Condition for the session // Condition for the session
$session_id = $sessionId ?: api_get_session_id(); $session_id = $sessionId ?: api_get_session_id();
$course_id = $courseId ?: api_get_course_int_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) { switch ($course_tool_category) {
case TOOL_STUDENT_VIEW: case TOOL_STUDENT_VIEW:
@ -698,11 +703,15 @@ class CourseHome
$web_code_path = api_get_path(WEB_CODE_PATH); $web_code_path = api_get_path(WEB_CODE_PATH);
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$is_platform_admin = api_is_platform_admin(); $is_platform_admin = api_is_platform_admin();
$allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
if ($session_id == 0) { if ($session_id == 0) {
$is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin(); $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
} else { } else {
$is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach(); $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; $i = 0;
@ -711,12 +720,10 @@ class CourseHome
if (isset($all_tools_list)) { if (isset($all_tools_list)) {
$lnk = ''; $lnk = '';
foreach ($all_tools_list as & $tool) { foreach ($all_tools_list as & $tool) {
$item = array(); $item = array();
$studentview = false; $studentview = false;
$tool['original_link'] = $tool['link']; $tool['original_link'] = $tool['link'];
if ($tool['image'] == 'scormbuilder.gif') { if ($tool['image'] == 'scormbuilder.gif') {
// check if the published learnpath is visible for student // check if the published learnpath is visible for student
$published_lp_id = self::get_published_lp_id_from_link($tool['link']); $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
@ -772,6 +779,51 @@ class CourseHome
$lnk[] = $link; $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'])) { if (!empty($tool['adminlink'])) {
$item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>'; $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)) { if (isset($lnk) && is_array($lnk)) {
foreach ($lnk as $this_link) { foreach ($lnk as $this_link) {
if (empty($tool['adminlink'])) { 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>'; $this_link['name'].'</a>';
} }
} }

@ -373,3 +373,5 @@ $_configuration['agenda_legend'] = [
//$_configuration['session_admins_access_all_content'] = false; //$_configuration['session_admins_access_all_content'] = false;
// Adds roles to the system announcements (requires DB change BT#12476) // Adds roles to the system announcements (requires DB change BT#12476)
//$_configuration['system_announce_extra_roles'] = false; //$_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; 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 * Set name
* *

Loading…
Cancel
Save