From 076109dfbe20f658ac5be9ab59ba92fc3af401e8 Mon Sep 17 00:00:00 2001 From: Julien Boulen Date: Fri, 3 Oct 2014 17:58:21 +0200 Subject: [PATCH 1/2] MDL-40351 Blocks, My home: Course Categories on the My Home Page --- .../lang/en/block_course_overview.php | 5 +++++ blocks/course_overview/locallib.php | 4 ++++ blocks/course_overview/renderer.php | 22 +++++++++++++++++++ blocks/course_overview/settings.php | 7 ++++++ blocks/course_overview/styles.css | 4 ++++ 5 files changed, 42 insertions(+) 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..51556725dde 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..521fc1ab6d4 100644 --- a/blocks/course_overview/styles.css +++ b/blocks/course_overview/styles.css @@ -3,6 +3,10 @@ font-style: italic; } +.block_course_overview .categorypath{ + text-align: right; +} + .block_course_overview .content { margin: 0 20px; } From d512e5f83386981b1323ec3698d983113b813e43 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 6 Oct 2014 09:36:58 +0800 Subject: [PATCH 2/2] MDL-40351 block_course_overview: minor corrections --- blocks/course_overview/renderer.php | 6 +++--- blocks/course_overview/styles.css | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/blocks/course_overview/renderer.php b/blocks/course_overview/renderer.php index 51556725dde..8923322818f 100644 --- a/blocks/course_overview/renderer.php +++ b/blocks/course_overview/renderer.php @@ -41,7 +41,7 @@ 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) { + if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { global $CFG; require_once($CFG->libdir.'/coursecatlib.php'); } @@ -132,12 +132,12 @@ 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) { + 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) { + if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) { foreach ($currentcategory->get_parents() as $categoryid) { $category = coursecat::get($categoryid, IGNORE_MISSING); if ($category !== null) { diff --git a/blocks/course_overview/styles.css b/blocks/course_overview/styles.css index 521fc1ab6d4..7a6ab5ef0b4 100644 --- a/blocks/course_overview/styles.css +++ b/blocks/course_overview/styles.css @@ -7,6 +7,10 @@ text-align: right; } +.dir-rtl .block_course_overview .categorypath{ + text-align: left; +} + .block_course_overview .content { margin: 0 20px; }