Add setting "allow_base_course_category" see BT#13829

Show base course categories in portal children.
pull/2458/head
jmontoyaa 8 years ago
parent 5185bb89c4
commit 597a7456c7
  1. 11
      main/admin/course_add.php
  2. 15
      main/admin/course_category.php
  3. 10
      main/admin/course_edit.php
  4. 2
      main/auth/courses.php
  5. 297
      main/auth/courses_categories.php
  6. 11
      main/create_course/add_course.php
  7. 72
      main/inc/lib/course_category.lib.php
  8. 3
      main/install/configuration.dist.php
  9. 33
      src/Chamilo/CoreBundle/Entity/Repository/CourseCategoryRepository.php

@ -59,7 +59,10 @@ $form->addText(
$form->applyFilter('visual_code', 'api_strtoupper');
$form->applyFilter('visual_code', 'html_filter');
$countCategories = $courseCategoriesRepo->countAllInAccessUrl($accessUrlId);
$countCategories = $courseCategoriesRepo->countAllInAccessUrl(
$accessUrlId,
api_get_configuration_value('allow_base_course_category')
);
if ($countCategories >= 100) {
// Category code
@ -73,9 +76,11 @@ if ($countCategories >= 100) {
['url' => $url]
);
} else {
$categories = $courseCategoriesRepo->findAllInAccessUrl($accessUrlId);
$categories = $courseCategoriesRepo->findAllInAccessUrl(
$accessUrlId,
api_get_configuration_value('allow_base_course_category')
);
$categoriesOptions = [null => get_lang('None')];
/** @var CourseCategory $category */
foreach ($categories as $category) {
$categoriesOptions[$category->getCode()] = (string) $category;

@ -80,6 +80,7 @@ $interbreadcrumb[] = [
];
Display::display_header($tool_name);
$urlId = api_get_current_access_url_id();
if ($action == 'add' || $action == 'edit') {
echo '<div class="actions">';
@ -168,7 +169,7 @@ if ($action == 'add' || $action == 'edit') {
$form->display();
} else {
// If multiple URLs and not main URL, prevent deletion and inform user
if ($action == 'delete' && api_get_multiple_access_url() && api_get_current_access_url_id() != 1) {
if ($action == 'delete' && api_get_multiple_access_url() && $urlId != 1) {
echo Display::return_message(get_lang('CourseCategoriesAreGlobal'), 'warning');
}
echo '<div class="actions">';
@ -176,18 +177,22 @@ if ($action == 'add' || $action == 'edit') {
if (!empty($parentInfo)) {
$parentCode = $parentInfo['parent_id'];
echo Display::url(
Display::return_icon('back.png', get_lang("Back"), '', ICON_SIZE_MEDIUM),
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$parentCode
);
}
if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'TRUE') {
echo Display::url(
Display::return_icon('new_folder.png', get_lang("AddACategory"), '', ICON_SIZE_MEDIUM),
$newCategoryLink = Display::url(
Display::return_icon('new_folder.png', get_lang('AddACategory'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&category='.Security::remove_XSS($category)
);
}
if (!empty($parentInfo) && $parentInfo['access_url_id'] != $urlId) {
$newCategoryLink = '';
}
echo $newCategoryLink;
}
echo '</div>';
if (!empty($parentInfo)) {
echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');

@ -145,7 +145,10 @@ $form->addText(
$form->applyFilter('visual_code', 'strtoupper');
$form->applyFilter('visual_code', 'html_filter');
$countCategories = $courseCategoriesRepo->countAllInAccessUrl($urlId);
$countCategories = $courseCategoriesRepo->countAllInAccessUrl(
$urlId,
api_get_configuration_value('allow_base_course_category')
);
if ($countCategories >= 100) {
// Category code
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
@ -164,7 +167,10 @@ if ($countCategories >= 100) {
}
} else {
$courseInfo['category_code'] = $courseInfo['categoryCode'];
$categories = $courseCategoriesRepo->findAllInAccessUrl($urlId);
$categories = $courseCategoriesRepo->findAllInAccessUrl(
$urlId,
api_get_configuration_value('allow_base_course_category')
);
$categoriesOptions = [null => get_lang('None')];
/** @var CourseCategory $category */

@ -4,7 +4,7 @@
use Chamilo\CoreBundle\Entity\SequenceResource;
/**
* Template (front controller in MVC pattern) used for distpaching
* Template (front controller in MVC pattern) used for dispatching
* to the controllers depend on the current action
* @author Christian Fasanando <christian1827@gmail.com> - Beeznest
* @package chamilo.auth

@ -56,13 +56,11 @@ $code = isset($code) ? $code : null;
return parseInt(parts[1], 10);
};
<?php if ($showSessions) {
?>
<?php if ($showSessions) { ?>
$('#date').datepicker({
dateFormat: 'yy-mm-dd'
});
<?php
} ?>
<?php } ?>
});
</script>
<div class="row">
@ -70,11 +68,9 @@ $code = isset($code) ? $code : null;
<h2 class="title-courses"><?php echo get_lang('CourseManagement'); ?></h2>
<div class="search-courses">
<div class="row">
<?php if ($showCourses) {
?>
<?php if ($showCourses) { ?>
<div class="col-md-<?php echo($showSessions ? '4' : '6'); ?>">
<?php if (!isset($_GET['hidden_links']) || intval($_GET['hidden_links']) != 1) {
?>
<?php if (!isset($_GET['hidden_links']) || intval($_GET['hidden_links']) != 1) { ?>
<form method="post"
action="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, 'ALL', 0, 'subscribe'); ?>">
<input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
@ -92,195 +88,196 @@ $code = isset($code) ? $code : null;
</div>
</div>
</form>
<?php
} ?>
<?php } ?>
</div>
<div class="col-md-<?php echo($showSessions ? '4' : '6'); ?>">
<?php
$webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php';
$form = '<form action="'.$webAction.'" method="GET">';
$form .= '<input type="hidden" name="action" value="'.$action.'">';
$form .= '<input type="hidden" name="pageCurrent" value="'.$pageCurrent.'">';
$form .= '<input type="hidden" name="pageLength" value="'.$pageLength.'">';
$form .= '<div class="form-group">';
$form .= '<label>'.get_lang('CourseCategories').'</label>';
$form .= '<select name="category_code" onchange="submit();" class="selectpicker show-tick form-control">';
foreach ($browse_course_categories[0] as $category) {
$categoryCode = $category['code'];
$countCourse = $category['count_courses'];
$form .= '<option '.($categoryCode == $codeType ? 'selected="selected" ' : '')
.' value="'.$category['code'].'">'.$category['name'].' ('.$countCourse.') </option>';
if (!empty($browse_course_categories[$categoryCode])) {
foreach ($browse_course_categories[$categoryCode] as $subCategory) {
$subCategoryCode = $subCategory['code'];
$form .= '<option '
.($subCategoryCode == $codeType
? 'selected="selected" '
: '')
.' value="'.$subCategory['code'].'">---'.$subCategory['name'].' ('.$subCategory['count_courses'].')</option>';
}
<?php
$webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php';
$form = '<form action="'.$webAction.'" method="GET">';
$form .= '<input type="hidden" name="action" value="'.$action.'">';
$form .= '<input type="hidden" name="pageCurrent" value="'.$pageCurrent.'">';
$form .= '<input type="hidden" name="pageLength" value="'.$pageLength.'">';
$form .= '<div class="form-group">';
$form .= '<label>'.get_lang('CourseCategories').'</label>';
$form .= '<select name="category_code" onchange="submit();" class="selectpicker show-tick form-control">';
foreach ($browse_course_categories[0] as $category) {
$categoryCode = $category['code'];
$countCourse = $category['count_courses'];
$form .= '<option '.($categoryCode == $codeType ? 'selected="selected" ' : '')
.' value="'.$category['code'].'">'.$category['name'].' ('.$countCourse.') </option>';
if (!empty($browse_course_categories[$categoryCode])) {
foreach ($browse_course_categories[$categoryCode] as $subCategory) {
$subCategoryCode = $subCategory['code'];
$form .= '<option '.($subCategoryCode == $codeType
? 'selected="selected" '
: '')
.' value="'.$subCategory['code'].'">---';
echo $subCategory['name'].' ('.$subCategory['count_courses'].')</option>';
}
}
$form .= '</select>';
$form .= '</div>';
$form .= '</form>';
echo $form; ?>
</div>
<?php
} ?>
<?php if ($showSessions) {
?>
<div class="col-md-4">
<div class="return-catalog">
<a class="btn btn-default btn-lg btn-block"
href="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions'); ?>">
<em class="fa fa-arrow-right"></em> <?php echo get_lang('SessionList'); ?>
</a>
</div>
</div>
<?php
} ?>
}
$form .= '</select>';
$form .= '</div>';
$form .= '</form>';
echo $form;
echo '</div>';
}
if ($showSessions) { ?>
<div class="col-md-4">
<div class="return-catalog">
<a class="btn btn-default btn-lg btn-block"
href="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions'); ?>">
<em class="fa fa-arrow-right"></em> <?php echo get_lang('SessionList'); ?>
</a>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
<?php
if ($showCourses && $action != 'display_sessions') {
if (!empty($message)) {
echo Display::return_message($message, 'confirmation', false);
}
if (!empty($error)) {
echo Display::return_message($error, 'error', false);
}
if (!empty($content)) {
echo $content;
}
if (!empty($message)) {
echo Display::return_message($message, 'confirmation', false);
}
if (!empty($error)) {
echo Display::return_message($error, 'error', false);
}
if (!empty($searchTerm)) {
echo "<p><strong>".get_lang('SearchResultsFor')." ".$searchTerm."</strong><br />";
}
if (!empty($content)) {
echo $content;
}
$showTeacher = api_get_setting('display_teacher_in_courselist') === 'true';
if (!empty($searchTerm)) {
echo "<p><strong>".get_lang('SearchResultsFor')." ".$searchTerm."</strong><br />";
}
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$user_id = api_get_user_id();
$categoryList = CourseManager::getCategoriesList();
$showTeacher = api_get_setting('display_teacher_in_courselist') === 'true';
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$user_id = api_get_user_id();
$categoryListFromDatabase = CourseCategory::getCategories();
if (!empty($browse_courses_in_category)) {
echo '<div class="grid-courses row">';
foreach ($browse_courses_in_category as $course) {
$course_hidden = $course['visibility'] == COURSE_VISIBILITY_HIDDEN;
$categoryList = [];
if (!empty($categoryListFromDatabase)) {
foreach ($categoryListFromDatabase as $categoryItem) {
$categoryList[$categoryItem['code']] = $categoryItem['name'];
}
}
if ($course_hidden) {
continue;
}
if (!empty($browse_courses_in_category)) {
echo '<div class="grid-courses row">';
foreach ($browse_courses_in_category as $course) {
$course_hidden = $course['visibility'] == COURSE_VISIBILITY_HIDDEN;
$userRegisteredInCourse = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
$userRegisteredInCourseAsTeacher = CourseManager::is_course_teacher($user_id, $course['code']);
$userRegistered = $userRegisteredInCourse && $userRegisteredInCourseAsTeacher;
if ($course_hidden) {
continue;
}
$course_public = $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD;
$course_open = $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM;
$course_private = $course['visibility'] == COURSE_VISIBILITY_REGISTERED;
$course_closed = $course['visibility'] == COURSE_VISIBILITY_CLOSED;
$userRegisteredInCourse = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
$userRegisteredInCourseAsTeacher = CourseManager::is_course_teacher($user_id, $course['code']);
$userRegistered = $userRegisteredInCourse && $userRegisteredInCourseAsTeacher;
$course_subscribe_allowed = $course['subscribe'] == 1;
$course_unsubscribe_allowed = $course['unsubscribe'] == 1;
$count_connections = $course['count_connections'];
$creation_date = substr($course['creation_date'], 0, 10);
$course_public = $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD;
$course_open = $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM;
$course_private = $course['visibility'] == COURSE_VISIBILITY_REGISTERED;
$course_closed = $course['visibility'] == COURSE_VISIBILITY_CLOSED;
// display the course bloc
$html = '<div class="col-xs-12 col-sm-6 col-md-4"><div class="items items-courses">';
$course_subscribe_allowed = $course['subscribe'] == 1;
$course_unsubscribe_allowed = $course['unsubscribe'] == 1;
$count_connections = $course['count_connections'];
$creation_date = substr($course['creation_date'], 0, 10);
$course['category_title'] = '';
if (isset($course['category'])) {
$course['category_title'] = isset($categoryList[$course['category']]) ? $categoryList[$course['category']] : '';
}
// display the course bloc
$html = '<div class="col-xs-12 col-sm-6 col-md-4"><div class="items items-courses">';
// Display thumbnail
$html .= returnThumbnail($course, $userRegistered);
$course['category_title'] = '';
if (isset($course['category'])) {
$course['category_title'] = isset($categoryList[$course['category']]) ? $categoryList[$course['category']] : '';
}
$separator = null;
$subscribeButton = return_register_button($course, $stok, $code, $searchTerm);
// Display thumbnail
$html .= returnThumbnail($course, $userRegistered);
// Start buy course validation
// display the course price and buy button if the buycourses plugin is enabled and this course is configured
$plugin = BuyCoursesPlugin::create();
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator(
$separator = null;
$subscribeButton = return_register_button($course, $stok, $code, $searchTerm);
// Start buy course validation
// display the course price and buy button if the buycourses plugin is enabled and this course is configured
$plugin = BuyCoursesPlugin::create();
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator(
$course['real_id'],
BuyCoursesPlugin::PRODUCT_TYPE_COURSE
);
if ($isThisCourseInSale) {
// set the Price label
$separator = $isThisCourseInSale['html'];
// set the Buy button instead register.
if ($isThisCourseInSale['verificator']) {
$subscribeButton = $plugin->returnBuyCourseButton(
if ($isThisCourseInSale) {
// set the Price label
$separator = $isThisCourseInSale['html'];
// set the Buy button instead register.
if ($isThisCourseInSale['verificator']) {
$subscribeButton = $plugin->returnBuyCourseButton(
$course['real_id'],
BuyCoursesPlugin::PRODUCT_TYPE_COURSE
);
}
}
// end buy course validation
}
// end buy course validation
// display course title and button bloc
$html .= '<div class="description">';
$html .= return_title($course, $userRegisteredInCourse);
// display course title and button bloc
$html .= '<div class="description">';
$html .= return_title($course, $userRegisteredInCourse);
if ($showTeacher) {
$html .= return_teacher($course);
}
if ($showTeacher) {
$html .= return_teacher($course);
}
// display button line
$html .= '<div class="toolbar row">';
$html .= $separator ? '<div class="col-sm-4">'.$separator.'</div>' : '';
$html .= '<div class="col-sm-8">';
// if user registered as student
if ($userRegisteredInCourse) {
$html .= return_already_registered_label('student');
if (!$course_closed) {
if ($course_unsubscribe_allowed) {
$html .= return_unregister_button($course, $stok, $searchTerm, $code);
}
}
} elseif ($userRegisteredInCourseAsTeacher) {
// if user registered as teacher
// display button line
$html .= '<div class="toolbar row">';
$html .= $separator ? '<div class="col-sm-4">'.$separator.'</div>' : '';
$html .= '<div class="col-sm-8">';
// if user registered as student
if ($userRegisteredInCourse) {
$html .= return_already_registered_label('student');
if (!$course_closed) {
if ($course_unsubscribe_allowed) {
$html .= return_unregister_button($course, $stok, $searchTerm, $code);
}
} else {
// if user not registered in the course
if (!$course_closed) {
if (!$course_private) {
if ($course_subscribe_allowed) {
$html .= $subscribeButton;
}
}
} elseif ($userRegisteredInCourseAsTeacher) {
// if user registered as teacher
if ($course_unsubscribe_allowed) {
$html .= return_unregister_button($course, $stok, $searchTerm, $code);
}
} else {
// if user not registered in the course
if (!$course_closed) {
if (!$course_private) {
if ($course_subscribe_allowed) {
$html .= $subscribeButton;
}
}
}
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
echo $html;
}
echo '</div>';
} else {
if (!isset($_REQUEST['subscribe_user_with_password']) &&
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
echo $html;
}
echo '</div>';
} else {
if (!isset($_REQUEST['subscribe_user_with_password']) &&
!isset($_REQUEST['subscribe_course'])
) {
echo Display::return_message(
echo Display::return_message(
get_lang('ThereAreNoCoursesInThisCategory'),
'warning'
);
}
}
}
}
echo '<div class="col-md-12">';
echo $cataloguePagination;
@ -409,9 +406,7 @@ function return_teacher($courseInfo)
function return_title($course, $registeredUser)
{
$linkCourse = api_get_course_url($course['code']);
$html = '<div class="block-title"><h4 class="title">';
if (!$registeredUser) {
$html .= $course['title'];
} else {

@ -91,12 +91,14 @@ $form->addElement(
'<div id="advanced_params_options" style="display:none">'
);
$countCategories = $courseCategoriesRepo->countAllInAccessUrl($accessUrlId);
$countCategories = $courseCategoriesRepo->countAllInAccessUrl(
$accessUrlId,
api_get_configuration_value('allow_base_course_category')
);
if ($countCategories >= 100) {
// Category code
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
$form->addElement(
'select_ajax',
'category_code',
@ -105,7 +107,10 @@ if ($countCategories >= 100) {
['url' => $url]
);
} else {
$categories = $courseCategoriesRepo->findAllInAccessUrl($accessUrlId);
$categories = $courseCategoriesRepo->findAllInAccessUrl(
$accessUrlId,
api_get_configuration_value('allow_base_course_category')
);
$categoriesOptions = [null => get_lang('None')];
/** @var CourseCategory $category */

@ -36,7 +36,17 @@ class CourseCategory
$sql = "SELECT * FROM $table WHERE code ='$category'";
$result = Database::query($sql);
if (Database::num_rows($result)) {
return Database::fetch_array($result, 'ASSOC');
$category = Database::fetch_array($result, 'ASSOC');
// Get access url id
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$sql = "SELECT * FROM $table WHERE course_category_id = ".$category['id'];
$result = Database::query($sql);
$result = Database::fetch_array($result);
if ($result) {
$category['access_url_id'] = $result['access_url_id'];
}
return $category;
}
return [];
@ -46,7 +56,7 @@ class CourseCategory
* @param string $category Optional. Parent category code
* @return array
*/
public static function getCategories($category = null)
public static function getCategories($category = '')
{
$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
@ -54,8 +64,13 @@ class CourseCategory
$conditions = null;
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$conditions = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
$whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
$allowBaseCategories = api_get_configuration_value('allow_base_course_category');
if ($allowBaseCategories) {
$whereCondition = " AND (a.access_url_id = ".api_get_current_access_url_id()." OR a.access_url_id = 1) ";
}
$parentIdCondition = " AND (t1.parent_id IS NULL OR t1.parent_id = '' )";
if (!empty($category)) {
@ -68,7 +83,8 @@ class CourseCategory
t1.parent_id,
t1.tree_pos,
t1.children_count,
COUNT(DISTINCT t3.code) AS nbr_courses
COUNT(DISTINCT t3.code) AS nbr_courses,
a.access_url_id
FROM $tbl_category t1
$conditions
LEFT JOIN $tbl_category t2
@ -87,7 +103,7 @@ class CourseCategory
ORDER BY t1.tree_pos";
$result = Database::query($sql);
$categories = Database::store_result($result);
$categories = Database::store_result($result, 'ASSOC');
return $categories;
}
@ -155,12 +171,9 @@ class CourseCategory
}
// Now we're at the top, get back down to update each child
//$children_count = courseCategoryChildrenCount($categoryId);
$sql = "UPDATE $table SET children_count = (children_count - ".abs($delta).") WHERE code = '$categoryId'";
if ($delta >= 0) {
$sql = "UPDATE $table SET children_count = (children_count + $delta)
WHERE code = '$categoryId'";
} else {
$sql = "UPDATE $table SET children_count = (children_count - ".abs($delta).")
WHERE code = '$categoryId'";
$sql = "UPDATE $table SET children_count = (children_count + $delta) WHERE code = '$categoryId'";
}
Database::query($sql);
}
@ -437,14 +450,19 @@ class CourseCategory
ICON_SIZE_SMALL
);
$urlId = api_get_current_access_url_id();
foreach ($categories as $category) {
$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';
$actions = Display::url($editIcon, $editUrl).
Display::url($moveIcon, $moveUrl).
Display::url($deleteIcon, $deleteUrl);
$actions = [];
if ($urlId == $category['access_url_id']) {
$actions[] = Display::url($editIcon, $editUrl);
$actions[] = Display::url($moveIcon, $moveUrl);
$actions[] = Display::url($deleteIcon, $deleteUrl);
}
$url = api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$category['code'];
$title = Display::url(
@ -460,7 +478,7 @@ class CourseCategory
$title,
$category['children_count'],
$category['nbr_courses'],
$actions
implode('', $actions)
];
$column = 0;
foreach ($content as $value) {
@ -536,18 +554,6 @@ class CourseCategory
*/
public static function browseCourseCategories()
{
$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$conditions = null;
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
$whereCondition = " WHERE a.access_url_id = ".api_get_current_access_url_id();
$sql = "SELECT c.* FROM $tbl_category c
$conditions
$whereCondition
ORDER BY tree_pos ASC";
$result = Database::query($sql);
$url_access_id = 1;
if (api_is_multiple_url_enabled()) {
$url_access_id = api_get_current_access_url_id();
@ -565,18 +571,17 @@ class CourseCategory
'count_courses' => $countCourses
];
while ($row = Database::fetch_array($result)) {
$categoriesFromDatabase = self::getCategories();
foreach ($categoriesFromDatabase as $row) {
$count_courses = self::countCoursesInCategory($row['code']);
$row['count_courses'] = $count_courses;
if (!isset($row['parent_id'])) {
if (empty($row['parent_id'])) {
$categories[0][$row['tree_pos']] = $row;
} else {
$categories[$row['parent_id']][$row['tree_pos']] = $row;
}
}
$count_courses = self::countCoursesInCategory();
$categories[0][count($categories[0]) + 1] = [
'id' => 0,
'name' => get_lang('None'),
@ -625,9 +630,11 @@ class CourseCategory
$searchFilter = '';
if (!empty($searchTerm)) {
$searchFilter = ' AND (code LIKE "%'.$searchTerm.'%"
OR title LIKE "%'.$searchTerm.'%"
OR tutor_name LIKE "%'.$searchTerm.'%") ';
$searchFilter = ' AND (
code LIKE "%'.$searchTerm.'%" OR
title LIKE "%'.$searchTerm.'%" OR
tutor_name LIKE "%'.$searchTerm.'%"
) ';
}
$url_access_id = api_get_current_access_url_id();
@ -1171,7 +1178,6 @@ class CourseCategory
}
$extension = getextension($fileData['name']);
$dirName = 'course_category/';
$fileDir = api_get_path(SYS_UPLOAD_PATH).$dirName;
$fileName = "cc_$categoryId.{$extension[0]}";

@ -741,6 +741,9 @@ $_configuration['gradebook_badge_sidebar'] = [
// Remove html tags when exporting glossary definitions in a CSV file
//$_configuration['allow_remove_tags_in_glossary_export'] = false;
// Show base course categories in portal children
//$_configuration['allow_base_course_category'] = false;
// ------ Custom DB changes
// Add user activation by confirmation email
// This option prevents the new user to login in the platform if your account is not confirmed via email

@ -15,35 +15,43 @@ class CourseCategoryRepository extends EntityRepository
/**
* Get all course categories in an access url
* @param int $accessUrl
* @param bool $allowBaseCategories
*
* @return array
*/
public function findAllInAccessUrl($accessUrl)
public function findAllInAccessUrl($accessUrl, $allowBaseCategories = false)
{
$qb = $this->createQueryBuilder('c');
$query = $qb
$qb
->innerJoin(
'ChamiloCoreBundle:AccessUrlRelCourseCategory',
'a',
Join::WITH,
'c = a.courseCategoryId'
)
->where(
$qb->expr()->eq('a.accessUrlId', $accessUrl)
)->orderBy('c.treePos', 'ASC')
->getQuery();
->where($qb->expr()->eq('a.accessUrlId', $accessUrl))
->orderBy('c.treePos', 'ASC')
;
if ($allowBaseCategories) {
$qb->orWhere($qb->expr()->eq('a.accessUrlId', 1));
}
$query = $qb->getQuery();
return $query->getResult();
}
/**
* Get the number of course categories in an access url
* @param int $accessUrl
* @param bool $allowBaseCategories
* @return int
*/
public function countAllInAccessUrl($accessUrl)
public function countAllInAccessUrl($accessUrl, $allowBaseCategories = false)
{
$qb = $this->createQueryBuilder('c');
$query = $qb
->select('COUNT(c)')
$qb->select('COUNT(c)')
->innerJoin(
'ChamiloCoreBundle:AccessUrlRelCourseCategory',
'a',
@ -52,8 +60,11 @@ class CourseCategoryRepository extends EntityRepository
)
->where(
$qb->expr()->eq('a.accessUrlId', $accessUrl)
)
->getQuery();
);
if ($allowBaseCategories) {
$qb->orWhere($qb->expr()->eq('a.accessUrlId', 1));
}
$count = $qb->getQuery()->getSingleScalarResult();

Loading…
Cancel
Save