MDL-58907 block_myoverview: added setting to select default tab

This commit is contained in:
Mark Nelson
2017-06-12 10:34:38 +08:00
parent 4c6063bff9
commit ff6cd55d79
6 changed files with 92 additions and 7 deletions
+22 -1
View File
@@ -24,6 +24,16 @@
defined('MOODLE_INTERNAL') || die();
/**
* The timeline view.
*/
define('BLOCK_MYOVERVIEW_TIMELINE_VIEW', 'timeline');
/**
* The courses view.
*/
define('BLOCK_MYOVERVIEW_COURSES_VIEW', 'courses');
/**
* My overview block class.
*
@@ -50,7 +60,9 @@ class block_myoverview extends block_base {
return $this->content;
}
$renderable = new \block_myoverview\output\main();
$config = get_config('block_myoverview');
$renderable = new \block_myoverview\output\main($config->defaulttab);
$renderer = $this->page->get_renderer('block_myoverview');
$this->content = new stdClass();
@@ -68,4 +80,13 @@ class block_myoverview extends block_base {
public function applicable_formats() {
return array('my' => true);
}
/**
* This block does contain a configuration settings.
*
* @return boolean
*/
public function has_config() {
return true;
}
}
+26 -1
View File
@@ -39,6 +39,20 @@ require_once($CFG->libdir . '/completionlib.php');
*/
class main implements renderable, templatable {
/**
* @var string The tab to display.
*/
public $tab;
/**
* Constructor.
*
* @param string $tab The tab to display.
*/
public function __construct($tab) {
$this->tab = $tab;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
@@ -73,13 +87,24 @@ class main implements renderable, templatable {
$nocoursesurl = $output->image_url('courses', 'block_myoverview')->out();
$noeventsurl = $output->image_url('activities', 'block_myoverview')->out();
// Now, set the tab we are going to be viewing.
$viewingtimeline = false;
$viewingcourses = false;
if ($this->tab == BLOCK_MYOVERVIEW_TIMELINE_VIEW) {
$viewingtimeline = true;
} else {
$viewingcourses = true;
}
return [
'midnight' => usergetmidnight(time()),
'coursesview' => $coursesview->export_for_template($output),
'urls' => [
'nocourses' => $nocoursesurl,
'noevents' => $noeventsurl
]
],
'viewingtimeline' => $viewingtimeline,
'viewingcourses' => $viewingcourses
];
}
}
@@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['defaulttab'] = 'Default tab';
$string['defaulttab_desc'] = 'This is the default tab that will be shown to a user.';
$string['future'] = 'Future';
$string['inprogress'] = 'In progress';
$string['morecourses'] = 'More courses';
+37
View File
@@ -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 overview block.
*
* @package block_myoverview
* @copyright 2017 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
$options = [
BLOCK_MYOVERVIEW_TIMELINE_VIEW => get_string('timeline', 'block_myoverview'),
BLOCK_MYOVERVIEW_COURSES_VIEW => get_string('courses')
];
$settings->add(new admin_setting_configselect('block_myoverview/defaulttab',
get_string('defaulttab', 'block_myoverview'),
get_string('defaulttab_desc', 'block_myoverview'), 'timeline', $options));
}
+4 -4
View File
@@ -26,21 +26,21 @@
<div id="block-myoverview-{{uniqid}}" class="block-myoverview" data-region="myoverview">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" href="#myoverview_timeline_view" role="tab" data-toggle="tab">
<a class="nav-link {{#viewingtimeline}}active{{/viewingtimeline}}" href="#myoverview_timeline_view" role="tab" data-toggle="tab">
{{#str}} timeline, block_myoverview {{/str}}
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#myoverview_courses_view" role="tab" data-toggle="tab">
<a class="nav-link {{#viewingcourses}}active{{/viewingcourses}}" href="#myoverview_courses_view" role="tab" data-toggle="tab">
{{#str}} courses {{/str}}
</a>
</li>
</ul>
<div class="tab-content content-centred">
<div role="tabpanel" class="tab-pane fade in active" id="myoverview_timeline_view">
<div role="tabpanel" class="tab-pane fade {{#viewingtimeline}}in active{{/viewingtimeline}}" id="myoverview_timeline_view">
{{> block_myoverview/timeline-view }}
</div>
<div role="tabpanel" class="tab-pane fade" id="myoverview_courses_view">
<div role="tabpanel" class="tab-pane fade {{#viewingcourses}}in active{{/viewingcourses}}" id="myoverview_courses_view">
{{#coursesview}}
{{> block_myoverview/courses-view }}
{{/coursesview}}
+1 -1
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017051500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2017051501; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2017050500; // Requires this Moodle version.
$plugin->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).