2022-06-26 20:05:36 +02:00
|
|
|
<?php
|
|
|
|
use local_treestudyplan\studyplan;
|
|
|
|
|
|
|
|
class block_mytreestudyplan extends \block_base {
|
|
|
|
|
|
|
|
public $levelset;
|
|
|
|
|
|
|
|
public function init() {
|
|
|
|
global $PAGE;
|
|
|
|
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{
|
|
|
|
$PAGE->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue.min.css'));
|
|
|
|
$PAGE->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
|
|
|
|
// include javascript and run studyplan renderer when page loading is complete
|
|
|
|
$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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function get_content() {
|
|
|
|
global $CFG;
|
|
|
|
global $USER;
|
|
|
|
global $COURSE;
|
|
|
|
global $OUTPUT;
|
|
|
|
|
|
|
|
if ($this->content !== null) {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
$coursecontext = \context_course::instance($COURSE->id);
|
|
|
|
$systemcontext = \context_system::instance();
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$invite_url =$CFG->wwwroot.'/local/treestudyplan/invitations.php';
|
|
|
|
$invite_text = get_string('manage_invites','local_treestudyplan');
|
|
|
|
|
|
|
|
|
|
|
|
if($teachermode){
|
2022-06-26 20:57:42 +02:00
|
|
|
$this->content->footer = "<a class='btn btn-primary' href='/local/treestudyplan/view-plans.php'>".get_string("view_plan","local_treestudyplan")."</a>";
|
2022-06-26 20:05:36 +02:00
|
|
|
if(has_capability("local/treestudyplan:editstudyplan",$systemcontext)){
|
|
|
|
$this->content->footer .= " <a class='btn btn-primary' href='{$invite_url}'>".get_string("cfg_plans","local_treestudyplan")."</a>";
|
|
|
|
}
|
|
|
|
} else if (count($mystudyplans) > 0) {
|
2022-06-26 20:57:42 +02:00
|
|
|
$this->content->footer = "<a class='btn btn-primary' href='/local/treestudyplan/edit-plans.php' id='manage_invites'><i class='fa fa-share'></i>{$invite_text}</a>";
|
2022-06-26 20:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function hide_header() { return false; }
|
|
|
|
|
|
|
|
public function has_config() { return false; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|