Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/Resources/public/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -9615,6 +9615,23 @@ ul.dropdown-menu.inner > li > a {
padding-bottom: 133.33%;
}

.dropdown-menu li a + .dropdown-menu {
display: block;
left: 0;
top: 0;
box-shadow: none;
margin-top: 0;
border: 0;
position: relative;
padding: 0;
}

.dropdown-menu li a + .dropdown-menu li a {
padding-top: 6px;
padding-bottom: 6px;
padding-right: 9px;
}

/* CSS Responsive */
@media (min-width: 1025px) and (max-width: 1200px) {
.sidebar-scorm {
Expand Down
54 changes: 54 additions & 0 deletions main/inc/lib/banner.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ function return_navigation_array()
$navigation['follow_up']['icon'] = 'homepage.png';
}

buildParentCourseCategoriesMenu($navigation);

// Administration
if (api_is_platform_admin(true)) {
if (api_get_setting('show_tabs', 'platform_administration') == 'true') {
Expand Down Expand Up @@ -481,6 +483,8 @@ function return_navigation_array()
}
}
} else {
buildParentCourseCategoriesMenu($navigation);

// Show custom tabs that are specifically marked as public
$customTabs = getCustomTabs();
if (!empty($customTabs)) {
Expand Down Expand Up @@ -508,6 +512,56 @@ function return_navigation_array()
];
}

function buildParentCourseCategoriesMenu(array &$navigation) {
if (!api_get_configuration_value('display_menu_use_course_categories')
|| 'true' !== api_get_setting('course_catalog_published')
) {
return;
}

foreach (CourseCategory::getCategoriesToDisplayInHomePage() as $category) {
$key = 'category_'.$category['code'];
$navigation[$key] = [
'url' => '#',
'title' => $category['name'],
'key' => $key,
'items' => buildChildrenCourseCategoriesMenu($category['code']),
];
}
}

function buildChildrenCourseCategoriesMenu($parentCode = 0): array
{
$baseCategoryUrl = api_get_path(WEB_CODE_PATH).'auth/courses.php?';

$commonParams = [
'search_term' => '',
'submit' => '_qf__s',
];

$items = [];

foreach (CourseCategory::getChildren($parentCode, false) as $category) {
$commonParams['category_code'] = $category['code'];

$categoryItem = [
'title' => $category['name'],
'key' => 'category_'.$category['code'],
'url' => $baseCategoryUrl.http_build_query($commonParams),
];

$children = buildChildrenCourseCategoriesMenu($category['code']);

if (!empty($children)) {
$categoryItem['items'] = $children;
}

$items[] = $categoryItem;
}

return $items;
}

/**
* Return the navigation menu elements as a flat array.
*
Expand Down
17 changes: 7 additions & 10 deletions main/inc/lib/course_category.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,23 +398,20 @@ public static function moveNodeUp($code, $tree_pos, $parent_id)
return true;
}

/**
* @param string $categoryCode
*
* @return array
*/
public static function getChildren($categoryCode)
public static function getChildren(string $categoryCode, bool $getChildren = true): array
{
$table = Database::get_main_table(TABLE_MAIN_CATEGORY);
$categoryCode = Database::escape_string($categoryCode);
$sql = "SELECT code, id FROM $table
$sql = "SELECT name, code, id FROM $table
WHERE parent_id = '$categoryCode'";
$result = Database::query($sql);
$children = [];
while ($row = Database::fetch_array($result, 'ASSOC')) {
$children[] = $row;
$subChildren = self::getChildren($row['code']);
$children = array_merge($children, $subChildren);
if ($getChildren) {
$subChildren = self::getChildren($row['code']);
$children = array_merge($children, $subChildren);
}
}

return $children;
Expand Down Expand Up @@ -591,7 +588,7 @@ public static function listCategories($categorySource)
public static function getCategoriesToDisplayInHomePage()
{
$table = Database::get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT name FROM $table
$sql = "SELECT name, code FROM $table
WHERE parent_id IS NULL
ORDER BY tree_pos";

Expand Down
3 changes: 3 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,9 @@
// 3. Uncomment $parentId var in src/Chamilo/CoreBundle/Entity/Career.php
// $_configuration['career_hierarchy_enable'] = false;

// Use courses categories as top horizontal bar menu (#navbar) entries and submenus, to point to the catalogue with a filter on these categories
//$_configuration['display_menu_use_course_categories'] = false;

// KEEP THIS AT THE END
// -------- Custom DB changes
// Set to true to hide settings completely in a sub-URL if the setting is disabled in the
Expand Down
44 changes: 39 additions & 5 deletions main/template/default/layout/menu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,45 @@
{% endif %}

{% if show_item %}
<li class="{{ item.key }} {{ item.current }}">
<a href="{{ item.url }}" {{ item.target ? 'target="' ~ item.target ~ '"' : '' }} title="{{ item.title }}">
{{ item.title }}
</a>
</li>
{% if item.items %}
<li class="dropdown {{ item.key }} {{ item.current }}">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
aria-haspopup="true" aria-expanded="false">
{{ item.title }}
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
{% for subitem in item.items %}
<li>
<a href="{{ subitem.url }}" class="{{ subitem.key }}">
{{ subitem.title }}
{% if subitem.items|length > 0 %}
<span class="caret"></span>
{% endif %}
</a>

{% if subitem.items|length > 0 %}
<ul class="dropdown-menu">
{% for subsubitem in subitem.items %}
<li>
<a href="{{ subsubitem.url }}" class="{{ subsubitem.key }}">
{{ subsubitem.title }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</li>
{% else %}
<li class="{{ item.key }} {{ item.current }}">
<a href="{{ item.url }}" {{ item.target ? 'target="' ~ item.target ~ '"' : '' }} title="{{ item.title }}">
{{ item.title }}
</a>
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
Expand Down
Loading