PHP coding style match

This commit is contained in:
PMKuipers 2023-08-27 08:36:25 +02:00
parent a669e34796
commit 1532a0d233
11 changed files with 320 additions and 152 deletions

View File

@ -9,16 +9,16 @@
import {call} from 'core/ajax'; import {call} from 'core/ajax';
import notification from 'core/notification'; import notification from 'core/notification';
import Vue from 'local_treestudyplan/vue'; import Vue from 'local_treestudyplan/vue/vue';
import RVComponents from 'local_treestudyplan/report-viewer-components'; import RVComponents from 'local_treestudyplan/report-viewer-components';
import TSComponents from 'local_treestudyplan/treestudyplan-components'; import TSComponents from 'local_treestudyplan/treestudyplan-components';
import Debugger from 'local_treestudyplan/debugger'; import Debugger from 'local_treestudyplan/util/debugger';
import {load_strings} from 'local_treestudyplan/string-helper'; import {load_strings} from 'local_treestudyplan/util/string-helper';
import {ProcessStudyplans, fixLineWrappers} from 'local_treestudyplan/studyplan-processor'; import {ProcessStudyplans} from 'local_treestudyplan/studyplan-processor';
import PortalVue from 'local_treestudyplan/portal-vue'; import PortalVue from 'local_treestudyplan/portal-vue/portal-vue.esm';
import BootstrapVue from 'local_treestudyplan/bootstrap-vue'; import BootstrapVue from 'local_treestudyplan/bootstrap-vue/bootstrap-vue.esm';
Vue.use(TSComponents); Vue.use(TSComponents);
Vue.use(RVComponents); Vue.use(RVComponents);
Vue.use(PortalVue); Vue.use(PortalVue);

View File

