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

@ -1,4 +1,4 @@
Copyright (C) 2022 Peter-Martijn Kuipers 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 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. 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. 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.

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,87 +1,108 @@
<?php <?php
use local_treestudyplan\studyplan; // This file is part of the Studyplan plugin for Moodle
//
class block_mytreestudyplan extends \block_base { // Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
public $levelset; // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
public function init() { //
global $PAGE; // Moodle is distributed in the hope that it will be useful,
global $CFG; // but WITHOUT ANY WARRANTY; without even the implied warranty of
$this->title = get_string('title', 'block_mytreestudyplan'); // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
$systemcontext = \context_system::instance(); // GNU General Public License for more details.
$teachermode = has_capability("local/treestudyplan:viewuserreports",$systemcontext); //
// You should have received a copy of the GNU General Public License
// Load CSS files from treestudyplan // along with Moodle. If not, see <https://www.gnu.org/licenses/>.
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')); * @package block_mytreestudyplan
// include javascript and run studyplan renderer when page loading is complete * @copyright 2023 P.M. Kuipers
$PAGE->requires->js_call_amd('block_mytreestudyplan/block_mytreestudyplan', 'init',[$teachermode?'teaching':'myreport']); * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
} 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 use local_treestudyplan\studyplan;
}
} class block_mytreestudyplan extends \block_base {
public $levelset;
public function applicable_formats()
{ public function init() {
// Limit this block to the site index and the dashboard (my) pages }
return [
'admin' => false, public function specialization() {
'site-index' => true, global $CFG;
'course-view' => false, $this->title = get_string('title', 'block_mytreestudyplan');
'mod' => false,
'my' => true $systemcontext = \context_system::instance();
]; $teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext);
}
// Load CSS files from treestudyplan.
try {
public function get_content() { $this->page->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue.min.css'));
global $CFG; $this->page->requires->css(new \moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
global $USER; // Include javascript and run studyplan renderer when page loading is complete.
global $COURSE; $this->page->requires->js_call_amd('block_mytreestudyplan/block_mytreestudyplan',
global $OUTPUT; 'init',
[$teachermode ? 'teaching' : 'myreport']);
if ($this->content !== null) { } catch (Exception $x) {
return $this->content; // 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.
$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); public function applicable_formats() {
// Limit this block to the site index and the dashboard (my) pages.
$this->content = new \stdClass; return [
$this->content->text = ""; 'admin' => false,
'site-index' => true,
$mystudyplans = studyplan::find_for_user($USER->id); 'course-view' => false,
'mod' => false,
$data = [ 'my' => true
'teachermode' => $teachermode, ];
]; }
$this->content->text = $OUTPUT->render_from_template("block_mytreestudyplan/block",$data); public function get_content() {
global $CFG;
$invite_url =$CFG->wwwroot.'/local/treestudyplan/invitations.php'; global $USER;
$invite_text = get_string('manage_invites','local_treestudyplan'); global $COURSE;
global $OUTPUT;
if ( (!$teachermode ) && count($mystudyplans) > 0) { if ($this->content !== null) {
$this->content->footer = "&nbsp; <a class='btn btn-primary' href='{$invite_url}'>{$invite_text}</a>"; return $this->content;
} }
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);
public function hide_header() { return false; }
$this->content = new \stdClass;
public function has_config() { return false; } $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 = "&nbsp; <a class='btn btn-primary' href='{$inviteurl}'>{$invitetext}</a>";
}
return $this->content;
}
public function hide_header() {
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
//
'block/mytreestudyplan:addinstance' => array( // Moodle is free software: you can redistribute it and/or modify
'riskbitmask' => RISK_SPAM | RISK_XSS, // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
'captype' => 'write', // (at your option) any later version.
'contextlevel' => CONTEXT_BLOCK, //
'archetypes' => array( // Moodle is distributed in the hope that it will be useful,
'editingteacher' => CAP_ALLOW, // but WITHOUT ANY WARRANTY; without even the implied warranty of
'manager' => CAP_ALLOW // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
), // GNU General Public License for more details.
//
'clonepermissionsfrom' => 'moodle/site:manageblocks' // 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();
$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'
],
];

View File

@ -1,6 +1,27 @@
<?php <?php
$string['pluginname'] = 'My Treestudyplan'; // This file is part of the Studyplan plugin for Moodle
$string['mytreestudyplan'] = 'MyTreestudyplan'; //
$string['title'] = 'My Studyplan'; // Moodle is free software: you can redistribute it and/or modify
$string['mytreestudyplan:addinstance'] = 'Add my studyplan block'; // 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['mytreestudyplan'] = 'MyTreestudyplan';
$string['title'] = 'My Studyplan';
$string['mytreestudyplan:addinstance'] = 'Add my studyplan block';

View File

@ -1,6 +1,27 @@
<?php <?php
$string['pluginname'] = 'Mijn Treestudyplan'; // This file is part of the Studyplan plugin for Moodle
$string['mytreestudyplan'] = 'MyTreestudyplan'; //
$string['title'] = 'Mijn Studieplan'; // Moodle is free software: you can redistribute it and/or modify
$string['mytreestudyplan:addinstance'] = 'Voeg mijn studieplan block toe'; // 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['mytreestudyplan'] = 'MyTreestudyplan';
$string['title'] = 'Mijn Studieplan';
$string['mytreestudyplan:addinstance'] = 'Voeg mijn studieplan block toe';

22
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
$plugin->dependencies = [ // the Free Software Foundation, either version 3 of the License, or
'local_treestudyplan' => 2022090800, // (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 = [
'local_treestudyplan' => 2023082101,
];