Merge branch 'MDL-64901-37_block_myoverview_layout_settings' of https://github.com/tomdickman/moodle

This commit is contained in:
Andrew Nicols
2019-06-24 06:44:11 +08:00
10 changed files with 109 additions and 34 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -363,7 +363,7 @@ function(
var filters = getFilterValues(root);
var currentTemplate = '';
if (filters.display == 'cards') {
if (filters.display == 'card') {
currentTemplate = TEMPLATES.COURSES_CARDS;
} else if (filters.display == 'list') {
currentTemplate = TEMPLATES.COURSES_LIST;
+1 -1
View File
@@ -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
*/
+80 -11
View File
@@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use templatable;
use stdClass;
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 {
/**
* Store the grouping preference
* Store the grouping preference.
*
* @var string String matching the grouping constants defined in myoverview/lib.php
*/
private $grouping;
/**
* Store the sort preference
* Store the sort preference.
*
* @var string String matching the sort constants defined in myoverview/lib.php
*/
private $sort;
/**
* Store the view preference
* Store the view preference.
*
* @var string String matching the view/display constants defined in myoverview/lib.php
*/
private $view;
/**
* Store the paging preference
* Store the paging preference.
*
* @var string String matching the paging constants defined in myoverview/lib.php
*/
private $paging;
/**
* Store the display categories config setting
* Store the display categories config setting.
*
* @var boolean
*/
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.
* Initialize the user preferences
@@ -80,34 +88,91 @@ class main implements renderable, templatable {
* @param string $grouping Grouping user preference
* @param string $sort Sort user preference
* @param string $view Display user preference
*
* @throws \dml_exception
*/
public function __construct($grouping, $sort, $view, $paging) {
$this->grouping = $grouping ? $grouping : BLOCK_MYOVERVIEW_GROUPING_ALL;
$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;
}
$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
*/
public function get_preferences_as_booleans() {
$preferences = [];
$preferences[$this->view] = true;
$preferences[$this->sort] = 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;
}
/**
* 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.
*
@@ -118,16 +183,20 @@ class main implements renderable, templatable {
$nocoursesurl = $output->image_url('courses', 'block_myoverview')->out();
$preferences = $this->get_preferences_as_booleans();
$availablelayouts = $this->get_formatted_available_layouts_for_export();
$defaultvariables = [
'nocoursesimg' => $nocoursesurl,
'grouping' => $this->grouping,
'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,
'layouts' => $availablelayouts,
'displaycategories' => $this->displaycategories,
'displaydropdown' => (count($availablelayouts) > 1) ? true : false,
];
$preferences = $this->get_preferences_as_booleans();
return array_merge($defaultvariables, $preferences);
}
@@ -55,6 +55,8 @@ $string['favourites'] = 'Starred';
$string['future'] = 'Future';
$string['inprogress'] = 'In progress';
$string['lastaccessed'] = 'Last accessed';
$string['layouts'] = 'Available Layouts';
$string['layouts_help'] = 'The layouts which are available for selection by users';
$string['list'] = 'List';
$string['myoverview:myaddinstance'] = 'Add a new course overview block to Dashboard';
$string['past'] = 'Past';
+1 -1
View File
@@ -44,7 +44,7 @@ define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed');
/**
* 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_SUMMARY', 'summary');
+11
View File
@@ -34,4 +34,15 @@ if ($ADMIN->fulltree) {
get_string('displaycategories_help', 'block_myoverview'),
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));
}
+3 -2
View File
@@ -29,8 +29,9 @@
{{> block_myoverview/nav-grouping-selector }}
{{> block_myoverview/nav-sort-selector }}
{{> block_myoverview/nav-display-selector }}
{{#displaydropdown}}
{{> block_myoverview/nav-display-selector }}
{{/displaydropdown}}
</div>
<div class="container-fluid p-0">
@@ -31,26 +31,18 @@
aria-label="{{#str}} aria:displaydropdown, block_myoverview {{/str}}">
{{#pix}} a/view_icon_active {{/pix}}
<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}}
{{#summary}}{{#str}} summary, block_myoverview {{/str}}{{/summary}}
</span>
</button>
<ul class="dropdown-menu" data-show-active-item aria-labelledby="displaydropdown">
<li>
<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}}">
{{#str}} card, block_myoverview {{/str}}
</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}}">
{{#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>
{{#layouts}}
<li>
<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}}">
{{name}}
</a>
</li>
{{/layouts}}
</ul>
</div>
+1 -1
View File
@@ -24,6 +24,6 @@
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->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).