Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
New: Custom category icon images - #622.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Mar 31, 2017
1 parent bbfe99c commit 5312615
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ New in 3.2.1.1
- FIX: Font-awesome icon for the recycle bin.
- FIX: Font-awesome icon for the repositories.
- FIX: MyCourses default icon.
- NEW: Issue #622: Custom category icon images.

New in 3.2.1.0 - First stable version.
==============
Expand Down
35 changes: 21 additions & 14 deletions classes/core_course_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,34 @@ protected function coursecat_category(coursecat_helper $chelper, $coursecat, $de
// Category name.
$categoryname = html_writer::tag('span', $coursecat->get_formatted_name());

// Do a settings check to output our icon for the category.
if (\theme_essential\toolbox::get_setting('enablecategoryicon')) {
$customcategoryicon = \theme_essential\toolbox::get_setting('categoryicon'.$coursecat->id);
if ($customcategoryicon &&
\theme_essential\toolbox::get_setting('enablecustomcategoryicon')) {
// User has set a value for the category.
$val = $customcategoryicon;
} else {
// User hasn't set a value for the category, get the default.
$val = \theme_essential\toolbox::get_setting('defaultcategoryicon');
// Do a settings check to output our icon / image for the category.
if (\theme_essential\toolbox::get_setting('enablecustomcategoryicon')) {
// User may have set a value for the category.
$image = \theme_essential\toolbox::get_setting('categoryimage'.$coursecat->id, 'format_file_url');
if (empty($image)) {
$icon = \theme_essential\toolbox::get_setting('categoryicon'.$coursecat->id);;
}
}
if ((empty($icon)) && (empty($image))) {
// User hasn't set a value for the category, get the default.
$image = \theme_essential\toolbox::get_setting('defaultcategoryimage', 'format_file_url');
if (empty($image)) {
$icon = \theme_essential\toolbox::get_setting('defaultcategoryicon');
}
}
if (!empty($val)) {
$icon = html_writer::tag('span', '', array('aria-hidden' => 'true', 'class' => 'fa fa-'.$val));
if (!empty($image)) {
$categoryrepresentation = html_writer::start_tag('div', array('class' => 'categoryimage'));
$categoryrepresentation .= html_writer::empty_tag('img', array('src' => $image, 'class' => 'img-responsive'));
$categoryrepresentation .= html_writer::end_tag('div');
} else if (!empty($icon)) {
$categoryrepresentation = html_writer::tag('span', '', array('aria-hidden' => 'true', 'class' => 'fa fa-'.$icon));
} else {
$icon = '';
$categoryrepresentation = '';
}

$categoryname = html_writer::link(new moodle_url('/course/index.php',
array('categoryid' => $coursecat->id)),
$icon . $categoryname);
$categoryrepresentation.$categoryname);
$content .= html_writer::start_tag('div', array('class' => 'info'));

$content .= html_writer::tag(($depth > 1) ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname'));
Expand Down
24 changes: 13 additions & 11 deletions lang/en/theme_essential.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,25 +657,27 @@
$string['ctioverridetextbackgroundopacitydesc'] = 'Default overridden text background opacity for the course title.';

// Category Icons.
$string['categoryiconheading'] = 'Category icons';
$string['categoryiconheading'] = 'Category icons / images';
$string['categoryiconheadingsub'] = 'Use icons to represent your categories';
$string['categoryicondesc'] = 'If enabled this will allow you to set icons for each category of course.';
$string['categoryicondesc'] = 'If enabled this will allow you to set icons / images for each category.';
$string['categoryiconcategory'] = 'The icon for the category: {$a->category}.';
$string['categoryimagecategory'] = 'The image for the category: {$a->category}.';

$string['enablecategoryicon'] = 'Enable category icons';
$string['enablecategoryicondesc'] = 'If enabled you will be able to select category icons after clicking "Save changes".';
$string['enablecategoryicon'] = 'Enable category icons / images';
$string['enablecategoryicondesc'] = 'If enabled you will be able to select category icons / images after clicking "Save changes".';

$string['usecategoryicon'] = 'Enable category icons';
$string['usecategoryicondesc'] = 'Use custom icons for categories';
$string['defaultcategoryicon'] = 'Default category icon';
$string['defaultcategoryicondesc'] = 'Set a default category icon.';
$string['defaultcategoryimage'] = 'Default category image';
$string['defaultcategoryimagedesc'] = 'Set a default category image. Will override the icon when populated.';

$string['defaultcategoryicon'] = 'Default category icons';
$string['defaultcategoryicondesc'] = 'Set a default category icon';

$string['enablecustomcategoryicon'] = 'Enable custom category icons';
$string['enablecustomcategoryicon'] = 'Enable custom category icons / images';
$string['enablecustomcategoryicondesc'] = 'If enabled below this section you will see each category with a customizable option behind each category, please save after enabling and disabling this option.';
$string['icon'] = 'icon';
$string['image'] = 'image';

$string['categoryiconinfo'] = 'Set custom category icons';
$string['categoryiconinfodesc'] = 'Enter the name of the icon you wish to use. List is <a href="http://fortawesome.github.io/Font-Awesome/cheatsheet/" target="_new">here</a>. Just enter what is after "fa-".';
$string['categoryiconinfodesc'] = 'Enter the name of the icon or upload an image you wish to use. List is <a href="http://fortawesome.github.io/Font-Awesome/cheatsheet/" target="_new">here</a>. Just enter what is after "fa-".';

$string['numberofcoursesandsubcatcourses'] = 'Number of courses - sub category courses';

Expand Down
9 changes: 8 additions & 1 deletion less/essential/categories.less
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,16 @@
width: 176px;
> .@{fa-css-prefix} {
font-size: 140px;
padding-top: 6px;
padding-top: 8px;
width: 100%;
}
> .categoryimage {
line-height: 140px;
padding-top: 8px;
> img {
max-height: 140px;
}
}
> span {
font-size: 18px;
}
Expand Down
4 changes: 4 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ function theme_essential_pluginfile($course, $cm, $context, $filearea, $args, $f
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
} else if (preg_match("/^(marketing|slide|categoryct)[1-9][0-9]*image$/", $filearea)) {
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
} else if ($filearea === 'defaultcategoryimage') {
return $theme->setting_file_serve('defaultcategoryimage', $args, $forcedownload, $options);
} else if (preg_match("/^categoryimage[1-9][0-9]*$/", $filearea)) {
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
} else if ($filearea === 'iphoneicon') {
return $theme->setting_file_serve('iphoneicon', $args, $forcedownload, $options);
} else if ($filearea === 'iphoneretinaicon') {
Expand Down
30 changes: 24 additions & 6 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@
get_string('categoryctiheadingsub', 'theme_essential'),
format_text(get_string('categoryctidesc', 'theme_essential'), FORMAT_MARKDOWN)));

// Category icons.
// Category course title images.
$name = 'theme_essential/enablecategorycti';
$title = get_string('enablecategorycti', 'theme_essential');
$description = get_string('enablecategoryctidesc', 'theme_essential');
Expand All @@ -2239,7 +2239,7 @@
$setting->set_updatedcallback('theme_reset_all_caches');
$essentialsettingscategorycti->add($setting);

// Category icons category setting pages.
// Category course title image setting pages.
$name = 'theme_essential/enablecategoryctics';
$title = get_string('enablecategoryctics', 'theme_essential');
$description = get_string('enablecategorycticsdesc', 'theme_essential');
Expand Down Expand Up @@ -2417,7 +2417,7 @@
// We only want to output category icon options if the parent setting is enabled.
if (get_config('theme_essential', 'enablecategoryicon')) {

// Default icon selector.
// Default icon.
$name = 'theme_essential/defaultcategoryicon';
$title = get_string('defaultcategoryicon', 'theme_essential');
$description = get_string('defaultcategoryicondesc', 'theme_essential');
Expand All @@ -2426,6 +2426,14 @@
$setting->set_updatedcallback('theme_reset_all_caches');
$essentialsettingscategoryicon->add($setting);

// Default image.
$name = 'theme_essential/defaultcategoryimage';
$title = get_string('defaultcategoryimage', 'theme_essential');
$description = get_string('defaultcategoryimagedesc', 'theme_essential');
$setting = new admin_setting_configstoredfile($name, $title, $description, 'defaultcategoryimage');
$setting->set_updatedcallback('theme_reset_all_caches');
$essentialsettingscategoryicon->add($setting);

// Category icons.
$name = 'theme_essential/enablecustomcategoryicon';
$title = get_string('enablecustomcategoryicon', 'theme_essential');
Expand All @@ -2435,6 +2443,8 @@
$essentialsettingscategoryicon->add($setting);

if (get_config('theme_essential', 'enablecustomcategoryicon')) {
$iconstring = get_string('icon', 'theme_essential');
$imagestring = get_string('image', 'theme_essential');

// This is the descriptor for custom category icons.
$name = 'theme_essential/categoryiconinfo';
Expand All @@ -2455,12 +2465,20 @@
// Go through all categories and create the necessary settings.
foreach ($coursecats as $key => $value) {
$namepath = join(' / ', $value->namechunks);
// Category icons for each category.
// Category icon for each category.
$name = 'theme_essential/categoryicon';
$title = $namepath;
$title = $namepath.' '.$iconstring;
$description = get_string('categoryiconcategory', 'theme_essential', array('category' => $namepath));
$default = $defaultcategoryicon;
$setting = new admin_setting_configtext($name . $key, $title, $description, $default);
$setting = new admin_setting_configtext($name.$key, $title, $description, $default);
$setting->set_updatedcallback('theme_reset_all_caches');
$essentialsettingscategoryicon->add($setting);

// Category image for each category.
$name = 'theme_essential/categoryimage';
$title = $namepath.' '.$imagestring;
$description = get_string('categoryimagecategory', 'theme_essential', array('category' => $namepath));
$setting = new admin_setting_configstoredfile($name.$key, $title, $description, 'categoryimage'.$key);
$setting->set_updatedcallback('theme_reset_all_caches');
$essentialsettingscategoryicon->add($setting);
}
Expand Down
11 changes: 10 additions & 1 deletion style/essential.css
Original file line number Diff line number Diff line change
Expand Up @@ -20723,9 +20723,18 @@ table.calendarmonth.calendartable {
.categoryicons .course_category_tree .category > .info a > .fa,
.categoryicons .course_category_tree .category > .info > .categoryname a > .fa {
font-size: 140px;
padding-top: 6px;
padding-top: 8px;
width: 100%;
}
.categoryicons .course_category_tree .category > .info a > .categoryimage,
.categoryicons .course_category_tree .category > .info > .categoryname a > .categoryimage {
line-height: 140px;
padding-top: 8px;
}
.categoryicons .course_category_tree .category > .info a > .categoryimage > img,
.categoryicons .course_category_tree .category > .info > .categoryname a > .categoryimage > img {
max-height: 140px;
}
.categoryicons .course_category_tree .category > .info a > span,
.categoryicons .course_category_tree .category > .info > .categoryname a > span {
font-size: 18px;
Expand Down

0 comments on commit 5312615

Please sign in to comment.