Add description for course category see BT#13155

Requires DB change:
- ALTER TABLE course_category ADD description LONGTEXT NULL;
- Turn on setting:
$_configuration['my_courses_list_as_category'] = true;
pull/2487/head
jmontoyaa 7 years ago
parent 62e3dfa06b
commit e8e716f35b
  1. 18
      main/admin/course_category.php
  2. 31
      main/inc/lib/course_category.lib.php
  3. 1
      main/install/configuration.dist.php
  4. 3
      main/template/default/user_portal/course_categories.tpl

@ -54,8 +54,11 @@ if (!empty($action)) {
if (!$ret) {
$errorMsg = Display::return_message(get_lang('CatCodeAlreadyUsed'), 'error');
} else {
if ($myCourseListAsCategory && isset($_FILES['image'])) {
CourseCategory::saveImage($ret, $_FILES['image']);
if ($myCourseListAsCategory) {
if (isset($_FILES['image'])) {
CourseCategory::saveImage($ret, $_FILES['image']);
}
CourseCategory::saveDescription($ret, $_POST['description']);
}
}
@ -129,12 +132,19 @@ if ($action == 'add' || $action == 'edit') {
$form->addGroup($group, null, get_lang("AllowCoursesInCategory"));
if ($myCourseListAsCategory) {
$form->addHtmlEditor(
'description',
get_lang('Description'),
false,
false,
['ToolbarSet' => 'Minimal']
);
$form->addFile('image', get_lang('Image'), ['accept' => 'image/*']);
if ($action == 'edit' && !empty($categoryInfo['image'])) {
$form->addHtml('
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">'.Display::img(
<div class="col-sm-offset-2 col-sm-8">'.
Display::img(
api_get_path(WEB_UPLOAD_PATH).$categoryInfo['image'],
get_lang('Image'),
['width' => 256]

@ -1158,6 +1158,11 @@ class CourseCategory
*/
public static function saveImage($categoryId, $fileData)
{
$categoryInfo = self::getCategoryById($categoryId);
if (empty($categoryInfo)) {
return;
}
if (!empty($fileData['error'])) {
return;
}
@ -1176,7 +1181,31 @@ class CourseCategory
$image->send_image($fileDir.$fileName);
$table = Database::get_main_table(TABLE_MAIN_CATEGORY);
Database::update(
$table,
['image' => $dirName.$fileName],
['id = ?' => $categoryId]
);
}
Database::update($table, ['image' => $dirName.$fileName], ['id = ?' => $categoryId]);
/**
* @param $categoryId
* @param string $description
*
* @return string
*/
public static function saveDescription($categoryId, $description)
{
$categoryInfo = self::getCategoryById($categoryId);
if (empty($categoryInfo)) {
return false;
}
$table = Database::get_main_table(TABLE_MAIN_CATEGORY);
Database::update(
$table,
['description' => $description],
['id = ?' => $categoryId]
);
return true;
}
}

@ -572,6 +572,7 @@ $_configuration['score_grade_model'] = [
//$_configuration['show_simple_session_info'] = true;
// Show course category list on My Courses page before the courses. Requires a DB change
//ALTER TABLE course_category ADD image varchar(255) NULL;
//ALTER TABLE course_category ADD description LONGTEXT NULL;
//$_configuration['my_courses_list_as_category'] = false;
// ------

@ -12,6 +12,9 @@
<div class="media-body">
<h4 class="media-heading">{{ category.name }}</h4>
<p>{{ category.code }}</p>
{% if category.description %}
<p>{{ category.description }}</p>
{% endif %}
<a href="{{ _p.web_self ~ '?' ~ {'category':category.code}|url_encode }}" class="btn btn-default">
{{ 'View'|get_lang }} <span class="fa fa-arrow-right" aria-hidden="true"></span>
</a>

Loading…
Cancel
Save