diff --git a/main/auth/courses.php b/main/auth/courses.php index 5196085566..f23f5488e5 100755 --- a/main/auth/courses.php +++ b/main/auth/courses.php @@ -56,6 +56,7 @@ $actions = [ 'subscribe_to_session', 'search_tag', 'search_session', + 'set_collapsable', ]; $action = CoursesAndSessionsCatalog::is(CATALOG_SESSIONS) ? 'display_sessions' : 'display_courses'; @@ -330,4 +331,29 @@ switch ($action) { $courseController->sessionListBySearch($limit); break; + case 'set_collapsable': + api_block_anonymous_users(); + + if (!api_get_configuration_value('allow_user_course_category_collapsable')) { + api_not_allowed(true); + } + + $userId = api_get_user_id(); + $categoryId = isset($_REQUEST['categoryid']) ? (int) $_REQUEST['categoryid'] : 0; + $option = isset($_REQUEST['option']) ? (int) $_REQUEST['option'] : 0; + + if (empty($userId) || empty($categoryId)) { + api_not_allowed(true); + } + + $table = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); + $sql = "UPDATE $table + SET collapsed = $option + WHERE user_id = $userId AND id = $categoryId"; + Database::query($sql); + Display::addFlash(Display::return_message(get_lang('Updated'))); + $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses'; + header('Location: '.$url); + exit; + break; } diff --git a/main/auth/courses_list.php b/main/auth/courses_list.php index dc50c3dcfd..8b20b2924d 100755 --- a/main/auth/courses_list.php +++ b/main/auth/courses_list.php @@ -27,6 +27,8 @@ if (!empty($message)) { echo Display::return_message($message, 'confirm', false); } +$allowCollapsable = api_get_configuration_value('allow_user_course_category_collapsable'); + // COURSES WITH CATEGORIES if (!empty($user_course_categories)) { $counter = 0; @@ -34,6 +36,7 @@ if (!empty($user_course_categories)) { foreach ($user_course_categories as $row) { echo Display::page_subheader($row['title']); echo ''; + $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?categoryid='.$row['id'].'&sec_token='.$stok; if (isset($_GET['categoryid']) && $_GET['categoryid'] == $row['id']) { ?> @@ -46,6 +49,21 @@ if (!empty($user_course_categories)) { ', + $url.'&action=set_collapsable&option=1' + ); + } else { + echo Display::url( + '', + $url.'&action=set_collapsable&option=0' + ); + } + } + ?> @@ -83,6 +101,7 @@ if (!empty($user_course_categories)) {
'; // Show the courses inside this category diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 5f54408a91..41ca312b4e 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3802,7 +3802,7 @@ class CourseManager } // Step 1: We get all the categories of the user $table = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); - $sql = "SELECT id, title FROM $table + $sql = "SELECT * FROM $table WHERE user_id = '".$user_id."' ORDER BY sort ASC"; @@ -3811,6 +3811,7 @@ class CourseManager 'in_category' => [], 'not_category' => [], ]; + $collapsable = api_get_configuration_value('allow_user_course_category_collapsable'); while ($row = Database::fetch_array($result)) { // We simply display the title of the category. $courseInCategory = self::returnCoursesCategories( @@ -3820,9 +3821,14 @@ class CourseManager $useUserLanguageFilterIfAvailable ); + $collapsed = 0; + if ($collapsable) { + $collapsed = isset($row['collapsed']) && $row['collapsed'] ? 1 : 0; + } $params = [ 'id_category' => $row['id'], 'title_category' => $row['title'], + 'collapsed' => $collapsed, 'courses' => $courseInCategory, ]; $listItems['in_category'][] = $params; diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 64673614fc..e051f0d1e4 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -1047,6 +1047,10 @@ VALUES (2, 13, 'session_courses_read_only_mode', 'Lock Course In Session', 1, 1, // Improve speed when rendering gradebook student reports using Doctrine APCU cache // $_configuration['gradebook_use_apcu_cache'] = true; +// Add collapsable option for user course categories +// ALTER TABLE user_course_category ADD collapsed TINYINT(1) DEFAULT NULL; +// $_configuration['allow_user_course_category_collapsable'] = true; + // ------ Custom DB changes (keep this at the end) // Add user activation by confirmation email // This option prevents the new user to login in the platform if your account is not confirmed via email diff --git a/main/template/default/user_portal/classic_courses_with_category.tpl b/main/template/default/user_portal/classic_courses_with_category.tpl index 240407f442..ac82df1433 100644 --- a/main/template/default/user_portal/classic_courses_with_category.tpl +++ b/main/template/default/user_portal/classic_courses_with_category.tpl @@ -1,17 +1,16 @@ +{% import 'macro/macro.tpl'|get_template as display %} + {% if not categories is empty %}
{% for category in categories %} {% if category.courses %} -
-
- {{ category.title_category }} -
-
- {% for item in category.courses %} -
-
- {% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %} - + {% set course_content %} + + {% for item in category.courses %} +
+
+ {% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %} + {% if item.thumbnails != '' %} {{ item.title }} @@ -19,83 +18,84 @@ {{ 'blackboard.png' | img(48, item.title ) }} {% endif %} - {% else %} - - {% if item.thumbnails != '' %} - {{ item.title }} - {% else %} - {{ 'blackboard.png' | img(48, item.title ) }} - {% endif %} - - {% endif %} -
-
- {% if item.edit_actions != '' %} - +
+ {% if item.edit_actions != '' %} +
+ {% if item.document == '' %} + + + + {% else %} +
- {% else %} -
- - - - {{ item.document }} -
- {% endif %} -
- {% endif %} -

- {% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %} + {{ item.document }} +

+ {% endif %} +
+ {% endif %} +

+ {% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %} + {{ item.title }} {{ item.code_course }} + {% else %} + {{ item.title }} {{ item.code_course }} - {% else %} - - {{ item.title }} {{ item.code_course }} - - {{ item.notifications }} + + {{ item.notifications }} + {% endif %} +

+
+
+ {% if item.teachers|length > 0 %} +   + {% for teacher in item.teachers %} + {% set counter = counter + 1 %} + {% if counter > 1 %} | {% endif %} + + {{ teacher.firstname }} {{ teacher.lastname }} + + {% endfor %} {% endif %} - -
-
- {% if item.teachers|length > 0 %} -   - {% for teacher in item.teachers %} - {% set counter = counter + 1 %} - {% if counter > 1 %} | {% endif %} - - {{ teacher.firstname }} {{ teacher.lastname }} - - {% endfor %} - {% endif %} -
- {% if item.student_info %} - {% if item.student_info.progress is not null or item.student_info.score is not null or item.student_info.certificate is not null %} +
+ {% if item.student_info %} + {% if item.student_info.progress is not null or item.student_info.score is not null or item.student_info.certificate is not null %}
{% if (item.student_info.progress is not null) %} - {{ "StudentCourseProgressX" | get_lang | format(item.student_info.progress) }} + {{ "StudentCourseProgressX" | get_lang | format(item.student_info.progress) }} {% endif %} {% if (item.student_info.score is not null) %} - {{ "StudentCourseScoreX" | get_lang | format(item.student_info.score) }} + {{ "StudentCourseScoreX" | get_lang | format(item.student_info.score) }} {% endif %} {% if (item.student_info.certificate is not null) %} - {{ "StudentCourseCertificateX" | get_lang | format(item.student_info.certificate) }} + {{ "StudentCourseCertificateX" | get_lang | format(item.student_info.certificate) }} {% endif %}
- {% endif %} {% endif %} -
+ {% endif %}
- {% endfor %} -
-
+
+ {% endfor %} + {% endset %} + + {{ display.collapse('course_category_' ~ category.id_category, category.title_category, course_content, false, category.collapsed == 0) }} {% endif %} {% endfor %}