diff --git a/main/inc/lib/course_home.lib.php b/main/inc/lib/course_home.lib.php index f398d23aa0f..536e5ead559 100755 --- a/main/inc/lib/course_home.lib.php +++ b/main/inc/lib/course_home.lib.php @@ -721,10 +721,10 @@ public static function get_tools_category($course_tool_category, $courseId = 0, } break; case 'lp_category.gif': - $lpCategory = self::getPublishedLpCategoryFromLink($temp_row['link']); if ($showInvisibleLpsForStudents) { $add = true; } else { + $lpCategory = self::getPublishedLpCategoryFromLink($temp_row['link']); $add = learnpath::categoryIsVisibleForStudent($lpCategory, $user); } @@ -1384,18 +1384,19 @@ public static function getPublishedLpIdFromLink($link) /** * Get published learning path category from link inside course home. - * - * @param string $link - * - * @return CLpCategory */ - public static function getPublishedLpCategoryFromLink($link) + public static function getPublishedLpCategoryFromLink(string $link): ?CLpCategory { $query = parse_url($link, PHP_URL_QUERY); parse_str($query, $params); $id = isset($params['id']) ? (int) $params['id'] : 0; + + if (empty($id)) { + return null; + } + $em = Database::getManager(); - /** @var CLpCategory $category */ + /** @var ?CLpCategory $category */ $category = $em->find('ChamiloCourseBundle:CLpCategory', $id); return $category; diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 69587c0f5bc..dc02c799ce5 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -4860,17 +4860,19 @@ public static function toggleCategoryPublish($id, $setVisibility = 1) /** * Check if the learnpath category is visible for a user. * - * @param int - * @param int + * @param CLpCategory|null $category + * @param User $user + * @param int $courseId + * @param int $sessionId * * @return bool */ public static function categoryIsVisibleForStudent( - CLpCategory $category, + ?CLpCategory $category, User $user, $courseId = 0, $sessionId = 0 - ) { + ): bool { if (empty($category)) { return false; } @@ -4899,7 +4901,7 @@ public static function categoryIsVisibleForStudent( $subscriptionSettings = self::getSubscriptionSettings(); - if ($subscriptionSettings['allow_add_users_to_lp_category'] == false) { + if (!$subscriptionSettings['allow_add_users_to_lp_category']) { return true; } @@ -4951,9 +4953,8 @@ public static function categoryIsVisibleForStudent( } } } - $response = $noGroupSubscribed && $noUserSubscribed; - return $response; + return $noGroupSubscribed && $noUserSubscribed; } /** @@ -12959,10 +12960,8 @@ public static function getCategorySessionId($id) /** * @param int $id - * - * @return CLpCategory */ - public static function getCategory($id) + public static function getCategory($id): ?CLpCategory { $id = (int) $id; $em = Database::getManager();