Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions public/main/inc/lib/gradebook.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,64 @@ public static function is_active($c_id = null)
{
$name = 'gradebook';
$table = Database::get_main_table(TABLE_MAIN_SETTINGS);
$sql = "SELECT * from $table
WHERE variable='course_hide_tools' AND subkey='$name'
LIMIT 1";
$sql = "SELECT * FROM $table
WHERE variable='course_hide_tools' AND subkey='$name'
LIMIT 1";
$result = Database::query($sql);
$setting = Database::store_result($result);
$setting = isset($setting[0]) ? $setting[0] : null;
$setting = $setting ? $setting : [];
$inactive = isset($setting['selected_value']) && 'true' == $setting['selected_value'];
$setting = $setting[0] ?? [];
$inactive = isset($setting['selected_value']) && 'true' === $setting['selected_value'];

if ($inactive) {
return false;
}

$c_id = $c_id ? intval($c_id) : api_get_course_int_id();
$table = Database::get_course_table(TABLE_TOOL_LIST);
$sql = "SELECT * from $table
WHERE c_id = $c_id and title = '$name'
LIMIT 1";
$c_id = $c_id ? (int) $c_id : api_get_course_int_id();
$toolTable = Database::get_course_table(TABLE_TOOL_LIST);
$sql = "SELECT resource_node_id, session_id
FROM $toolTable
WHERE c_id = $c_id AND title = '$name'
LIMIT 1";
$result = Database::query($sql);
$item = Database::store_result($result, 'ASSOC');
$item = isset($item[0]) ? $item[0] : null;
$item = $item[0] ?? null;
if (empty($item)) {
return true;
}

return '1' == $item['visibility'];
$nodeId = (int) ($item['resource_node_id'] ?? 0);
if ($nodeId <= 0) {
return true;
}

// Visibility is now stored in resource_link.visibility
$rlTable = Database::get_main_table('resource_link');
$sessionId = $item['session_id'] ?? null;

$sessionCondition = empty($sessionId)
? "session_id IS NULL"
: "session_id = ".((int) $sessionId);

$sql = "SELECT visibility
FROM $rlTable
WHERE resource_node_id = $nodeId
AND c_id = $c_id
AND $sessionCondition
AND user_id IS NULL
AND usergroup_id IS NULL
AND group_id IS NULL
AND deleted_at IS NULL
ORDER BY id DESC
LIMIT 1";
$result = Database::query($sql);
$link = Database::store_result($result, 'ASSOC');
$link = $link[0] ?? null;

if (empty($link) || !isset($link['visibility'])) {
return true;
}

return (int) $link['visibility'] === 2;
}

public function get_all(array $options = []): array
Expand Down
Loading