Moodle code style fixes part 9

This commit is contained in:
PMKuipers 2023-08-25 13:04:19 +02:00
parent 6e9d0cac4a
commit 00b38f0a49
48 changed files with 235 additions and 337 deletions

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan;
defined('MOODLE_INTERNAL') || die();
class contextinfo {
public $context;

View File

@ -162,7 +162,7 @@ class courseservice extends \external_api {
$cats = static::categories_by_capability($capability);
$list = [];
/* @var $cat \core_course_category */
foreach ($cats as $cat) {
$list[] = static::map_category($cat, true);
}
@ -390,7 +390,9 @@ class courseservice extends \external_api {
// Get the connected users.
$students = associationservice::all_associated($studyplanid);
// Just get the user ids.
$studentids = array_map(function ($a) { return $a["id"];}, $students);
$studentids = array_map(function ($a) {
return $a["id"];
}, $students);
return [
"total" => count($studentids),

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan\local\aggregators;
defined('MOODLE_INTERNAL') || die();
use \local_treestudyplan\courseinfo;
use \local_treestudyplan\gradeinfo;

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan\local\aggregators;
defined('MOODLE_INTERNAL') || die();
use \local_treestudyplan\courseinfo;
use \local_treestudyplan\corecompletioninfo;

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan\local\aggregators;
defined('MOODLE_INTERNAL') || die();
use \local_treestudyplan\courseinfo;
use \local_treestudyplan\gradeinfo;
@ -91,7 +90,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
return completion::INCOMPLETE;
}
} else {
// Indeterminable, return null.
// Indeterminable.
return null;
}
}

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan\local;
defined('MOODLE_INTERNAL') || die();
use Exception;

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan\local\ungradedscanners;
defined('MOODLE_INTERNAL') || die();
class assign_scanner extends scanner_base {

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan\local\ungradedscanners;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/question/engine/states.php'); // For reading question state.

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan\local\ungradedscanners;
defined('MOODLE_INTERNAL') || die();
use \grade_item;

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\collection;
use \core_privacy\local\request\userlist;

View File

@ -27,13 +27,11 @@ require_once("$CFG->dirroot/local/treestudyplan/lib.php");
class reportinvite_form extends moodleform {
// Add elements to form.
const GOALS_EDITOR_OPTIONS = array('trusttext' => true, 'subdirs' => true, 'maxfiles' => 0, 'maxbytes' => 5*1024*1025);
public function definition() {
global $CFG;
// 'code', 'revision', 'description', 'goals', 'complexity', 'points', 'studyhours'.
$mform = $this->_form; // Don't forget the underscore! .
$mform = $this->_form; // Don't forget the underscore!
$mform->addElement('hidden', 'add', 0);
$mform->setType('add', PARAM_ALPHANUM);
@ -61,11 +59,6 @@ class reportinvite_form extends moodleform {
return array();
}
public function set_data($data) {
parent::set_data($data);
}
public function get_data() {
global $DB, $USER;
@ -87,10 +80,10 @@ class reportinvite_form extends moodleform {
do {
$length = 20;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$characterslength = strlen($characters);
$randomkey = '';
for ($i = 0; $i < $length; $i++) {
$randomkey .= $characters[rand(0, $charactersLength - 1)];
$randomkey .= $characters[rand(0, $characterslength - 1)];
}
// Double check that the key is unique before inserting.

View File

@ -555,7 +555,7 @@ class studyplan {
return $plan->import_pages_model($content["studyplan"]["pages"]);
} else {
error_log("Invalid format and type: {$content['type']} version {$content['version']}");
debugging("Invalid format and type: {$content['type']} version {$content['version']}");
return false;
}
}

View File

@ -590,9 +590,7 @@ class studyplanservice extends \external_api {
$badges = badges_get_badges(BADGE_TYPE_SITE, "timemodified");
foreach ($badges as $badge) {
// TODO: Add config option to list only active badges.
// if ($badge->is_active()) {.
$result[] = (new badgeinfo($badge))->editor_model();
// }.
// TODO: Include course badges somehow... Just site badges is not enough.

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan;
defined('MOODLE_INTERNAL') || die();
class success {
private $success;

View File

@ -21,7 +21,6 @@
*/
namespace local_treestudyplan;
defined('MOODLE_INTERNAL') || die();
class teachingfinder {
const TABLE = "local_treestudyplan_teachers";

View File

@ -66,7 +66,7 @@ if ($options['help']) {
exit(2);
}
/////////////////////////////////.
// Get administrator role and log in as.
$user = get_admin();
if (!$user) {
@ -74,7 +74,7 @@ if (!$user) {
}
$auth = empty($user->auth) ? 'manual' : $user->auth;
if ($auth == 'nologin' or !is_enabled_auth($auth)) {
if ($auth == 'nologin' || !is_enabled_auth($auth)) {
cli_error(sprintf("User authentication is either 'nologin' or disabled. Check Moodle authentication method for '%s'",
$user->username));
}
@ -84,7 +84,7 @@ $authplugin->sync_roles($user);
login_attempt_valid($user);
complete_user_login($user);
////////////////////////////////.
// Handle the studyplans.
if (empty($options['studyplan']) && empty($options["all"])) {
cli_error('Missing mandatory argument studyplan.', 2);

View File

@ -19,6 +19,7 @@
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = [

View File

@ -1,18 +0,0 @@
SLOT INDEX 0 SLOT INDEX [1,slots]
--------------- --------------------------------------
[FILTER SLOT] [ [COMPETENCY SLOT] [FILTER SLOT ] ]
Types allowed Types allowed Types allowed
- START - COMPETENCY - JUNCTION
- BADGE
- FINISH
- CONTINUATION
Type description
- START : Copies the state of an ITEM (FINISH ITEM) in another studyplan. It is used to allow continuation across studyplans
- COMPETENCY :
- JUNCTION :
- BADGE :
- FINISH : Denotes the final outcome of a studyline in a studyplan
CONDITIONS:

View File

@ -20,6 +20,8 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$services = [
"Competency listing" => [
'functions' => [

View File

@ -19,6 +19,7 @@
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = [
[

View File

@ -311,7 +311,7 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
$plans->close();
}
/**
/*******
* Finalize studyline table to drop studyplan_id field and have page id be a non-nullable and foreign key
*/
@ -338,7 +338,7 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
// Launch add key page_id-id.
$dbman->add_key($table, $key);
/***
/*******
* Create Period table and make a period record for all studyplan periods
*/

View File

@ -59,7 +59,7 @@ if (!empty($add)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $update));
$data->update = $update;
if (empty($data) || $data->user_id != $USER->id) {
print_error('invalidaction');
throw new \moodle_exception('invalidaction', 'local_treestudyplan');;
exit;
}
@ -67,7 +67,7 @@ if (!empty($add)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend));
$data->resend = $resend;
if (empty($data) || $data->user_id != $USER->id) {
print_error('invalidaction');
throw new \moodle_exception('invalidaction', 'local_treestudyplan');;
exit;
}
@ -80,7 +80,7 @@ if (!empty($add)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete));
$data->delete = $delete;
if (empty($data) || $data->user_id != $USER->id) {
print_error('invalidaction');
throw new \moodle_exception('invalidaction', 'local_treestudyplan');;
exit;
}
@ -90,7 +90,7 @@ if (!empty($add)) {
print $OUTPUT->footer();
exit;
} else {
print_error('invalidaction');
throw new \moodle_exception('invalidaction', 'local_treestudyplan');;
}
$mform = new reportinvite_form();
@ -120,9 +120,8 @@ if ($mform->is_cancelled()) {
exit;
} else if (!empty($data->delete)) {
exit;
} else
{
print_error("invaliddata");
} else {
throw new \moodle_exception("invaliddata", 'local_treestudyplan');;
}
exit;

View File

@ -41,8 +41,7 @@ if ($categoryid > 0) {
$studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
$categoryid = $studyplancontext->instanceid;
} else
{
} else {
$studyplancontext = $systemcontext;
}
} else {

View File

@ -20,24 +20,16 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (isset($_SERVER['SCRIPT_FILENAME'])) {
// If SCRIPT_FILENAME is set, use that so the symlinked directories the developmen environment uses are handled correctly.
$root = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
error_log("Using {$root}/config.php");
require_once($root."/config.php");
} else {
// If not, assume the cwd is not symlinked and proceed as we are used to.
require_once("../../config.php");
}
require_once($CFG->libdir.'/weblib.php');
require_once($CFG->dirroot.'/grade/querylib.php');
use local_treestudyplan;
$INVITEDURL = "/local/treestudyplan/invited.php";
$invitedurl = "/local/treestudyplan/invited.php";
// Admin_externalpage_setup('major');.
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/invitations.php", array());
@ -52,7 +44,7 @@ $PAGE->set_heading(get_string('manage_invites', 'local_treestudyplan'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-invitemanager', 'init');
$PAGE->requires->js_call_amd('local_treestudyplan/buttonlinks', 'init');
// retrieve list of courses that the student is enrolled in.
// Retrieve list of courses that the student is enrolled in.
$sent = optional_param('sent', '', PARAM_INT);
if (!empty($sent)) {
$invite = $DB->get_record('local_treestudyplan_invit', array('id' => $sent));
@ -78,7 +70,7 @@ print "</thead>";
print "<tbody>";
if (count($invites) > 0) {
foreach ($invites as $invite) {
$testlink = $INVITEDURL."?key={$invite->invitekey}";
$testlink = $invitedurl."?key={$invite->invitekey}";
print "<tr data-id='{$invite->id}'>";
print "<td data-field='name'>{$invite->name}</td>";
print "<td data-field='email'>{$invite->email}</td>";

View File

@ -21,6 +21,7 @@
*/
require_once("../../config.php");
// Since this page is externally accessed and validated in a different way, no login is needed.
// Local translate function.
function t($str, $param = null, $plugin = 'local_treestudyplan') {

28
lib.php
View File

@ -20,17 +20,19 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/modlib.php');
use local_treestudyplan\local\helpers\webservicehelper;
use \local_treestudyplan\studyplan;
defined('MOODLE_INTERNAL') || die();
function local_treestudyplan_unit_get_editor_options($context) {
global $CFG;
return ['subdirs' => 1,
'maxbytes' => $CFG->maxbytes,
'maxfiles' =>-1, 'changeformat' => 1,
'maxfiles' => -1,
'changeformat' => 1,
'context' => $context,
'noclean' => 1,
'trusttext' => 0];
@ -56,7 +58,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
and not much more complex than loading a separate stylesheet for each link we want to hide).
We will add all the hrefs that should be hidden to this variable below.
*/
$hideprimary_hrefs = [];
$hideprimaryhrefs = [];
if ($USER->id > 1) {
// Don't show if user is not logged in (id == 0) or is guest user (id == 1).
@ -90,7 +92,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$navigation->add_node($node, 'mycourses');
} else {
$hideprimary_hrefs[] = "/local/treestudyplan/myreport.php";
$hideprimaryhrefs[] = "/local/treestudyplan/myreport.php";
}
if ( has_capability('local/treestudyplan:viewuserreports', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports')) {
@ -106,7 +108,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$node->showinsecondarynavigation = true;
$navigation->add_node($node, 'mycourses');
} else {
$hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php";
$hideprimaryhrefs[] = "/local/treestudyplan/view-plan.php";
}
if ( has_capability('local/treestudyplan:editstudyplan', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan')
@ -123,12 +125,12 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$node->showinsecondarynavigation = true;
$navigation->add_node($node, 'mycourses');
} else {
$hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php";
$hideprimaryhrefs[] = "/local/treestudyplan/edit-plan.php";
}
} else {
$hideprimary_hrefs[] = "/local/treestudyplan/myreport.php";
$hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php";
$hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php";
$hideprimaryhrefs[] = "/local/treestudyplan/myreport.php";
$hideprimaryhrefs[] = "/local/treestudyplan/edit-plan.php";
$hideprimaryhrefs[] = "/local/treestudyplan/view-plan.php";
}
// Create invitenode node.
$invitenode = navigation_node::create(
@ -143,7 +145,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$navigation->add_node($invitenode, 'mycourses');
// Now using some javascript magic, we'll hide the links that are not accessible.
$PAGE->requires->js_call_amd('local_treestudyplan/primary-nav-tools', 'hide_primary', [$hideprimary_hrefs]);
$PAGE->requires->js_call_amd('local_treestudyplan/primary-nav-tools', 'hide_primary', [$hideprimaryhrefs]);
}
@ -275,7 +277,9 @@ function local_treestudyplan_get_cohort_path($cohort) {
$cohortcontext = context::instance_by_id($cohort->contextid);
if ($cohortcontext && $cohortcontext->id != SYSCONTEXTID) {
$ctxpath = array_map(
function($ctx) { return $ctx->get_context_name(false);},
function($ctx) {
return $ctx->get_context_name(false);
},
$cohortcontext->get_parent_contexts(true)
);
array_pop($ctxpath); // Pop system context off the list.
@ -313,7 +317,7 @@ function local_treestudyplan_output_fragment_mod_edit_form($args) {
if (file_exists($modmoodleform)) {
require_once($modmoodleform);
} else {
print_error('noformdesc');
throw new \moodle_exception('noformdesc', 'local_treestudyplan');;
}
$mformclassname = 'mod_'.$module->name.'_mod_form';

View File

@ -1,64 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<style>
.scroll-y {
overflow-y: auto;
height: 200px;
background-color:aquamarine;
}
.scroll-x {
overflow-x: auto;
width: 400px;
background-color: lawngreen;
}
.container {
position: relative;
}
.gridcontainer {
display: grid;
grid-template-columns: 200px auto 200px;
}
.simpleline {
color: brown;
}
.item {
border-style:solid;
border-width: 1px;
border-color: darkgreen;
background-color: lightgreen;
}
.block {
display: inline-block;
}
</style>
<script type ="module" defer>
import { SimpleLine } from "../amd/src/simpleline.js";
let line = new SimpleLine("#start","#end", {autorefresh: 10});
let line2 = new SimpleLine("#start2","#end2",{autorefresh: 10, anchors: {start: ["bottom","right"], end: ["top","left"]}});
</script>
</head>
<body>
<div class="scroll-y">
<h2> Header</h2>
<div class="scroll-x container">
<div class="gridcontainer">
<div id="start" class="item">Random text to show stuff</div>
<div class="item"><textarea></textarea></div>
<div></div>
<div></div>
<div></div>
<div id="end" class="item">More random text</div>
</div>
</div>
</div>
<div class="container">
<div id="start2" class="item block">Random text to show stuff</div>
<div class="item block"><textarea></textarea></div>
<div id="end2" class="item block">More random text</div>
</div>
</body>
</html>

View File

@ -41,8 +41,7 @@ if ($categoryid > 0) {
$studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
$categoryid = $studyplancontext->instanceid;
} else
{
} else {
$studyplancontext = $systemcontext;
}
} else {