From 1532a0d233af11635f55b13cd8d8d2f74a70958a Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Sun, 27 Aug 2023 08:36:25 +0200 Subject: [PATCH] PHP coding style match --- LICENSE | 8 +- amd/src/block_mytreestudyplan.js | 12 +- block_mytreestudyplan.php | 195 +++++++++++++++++------------- build.php | 44 +++++-- db/access.php | 53 +++++--- lang/en/block_mytreestudyplan.php | 33 ++++- lang/nl/block_mytreestudyplan.php | 33 ++++- lib.php | 22 +++- settings.php | 23 +++- templates/block.mustache | 6 +- version.php | 43 +++++-- 11 files changed, 320 insertions(+), 152 deletions(-) diff --git a/LICENSE b/LICENSE index 3072204..c17f2e0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (C) 2022 Peter-Martijn Kuipers -This program 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 2 of the License, or (at your option) any later version. -This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 , USA. Also add information on how to contact you by electronic and paper mail. +Copyright (C) 2022 Peter-Martijn Kuipers +This program 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 2 of the License, or (at your option) any later version. +This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 , USA. Also add information on how to contact you by electronic and paper mail. diff --git a/amd/src/block_mytreestudyplan.js b/amd/src/block_mytreestudyplan.js index ec14ed1..e246dee 100644 --- a/amd/src/block_mytreestudyplan.js +++ b/amd/src/block_mytreestudyplan.js @@ -9,16 +9,16 @@ import {call} from 'core/ajax'; 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 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 {ProcessStudyplans, fixLineWrappers} from 'local_treestudyplan/studyplan-processor'; +import {load_strings} from 'local_treestudyplan/util/string-helper'; +import {ProcessStudyplans} from 'local_treestudyplan/studyplan-processor'; -import PortalVue from 'local_treestudyplan/portal-vue'; -import BootstrapVue from 'local_treestudyplan/bootstrap-vue'; +import PortalVue from 'local_treestudyplan/portal-vue/portal-vue.esm'; +import BootstrapVue from 'local_treestudyplan/bootstrap-vue/bootstrap-vue.esm'; Vue.use(TSComponents); Vue.use(RVComponents); Vue.use(PortalVue); diff --git a/block_mytreestudyplan.php b/block_mytreestudyplan.php index 5e9ebd7..4a3e43f 100644 --- a/block_mytreestudyplan.php +++ b/block_mytreestudyplan.php @@ -1,87 +1,108 @@ -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(); - //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); - - $invite_url =$CFG->wwwroot.'/local/treestudyplan/invitations.php'; - $invite_text = get_string('manage_invites','local_treestudyplan'); - - - if ( (!$teachermode ) && count($mystudyplans) > 0) { - $this->content->footer = "  {$invite_text}"; - } - - return $this->content; - } - - - public function hide_header() { return false; } - - public function has_config() { return false; } - - - - - -} \ No newline at end of file +. +/** + * + * @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; + +class block_mytreestudyplan extends \block_base { + + public $levelset; + + public function init() { + } + + 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 { + $this->page->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue.min.css')); + $this->page->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css')); + // 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. + } + } + + 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; + } + + $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 = "  {$invitetext}"; + } + + return $this->content; + } + + public function hide_header() { + return false; + } + + public function has_config() { + return false; + } +} diff --git a/build.php b/build.php index 39115f9..e83604c 100644 --- a/build.php +++ b/build.php @@ -1,15 +1,38 @@ . +/** + * + * @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; -include('version.php'); +require_once('version.php'); -$a = explode("_",$plugin->component,2); +$a = explode("_", $plugin->component, 2); $plugin->type = $a[0]; $plugin->name = $a[1]; -$exclude_paths = [ - "build", // dir for build zip files +$excludepaths = [ + "build", // Dir for build zip files. "build/*", "build.*", + "vuemode.sh", "amd/src", "amd/src/*", ".git", @@ -18,28 +41,28 @@ $exclude_paths = [ "*.zip", ]; -// Determine some paths +// Determine some paths. $wd = realpath(dirname(__FILE__)); $parent = dirname($wd); $plugindirname = basename($wd); $builddir = $wd."/"."build"; $zipname = $builddir."/"."{$plugin->name}-{$plugin->version}.zip"; -// create the exclude line +// Create the exclude line. $exclude = "-x "; -foreach($exclude_paths as $x){ +foreach ($excludepaths as $x) { $exclude .= "'{$plugindirname}/{$x}' "; } -if(!is_dir($builddir)){ +if (!is_dir($builddir)) { mkdir($builddir); - if(!is_dir($builddir)){ + if (!is_dir($builddir)) { print("Cannot access dir '{$builddir}' to store zip files\n"); exit(1); } } -if(file_exists($zipfile)){ +if (file_exists($zipfile)) { print("Zip file '{$zipfile}' already exists. Exiting...\n"); exit(1); } @@ -51,4 +74,3 @@ $cmd = "zip -r '{$zipname}' '{$plugindirname}' {$exclude}"; system($cmd); chdir($cwd); - diff --git a/db/access.php b/db/access.php index 0ad179a..7bc4266 100644 --- a/db/access.php +++ b/db/access.php @@ -1,18 +1,35 @@ - array( - 'riskbitmask' => RISK_SPAM | RISK_XSS, - - 'captype' => 'write', - 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array( - 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - - 'clonepermissionsfrom' => 'moodle/site:manageblocks' - ), - - -); \ No newline at end of file +. +/** + * + * @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(); + +$capabilities = [ + 'block/mytreestudyplan:addinstance' => [ + 'riskbitmask' => RISK_SPAM | RISK_XSS, + 'captype' => 'write', + 'contextlevel' => CONTEXT_BLOCK, + 'archetypes' => [ + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ], + 'clonepermissionsfrom' => 'moodle/site:manageblocks' + ], +]; diff --git a/lang/en/block_mytreestudyplan.php b/lang/en/block_mytreestudyplan.php index 73acb80..f16d122 100644 --- a/lang/en/block_mytreestudyplan.php +++ b/lang/en/block_mytreestudyplan.php @@ -1,6 +1,27 @@ -. +/** + * + * @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['mytreestudyplan'] = 'MyTreestudyplan'; +$string['title'] = 'My Studyplan'; +$string['mytreestudyplan:addinstance'] = 'Add my studyplan block'; + diff --git a/lang/nl/block_mytreestudyplan.php b/lang/nl/block_mytreestudyplan.php index 8e50a83..83bf69a 100644 --- a/lang/nl/block_mytreestudyplan.php +++ b/lang/nl/block_mytreestudyplan.php @@ -1,6 +1,27 @@ -. +/** + * + * @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['mytreestudyplan'] = 'MyTreestudyplan'; +$string['title'] = 'Mijn Studieplan'; +$string['mytreestudyplan:addinstance'] = 'Voeg mijn studieplan block toe'; + diff --git a/lib.php b/lib.php index 6fd199e..7a8c719 100644 --- a/lib.php +++ b/lib.php @@ -1 +1,21 @@ -. +/** + * + * @package block_mytreestudyplan + * @copyright 2023 P.M. Kuipers + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ diff --git a/settings.php b/settings.php index ab4fa67..7a8c719 100644 --- a/settings.php +++ b/settings.php @@ -1,2 +1,21 @@ -. +/** + * + * @package block_mytreestudyplan + * @copyright 2023 P.M. Kuipers + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ diff --git a/templates/block.mustache b/templates/block.mustache index 99442e3..af83c85 100644 --- a/templates/block.mustache +++ b/templates/block.mustache @@ -15,9 +15,9 @@ along with Moodle. If not, see . }} {{! - @template plugintype_pluginname/template_name + @template block_mytreestudyplan/block - Template purpose and description. + Render my treestudyplan block Classes required for JS: * none @@ -33,7 +33,7 @@ } }} -
+
Loading... diff --git a/version.php b/version.php index 88c4a66..bbf0ca1 100644 --- a/version.php +++ b/version.php @@ -1,8 +1,35 @@ -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->dependencies = [ - 'local_treestudyplan' => 2022090800, -]; \ No newline at end of file +. +/** + * + * @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 = [ + 'local_treestudyplan' => 2023082101, +];