Skip to content

Commit

Permalink
Fix params and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Jan 13, 2025
1 parent 4d3c2a9 commit 27b344e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
15 changes: 8 additions & 7 deletions main/inc/lib/course_home.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
19 changes: 9 additions & 10 deletions main/lp/learnpath.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -4951,9 +4953,8 @@ public static function categoryIsVisibleForStudent(
}
}
}
$response = $noGroupSubscribed && $noUserSubscribed;

return $response;
return $noGroupSubscribed && $noUserSubscribed;
}

/**
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 27b344e

Please sign in to comment.