Course categories: add export CSV + add confirm delete BT#18812

pull/3891/head
Julio Montoya 4 years ago
parent 2c51754926
commit 8889b293a1
  1. 24
      main/admin/course_category.php
  2. 11
      main/inc/lib/course_category.lib.php

@ -18,11 +18,33 @@ $categoryId = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
if (!empty($categoryId)) {
$categoryInfo = CourseCategory::getCategory($categoryId);
}
$action = isset($_GET['action']) ? $_GET['action'] : null;
$action = $_GET['action'] ?? null;
$myCourseListAsCategory = api_get_configuration_value('my_courses_list_as_category');
if (!empty($action)) {
if ('export' === $action) {
$categoryInfo = CourseCategory::getCategoryById($categoryId);
if (!empty($categoryInfo)) {
$courses = CourseCategory::getCoursesInCategory($categoryInfo['code']);
if (!empty($courses)) {
$name = api_get_local_time().'_'.$categoryInfo['code'];
$courseList = array_map(
function ($value) {
return [$value];
},
array_column($courses, 'title')
);
Export::arrayToCsv($courseList, $name);
}
}
Display::addFlash(Display::return_message(get_lang('HaveNoCourse')));
header('Location: '.api_get_self());
exit;
}
if ($action === 'delete') {
CourseCategory::deleteNode($categoryId);
Display::addFlash(Display::return_message(get_lang('Deleted')));

@ -84,6 +84,7 @@ class CourseCategory
}
$sql = "SELECT
t1.id,
t1.name,
t1.code,
t1.parent_id,
@ -483,6 +484,8 @@ class CourseCategory
null,
ICON_SIZE_SMALL
);
$exportIcon = Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '');
$deleteIcon = Display::return_icon(
'delete.png',
get_lang('DeleteNode'),
@ -501,12 +504,18 @@ class CourseCategory
$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';
$actions = [];
if ($urlId == $category['access_url_id']) {
$actions[] = Display::url($editIcon, $editUrl);
$actions[] = Display::url($moveIcon, $moveUrl);
$actions[] = Display::url($deleteIcon, $deleteUrl);
$actions[] = Display::url($exportIcon, $exportUrl);
$actions[] = Display::url(
$deleteIcon,
$deleteUrl,
['onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ConfirmYourChoice')), ENT_QUOTES)).'\')) return false;',]
);
}
$url = api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$category['code'];

Loading…
Cancel
Save