Add setting 'allow_user_course_category_collapsable' see BT#15126

Course list inside a user category can be set to be collapsed or not.

Requires a DB change.
pull/2757/head^2
Julio Montoya 7 years ago
parent 3d1cf0d31c
commit 3520689c33
  1. 26
      main/auth/courses.php
  2. 19
      main/auth/courses_list.php
  3. 8
      main/inc/lib/course.lib.php
  4. 4
      main/install/configuration.dist.php
  5. 134
      main/template/default/user_portal/classic_courses_with_category.tpl

@ -56,6 +56,7 @@ $actions = [
'subscribe_to_session', 'subscribe_to_session',
'search_tag', 'search_tag',
'search_session', 'search_session',
'set_collapsable',
]; ];
$action = CoursesAndSessionsCatalog::is(CATALOG_SESSIONS) ? 'display_sessions' : 'display_courses'; $action = CoursesAndSessionsCatalog::is(CATALOG_SESSIONS) ? 'display_sessions' : 'display_courses';
@ -330,4 +331,29 @@ switch ($action) {
$courseController->sessionListBySearch($limit); $courseController->sessionListBySearch($limit);
break; 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;
} }

@ -27,6 +27,8 @@ if (!empty($message)) {
echo Display::return_message($message, 'confirm', false); echo Display::return_message($message, 'confirm', false);
} }
$allowCollapsable = api_get_configuration_value('allow_user_course_category_collapsable');
// COURSES WITH CATEGORIES // COURSES WITH CATEGORIES
if (!empty($user_course_categories)) { if (!empty($user_course_categories)) {
$counter = 0; $counter = 0;
@ -34,6 +36,7 @@ if (!empty($user_course_categories)) {
foreach ($user_course_categories as $row) { foreach ($user_course_categories as $row) {
echo Display::page_subheader($row['title']); echo Display::page_subheader($row['title']);
echo '<a name="category'.$row['id'].'"></a>'; echo '<a name="category'.$row['id'].'"></a>';
$url = api_get_path(WEB_CODE_PATH).'auth/courses.php?categoryid='.$row['id'].'&sec_token='.$stok;
if (isset($_GET['categoryid']) && $_GET['categoryid'] == $row['id']) { if (isset($_GET['categoryid']) && $_GET['categoryid'] == $row['id']) {
?> ?>
<!-- We display the edit form for the category --> <!-- We display the edit form for the category -->
@ -46,6 +49,21 @@ if (!empty($user_course_categories)) {
<?php <?php
} }
if ($action != 'unsubscribe') { if ($action != 'unsubscribe') {
if ($allowCollapsable) {
if ($row['collapsed'] == 0) {
echo Display::url(
'<i class="fa fa-folder-open"></i>',
$url.'&action=set_collapsable&option=1'
);
} else {
echo Display::url(
'<i class="fa fa-folder"></i>',
$url.'&action=set_collapsable&option=0'
);
}
}
?> ?>
<a href="courses.php?action=sortmycourses&amp;categoryid=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>#category<?php echo $row['id']; ?>"> <a href="courses.php?action=sortmycourses&amp;categoryid=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>#category<?php echo $row['id']; ?>">
<?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?> <?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
@ -83,6 +101,7 @@ if (!empty($user_course_categories)) {
</a> </a>
<?php <?php
} }
$counter++; $counter++;
echo '<br /><br />'; echo '<br /><br />';
// Show the courses inside this category // Show the courses inside this category

@ -3802,7 +3802,7 @@ class CourseManager
} }
// Step 1: We get all the categories of the user // Step 1: We get all the categories of the user
$table = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); $table = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
$sql = "SELECT id, title FROM $table $sql = "SELECT * FROM $table
WHERE user_id = '".$user_id."' WHERE user_id = '".$user_id."'
ORDER BY sort ASC"; ORDER BY sort ASC";
@ -3811,6 +3811,7 @@ class CourseManager
'in_category' => [], 'in_category' => [],
'not_category' => [], 'not_category' => [],
]; ];
$collapsable = api_get_configuration_value('allow_user_course_category_collapsable');
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
// We simply display the title of the category. // We simply display the title of the category.
$courseInCategory = self::returnCoursesCategories( $courseInCategory = self::returnCoursesCategories(
@ -3820,9 +3821,14 @@ class CourseManager
$useUserLanguageFilterIfAvailable $useUserLanguageFilterIfAvailable
); );
$collapsed = 0;
if ($collapsable) {
$collapsed = isset($row['collapsed']) && $row['collapsed'] ? 1 : 0;
}
$params = [ $params = [
'id_category' => $row['id'], 'id_category' => $row['id'],
'title_category' => $row['title'], 'title_category' => $row['title'],
'collapsed' => $collapsed,
'courses' => $courseInCategory, 'courses' => $courseInCategory,
]; ];
$listItems['in_category'][] = $params; $listItems['in_category'][] = $params;

@ -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 // Improve speed when rendering gradebook student reports using Doctrine APCU cache
// $_configuration['gradebook_use_apcu_cache'] = true; // $_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) // ------ Custom DB changes (keep this at the end)
// Add user activation by confirmation email // 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 // This option prevents the new user to login in the platform if your account is not confirmed via email

@ -1,17 +1,16 @@
{% import 'macro/macro.tpl'|get_template as display %}
{% if not categories is empty %} {% if not categories is empty %}
<div class="classic-courses"> <div class="classic-courses">
{% for category in categories %} {% for category in categories %}
{% if category.courses %} {% if category.courses %}
<div class="panel panel-default"> {% set course_content %}
<div id="category-{{ category.id_category }}" class="panel-heading">
{{ category.title_category }} {% for item in category.courses %}
</div> <div class="row">
<div class="panel-body"> <div class="col-md-2">
{% for item in category.courses %} {% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %}
<div class="row"> <span class="thumbnail">
<div class="col-md-2">
{% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %}
<span class="thumbnail">
{% if item.thumbnails != '' %} {% if item.thumbnails != '' %}
<img src="{{ item.thumbnails }}" title="{{ item.title }}" <img src="{{ item.thumbnails }}" title="{{ item.title }}"
alt="{{ item.title }}"/> alt="{{ item.title }}"/>
@ -19,83 +18,84 @@
{{ 'blackboard.png' | img(48, item.title ) }} {{ 'blackboard.png' | img(48, item.title ) }}
{% endif %} {% endif %}
</span> </span>
{% else %} {% else %}
<a href="{{ item.link }}" class="thumbnail"> <a href="{{ item.link }}" class="thumbnail">
{% if item.thumbnails != '' %} {% if item.thumbnails != '' %}
<img src="{{ item.thumbnails }}" title="{{ item.title }}" <img src="{{ item.thumbnails }}" title="{{ item.title }}"
alt="{{ item.title }}"/> alt="{{ item.title }}"/>
{% else %} {% else %}
{{ 'blackboard.png' | img(48, item.title ) }} {{ 'blackboard.png' | img(48, item.title ) }}
{% endif %} {% endif %}
</a> </a>
{% endif %} {% endif %}
</div> </div>
<div class="col-md-10"> <div class="col-md-10">
{% if item.edit_actions != '' %} {% if item.edit_actions != '' %}
<div class="pull-right"> <div class="pull-right">
{% if item.document == '' %} {% if item.document == '' %}
<a class="btn btn-default btn-sm" href="{{ item.edit_actions }}">
<i class="fa fa-pencil" aria-hidden="true"></i>
</a>
{% else %}
<div class="btn-group" role="group">
<a class="btn btn-default btn-sm" href="{{ item.edit_actions }}"> <a class="btn btn-default btn-sm" href="{{ item.edit_actions }}">
<i class="fa fa-pencil" aria-hidden="true"></i> <i class="fa fa-pencil" aria-hidden="true"></i>
</a> </a>
{% else %} {{ item.document }}
<div class="btn-group" role="group"> </div>
<a class="btn btn-default btn-sm" href="{{ item.edit_actions }}"> {% endif %}
<i class="fa fa-pencil" aria-hidden="true"></i> </div>
</a> {% endif %}
{{ item.document }} <h4 class="course-items-title">
</div> {% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %}
{% endif %} {{ item.title }} {{ item.code_course }}
</div> {% else %}
{% endif %} <a href="{{ item.link }}">
<h4 class="course-items-title">
{% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %}
{{ item.title }} {{ item.code_course }} {{ item.title }} {{ item.code_course }}
{% else %} </a>
<a href="{{ item.link }}"> {{ item.notifications }}
{{ item.title }} {{ item.code_course }} {% endif %}
</a> </h4>
{{ item.notifications }} <div class="course-items-session">
<div class="list-teachers">
{% if item.teachers|length > 0 %}
<img src="{{ 'teacher.png'|icon(16) }}" width="16" height="16">&nbsp;
{% for teacher in item.teachers %}
{% set counter = counter + 1 %}
{% if counter > 1 %} | {% endif %}
<a href="{{ teacher.url }}" class="ajax"
data-title="{{ teacher.firstname }} {{ teacher.lastname }}">
{{ teacher.firstname }} {{ teacher.lastname }}
</a>
{% endfor %}
{% endif %} {% endif %}
</h4> </div>
<div class="course-items-session"> {% if item.student_info %}
<div class="list-teachers"> {% 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.teachers|length > 0 %}
<img src="{{ 'teacher.png'|icon(16) }}" width="16" height="16">&nbsp;
{% for teacher in item.teachers %}
{% set counter = counter + 1 %}
{% if counter > 1 %} | {% endif %}
<a href="{{ teacher.url }}" class="ajax"
data-title="{{ teacher.firstname }} {{ teacher.lastname }}">
{{ teacher.firstname }} {{ teacher.lastname }}
</a>
{% endfor %}
{% endif %}
</div>
{% 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 %}
<div class="course-student-info"> <div class="course-student-info">
<div class="student-info"> <div class="student-info">
{% if (item.student_info.progress 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 %} {% endif %}
{% if (item.student_info.score is not null) %} {% 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 %} {% endif %}
{% if (item.student_info.certificate is not null) %} {% 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 %}
</div> </div>
</div> </div>
{% endif %}
{% endif %} {% endif %}
</div> {% endif %}
</div> </div>
</div> </div>
{% endfor %} </div>
</div> {% endfor %}
</div> {% endset %}
{{ display.collapse('course_category_' ~ category.id_category, category.title_category, course_content, false, category.collapsed == 0) }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>

Loading…
Cancel
Save