mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-64901 block_myoverview: admin settings to control available layouts
Added an admin setting which allows the administrator to set the available layouts for users and which defaults to all layouts being available, or the card layout only if no layouts are enabled. If only one layout is enabled, the dropdown `nav-display-selector` template will not be displayed as it can no longer be utilised. If the user preference is set to a layout that is no longer available, this is ignored and the first available layout defaulted to.
This commit is contained in:
parent
29c395187f
commit
5f59a4c063
10 changed files with 109 additions and 34 deletions
2
blocks/myoverview/amd/build/view.min.js
vendored
2
blocks/myoverview/amd/build/view.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -363,7 +363,7 @@ function(
|
||||||
var filters = getFilterValues(root);
|
var filters = getFilterValues(root);
|
||||||
|
|
||||||
var currentTemplate = '';
|
var currentTemplate = '';
|
||||||
if (filters.display == 'cards') {
|
if (filters.display == 'card') {
|
||||||
currentTemplate = TEMPLATES.COURSES_CARDS;
|
currentTemplate = TEMPLATES.COURSES_CARDS;
|
||||||
} else if (filters.display == 'list') {
|
} else if (filters.display == 'list') {
|
||||||
currentTemplate = TEMPLATES.COURSES_LIST;
|
currentTemplate = TEMPLATES.COURSES_LIST;
|
||||||
|
|
|
@ -74,7 +74,7 @@ class block_myoverview extends block_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow the block to have a configuration page
|
* Allow the block to have a configuration page.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
use renderable;
|
use renderable;
|
||||||
use renderer_base;
|
use renderer_base;
|
||||||
use templatable;
|
use templatable;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
require_once($CFG->dirroot . '/blocks/myoverview/lib.php');
|
require_once($CFG->dirroot . '/blocks/myoverview/lib.php');
|
||||||
|
|
||||||
|
@ -39,40 +40,47 @@ require_once($CFG->dirroot . '/blocks/myoverview/lib.php');
|
||||||
class main implements renderable, templatable {
|
class main implements renderable, templatable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the grouping preference
|
* Store the grouping preference.
|
||||||
*
|
*
|
||||||
* @var string String matching the grouping constants defined in myoverview/lib.php
|
* @var string String matching the grouping constants defined in myoverview/lib.php
|
||||||
*/
|
*/
|
||||||
private $grouping;
|
private $grouping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the sort preference
|
* Store the sort preference.
|
||||||
*
|
*
|
||||||
* @var string String matching the sort constants defined in myoverview/lib.php
|
* @var string String matching the sort constants defined in myoverview/lib.php
|
||||||
*/
|
*/
|
||||||
private $sort;
|
private $sort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the view preference
|
* Store the view preference.
|
||||||
*
|
*
|
||||||
* @var string String matching the view/display constants defined in myoverview/lib.php
|
* @var string String matching the view/display constants defined in myoverview/lib.php
|
||||||
*/
|
*/
|
||||||
private $view;
|
private $view;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the paging preference
|
* Store the paging preference.
|
||||||
*
|
*
|
||||||
* @var string String matching the paging constants defined in myoverview/lib.php
|
* @var string String matching the paging constants defined in myoverview/lib.php
|
||||||
*/
|
*/
|
||||||
private $paging;
|
private $paging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the display categories config setting
|
* Store the display categories config setting.
|
||||||
*
|
*
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
private $displaycategories;
|
private $displaycategories;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the configuration values for the myoverview block.
|
||||||
|
*
|
||||||
|
* @var array Array of available layouts matching view/display constants defined in myoverview/lib.php
|
||||||
|
*/
|
||||||
|
private $layouts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main constructor.
|
* main constructor.
|
||||||
* Initialize the user preferences
|
* Initialize the user preferences
|
||||||
|
@ -80,34 +88,91 @@ class main implements renderable, templatable {
|
||||||
* @param string $grouping Grouping user preference
|
* @param string $grouping Grouping user preference
|
||||||
* @param string $sort Sort user preference
|
* @param string $sort Sort user preference
|
||||||
* @param string $view Display user preference
|
* @param string $view Display user preference
|
||||||
|
*
|
||||||
|
* @throws \dml_exception
|
||||||
*/
|
*/
|
||||||
public function __construct($grouping, $sort, $view, $paging) {
|
public function __construct($grouping, $sort, $view, $paging) {
|
||||||
$this->grouping = $grouping ? $grouping : BLOCK_MYOVERVIEW_GROUPING_ALL;
|
$this->grouping = $grouping ? $grouping : BLOCK_MYOVERVIEW_GROUPING_ALL;
|
||||||
$this->sort = $sort ? $sort : BLOCK_MYOVERVIEW_SORTING_TITLE;
|
$this->sort = $sort ? $sort : BLOCK_MYOVERVIEW_SORTING_TITLE;
|
||||||
$this->view = $view ? $view : BLOCK_MYOVERVIEW_VIEW_CARD;
|
|
||||||
$this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12;
|
$this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12;
|
||||||
|
|
||||||
$config = get_config('block_myoverview');
|
$config = get_config('block_myoverview');
|
||||||
if (!$config->displaycategories) {
|
if (!$config->displaycategories) {
|
||||||
$this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF;
|
$this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF;
|
||||||
} else {
|
} else {
|
||||||
$this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON;
|
$this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->set_available_layouts();
|
||||||
|
$this->view = $view ? $view : reset($this->layouts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the available layouts based on the config table settings,
|
||||||
|
* if none are available, defaults to the cards view.
|
||||||
|
*
|
||||||
|
* @throws \dml_exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function set_available_layouts() {
|
||||||
|
|
||||||
|
if ($config = get_config('block_myoverview', 'layouts')) {
|
||||||
|
$this->layouts = explode(',', $config);
|
||||||
|
} else {
|
||||||
|
$this->layouts = array(BLOCK_MYOVERVIEW_VIEW_CARD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user preferences as an array to figure out what has been selected
|
* Get the user preferences as an array to figure out what has been selected.
|
||||||
*
|
*
|
||||||
* @return array $preferences Array with the pref as key and value set to true
|
* @return array $preferences Array with the pref as key and value set to true
|
||||||
*/
|
*/
|
||||||
public function get_preferences_as_booleans() {
|
public function get_preferences_as_booleans() {
|
||||||
$preferences = [];
|
$preferences = [];
|
||||||
$preferences[$this->view] = true;
|
|
||||||
$preferences[$this->sort] = true;
|
$preferences[$this->sort] = true;
|
||||||
$preferences[$this->grouping] = true;
|
$preferences[$this->grouping] = true;
|
||||||
|
// Only use the user view/display preference if it is in available layouts.
|
||||||
|
if (in_array($this->view, $this->layouts)) {
|
||||||
|
$preferences[$this->view] = true;
|
||||||
|
} else {
|
||||||
|
$preferences[reset($this->layouts)] = true;
|
||||||
|
}
|
||||||
|
|
||||||
return $preferences;
|
return $preferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a layout into an object for export as a Context variable to template.
|
||||||
|
*
|
||||||
|
* @param string $layoutname
|
||||||
|
*
|
||||||
|
* @return \stdClass $layout an object representation of a layout
|
||||||
|
* @throws \coding_exception
|
||||||
|
*/
|
||||||
|
public function format_layout_for_export($layoutname) {
|
||||||
|
$layout = new stdClass();
|
||||||
|
|
||||||
|
$layout->id = $layoutname;
|
||||||
|
$layout->name = get_string($layoutname, 'block_myoverview');
|
||||||
|
$layout->active = $this->view == $layoutname ? true : false;
|
||||||
|
$layout->arialabel = get_string('aria:' . $layoutname, 'block_myoverview');
|
||||||
|
|
||||||
|
return $layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the available layouts formatted for export.
|
||||||
|
*
|
||||||
|
* @return array an array of objects representing available layouts
|
||||||
|
*/
|
||||||
|
public function get_formatted_available_layouts_for_export() {
|
||||||
|
|
||||||
|
return array_map(array($this, 'format_layout_for_export'), $this->layouts);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export this data so it can be used as the context for a mustache template.
|
* Export this data so it can be used as the context for a mustache template.
|
||||||
*
|
*
|
||||||
|
@ -118,16 +183,20 @@ class main implements renderable, templatable {
|
||||||
|
|
||||||
$nocoursesurl = $output->image_url('courses', 'block_myoverview')->out();
|
$nocoursesurl = $output->image_url('courses', 'block_myoverview')->out();
|
||||||
|
|
||||||
|
$preferences = $this->get_preferences_as_booleans();
|
||||||
|
$availablelayouts = $this->get_formatted_available_layouts_for_export();
|
||||||
|
|
||||||
$defaultvariables = [
|
$defaultvariables = [
|
||||||
'nocoursesimg' => $nocoursesurl,
|
'nocoursesimg' => $nocoursesurl,
|
||||||
'grouping' => $this->grouping,
|
'grouping' => $this->grouping,
|
||||||
'sort' => $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc',
|
'sort' => $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc',
|
||||||
'view' => $this->view,
|
// If the user preference display option is not available, default to first available layout.
|
||||||
|
'view' => in_array($this->view, $this->layouts) ? $this->view : reset($this->layouts),
|
||||||
'paging' => $this->paging,
|
'paging' => $this->paging,
|
||||||
|
'layouts' => $availablelayouts,
|
||||||
'displaycategories' => $this->displaycategories,
|
'displaycategories' => $this->displaycategories,
|
||||||
|
'displaydropdown' => (count($availablelayouts) > 1) ? true : false,
|
||||||
];
|
];
|
||||||
|
|
||||||
$preferences = $this->get_preferences_as_booleans();
|
|
||||||
return array_merge($defaultvariables, $preferences);
|
return array_merge($defaultvariables, $preferences);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,8 @@ $string['favourites'] = 'Starred';
|
||||||
$string['future'] = 'Future';
|
$string['future'] = 'Future';
|
||||||
$string['inprogress'] = 'In progress';
|
$string['inprogress'] = 'In progress';
|
||||||
$string['lastaccessed'] = 'Last accessed';
|
$string['lastaccessed'] = 'Last accessed';
|
||||||
|
$string['layouts'] = 'Available Layouts';
|
||||||
|
$string['layouts_help'] = 'The layouts which are available for selection by users';
|
||||||
$string['list'] = 'List';
|
$string['list'] = 'List';
|
||||||
$string['myoverview:myaddinstance'] = 'Add a new course overview block to Dashboard';
|
$string['myoverview:myaddinstance'] = 'Add a new course overview block to Dashboard';
|
||||||
$string['past'] = 'Past';
|
$string['past'] = 'Past';
|
||||||
|
|
|
@ -44,7 +44,7 @@ define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed');
|
||||||
/**
|
/**
|
||||||
* Constants for the user preferences view options
|
* Constants for the user preferences view options
|
||||||
*/
|
*/
|
||||||
define('BLOCK_MYOVERVIEW_VIEW_CARD', 'cards');
|
define('BLOCK_MYOVERVIEW_VIEW_CARD', 'card');
|
||||||
define('BLOCK_MYOVERVIEW_VIEW_LIST', 'list');
|
define('BLOCK_MYOVERVIEW_VIEW_LIST', 'list');
|
||||||
define('BLOCK_MYOVERVIEW_VIEW_SUMMARY', 'summary');
|
define('BLOCK_MYOVERVIEW_VIEW_SUMMARY', 'summary');
|
||||||
|
|
||||||
|
|
|
@ -34,4 +34,15 @@ if ($ADMIN->fulltree) {
|
||||||
get_string('displaycategories_help', 'block_myoverview'),
|
get_string('displaycategories_help', 'block_myoverview'),
|
||||||
1));
|
1));
|
||||||
|
|
||||||
|
$choices = array(BLOCK_MYOVERVIEW_VIEW_CARD => get_string('card', 'block_myoverview'),
|
||||||
|
BLOCK_MYOVERVIEW_VIEW_LIST => get_string('list', 'block_myoverview'),
|
||||||
|
BLOCK_MYOVERVIEW_VIEW_SUMMARY => get_string('summary', 'block_myoverview'));
|
||||||
|
|
||||||
|
$settings->add(new admin_setting_configmulticheckbox(
|
||||||
|
'block_myoverview/layouts',
|
||||||
|
get_string('layouts', 'block_myoverview'),
|
||||||
|
get_string('layouts_help', 'block_myoverview'),
|
||||||
|
$choices,
|
||||||
|
$choices));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,9 @@
|
||||||
{{> block_myoverview/nav-grouping-selector }}
|
{{> block_myoverview/nav-grouping-selector }}
|
||||||
|
|
||||||
{{> block_myoverview/nav-sort-selector }}
|
{{> block_myoverview/nav-sort-selector }}
|
||||||
|
{{#displaydropdown}}
|
||||||
{{> block_myoverview/nav-display-selector }}
|
{{> block_myoverview/nav-display-selector }}
|
||||||
|
{{/displaydropdown}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container-fluid p-0">
|
<div class="container-fluid p-0">
|
||||||
|
|
|
@ -31,26 +31,18 @@
|
||||||
aria-label="{{#str}} aria:displaydropdown, block_myoverview {{/str}}">
|
aria-label="{{#str}} aria:displaydropdown, block_myoverview {{/str}}">
|
||||||
{{#pix}} a/view_icon_active {{/pix}}
|
{{#pix}} a/view_icon_active {{/pix}}
|
||||||
<span class="d-sm-inline-block" data-active-item-text>
|
<span class="d-sm-inline-block" data-active-item-text>
|
||||||
{{#cards}}{{#str}} card, block_myoverview {{/str}}{{/cards}}
|
{{#card}}{{#str}} card, block_myoverview {{/str}}{{/card}}
|
||||||
{{#list}}{{#str}} list, block_myoverview {{/str}}{{/list}}
|
{{#list}}{{#str}} list, block_myoverview {{/str}}{{/list}}
|
||||||
{{#summary}}{{#str}} summary, block_myoverview {{/str}}{{/summary}}
|
{{#summary}}{{#str}} summary, block_myoverview {{/str}}{{/summary}}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu" data-show-active-item aria-labelledby="displaydropdown">
|
<ul class="dropdown-menu" data-show-active-item aria-labelledby="displaydropdown">
|
||||||
<li>
|
{{#layouts}}
|
||||||
<a class="dropdown-item {{#cards}}active{{/cards}}" href="#" data-display-option="display" data-value="cards" data-pref="cards" aria-label="{{#str}} aria:card, block_myoverview {{/str}}" aria-controls="courses-view-{{uniqid}}">
|
<li>
|
||||||
{{#str}} card, block_myoverview {{/str}}
|
<a class="dropdown-item {{#active}}active{{/active}}" href="#" data-display-option="display" data-value="{{id}}" data-pref="{{id}}" aria-label="{{arialabel}}" aria-controls="courses-view-{{uniqid}}">
|
||||||
</a>
|
{{name}}
|
||||||
</li>
|
</a>
|
||||||
<li>
|
</li>
|
||||||
<a class="dropdown-item {{#list}}active{{/list}}" href="#" data-display-option="display" data-value="list" data-pref="list" aria-label="{{#str}} aria:list, block_myoverview {{/str}}" aria-controls="courses-view-{{uniqid}}">
|
{{/layouts}}
|
||||||
{{#str}} list, block_myoverview {{/str}}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a class="dropdown-item {{#summary}}active{{/summary}}" href="#" data-display-option="display" data-value="summary" data-pref="summary" aria-label="{{#str}} aria:summary, block_myoverview {{/str}}" aria-controls="courses-view-{{uniqid}}">
|
|
||||||
{{#str}} summary, block_myoverview {{/str}}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$plugin->version = 2019052000; // The current plugin version (Date: YYYYMMDDXX).
|
$plugin->version = 2019060400; // The current plugin version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2019051100; // Requires this Moodle version.
|
$plugin->requires = 2019051100; // Requires this Moodle version.
|
||||||
$plugin->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).
|
$plugin->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue