diff --git a/main/inc/lib/link.lib.php b/main/inc/lib/link.lib.php index 34c4fef700..249d65d3d5 100755 --- a/main/inc/lib/link.lib.php +++ b/main/inc/lib/link.lib.php @@ -782,15 +782,23 @@ class Link extends Model * session * @param int $courseId * @param int $sessionId + * @param bool $withBaseContent + * * @return array */ - public static function getLinkCategories($courseId, $sessionId) + public static function getLinkCategories($courseId, $sessionId, $withBaseContent = true) { $tblLinkCategory = Database:: get_course_table(TABLE_LINK_CATEGORY); $tblItemProperty = Database:: get_course_table(TABLE_ITEM_PROPERTY); $courseId = intval($courseId); + // Condition for the session. - $sessionCondition = api_get_session_condition($sessionId, true, true, 'linkcat.session_id'); + $sessionCondition = api_get_session_condition( + $sessionId, + true, + $withBaseContent, + 'linkcat.session_id' + ); // Getting links $sql = "SELECT *, linkcat.id @@ -846,42 +854,71 @@ class Link extends Model } /** - * Displays all the links of a given category. - * @author Patrick Cool , Ghent University + * @param $categoryId + * @param $courseId + * @param $sessionId + * @param bool $withBaseContent + * + * @return array */ - public static function showlinksofcategory($catid) + public static function getLinksPerCategory($categoryId, $courseId, $sessionId, $withBaseContent = true) { - global $token; - $_user = api_get_user_info(); - $course_id = api_get_course_int_id(); - $session_id = api_get_session_id(); - $catid = intval($catid); - $tbl_link = Database:: get_course_table(TABLE_LINK); $TABLE_ITEM_PROPERTY = Database:: get_course_table(TABLE_ITEM_PROPERTY); + $courseId = (int) $courseId; + $sessionId = (int) $sessionId; + $categoryId = (int) $categoryId; // Condition for the session. - $condition_session = api_get_session_condition($session_id, true, true, 'link.session_id'); - $content = ''; + $condition_session = api_get_session_condition( + $sessionId, + true, + $withBaseContent, + 'link.session_id' + ); + $sql = "SELECT *, link.id FROM $tbl_link link INNER JOIN $TABLE_ITEM_PROPERTY ip - ON (link.id=ip.ref AND link.c_id = ip.c_id) + ON (link.id = ip.ref AND link.c_id = ip.c_id) WHERE - ip.tool='" . TOOL_LINK . "' AND - link.category_id='" . $catid . "' AND - (ip.visibility='0' OR ip.visibility='1') + ip.tool = '" . TOOL_LINK . "' AND + link.category_id = '" . $categoryId . "' AND + (ip.visibility = '0' OR ip.visibility = '1') $condition_session AND - link.c_id = " . $course_id . " AND - ip.c_id = " . $course_id . " + link.c_id = $courseId AND + ip.c_id = $courseId ORDER BY link.display_order ASC"; $result = Database:: query($sql); - $numberoflinks = Database:: num_rows($result); - if ($numberoflinks > 0) { + + return Database::store_result($result); + } + + /** + * Displays all the links of a given category. + * @author Patrick Cool , Ghent University + * @author Julio Montoya + * + * @param $catid + * @param $courseId + * @param $session_id + * @return string + */ + public static function showLinksPerCategory($catid, $courseId, $session_id) + { + global $token; + $_user = api_get_user_info(); + $catid = intval($catid); + + $links = self::getLinksPerCategory($catid, $courseId, $session_id); + $content = ''; + $numberoflinks = count($links); + + if (!empty($links)) { $content .= '