Added optional session parameter to api_get_item_visibility() - see CT#1653

skala
Yannick Warnier 15 years ago
parent cf74318934
commit 7a8ac38a41
  1. 11
      main/inc/lib/main_api.lib.php
  2. 4
      main/newscorm/learnpathList.class.php
  3. 18
      main/newscorm/lp_list.php

@ -2295,17 +2295,24 @@ function api_get_datetime($time = null) {
/**
* Gets item visibility from the item_property table
*
* Getting the visibility is done by getting the last updated visibility entry,
* using the largest session ID found if session 0 and another was found (meaning
* the only one that is actually from the session, in case there are results from
* session 0 *AND* session n).
* @param array Course properties array (result of api_get_course_info())
* @param string Tool (learnpath, document, etc)
* @param int The item ID in the given tool
* @param int The session ID (optional)
* @return int -1 on error, 0 if invisible, 1 if visible
*/
function api_get_item_visibility($_course, $tool, $id) {
function api_get_item_visibility($_course, $tool, $id, $session=0) {
if (!is_array($_course) || count($_course) == 0 || empty($tool) || empty($id)) { return -1; }
$tool = Database::escape_string($tool);
$id = Database::escape_string($id);
$session = (int) $session;
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY, $_course['dbName']);
$sql = "SELECT visibility FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = $id";
$sql = "SELECT visibility FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = $id AND (id_session = $session OR id_session = 0) ORDER BY id_session DESC, lastedit_date DESC";
$res = Database::query($sql);
if ($res === false || Database::num_rows($res) == 0) { return -1; }
$row = Database::fetch_array($res);

@ -45,7 +45,7 @@ class learnpathList {
} else {
$session_id = api_get_session_id();
}
$condition_session = api_get_session_condition($session_id, false);
$condition_session = api_get_session_condition($session_id, false, true);
$sql = "SELECT * FROM $lp_table $condition_session ORDER BY display_order ASC, name ASC";
$res = Database::query($sql);
@ -70,7 +70,7 @@ class learnpathList {
$pub = 'i';
}
//check if visible
$vis = api_get_item_visibility(api_get_course_info($course_code),'learnpath',$row['id']);
$vis = api_get_item_visibility(api_get_course_info($course_code),'learnpath',$row['id'],$session_id);
$this->list[$row['id']] = array(
'lp_type' => $row['lp_type'],

@ -299,24 +299,24 @@ if (is_array($flat_list)) {
/* VISIBILITY COMMAND */
if ($current_session == $details['lp_session']) {
// session test not necessary if we want to show base course learning paths inside the session (see http://support.chamilo.org/projects/chamilo-18/wiki/Tools_and_sessions)
error_log(print_r($details,1));
//if ($current_session == $details['lp_session']) {
if ($details['lp_visibility'] == 0)
{
$dsp_visible = "<a href=\"".api_get_self()."?".api_get_cidreq()."&lp_id=$id&action=toggle_visible&new_status=1\">" .
"<img src=\"../img/invisible.gif\" border=\"0\" title=\"".get_lang('Show')."\" />" .
"</a>" .
"";
"</a>";
}
else
{
$dsp_visible = "<a href='".api_get_self()."?".api_get_cidreq()."&lp_id=$id&action=toggle_visible&new_status=0'>" .
"<img src=\"../img/visible.gif\" border=\"0\" title=\"".get_lang('Hide')."\" />" .
"</a>".
"";
"</a>";
}
} else {
$dsp_visible = '<img src="../img/invisible.gif" border="0" title="'.get_lang('Show').'" />';
}
//} else {
// $dsp_visible = '<img src="../img/invisible.gif" border="0" title="'.get_lang('Show').'" />';
//}
/* PUBLISH COMMAND */
@ -514,4 +514,4 @@ echo "<br/><br/>";
FOOTER
*/
Display::display_footer();
?>
?>

Loading…
Cancel
Save