From 6bded67d4aa1ece344fab72baae16588bb7bd0ab Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Thu, 20 Sep 2007 00:14:31 +0200 Subject: [PATCH] [svn r13103] Added api_get_item_visibility() to fetch an item_property row's visibility directly (just pass course, tool and id). --- main/inc/lib/main_api.lib.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 9bfa547c45..d378f8b328 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -1604,6 +1604,26 @@ function convert_mysql_date($last_post_datetime) return $announceDate; } +/** + * Gets item visibility from the item_property table + * @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 + * @return int -1 on error, 0 if invisible, 1 if visible + */ +function api_get_item_visibility($_course,$tool,$id) +{ + if(!is_array($_course) or count($_course)==0 or empty($tool) or empty($id)) return -1; + $tool = Database::escape_string($tool); + $id = Database::escape_string($id); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY,$_course['dbName']); + $sql = "SELECT FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = $id"; + $res = api_sql_query($sql); + if($res === false or Database::num_rows($res)==0) return -1; + $row = Database::fetch_array($res); + return $row['visibility']; +} + /** * Updates or adds item properties to the Item_propetry table * Tool and lastedit_type are language independant strings (langvars->get_lang!)