2023-08-27 08:36:25 +02:00
|
|
|
<?php
|
|
|
|
// This file is part of the Studyplan plugin for Moodle
|
|
|
|
//
|
|
|
|
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
/**
|
2023-08-27 08:53:37 +02:00
|
|
|
* Main block code
|
2023-08-27 08:36:25 +02:00
|
|
|
*
|
|
|
|
* @package block_mytreestudyplan
|
|
|
|
* @copyright 2023 P.M. Kuipers
|
|
|
|
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
use local_treestudyplan\studyplan;
|
|
|
|
|
2023-08-27 08:53:37 +02:00
|
|
|
/**
|
|
|
|
* MyTreestudyplan block base code
|
|
|
|
*/
|
2023-08-27 08:36:25 +02:00
|
|
|
class block_mytreestudyplan extends \block_base {
|
|
|
|
|
2023-08-27 08:53:37 +02:00
|
|
|
/**
|
|
|
|
* Plugin initialization (before $this->config and $this->page are loaded)
|
|
|
|
*/
|
2023-08-27 08:36:25 +02:00
|
|
|
public function init() {
|
|
|
|
}
|
|
|
|
|
2023-08-27 08:53:37 +02:00
|
|
|
/**
|
|
|
|
* Plugin specialization (directly called after $this->config and $this->page are ready)
|
|
|
|
*/
|
2023-08-27 08:36:25 +02:00
|
|
|
public function specialization() {
|
|
|
|
global $CFG;
|
|
|
|
$this->title = get_string('title', 'block_mytreestudyplan');
|
|
|
|
|
|
|
|
$systemcontext = \context_system::instance();
|
|
|
|
$teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext);
|
|
|
|
|
|
|
|
// Load CSS files from treestudyplan.
|
|
|
|
try {
|
2023-09-08 09:03:30 +02:00
|
|
|
$this->page->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.min.css'));
|
|
|
|
if($CFG->debugdeveloper){
|
|
|
|
$this->page->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
|
|
|
|
}
|
|
|
|
$this->page->add_body_class("features-treestudyplan"); // Mark body as containing treestudyplan content.
|
2023-08-27 08:36:25 +02:00
|
|
|
// Include javascript and run studyplan renderer when page loading is complete.
|
|
|
|
$this->page->requires->js_call_amd('block_mytreestudyplan/block_mytreestudyplan',
|
|
|
|
'init',
|
|
|
|
[$teachermode ? 'teaching' : 'myreport']);
|
|
|
|
} catch (Exception $x) {
|
|
|
|
// On some occasions (Plugin management), the plugin is loaded after HEAD has been printed.
|
|
|
|
// In those cases we don't want to show the block anyway, so ignore the error that gets inevitably thrown.
|
|
|
|
$off = 0; // Empty statement to satisfy code checker.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-27 08:53:37 +02:00
|
|
|
/**
|
|
|
|
* Publish the pages this block can be shown on
|
|
|
|
*/
|
2023-08-27 08:36:25 +02:00
|
|
|
public function applicable_formats() {
|
|
|
|
// Limit this block to the site index and the dashboard (my) pages.
|
|
|
|
return [
|
|
|
|
'admin' => false,
|
|
|
|
'site-index' => true,
|
|
|
|
'course-view' => false,
|
|
|
|
'mod' => false,
|
|
|
|
'my' => true
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-08-27 08:53:37 +02:00
|
|
|
/**
|
|
|
|
* Render block content
|
|
|
|
*/
|
2023-08-27 08:36:25 +02:00
|
|
|
public function get_content() {
|
|
|
|
global $CFG;
|
|
|
|
global $USER;
|
|
|
|
global $COURSE;
|
|
|
|
global $OUTPUT;
|
|
|
|
|
|
|
|
if ($this->content !== null) {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
$systemcontext = \context_system::instance();
|
|
|
|
|
|
|
|
// TODO: Check if they have the permission in any relevant context, not just system.
|
|
|
|
$teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext);
|
|
|
|
|
|
|
|
$this->content = new \stdClass;
|
|
|
|
$this->content->text = "";
|
|
|
|
|
|
|
|
$mystudyplans = studyplan::find_for_user($USER->id);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'teachermode' => $teachermode,
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->content->text = $OUTPUT->render_from_template("block_mytreestudyplan/block", $data);
|
|
|
|
|
|
|
|
$inviteurl = $CFG->wwwroot.'/local/treestudyplan/invitations.php';
|
|
|
|
$invitetext = get_string('manage_invites', 'local_treestudyplan');
|
|
|
|
|
|
|
|
if ( (!$teachermode ) && count($mystudyplans) > 0) {
|
|
|
|
$this->content->footer = " <a class='btn btn-primary' href='{$inviteurl}'>{$invitetext}</a>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
2023-08-27 08:53:37 +02:00
|
|
|
/**
|
|
|
|
* Whether to hide the header or not
|
|
|
|
*/
|
2023-08-27 08:36:25 +02:00
|
|
|
public function hide_header() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-27 08:53:37 +02:00
|
|
|
/**
|
|
|
|
* Whether this block has config or not
|
|
|
|
*/
|
2023-08-27 08:36:25 +02:00
|
|
|
public function has_config() {
|
|
|
|
return false;
|
|
|
|
}
|
2023-09-08 09:03:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true to avoid broken self-test message
|
|
|
|
*/
|
|
|
|
function _self_test() {
|
|
|
|
return true;
|
|
|
|
}
|
2023-08-27 08:36:25 +02:00
|
|
|
}
|