diff --git a/blocks/course_overview/lang/en/block_course_overview.php b/blocks/course_overview/lang/en/block_course_overview.php index 8ac27ed5b66..96a4359ecab 100644 --- a/blocks/course_overview/lang/en/block_course_overview.php +++ b/blocks/course_overview/lang/en/block_course_overview.php @@ -34,6 +34,7 @@ $string['defaultmaxcoursesdesc'] = 'Maximum courses which should be displayed on $string['expandall'] = 'Expand all course lists'; $string['forcedefaultmaxcourses'] = 'Force maximum courses'; $string['forcedefaultmaxcoursesdesc'] = 'If set then user will not be able to change his/her personal setting'; +$string['fullpath'] = 'Full path'; $string['hiddencoursecount'] = 'You have {$a} hidden course'; $string['hiddencoursecountplural'] = 'You have {$a} hidden courses'; $string['hiddencoursecountwithshowall'] = 'You have {$a->coursecount} hidden course ({$a->showalllink})'; @@ -45,13 +46,17 @@ $string['movecoursehere'] = 'Move course here'; $string['movetofirst'] = 'Move {$a} course to top'; $string['moveafterhere'] = 'Move {$a->movingcoursename} course after {$a->currentcoursename}'; $string['movingcourse'] = 'You are moving: {$a->fullname} ({$a->cancellink})'; +$string['none'] = 'None'; $string['numtodisplay'] = 'Number of courses to display: '; +$string['onlyparentname'] = 'Only parent name'; $string['otherexpanded'] = 'Other courses expanded'; $string['pluginname'] = 'Course overview'; $string['preservestates'] = 'Preserve expanded states'; $string['shortnameprefix'] = 'Includes {$a}'; $string['shortnamesufixsingular'] = ' (and {$a} other)'; $string['shortnamesufixprural'] = ' (and {$a} others)'; +$string['showcategories'] = 'Show categories'; +$string['showcategoriesdesc'] = 'Should categories be displayed for each course boxes?'; $string['showchildren'] = 'Show children'; $string['showchildrendesc'] = 'Should child courses be listed underneath the main course title?'; $string['showwelcomearea'] = 'Show welcome area'; diff --git a/blocks/course_overview/locallib.php b/blocks/course_overview/locallib.php index df9444524cd..746ccf4eee1 100644 --- a/blocks/course_overview/locallib.php +++ b/blocks/course_overview/locallib.php @@ -22,6 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +define('BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE', '0'); +define('BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_ONLY_PARENT_NAME', '1'); +define('BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH', '2'); + /** * Display overview for courses * diff --git a/blocks/course_overview/renderer.php b/blocks/course_overview/renderer.php index 76ef098c1db..8923322818f 100644 --- a/blocks/course_overview/renderer.php +++ b/blocks/course_overview/renderer.php @@ -41,6 +41,10 @@ class block_course_overview_renderer extends plugin_renderer_base { public function course_overview($courses, $overviews) { $html = ''; $config = get_config('block_course_overview'); + if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { + global $CFG; + require_once($CFG->libdir.'/coursecatlib.php'); + } $ismovingcourse = false; $courseordernumber = 0; $maxcourses = count($courses); @@ -128,6 +132,24 @@ class block_course_overview_renderer extends plugin_renderer_base { $html .= $this->activity_display($course->id, $overviews[$course->id]); } + if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { + // List category parent or categories path here. + $currentcategory = coursecat::get($course->category, IGNORE_MISSING); + if ($currentcategory !== null) { + $html .= html_writer::start_tag('div', array('class' => 'categorypath')); + if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) { + foreach ($currentcategory->get_parents() as $categoryid) { + $category = coursecat::get($categoryid, IGNORE_MISSING); + if ($category !== null) { + $html .= $category->get_formatted_name().' / '; + } + } + } + $html .= $currentcategory->get_formatted_name(); + $html .= html_writer::end_tag('div'); + } + } + $html .= $this->output->box('', 'flush'); $html .= $this->output->box_end(); $courseordernumber++; diff --git a/blocks/course_overview/settings.php b/blocks/course_overview/settings.php index c8ce5412d68..d1c42758135 100644 --- a/blocks/course_overview/settings.php +++ b/blocks/course_overview/settings.php @@ -32,4 +32,11 @@ if ($ADMIN->fulltree) { new lang_string('showchildrendesc', 'block_course_overview'), 1, PARAM_INT)); $settings->add(new admin_setting_configcheckbox('block_course_overview/showwelcomearea', new lang_string('showwelcomearea', 'block_course_overview'), new lang_string('showwelcomeareadesc', 'block_course_overview'), 1, PARAM_INT)); + $showcategories = array( + BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE => new lang_string('none', 'block_course_overview'), + BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_ONLY_PARENT_NAME => new lang_string('onlyparentname', 'block_course_overview'), + BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH => new lang_string('fullpath', 'block_course_overview') + ); + $settings->add(new admin_setting_configselect('block_course_overview/showcategories', new lang_string('showcategories', 'block_course_overview'), + new lang_string('showcategoriesdesc', 'block_course_overview'), BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE, $showcategories)); } diff --git a/blocks/course_overview/styles.css b/blocks/course_overview/styles.css index 69905d7cb96..7a6ab5ef0b4 100644 --- a/blocks/course_overview/styles.css +++ b/blocks/course_overview/styles.css @@ -3,6 +3,14 @@ font-style: italic; } +.block_course_overview .categorypath{ + text-align: right; +} + +.dir-rtl .block_course_overview .categorypath{ + text-align: left; +} + .block_course_overview .content { margin: 0 20px; }