@ -1,4 +1,25 @@
<?php <?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/>.
/**
*
* @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; use local_treestudyplan\studyplan;
class block_mytreestudyplan extends \block_base { class block_mytreestudyplan extends \block_base {
@ -6,28 +27,32 @@ class block_mytreestudyplan extends \block_base {
public $levelset; public $levelset;
public function init() { public function init() {
global $PAGE; }
public function specialization() {
global $CFG; global $CFG;
$this->title = get_string('title', 'block_mytreestudyplan'); $this->title = get_string('title', 'block_mytreestudyplan');
$systemcontext = \context_system::instance();
$teachermode = has_capability("local/treestudyplan:viewuserreports",$systemcontext);
// Load CSS files from treestudyplan $systemcontext = \context_system::instance();
try{ $teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext);
$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')); // Load CSS files from treestudyplan.
// include javascript and run studyplan renderer when page loading is complete try {
$PAGE->requires->js_call_amd('block_mytreestudyplan/block_mytreestudyplan', 'init',[$teachermode?'teaching':'myreport']); $this->page->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue.min.css'));
} catch( Exception $x) { $this->page->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
// 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, // Include javascript and run studyplan renderer when page loading is complete.
// so ignore the error that gets inevitably thrown $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.
} }
} }
public function applicable_formats() {
public function applicable_formats() // Limit this block to the site index and the dashboard (my) pages.
{
// Limit this block to the site index and the dashboard (my) pages
return [ return [
'admin' => false, 'admin' => false,
'site-index' => true, 'site-index' => true,
@ -37,7 +62,6 @@ class block_mytreestudyplan extends \block_base {
]; ];
} }
public function get_content() { public function get_content() {
global $CFG; global $CFG;
global $USER; global $USER;
@ -48,12 +72,12 @@ class block_mytreestudyplan extends \block_base {
return $this->content; return $this->content;
} }
$coursecontext = \context_course::instance($COURSE->id);
$systemcontext = \context_system::instance(); $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; // 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 = ""; $this->content->text = "";
$mystudyplans = studyplan::find_for_user($USER->id); $mystudyplans = studyplan::find_for_user($USER->id);
@ -62,26 +86,23 @@ class block_mytreestudyplan extends \block_base {
'teachermode' => $teachermode, 'teachermode' => $teachermode,
]; ];
$this->content->text = $OUTPUT->render_from_template("block_mytreestudyplan/block",$data); $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');
$inviteurl = $CFG->wwwroot.'/local/treestudyplan/invitations.php';
$invitetext = get_string('manage_invites', 'local_treestudyplan');
if ( (!$teachermode ) && count($mystudyplans) > 0) { if ( (!$teachermode ) && count($mystudyplans) > 0) {
$this->content->footer = "&nbsp; <a class='btn btn-primary' href='{$invite_url}'>{$invite_text}</a>"; $this->content->footer = "&nbsp; <a class='btn btn-primary' href='{$inviteurl}'>{$invitetext}</a>";
} }
return $this->content; return $this->content;
} }
public function hide_header() {
return false;
}
public function hide_header() { return false; } public function has_config() {
return false;
public function has_config() { return false; } }
} }

View File

@ -1,15 +1,38 @@
<?php <?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/>.
/**
*
* @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('CLI_SCRIPT', true);
require_once("../../config.php");
$plugin = new stdClass; $plugin = new stdClass;
include('version.php'); require_once('version.php');
$a = explode("_",$plugin->component,2); $a = explode("_", $plugin->component, 2);
$plugin->type = $a[0]; $plugin->type = $a[0];
$plugin->name = $a[1]; $plugin->name = $a[1];
$exclude_paths = [ $excludepaths = [
"build", // dir for build zip files "build", // Dir for build zip files.
"build/*", "build/*",
"build.*", "build.*",
"vuemode.sh",
"amd/src", "amd/src",
"amd/src/*", "amd/src/*",
".git", ".git",
@ -18,28 +41,28 @@ $exclude_paths = [
"*.zip", "*.zip",
]; ];
// Determine some paths // Determine some paths.
$wd = realpath(dirname(__FILE__)); $wd = realpath(dirname(__FILE__));
$parent = dirname($wd); $parent = dirname($wd);
$plugindirname = basename($wd); $plugindirname = basename($wd);
$builddir = $wd."/"."build"; $builddir = $wd."/"."build";
$zipname = $builddir."/"."{$plugin->name}-{$plugin->version}.zip"; $zipname = $builddir."/"."{$plugin->name}-{$plugin->version}.zip";
// create the exclude line // Create the exclude line.
$exclude = "-x "; $exclude = "-x ";
foreach($exclude_paths as $x){ foreach ($excludepaths as $x) {
$exclude .= "'{$plugindirname}/{$x}' "; $exclude .= "'{$plugindirname}/{$x}' ";
} }
if(!is_dir($builddir)){ if (!is_dir($builddir)) {
mkdir($builddir); mkdir($builddir);
if(!is_dir($builddir)){ if (!is_dir($builddir)) {
print("Cannot access dir '{$builddir}' to store zip files\n"); print("Cannot access dir '{$builddir}' to store zip files\n");
exit(1); exit(1);
} }
} }
if(file_exists($zipfile)){ if (file_exists($zipfile)) {
print("Zip file '{$zipfile}' already exists. Exiting...\n"); print("Zip file '{$zipfile}' already exists. Exiting...\n");
exit(1); exit(1);
} }
@ -51,4 +74,3 @@ $cmd = "zip -r '{$zipname}' '{$plugindirname}' {$exclude}";
system($cmd); system($cmd);
chdir($cwd); chdir($cwd);

View File

@ -1,18 +1,35 @@
<?php <?php
$capabilities = array( // 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/>.
/**
*
* @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
'block/mytreestudyplan:addinstance' => array( $capabilities = [
'block/mytreestudyplan:addinstance' => [
'riskbitmask' => RISK_SPAM | RISK_XSS, 'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write', 'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK, 'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array( 'archetypes' => [
'editingteacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW 'manager' => CAP_ALLOW
), ],
'clonepermissionsfrom' => 'moodle/site:manageblocks' 'clonepermissionsfrom' => 'moodle/site:manageblocks'
), ],
];
);

View File

@ -1,4 +1,25 @@
<?php <?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/>.
/**
*
* @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'My Treestudyplan'; $string['pluginname'] = 'My Treestudyplan';
$string['mytreestudyplan'] = 'MyTreestudyplan'; $string['mytreestudyplan'] = 'MyTreestudyplan';
$string['title'] = 'My Studyplan'; $string['title'] = 'My Studyplan';

View File

@ -1,4 +1,25 @@
<?php <?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/>.
/**
*
* @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Mijn Treestudyplan'; $string['pluginname'] = 'Mijn Treestudyplan';
$string['mytreestudyplan'] = 'MyTreestudyplan'; $string['mytreestudyplan'] = 'MyTreestudyplan';
$string['title'] = 'Mijn Studieplan'; $string['title'] = 'Mijn Studieplan';

20
lib.php
View File

@ -1 +1,21 @@
<?php <?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/>.
/**
*
* @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View File

@ -1,2 +1,21 @@
<?php <?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/>.
/**
*
* @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View File

@ -15,9 +15,9 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>. along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}} }}
{{! {{!
@template plugintype_pluginname/template_name @template block_mytreestudyplan/block
Template purpose and description. Render my treestudyplan block
Classes required for JS: Classes required for JS:
* none * none
@ -33,7 +33,7 @@
} }
}} }}
<div id='block_mytreestudyplan' class='path-local-treestudyplan'> <div id='block_mytreestudyplan' class='features-treestudyplan'>
<div class='vue-loader' v-show='false'> <div class='vue-loader' v-show='false'>
<div class='spinner-border text-primary' role='status'> <div class='spinner-border text-primary' role='status'>
<span class='sr-only'>Loading...</span> <span class='sr-only'>Loading...</span>

View File

@ -1,8 +1,35 @@
<?php <?php
$plugin->component = 'block_mytreestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494) // This file is part of the Studyplan plugin for Moodle
$plugin->version = 2023081800; // YYYYMMDDHH (year, month, day, iteration) //
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11) // 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/>.
/**
*
* @package block_mytreestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'block_mytreestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
$plugin->version = 2023081800; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->release = "1.0.0";
$plugin->maturity = MATURITY_RC;
// Supported from Moodle 3.11 to 4.1 (4.2 not yet tested).
$plugin->supported = [ 311, 401 ];
$plugin->dependencies = [ $plugin->dependencies = [
'local_treestudyplan' => 2022090800, 'local_treestudyplan' => 2023082101,
]; ];