Course categories: Add show courses button BT#18812

pull/3892/head
Julio Montoya 4 years ago
parent a0c3225563
commit 93dc3af66c
  1. 27
      main/admin/course_category.php
  2. 42
      main/inc/ajax/course_category.ajax.php
  3. 20
      main/inc/lib/course_category.lib.php

@ -92,6 +92,33 @@ if (!empty($action)) {
exit();
}
}
$htmlHeadXtra[] = '
<script>
function showCourses(button, categoryId) {
event.preventDefault();
let url = button.getAttribute("href");
let tableId = "cat_" + categoryId;
let exists = button.parentNode.parentNode.parentNode.querySelector("#" + tableId);
if (exists !== null) {
button.parentNode.parentNode.parentNode.removeChild(exists);
return ;
}
$.ajax({
url: url,
type: "GET",
success: function(result) {
let row = document.createElement("tr");
row.setAttribute("id", tableId);
let cell = document.createElement("td");
cell.setAttribute("colspan", "4");
cell.innerHTML= result;
row.appendChild(cell);
button.parentNode.parentNode.parentNode.insertBefore(row, button.parentNode.parentNode.nextSibling);
}
});
}
</script>';
$tool_name = get_lang('AdminCategories');
$interbreadcrumb[] = [

@ -0,0 +1,42 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls.
*/
require_once __DIR__.'/../global.inc.php';
api_protect_admin_script();
$action = $_REQUEST['a'];
switch ($action) {
case 'show_courses':
$categoryId = (int) $_REQUEST['id'];
$categoryInfo = CourseCategory::getCategoryById($categoryId);
if (!empty($categoryInfo)) {
$courses = CourseCategory::getCoursesInCategory($categoryInfo['code']);
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
$headers = [
get_lang('Name'),
];
$row = 0;
$column = 0;
foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header);
$column++;
}
$result = '';
foreach ($courses as $course) {
$row++;
$table->setCellContents($row, 0, $course['title']);
}
echo $table->toHtml();
exit;
}
break;
}
exit;

@ -477,14 +477,14 @@ class CourseCategory
}
$row++;
$mainUrl = api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$categorySource;
$ajaxUrl = api_get_path(WEB_AJAX_PATH).'course_category.ajax.php';
$editIcon = Display::return_icon(
'edit.png',
get_lang('EditNode'),
null,
ICON_SIZE_SMALL
);
$exportIcon = Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '');
$exportIcon = Display::return_icon('export_csv.png', get_lang('ExportAsCSV'));
$deleteIcon = Display::return_icon(
'delete.png',
@ -499,15 +499,29 @@ class CourseCategory
ICON_SIZE_SMALL
);
$showCoursesIcon = Display::return_icon(
'course.png',
get_lang('Courses'),
null,
ICON_SIZE_SMALL
);
$urlId = api_get_current_access_url_id();
foreach ($categories as $category) {
$categoryId = $category['id'];
$editUrl = $mainUrl.'&id='.$category['code'].'&action=edit';
$moveUrl = $mainUrl.'&id='.$category['code'].'&action=moveUp&tree_pos='.$category['tree_pos'];
$deleteUrl = $mainUrl.'&id='.$category['code'].'&action=delete';
$exportUrl = $mainUrl.'&id='.$category['id'].'&action=export';
$exportUrl = $mainUrl.'&id='.$categoryId.'&action=export';
$showCoursesUrl = $ajaxUrl.'?id='.$categoryId.'&a=show_courses';
$actions = [];
if ($urlId == $category['access_url_id']) {
$actions[] = Display::url(
$showCoursesIcon,
$showCoursesUrl,
['onclick' => 'showCourses(this, '.$categoryId.')']
);
$actions[] = Display::url($editIcon, $editUrl);
$actions[] = Display::url($moveIcon, $moveUrl);
$actions[] = Display::url($exportIcon, $exportUrl);

Loading…
Cancel
Save