Skip to content

Commit

Permalink
MDL-58907 block_myoverview: added setting to select default tab
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Jun 12, 2017
1 parent 4c6063b commit ff6cd55
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 7 deletions.
23 changes: 22 additions & 1 deletion blocks/myoverview/block_myoverview.php
Expand Up @@ -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.
*
Expand All @@ -50,7 +60,9 @@ public function get_content() {
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();
Expand All @@ -68,4 +80,13 @@ public function get_content() {
public function applicable_formats() {
return array('my' => true);
}

/**
* This block does contain a configuration settings.
*
* @return boolean
*/
public function has_config() {
return true;
}
}
27 changes: 26 additions & 1 deletion blocks/myoverview/classes/output/main.php
Expand Up @@ -39,6 +39,20 @@
*/
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.
*
Expand Down Expand Up @@ -73,13 +87,24 @@ public function export_for_template(renderer_base $output) {
$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
];
}
}
2 changes: 2 additions & 0 deletions blocks/myoverview/lang/en/block_myoverview.php
Expand Up @@ -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';
Expand Down
37 changes: 37 additions & 0 deletions blocks/myoverview/settings.php
@@ -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 <markn@moodle.com>
* @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));
}
8 changes: 4 additions & 4 deletions blocks/myoverview/templates/main.mustache
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion blocks/myoverview/version.php
Expand Up @@ -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).

0 comments on commit ff6cd55

Please sign in to comment.