@@ -508,11 +508,14 @@ public static function get_tools_category(
508508 't.session_id '
509509 );
510510
511+ $ lpTable = Database::get_course_table (TABLE_LP_MAIN );
512+
513+ $ orderBy = ' ORDER BY id ' ;
511514 switch ($ course_tool_category ) {
512515 case TOOL_STUDENT_VIEW :
513516 $ conditions = ' WHERE visibility = 1 AND
514517 (category = "authoring" OR category = "interaction" OR category = "plugin") AND
515- name <> "notebookteacher" ' ;
518+ t. name <> "notebookteacher" ' ;
516519 if ((api_is_coach () || api_is_course_tutor ()) && $ _SESSION ['studentview ' ] != 'studentview ' ) {
517520 $ conditions = ' WHERE (
518521 visibility = 1 AND (
@@ -522,16 +525,32 @@ public static function get_tools_category(
522525 ) OR (name = " ' .TOOL_TRACKING .'")
523526 ) ' ;
524527 }
525- $ sql = "SELECT *
528+
529+ /*$sql = "SELECT *
526530 FROM $course_tool_table t
527531 $conditions AND
528532 c_id = $course_id $condition_session
529- " ;
533+ ";*/
534+ // Add order if there are LPs
535+ $ sql = "SELECT t.* FROM $ course_tool_table t
536+ LEFT JOIN $ lpTable l
537+ ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%'))
538+ $ conditions AND
539+ t.c_id = $ course_id $ condition_session
540+ ORDER BY CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END, l.display_order, t.id " ;
541+ $ orderBy = '' ;
530542 break ;
531543 case TOOL_AUTHORING :
532- $ sql = "SELECT * FROM $ course_tool_table t
544+ /* $sql = "SELECT * FROM $course_tool_table t
533545 WHERE category = 'authoring' AND c_id = $course_id $condition_session
534- " ;
546+ ";*/
547+ $ sql = "SELECT t.* FROM $ course_tool_table t
548+ LEFT JOIN $ lpTable l
549+ ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%'))
550+ WHERE
551+ category = 'authoring' AND t.c_id = $ course_id $ condition_session
552+ ORDER BY CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END, l.display_order, t.id " ;
553+ $ orderBy = '' ;
535554 break ;
536555 case TOOL_INTERACTION :
537556 $ sql = "SELECT * FROM $ course_tool_table t
@@ -561,7 +580,7 @@ public static function get_tools_category(
561580 " ;
562581 break ;
563582 }
564- $ sql .= " ORDER BY id " ;
583+ $ sql .= $ orderBy ;
565584 $ result = Database::query ($ sql );
566585 $ tools = [];
567586 while ($ row = Database::fetch_assoc ($ result )) {
0 commit comments