MDL-64855 block_myoverview: add setting for course categories display
authorTom Dickman <tomdickman@catalyst-au.net>
Thu, 21 Mar 2019 00:56:02 +0000 (11:56 +1100)
committerTom Dickman <tomdickman@catalyst-au.net>
Fri, 29 Mar 2019 01:06:07 +0000 (12:06 +1100)
Added an administrator setting to set the visibility of the course category for the my overview
block on the users dashboard to support usage scenarios where displaying the course categories will
clutter course overviews.

blocks/myoverview/amd/build/view.min.js
blocks/myoverview/amd/src/view.js
blocks/myoverview/block_myoverview.php
blocks/myoverview/classes/output/main.php
blocks/myoverview/lang/en/block_myoverview.php
blocks/myoverview/lib.php
blocks/myoverview/settings.php [new file with mode: 0644]
blocks/myoverview/templates/courses-view.mustache
blocks/myoverview/templates/view-list.mustache
blocks/myoverview/templates/view-summary.mustache

index 9d6dfd0..3ce966a 100644 (file)
Binary files a/blocks/myoverview/amd/build/view.min.js and b/blocks/myoverview/amd/build/view.min.js differ
index 747d33f..928469e 100644 (file)
@@ -90,7 +90,8 @@ function(
         return {
             display: courseRegion.attr('data-display'),
             grouping: courseRegion.attr('data-grouping'),
-            sort: courseRegion.attr('data-sort')
+            sort: courseRegion.attr('data-sort'),
+            displaycategories: courseRegion.attr('data-displaycategories'),
         };
     };
 
@@ -370,9 +371,17 @@ function(
             currentTemplate = TEMPLATES.COURSES_SUMMARY;
         }
 
+        // Delete the course category if it is not to be displayed
+        if (filters.displaycategories != 'on') {
+            coursesData.courses = coursesData.courses.map(function(course) {
+                delete course.coursecategory;
+                return course;
+            });
+        }
+
         if (coursesData.courses.length) {
             return Templates.render(currentTemplate, {
-                courses: coursesData.courses
+                courses: coursesData.courses,
             });
         } else {
             var nocoursesimg = root.find(Selectors.courseView.region).attr('data-nocoursesimg');
index 85c208e..6177719 100644 (file)
@@ -72,4 +72,14 @@ class block_myoverview extends block_base {
     public function applicable_formats() {
         return array('my' => true);
     }
+
+    /**
+     * Allow the block to have a configuration page
+     *
+     * @return boolean
+     */
+    public function has_config() {
+        return true;
+    }
 }
+
index eb28dce..7ef8c38 100644 (file)
@@ -66,6 +66,13 @@ class main implements renderable, templatable {
      */
     private $paging;
 
+    /**
+     * Store the display categories config setting
+     *
+     * @var boolean
+     */
+    private $displaycategories;
+
     /**
      * main constructor.
      * Initialize the user preferences
@@ -79,6 +86,12 @@ class main implements renderable, templatable {
         $this->sort = $sort ? $sort : BLOCK_MYOVERVIEW_SORTING_TITLE;
         $this->view = $view ? $view : BLOCK_MYOVERVIEW_VIEW_CARD;
         $this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12;
+        $config = get_config('block_myoverview');
+        if (!$config->displaycategories) {
+            $this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF;
+        } else {
+            $this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON;
+        }
     }
 
     /**
@@ -110,7 +123,8 @@ class main implements renderable, templatable {
             'grouping' => $this->grouping,
             'sort' => $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc',
             'view' => $this->view,
-            'paging' => $this->paging
+            'paging' => $this->paging,
+            'displaycategories' => $this->displaycategories,
         ];
 
         $preferences = $this->get_preferences_as_booleans();
index 3ef06af..b6f51b8 100644 (file)
@@ -49,6 +49,8 @@ $string['card'] = 'Card';
 $string['cards'] = 'Cards';
 $string['courseprogress'] = 'Course progress:';
 $string['completepercent'] = '{$a}% complete';
+$string['displaycategories'] = 'Display Categories';
+$string['displaycategories_help'] = 'Display the Course Category on dashboard course items including cards, list items and summary items';
 $string['favourites'] = 'Starred';
 $string['future'] = 'Future';
 $string['inprogress'] = 'In progress';
index ed7334a..d5bc9e2 100644 (file)
@@ -55,6 +55,12 @@ define('BLOCK_MYOVERVIEW_PAGING_12', 12);
 define('BLOCK_MYOVERVIEW_PAGING_24', 24);
 define('BLOCK_MYOVERVIEW_PAGING_48', 48);
 
+/**
+ * Constants for the admin category display setting
+ */
+define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON', 'on');
+define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF', 'off');
+
 /**
  * Get the current user preferences that are available
  *
diff --git a/blocks/myoverview/settings.php b/blocks/myoverview/settings.php
new file mode 100644 (file)
index 0000000..f3b2edf
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Settings for the myoverview block
+ *
+ * @package    block_myoverview
+ * @copyright  2019 Tom Dickman <tomdickman@catalyst-au.net>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+    require_once($CFG->dirroot . '/blocks/myoverview/lib.php');
+
+    // Display Course Categories on Dashboard course items (cards, lists, summary items).
+    $settings->add(new admin_setting_configcheckbox(
+        'block_myoverview/displaycategories',
+        get_string('displaycategories', 'block_myoverview'),
+        get_string('displaycategories_help', 'block_myoverview'),
+        1));
+
+}
index 754d525..951cef9 100644 (file)
@@ -34,7 +34,8 @@
     data-sort="{{sort}}"
     data-prev-display="{{view}}"
     data-paging="{{paging}}"
-    data-nocoursesimg="{{nocoursesimg}}">
+    data-nocoursesimg="{{nocoursesimg}}"
+    data-displaycategories="{{displaycategories}}">
     <div data-region="course-view-content">
         {{> block_myoverview/placeholders }}
     </div>
index a39a9bb..21e1f43 100644 (file)
@@ -47,7 +47,9 @@
                         <span class="sr-only">
                             {{#str}}aria:coursecategory, core_course{{/str}}
                         </span>
-                        <div>{{{coursecategory}}}</div>
+                        {{#displaycategories}}
+                            <div>{{{coursecategory}}}</div>
+                        {{/displaycategories}}
                         {{#showshortname}}
                         <div class="pl-1 pr-1">|</div>
                         <span class="sr-only">
index 876a7ec..29b2aef 100644 (file)
@@ -54,7 +54,9 @@
                             <span class="sr-only">
                                 {{#str}}aria:coursecategory, core_course{{/str}}
                             </span>
-                            <div>{{{coursecategory}}}</div>
+                            {{#displaycategories}}
+                                <div>{{{coursecategory}}}</div>
+                            {{/displaycategories}}
                             {{#showshortname}}
                             <div class="pl-1 pr-1">|</div>
                             <span class="sr-only">