Admin: Add setting course_category_code_to_use_as_model BT#18083

Allow to group course templates by course category code.
pull/3668/head
Julio Montoya 5 years ago
parent 992d35a361
commit e5ebc9e1bc
  1. 15
      main/create_course/add_course.php
  2. 42
      main/inc/ajax/course.ajax.php
  3. 19
      main/inc/lib/CoursesAndSessionsCatalog.class.php
  4. 37
      main/inc/lib/course_category.lib.php
  5. 3
      main/install/configuration.dist.php

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\CourseCategory;
@ -9,10 +10,6 @@ use Chamilo\CoreBundle\Entity\Repository\CourseCategoryRepository;
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Roan Embrechts, refactoring
*
* @package chamilo.create_course
* "Course validation" feature:
*
* @author Jose Manuel Abuin Mosquera <chema@cesga.es>, Centro de Supercomputacion de Galicia
* "Course validation" feature, technical adaptation for Chamilo 1.8.8:
* @author Ivan Tcholakov <ivantcholakov@gmail.com>
@ -115,10 +112,18 @@ if ($countCategories >= 100) {
api_get_configuration_value('allow_base_course_category')
);
$categoriesOptions = [null => get_lang('None')];
$categoryToAvoid = '';
if (!api_is_platform_admin()) {
$categoryToAvoid = api_get_configuration_value('course_category_code_to_use_as_model');
}
/** @var CourseCategory $category */
foreach ($categories as $category) {
$categoriesOptions[$category->getCode()] = $category->__toString();
$categoryCode = $category->getCode();
if (!empty($categoryToAvoid) && $categoryToAvoid == $categoryCode) {
continue;
}
$categoriesOptions[$categoryCode] = $category->__toString();
}
$form->addSelect(

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
@ -121,11 +122,21 @@ switch ($action) {
break;
}
$categoryToAvoid = '';
if (!api_is_platform_admin()) {
$categoryToAvoid = api_get_configuration_value('course_category_code_to_use_as_model');
}
$list = [];
foreach ($categories as $item) {
$categoryCode = $item['code'];
if (!empty($categoryToAvoid) && $categoryToAvoid == $categoryCode) {
continue;
}
$list['items'][] = [
'id' => $item['code'],
'text' => '('.$item['code'].') '.strip_tags($item['name']),
'id' => $categoryCode,
'text' => '('.$categoryCode.') '.strip_tags($item['name']),
];
}
@ -145,22 +156,34 @@ switch ($action) {
//TODO change this function to search not only courses STARTING with $_GET['q']
if (api_is_platform_admin()) {
$courseList = CourseManager::get_courses_list(
0, //offset
0, //howMany
1, //$orderby = 1
0,
0,
1,
'ASC',
-1, //visibility
-1,
$_GET['q'],
null, //$urlId
true //AlsoSearchCode
null,
true
);
} elseif (api_is_teacher()) {
$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id(), $_GET['q']);
$category = api_get_configuration_value('course_category_code_to_use_as_model');
if (!empty($category)) {
$alreadyAdded = [];
if (!empty($courseList)) {
$alreadyAdded = array_column($courseList, 'id');
}
$coursesInCategory = CourseCategory::getCoursesInCategory($category, $_GET['q']);
foreach ($coursesInCategory as $course) {
if (!in_array($course['id'], $alreadyAdded)) {
$courseList[] = $course;
}
}
}
}
}
$results = [];
if (empty($courseList)) {
echo json_encode([]);
break;
@ -168,7 +191,6 @@ switch ($action) {
foreach ($courseList as $course) {
$title = $course['title'];
if (!empty($course['category_code'])) {
$parents = CourseCategory::getParentsToString($course['category_code']);
$title = $parents.$course['title'];

@ -181,17 +181,26 @@ class CoursesAndSessionsCatalog
];
$allCategories = CourseCategory::getAllCategories();
$categoryToAvoid = '';
if (api_is_student()) {
$categoryToAvoid = api_get_configuration_value('course_category_code_to_use_as_model');
}
foreach ($allCategories as $category) {
$categoryCode = $category['code'];
if (!empty($categoryToAvoid) && $categoryToAvoid == $categoryCode) {
continue;
}
if (empty($category['parent_id'])) {
$list[$category['code']] = $category;
$list[$category['code']]['level'] = 0;
list($subList, $childrenCount) = self::buildCourseCategoryTree($allCategories, $category['code'], 0);
$list[$categoryCode] = $category;
$list[$categoryCode]['level'] = 0;
list($subList, $childrenCount) = self::buildCourseCategoryTree($allCategories, $categoryCode, 0);
foreach ($subList as $item) {
$list[$item['code']] = $item;
}
// Real course count
$countCourses = CourseCategory::countCoursesInCategory($category['code']);
$list[$category['code']]['number_courses'] = $childrenCount + $countCourses;
$countCourses = CourseCategory::countCoursesInCategory($categoryCode);
$list[$categoryCode]['number_courses'] = $childrenCount + $countCourses;
}
}

@ -576,9 +576,18 @@ class CourseCategory
ORDER BY tree_pos";
$res = Database::query($sql);
$categoryToAvoid = '';
if (!api_is_platform_admin()) {
$categoryToAvoid = api_get_configuration_value('course_category_code_to_use_as_model');
}
$categories[''] = '-';
while ($cat = Database::fetch_array($res)) {
$categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
$categoryCode = $cat['code'];
if (!empty($categoryToAvoid) && $categoryToAvoid == $categoryCode) {
continue;
}
$categories[$categoryCode] = '('.$categoryCode.') '.$cat['name'];
ksort($categories);
}
@ -593,7 +602,16 @@ class CourseCategory
*
* @return int
*/
public static function countCoursesInCategory($category_code = '', $keyword = '', $avoidCourses = true, $conditions = [])
public static function countCoursesInCategory(
$category_code = '',
$keyword = '',
$avoidCourses = true,
$conditions = []
) {
return self::getCoursesInCategory($category_code, $keyword, $avoidCourses, $conditions, true);
}
public static function getCoursesInCategory($category_code = '', $keyword = '', $avoidCourses = true, $conditions = [], $getCount = false)
{
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$categoryCode = Database::escape_string($category_code);
@ -635,7 +653,11 @@ class CourseCategory
$urlCondition = ' access_url_id = '.api_get_current_access_url_id().' AND';
$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$sql = "SELECT count(DISTINCT course.id) as count
$select = " DISTINCT course.id, course.code, course.title, course.category_code ";
if ($getCount) {
$select = "count(DISTINCT course.id) as count";
}
$sql = "SELECT $select
FROM $tbl_course as course
INNER JOIN $tbl_url_rel_course as url_rel_course
ON (url_rel_course.c_id = course.id)
@ -653,9 +675,14 @@ class CourseCategory
";
$result = Database::query($sql);
$row = Database::fetch_array($result);
return (int) $row['count'];
if ($getCount) {
$row = Database::fetch_array($result);
return (int) $row['count'];
}
return Database::store_result($result, 'ASSOC');
}
/**

@ -1770,6 +1770,9 @@ $_configuration['auth_password_links'] = [
// Enable a "Previous question" button in surveys
// $_configuration['survey_backwards_enable'] = false;
// All courses with category MY_CATEGORY will be used as course templates BT#18083
// $_configuration['course_category_code_to_use_as_model'] = 'MY_CATEGORY';
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

Loading…
Cancel
Save