Skip to content

Commit cdec469

Browse files
committed
Add display_menu_use_course_categories config setting - refs BT#22676
Use courses categories as top horizontal bar menu (#navbar) entries and submenus, to point to the catalogue with a filter on these categories
1 parent 85febd5 commit cdec469

File tree

5 files changed

+112
-15
lines changed

5 files changed

+112
-15
lines changed

app/Resources/public/css/base.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9615,6 +9615,23 @@ ul.dropdown-menu.inner > li > a {
96159615
padding-bottom: 133.33%;
96169616
}
96179617

9618+
.dropdown-menu li a + .dropdown-menu {
9619+
display: block;
9620+
left: 0;
9621+
top: 0;
9622+
box-shadow: none;
9623+
margin-top: 0;
9624+
border: 0;
9625+
position: relative;
9626+
padding: 0;
9627+
}
9628+
9629+
.dropdown-menu li a + .dropdown-menu li a {
9630+
padding-top: 6px;
9631+
padding-bottom: 6px;
9632+
padding-right: 9px;
9633+
}
9634+
96189635
/* CSS Responsive */
96199636
@media (min-width: 1025px) and (max-width: 1200px) {
96209637
.sidebar-scorm {

main/inc/lib/banner.lib.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,38 @@ function return_navigation_array()
508508
];
509509
}
510510

511+
function buildCategoryTreeInternal($parentCode = 0): array
512+
{
513+
$baseCategoryUrl = api_get_path(WEB_CODE_PATH).'auth/courses.php?';
514+
515+
$commonParams = [
516+
'search_term' => '',
517+
'submit' => '_qf__s',
518+
];
519+
520+
$items = [];
521+
522+
foreach (CourseCategory::getChildren($parentCode, false) as $category) {
523+
$commonParams['category_code'] = $category['code'];
524+
525+
$categoryItem = [
526+
'title' => $category['name'],
527+
'key' => 'category_'.$category['code'],
528+
'url' => $baseCategoryUrl.http_build_query($commonParams),
529+
];
530+
531+
$children = buildCategoryTreeInternal($category['code']);
532+
533+
if (!empty($children)) {
534+
$categoryItem['items'] = $children;
535+
}
536+
537+
$items[] = $categoryItem;
538+
}
539+
540+
return $items;
541+
}
542+
511543
/**
512544
* Return the navigation menu elements as a flat array.
513545
*
@@ -527,6 +559,20 @@ function menuArray()
527559
$lang = $_SESSION['_user']['language'];
528560
}
529561

562+
if (api_get_configuration_value('display_menu_use_course_categories')
563+
&& 'true' === api_get_setting('course_catalog_published')
564+
) {
565+
foreach (CourseCategory::getCategoriesToDisplayInHomePage() as $category) {
566+
$key = 'category_'.$category['code'];
567+
$mainNavigation['navigation'][$key] = [
568+
'url' => '#',
569+
'title' => $category['name'],
570+
'key' => $key,
571+
'items' => buildCategoryTreeInternal($category['code']),
572+
];
573+
}
574+
}
575+
530576
// Preparing home folder for multiple urls
531577
if (api_get_multiple_access_url()) {
532578
$access_url_id = api_get_current_access_url_id();

main/inc/lib/course_category.lib.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,23 +398,20 @@ public static function moveNodeUp($code, $tree_pos, $parent_id)
398398
return true;
399399
}
400400

401-
/**
402-
* @param string $categoryCode
403-
*
404-
* @return array
405-
*/
406-
public static function getChildren($categoryCode)
401+
public static function getChildren(string $categoryCode, bool $getChildren = true): array
407402
{
408403
$table = Database::get_main_table(TABLE_MAIN_CATEGORY);
409404
$categoryCode = Database::escape_string($categoryCode);
410-
$sql = "SELECT code, id FROM $table
405+
$sql = "SELECT name, code, id FROM $table
411406
WHERE parent_id = '$categoryCode'";
412407
$result = Database::query($sql);
413408
$children = [];
414409
while ($row = Database::fetch_array($result, 'ASSOC')) {
415410
$children[] = $row;
416-
$subChildren = self::getChildren($row['code']);
417-
$children = array_merge($children, $subChildren);
411+
if ($getChildren) {
412+
$subChildren = self::getChildren($row['code']);
413+
$children = array_merge($children, $subChildren);
414+
}
418415
}
419416

420417
return $children;
@@ -591,7 +588,7 @@ public static function listCategories($categorySource)
591588
public static function getCategoriesToDisplayInHomePage()
592589
{
593590
$table = Database::get_main_table(TABLE_MAIN_CATEGORY);
594-
$sql = "SELECT name FROM $table
591+
$sql = "SELECT name, code FROM $table
595592
WHERE parent_id IS NULL
596593
ORDER BY tree_pos";
597594

main/install/configuration.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,9 @@
25232523
// 3. Uncomment $parentId var in src/Chamilo/CoreBundle/Entity/Career.php
25242524
// $_configuration['career_hierarchy_enable'] = false;
25252525

2526+
// Use courses categories as top horizontal bar menu (#navbar) entries and submenus, to point to the catalogue with a filter on these categories
2527+
//$_configuration['display_menu_use_course_categories'] = false;
2528+
25262529
// KEEP THIS AT THE END
25272530
// -------- Custom DB changes
25282531
// Set to true to hide settings completely in a sub-URL if the setting is disabled in the

main/template/default/layout/menu.tpl

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,45 @@
121121
{% endif %}
122122

123123
{% if show_item %}
124-
<li class="{{ item.key }} {{ item.current }}">
125-
<a href="{{ item.url }}" {{ item.target ? 'target="' ~ item.target ~ '"' : '' }} title="{{ item.title }}">
126-
{{ item.title }}
127-
</a>
128-
</li>
124+
{% if item.items %}
125+
<li class="dropdown {{ item.key }} {{ item.current }}">
126+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
127+
aria-haspopup="true" aria-expanded="false">
128+
{{ item.title }}
129+
<span class="caret"></span>
130+
</a>
131+
<ul class="dropdown-menu">
132+
{% for subitem in item.items %}
133+
<li>
134+
<a href="{{ subitem.url }}" class="{{ subitem.key }}">
135+
{{ subitem.title }}
136+
{% if subitem.items|length > 0 %}
137+
<span class="caret"></span>
138+
{% endif %}
139+
</a>
140+
141+
{% if subitem.items|length > 0 %}
142+
<ul class="dropdown-menu">
143+
{% for subsubitem in subitem.items %}
144+
<li>
145+
<a href="{{ subsubitem.url }}" class="{{ subsubitem.key }}">
146+
{{ subsubitem.title }}
147+
</a>
148+
</li>
149+
{% endfor %}
150+
</ul>
151+
{% endif %}
152+
</li>
153+
{% endfor %}
154+
</ul>
155+
</li>
156+
{% else %}
157+
<li class="{{ item.key }} {{ item.current }}">
158+
<a href="{{ item.url }}" {{ item.target ? 'target="' ~ item.target ~ '"' : '' }} title="{{ item.title }}">
159+
{{ item.title }}
160+
</a>
161+
</li>
162+
{% endif %}
129163
{% endif %}
130164
{% endfor %}
131165
</ul>

0 commit comments

Comments
 (0)