Skip to content
Permalink
Browse files

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.
  • Loading branch information...
jmontoyaa committed Dec 10, 2018
1 parent 3d1cf0d commit 3520689c330fd400b52976f184d9f9f2e7ca0f43
@@ -56,6 +56,7 @@
'subscribe_to_session',
'search_tag',
'search_session',
'set_collapsable',
];
$action = CoursesAndSessionsCatalog::is(CATALOG_SESSIONS) ? 'display_sessions' : 'display_courses';
@@ -330,4 +331,29 @@
$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;
}
@@ -27,13 +27,16 @@
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;
$last = end($user_course_categories);
foreach ($user_course_categories as $row) {
echo Display::page_subheader($row['title']);
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']) {
?>
<!-- We display the edit form for the category -->
@@ -46,6 +49,21 @@
<?php
}
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']; ?>">
<?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
@@ -83,6 +101,7 @@
</a>
<?php
}
$counter++;
echo '<br /><br />';
// Show the courses inside this category
@@ -3802,7 +3802,7 @@ public static function returnCourses(
}
// 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 @@ public static function returnCourses(
'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 @@ public static function returnCourses(
$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;
@@ -1047,6 +1047,10 @@
// 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
@@ -1,101 +1,101 @@
{% import 'macro/macro.tpl'|get_template as display %}

{% if not categories is empty %}
<div class="classic-courses">
{% for category in categories %}
{% if category.courses %}
<div class="panel panel-default">
<div id="category-{{ category.id_category }}" class="panel-heading">
{{ category.title_category }}
</div>
<div class="panel-body">
{% for item in category.courses %}
<div class="row">
<div class="col-md-2">
{% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %}
<span class="thumbnail">
{% set course_content %}

{% for item in category.courses %}
<div class="row">
<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 != '' %}
<img src="{{ item.thumbnails }}" title="{{ item.title }}"
alt="{{ item.title }}"/>
{% else %}
{{ 'blackboard.png' | img(48, item.title ) }}
{% endif %}
</span>
{% else %}
<a href="{{ item.link }}" class="thumbnail">
{% if item.thumbnails != '' %}
<img src="{{ item.thumbnails }}" title="{{ item.title }}"
alt="{{ item.title }}"/>
{% else %}
{{ 'blackboard.png' | img(48, item.title ) }}
{% endif %}
</a>
{% endif %}
</div>
<div class="col-md-10">
{% if item.edit_actions != '' %}
<div class="pull-right">
{% if item.document == '' %}
{% else %}
<a href="{{ item.link }}" class="thumbnail">
{% if item.thumbnails != '' %}
<img src="{{ item.thumbnails }}" title="{{ item.title }}"
alt="{{ item.title }}"/>
{% else %}
{{ 'blackboard.png' | img(48, item.title ) }}
{% endif %}
</a>
{% endif %}
</div>
<div class="col-md-10">
{% if item.edit_actions != '' %}
<div class="pull-right">
{% 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 }}">
<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 }}">
<i class="fa fa-pencil" aria-hidden="true"></i>
</a>
{{ item.document }}
</div>
{% endif %}
</div>
{% endif %}
<h4 class="course-items-title">
{% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %}
{{ item.document }}
</div>
{% endif %}
</div>
{% endif %}
<h4 class="course-items-title">
{% if item.visibility == constant('COURSE_VISIBILITY_CLOSED') and not item.current_user_is_teacher %}
{{ item.title }} {{ item.code_course }}
{% else %}
<a href="{{ item.link }}">
{{ item.title }} {{ item.code_course }}
{% else %}
<a href="{{ item.link }}">
{{ item.title }} {{ item.code_course }}
</a>
{{ item.notifications }}
</a>
{{ item.notifications }}
{% endif %}
</h4>
<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 %}
</h4>
<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 %}
</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>
{% 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="student-info">
{% 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 %}
</div>
</div>
{% endif %}
{% endif %}
</div>
{% endif %}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
{% endset %}

{{ display.collapse('course_category_' ~ category.id_category, category.title_category, course_content, false, category.collapsed == 0) }}
{% endif %}
{% endfor %}
</div>

0 comments on commit 3520689

Please sign in to comment.
You can’t perform that action at this time.