@@ -43,32 +43,64 @@ public static function is_active($c_id = null)
4343 {
4444 $ name = 'gradebook ' ;
4545 $ table = Database::get_main_table (TABLE_MAIN_SETTINGS );
46- $ sql = "SELECT * from $ table
47- WHERE variable='course_hide_tools' AND subkey=' $ name'
48- LIMIT 1 " ;
46+ $ sql = "SELECT * FROM $ table
47+ WHERE variable='course_hide_tools' AND subkey=' $ name'
48+ LIMIT 1 " ;
4949 $ result = Database::query ($ sql );
5050 $ setting = Database::store_result ($ result );
51- $ setting = isset ($ setting [0 ]) ? $ setting [0 ] : null ;
52- $ setting = $ setting ? $ setting : [];
53- $ inactive = isset ($ setting ['selected_value ' ]) && 'true ' == $ setting ['selected_value ' ];
51+ $ setting = $ setting [0 ] ?? [];
52+ $ inactive = isset ($ setting ['selected_value ' ]) && 'true ' === $ setting ['selected_value ' ];
5453
5554 if ($ inactive ) {
5655 return false ;
5756 }
5857
59- $ c_id = $ c_id ? intval ($ c_id ) : api_get_course_int_id ();
60- $ table = Database::get_course_table (TABLE_TOOL_LIST );
61- $ sql = "SELECT * from $ table
62- WHERE c_id = $ c_id and title = ' $ name'
63- LIMIT 1 " ;
58+ $ c_id = $ c_id ? (int ) $ c_id : api_get_course_int_id ();
59+ $ toolTable = Database::get_course_table (TABLE_TOOL_LIST );
60+ $ sql = "SELECT resource_node_id, session_id
61+ FROM $ toolTable
62+ WHERE c_id = $ c_id AND title = ' $ name'
63+ LIMIT 1 " ;
6464 $ result = Database::query ($ sql );
6565 $ item = Database::store_result ($ result , 'ASSOC ' );
66- $ item = isset ( $ item [0 ]) ? $ item [ 0 ] : null ;
66+ $ item = $ item [0 ] ?? null ;
6767 if (empty ($ item )) {
6868 return true ;
6969 }
7070
71- return '1 ' == $ item ['visibility ' ];
71+ $ nodeId = (int ) ($ item ['resource_node_id ' ] ?? 0 );
72+ if ($ nodeId <= 0 ) {
73+ return true ;
74+ }
75+
76+ // Visibility is now stored in resource_link.visibility
77+ $ rlTable = Database::get_main_table ('resource_link ' );
78+ $ sessionId = $ item ['session_id ' ] ?? null ;
79+
80+ $ sessionCondition = empty ($ sessionId )
81+ ? "session_id IS NULL "
82+ : "session_id = " .((int ) $ sessionId );
83+
84+ $ sql = "SELECT visibility
85+ FROM $ rlTable
86+ WHERE resource_node_id = $ nodeId
87+ AND c_id = $ c_id
88+ AND $ sessionCondition
89+ AND user_id IS NULL
90+ AND usergroup_id IS NULL
91+ AND group_id IS NULL
92+ AND deleted_at IS NULL
93+ ORDER BY id DESC
94+ LIMIT 1 " ;
95+ $ result = Database::query ($ sql );
96+ $ link = Database::store_result ($ result , 'ASSOC ' );
97+ $ link = $ link [0 ] ?? null ;
98+
99+ if (empty ($ link ) || !isset ($ link ['visibility ' ])) {
100+ return true ;
101+ }
102+
103+ return (int ) $ link ['visibility ' ] === 2 ;
72104 }
73105
74106 public function get_all (array $ options = []): array
0 commit comments