diff --git a/blocks/myoverview/block_myoverview.php b/blocks/myoverview/block_myoverview.php index f22ce15decb..f3885a1a81b 100644 --- a/blocks/myoverview/block_myoverview.php +++ b/blocks/myoverview/block_myoverview.php @@ -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; + } } diff --git a/blocks/myoverview/classes/output/main.php b/blocks/myoverview/classes/output/main.php index 6215a5a372d..bf3268e814f 100644 --- a/blocks/myoverview/classes/output/main.php +++ b/blocks/myoverview/classes/output/main.php @@ -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 ]; } } diff --git a/blocks/myoverview/lang/en/block_myoverview.php b/blocks/myoverview/lang/en/block_myoverview.php index 4c464f57c0b..99fb83f8864 100644 --- a/blocks/myoverview/lang/en/block_myoverview.php +++ b/blocks/myoverview/lang/en/block_myoverview.php @@ -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'; diff --git a/blocks/myoverview/settings.php b/blocks/myoverview/settings.php new file mode 100644 index 00000000000..f545d17328c --- /dev/null +++ b/blocks/myoverview/settings.php @@ -0,0 +1,37 @@ +. + +/** + * Settings for the overview block. + * + * @package block_myoverview + * @copyright 2017 Mark Nelson + * @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)); +} diff --git a/blocks/myoverview/templates/main.mustache b/blocks/myoverview/templates/main.mustache index 3a1a942c349..74bae299fa4 100644 --- a/blocks/myoverview/templates/main.mustache +++ b/blocks/myoverview/templates/main.mustache @@ -26,21 +26,21 @@
-
+
{{> block_myoverview/timeline-view }}
-
+
{{#coursesview}} {{> block_myoverview/courses-view }} {{/coursesview}} diff --git a/blocks/myoverview/version.php b/blocks/myoverview/version.php index fd45f7709a0..0452a78c820 100644 --- a/blocks/myoverview/version.php +++ b/blocks/myoverview/version.php @@ -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).