Skip to content

Instantly share code, notes, and snippets.

@willianmano
Created November 27, 2018 13:43
Show Gist options
  • Save willianmano/db047ea5b7c358608ff0ae9c3662ab5e to your computer and use it in GitHub Desktop.
Save willianmano/db047ea5b7c358608ff0ae9c3662ab5e to your computer and use it in GitHub Desktop.
Customização do block myoverview Moodle 3.5
{{!
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/>.
}}
{{!
@template block_myoverview/main
This template renders the main content area for the myoverview block.
Example context (json):
{}
}}
<div id="block-myoverview-{{uniqid}}" class="block-myoverview" data-region="myoverview">
<ul id="block-myoverview-view-choices-{{uniqid}}" class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link {{#viewingtimeline}}active{{/viewingtimeline}}" href="#myoverview_timeline_view" role="tab" data-toggle="tab" data-tabname="timeline">
{{#str}} timeline, block_myoverview {{/str}}
</a>
</li>
<li class="nav-item">
<a class="nav-link {{#viewingcourses}}active{{/viewingcourses}}" href="#myoverview_courses_view" role="tab" data-toggle="tab" data-tabname="courses">
{{#str}} courses {{/str}}
</a>
</li>
<li class="nav-item">
<a class="nav-link {{#viewingcategories}}active{{/viewingcategories}}" href="#myoverview_categories_view" role="tab" data-toggle="tab" data-tabname="categories">
Categorias
</a>
</li>
</ul>
<div class="tab-content content-centred">
<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 {{#viewingcourses}}in active{{/viewingcourses}}" id="myoverview_courses_view">
{{#coursesview}}
{{> block_myoverview/courses-view }}
{{/coursesview}}
</div>
<div role="tabpanel" class="tab-pane fade {{#viewingcategories}}in active{{/viewingcategories}}" id="myoverview_categories_view">
<ul>
{{#viewingcategories}}
<li>{{{name}}}</li>
{{/viewingcategories}}
</ul>
</div>
</div>
</div>
{{#js}}
require(['jquery', 'block_myoverview/tab_preferences'], function($, TabPreferences) {
var root = $('#block-myoverview-view-choices-{{uniqid}}');
TabPreferences.registerEventListeners(root);
});
{{/js}}
<?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/>.
/**
* Class containing data for my overview block.
*
* @package block_myoverview
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_myoverview\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use templatable;
use core_completion\progress;
require_once($CFG->dirroot . '/blocks/myoverview/lib.php');
require_once($CFG->libdir . '/completionlib.php');
/**
* Class containing data for my overview block.
*
* @copyright 2017 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
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.
*
* @param \renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $USER;
$courses = enrol_get_my_courses('*');
$coursesprogress = [];
foreach ($courses as $course) {
$completion = new \completion_info($course);
// First, let's make sure completion is enabled.
if (!$completion->is_enabled()) {
continue;
}
$percentage = progress::get_course_progress_percentage($course);
if (!is_null($percentage)) {
$percentage = floor($percentage);
}
$coursesprogress[$course->id]['completed'] = $completion->is_course_complete($USER->id);
$coursesprogress[$course->id]['progress'] = $percentage;
}
$coursesview = new courses_view($courses, $coursesprogress);
$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;
}
$viewingcategories = [
[
'name' => 'Categoria #1'
],
[
'name' => 'Categoria #2'
],
[
'name' => 'Categoria #3'
]
];
return [
'midnight' => usergetmidnight(time()),
'coursesview' => $coursesview->export_for_template($output),
'urls' => [
'nocourses' => $nocoursesurl,
'noevents' => $noeventsurl
],
'viewingtimeline' => $viewingtimeline,
'viewingcourses' => $viewingcourses,
'viewingcategories' => $viewingcategories
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment