Skip to content

Commit

Permalink
Add description for course category see BT#13155
Browse files Browse the repository at this point in the history
Requires DB change:
- ALTER TABLE course_category ADD description LONGTEXT NULL;
- Turn on setting:
$_configuration['my_courses_list_as_category'] = true;
  • Loading branch information
jmontoyaa committed Aug 4, 2017
1 parent 62e3dfa commit e8e716f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
18 changes: 14 additions & 4 deletions main/admin/course_category.php
Expand Up @@ -54,8 +54,11 @@
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']);
}
}

Expand Down Expand Up @@ -129,12 +132,19 @@
$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]
Expand Down
31 changes: 30 additions & 1 deletion main/inc/lib/course_category.lib.php
Expand Up @@ -1158,6 +1158,11 @@ public static function getCourseCatalogNameTools($action)
*/
public static function saveImage($categoryId, $fileData)
{
$categoryInfo = self::getCategoryById($categoryId);
if (empty($categoryInfo)) {
return;
}

if (!empty($fileData['error'])) {
return;
}
Expand All @@ -1176,7 +1181,31 @@ public static function saveImage($categoryId, $fileData)
$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;
}
}
1 change: 1 addition & 0 deletions main/install/configuration.dist.php
Expand Up @@ -572,6 +572,7 @@
//$_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;
// ------

Expand Down
3 changes: 3 additions & 0 deletions main/template/default/user_portal/course_categories.tpl
Expand Up @@ -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>
Expand Down

0 comments on commit e8e716f

Please sign in to comment.