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

@ -98,7 +98,7 @@ abstract class aggregator {
return ""; return "";
} }
public static function basic_structure($value=VALUE_REQUIRED) { public static function basic_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"useRequiredGrades" => new \external_value(PARAM_BOOL, 'id of studyplan'), "useRequiredGrades" => new \external_value(PARAM_BOOL, 'id of studyplan'),
"useItemConditions" => new \external_value(PARAM_BOOL, 'name of studyplan'), "useItemConditions" => new \external_value(PARAM_BOOL, 'name of studyplan'),
@ -112,7 +112,7 @@ abstract class aggregator {
]; ];
} }
public static function list_structure($value=VALUE_REQUIRED) { public static function list_structure($value = VALUE_REQUIRED) {
return new \external_multiple_structure(new \external_single_structure([ return new \external_multiple_structure(new \external_single_structure([
"id" => new \external_value(PARAM_TEXT, 'id of aggregator'), "id" => new \external_value(PARAM_TEXT, 'id of aggregator'),
"name" => new \external_value(PARAM_TEXT, 'name of agregator'), "name" => new \external_value(PARAM_TEXT, 'name of agregator'),

View File

@ -113,7 +113,7 @@ class associationservice extends \external_api {
} }
// Actual functions. // Actual functions.
public static function list_cohort($like='', $excludeid=null, $contextid=1) { public static function list_cohort($like = '', $excludeid = null, $contextid = 1) {
global $CFG, $DB; global $CFG, $DB;
// Only allow this if the user has the right to edit in this context. // Only allow this if the user has the right to edit in this context.
@ -159,7 +159,7 @@ class associationservice extends \external_api {
} }
// Actual functions. // Actual functions.
public static function find_user($like, $excludeid=null, $contextid=1) { public static function find_user($like, $excludeid = null, $contextid = 1) {
global $CFG, $DB; global $CFG, $DB;
// Only allow this if the user has the right to edit in this context. // Only allow this if the user has the right to edit in this context.
@ -427,7 +427,7 @@ class associationservice extends \external_api {
public static function sortusermodels(&$list) { public static function sortusermodels(&$list) {
return usort($list, function($a, $b) { return usort($list, function($a, $b) {
$m= []; $m = [];
if (preg_match("/.*?([A-Z].*)/", $a['lastname'], $m)) { if (preg_match("/.*?([A-Z].*)/", $a['lastname'], $m)) {
$sortln_a = $m[1]; $sortln_a = $m[1];
} else { } else {
@ -438,7 +438,7 @@ class associationservice extends \external_api {
} else { } else {
$sortln_b = $b['lastname']; $sortln_b = $b['lastname'];
} }
$cmp= $sortln_a <=> $sortln_b; $cmp = $sortln_a <=> $sortln_b;
return ($cmp != 0) ? $cmp : $a['firstname'] <=> $b['firstname']; return ($cmp != 0) ? $cmp : $a['firstname'] <=> $b['firstname'];
}); });
} }

View File

@ -63,7 +63,7 @@ class badgeinfo {
return is_numeric($id) && $DB->record_exists('badge', array('id' => $id)); return is_numeric($id) && $DB->record_exists('badge', array('id' => $id));
} }
public static function editor_structure($value=VALUE_REQUIRED) { public static function editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of badge'), "id" => new \external_value(PARAM_INT, 'id of badge'),
"infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL), "infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL),
@ -81,7 +81,7 @@ class badgeinfo {
], "Badge info", $value); ], "Badge info", $value);
} }
public function editor_model(array $studentlist=null) { public function editor_model(array $studentlist = null) {
if ($this->badge->type == BADGE_TYPE_SITE) { if ($this->badge->type == BADGE_TYPE_SITE) {
$context = \context_system::instance(); $context = \context_system::instance();
} else { } else {
@ -114,7 +114,7 @@ class badgeinfo {
return $model; return $model;
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of badge'), "id" => new \external_value(PARAM_INT, 'id of badge'),
"infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL), "infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL),

View File

@ -52,7 +52,7 @@ class completion {
} }
} }
public static function structure($value=VALUE_REQUIRED) { public static function structure($value = VALUE_REQUIRED) {
return new \external_value( PARAM_TEXT, return new \external_value( PARAM_TEXT,
'completion state (failed|incomplete|pending|progress|completed|good|excellent)', 'completion state (failed|incomplete|pending|progress|completed|good|excellent)',
$value); $value);

View File

@ -102,7 +102,7 @@ class completionscanner {
return $this->pending_cache[$userid]; return $this->pending_cache[$userid];
} }
public static function structure($value=VALUE_OPTIONAL) { public static function structure($value = VALUE_OPTIONAL) {
return new \external_single_structure([ return new \external_single_structure([
"ungraded" => new \external_value(PARAM_INT, 'number of ungraded submissions'), "ungraded" => new \external_value(PARAM_INT, 'number of ungraded submissions'),
"completed" => new \external_value(PARAM_INT, 'number of completed students'), "completed" => new \external_value(PARAM_INT, 'number of completed students'),

View File

@ -21,7 +21,6 @@
*/ */
namespace local_treestudyplan; namespace local_treestudyplan;
defined('MOODLE_INTERNAL') || die();
class contextinfo { class contextinfo {
public $context; public $context;
@ -29,7 +28,7 @@ class contextinfo {
$this->context = $context; $this->context = $context;
} }
public static function structure($value=VALUE_REQUIRED) { public static function structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"name" => new \external_value(PARAM_TEXT, 'context name'), "name" => new \external_value(PARAM_TEXT, 'context name'),
"shortname" => new \external_value(PARAM_TEXT, 'context short name'), "shortname" => new \external_value(PARAM_TEXT, 'context short name'),

View File

@ -73,7 +73,7 @@ class corecompletioninfo {
return self::$COMPLETIONHANDLES[$completion] ?? "undefined"; return self::$COMPLETIONHANDLES[$completion] ?? "undefined";
} }
public static function completion_item_editor_structure($value=VALUE_REQUIRED) { public static function completion_item_editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'criteria id', VALUE_OPTIONAL), "id" => new \external_value(PARAM_INT, 'criteria id', VALUE_OPTIONAL),
"title" => new \external_value(PARAM_TEXT, 'name of subitem', VALUE_OPTIONAL), "title" => new \external_value(PARAM_TEXT, 'name of subitem', VALUE_OPTIONAL),
@ -88,7 +88,7 @@ class corecompletioninfo {
], 'completion type', $value); ], 'completion type', $value);
} }
public static function completion_type_editor_structure($value=VALUE_REQUIRED) { public static function completion_type_editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"items" => new \external_multiple_structure(self::completion_item_editor_structure(), 'subitems', VALUE_OPTIONAL), "items" => new \external_multiple_structure(self::completion_item_editor_structure(), 'subitems', VALUE_OPTIONAL),
"title" => new \external_value(PARAM_TEXT, 'optional title', VALUE_OPTIONAL), "title" => new \external_value(PARAM_TEXT, 'optional title', VALUE_OPTIONAL),
@ -98,7 +98,7 @@ class corecompletioninfo {
], 'completion type', $value); ], 'completion type', $value);
} }
public static function editor_structure($value=VALUE_REQUIRED) { public static function editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"conditions" => new \external_multiple_structure(self::completion_type_editor_structure(), 'completion conditions'), "conditions" => new \external_multiple_structure(self::completion_type_editor_structure(), 'completion conditions'),
"aggregation" => new \external_value(PARAM_TEXT, 'completion aggregation ["all", "any"]'), "aggregation" => new \external_value(PARAM_TEXT, 'completion aggregation ["all", "any"]'),
@ -106,7 +106,7 @@ class corecompletioninfo {
], 'course completion info', $value); ], 'course completion info', $value);
} }
public static function completion_item_user_structure($value=VALUE_REQUIRED) { public static function completion_item_user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of completion', VALUE_OPTIONAL), "id" => new \external_value(PARAM_INT, 'id of completion', VALUE_OPTIONAL),
"title" => new \external_value(PARAM_TEXT, 'name of subitem', VALUE_OPTIONAL), "title" => new \external_value(PARAM_TEXT, 'name of subitem', VALUE_OPTIONAL),
@ -127,7 +127,7 @@ class corecompletioninfo {
], 'completion type', $value); ], 'completion type', $value);
} }
public static function completion_type_user_structure($value=VALUE_REQUIRED) { public static function completion_type_user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"items" => new \external_multiple_structure(self::completion_item_user_structure(), 'subitems', VALUE_OPTIONAL), "items" => new \external_multiple_structure(self::completion_item_user_structure(), 'subitems', VALUE_OPTIONAL),
"title" => new \external_value(PARAM_TEXT, 'optional title', VALUE_OPTIONAL), "title" => new \external_value(PARAM_TEXT, 'optional title', VALUE_OPTIONAL),
@ -142,7 +142,7 @@ class corecompletioninfo {
], 'completion type', $value); ], 'completion type', $value);
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"progress" => new \external_value(PARAM_INT, 'completed sub-conditions'), "progress" => new \external_value(PARAM_INT, 'completed sub-conditions'),
"enabled" => new \external_value(PARAM_BOOL, "whether completion is enabled here"), "enabled" => new \external_value(PARAM_BOOL, "whether completion is enabled here"),
@ -156,7 +156,7 @@ class corecompletioninfo {
} }
private static function aggregation_handle($method) { private static function aggregation_handle($method) {
return ($method==COMPLETION_AGGREGATION_ALL) ? "all" : "any"; return ($method ==COMPLETION_AGGREGATION_ALL) ? "all" : "any";
} }
public function editor_model() { public function editor_model() {
@ -447,7 +447,7 @@ class corecompletioninfo {
private function get_grade($cm, $userid) { private function get_grade($cm, $userid) {
// TODO: Display grade in the way described in the course setup (with letters if needed). // TODO: Display grade in the way described in the course setup (with letters if needed).
$gi= grade_item::fetch(['itemtype' => 'mod', $gi = grade_item::fetch(['itemtype' => 'mod',
'itemmodule' => $cm->modname, 'itemmodule' => $cm->modname,
'iteminstance' => $cm->instance, 'iteminstance' => $cm->instance,
'courseid' => $this->course->id]); // Make sure we only get results relevant to this course. 'courseid' => $this->course->id]); // Make sure we only get results relevant to this course.
@ -490,7 +490,7 @@ class corecompletioninfo {
*/ */
private function get_course_grade($userid) { private function get_course_grade($userid) {
// TODO: Display grade in the way described in the course setup (with letters if needed). // TODO: Display grade in the way described in the course setup (with letters if needed).
$gi= grade_item::fetch(['itemtype' => 'course', $gi = grade_item::fetch(['itemtype' => 'course',
'iteminstance' => $this->course->id, 'iteminstance' => $this->course->id,
'courseid' => $this->course->id]); 'courseid' => $this->course->id]);

View File

@ -76,7 +76,7 @@ class courseinfo {
return is_enrolled($this->coursecontext, $USER, 'mod/assign:grade'); return is_enrolled($this->coursecontext, $USER, 'mod/assign:grade');
} }
protected function iCanSelectGradables($userid=-1) { protected function iCanSelectGradables($userid = -1) {
global $USER, $DB; global $USER, $DB;
if ($userid <= 0) { if ($userid <= 0) {
$usr = $USER; $usr = $USER;
@ -157,7 +157,7 @@ class courseinfo {
return $this->course->shortname; return $this->course->shortname;
} }
public static function simple_structure($value=VALUE_REQUIRED) { public static function simple_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'linked course id'), "id" => new \external_value(PARAM_INT, 'linked course id'),
"fullname" => new \external_value(PARAM_TEXT, 'linked course name'), "fullname" => new \external_value(PARAM_TEXT, 'linked course name'),
@ -180,7 +180,7 @@ class courseinfo {
return $info; return $info;
} }
public static function editor_structure($value=VALUE_REQUIRED) { public static function editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'linked course id'), "id" => new \external_value(PARAM_INT, 'linked course id'),
"fullname" => new \external_value(PARAM_TEXT, 'linked course name'), "fullname" => new \external_value(PARAM_TEXT, 'linked course name'),
@ -201,7 +201,7 @@ class courseinfo {
], 'referenced course information', $value); ], 'referenced course information', $value);
} }
public function editor_model(studyitem $studyitem=null, $usecorecompletioninfo=false) { public function editor_model(studyitem $studyitem = null, $usecorecompletioninfo = false) {
global $DB; global $DB;
$contextinfo = new contextinfo($this->context); $contextinfo = new contextinfo($this->context);
@ -238,7 +238,7 @@ class courseinfo {
return $info; return $info;
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'linked course id'), "id" => new \external_value(PARAM_INT, 'linked course id'),
"fullname" => new \external_value(PARAM_TEXT, 'linked course name'), "fullname" => new \external_value(PARAM_TEXT, 'linked course name'),
@ -254,7 +254,7 @@ class courseinfo {
], 'course information', $value); ], 'course information', $value);
} }
public function user_model($userid, $usecorecompletioninfo=false) { public function user_model($userid, $usecorecompletioninfo = false) {
global $DB; global $DB;
$contextinfo = new contextinfo($this->context); $contextinfo = new contextinfo($this->context);

View File

@ -51,7 +51,7 @@ class courseservice extends \external_api {
return new \external_multiple_structure(static::map_category_structure(false)); return new \external_multiple_structure(static::map_category_structure(false));
} }
protected static function map_category_structure($lazy=false, $value=VALUE_REQUIRED) { protected static function map_category_structure($lazy = false, $value = VALUE_REQUIRED) {
$s = [ $s = [
"id" => new \external_value(PARAM_INT, 'course category id'), "id" => new \external_value(PARAM_INT, 'course category id'),
"context_id" => new \external_value(PARAM_INT, 'course category context id'), "context_id" => new \external_value(PARAM_INT, 'course category context id'),
@ -112,7 +112,7 @@ class courseservice extends \external_api {
return static::map_category($cat); return static::map_category($cat);
} }
protected static function map_category(\core_course_category $cat, $lazy=false) { protected static function map_category(\core_course_category $cat, $lazy = false) {
global $DB; global $DB;
$catcontext = $cat->get_context(); $catcontext = $cat->get_context();
$ctxinfo = new contextinfo($catcontext); $ctxinfo = new contextinfo($catcontext);
@ -152,7 +152,7 @@ class courseservice extends \external_api {
return new \external_multiple_structure(static::map_category_structure(true)); return new \external_multiple_structure(static::map_category_structure(true));
} }
public static function list_accessible_categories($operation="edit") { public static function list_accessible_categories($operation = "edit") {
if ($operation == "edit") { if ($operation == "edit") {
$capability = self::CAP_EDIT; $capability = self::CAP_EDIT;
} else { // Operation == "view" || default. } else { // Operation == "view" || default.
@ -162,7 +162,7 @@ class courseservice extends \external_api {
$cats = static::categories_by_capability($capability); $cats = static::categories_by_capability($capability);
$list = []; $list = [];
/* @var $cat \core_course_category */
foreach ($cats as $cat) { foreach ($cats as $cat) {
$list[] = static::map_category($cat, true); $list[] = static::map_category($cat, true);
} }
@ -170,7 +170,7 @@ class courseservice extends \external_api {
} }
public static function categories_by_capability($capability, \core_course_category $parent=null) { public static function categories_by_capability($capability, \core_course_category $parent = null) {
// List the categories in which the user has a specific capability. // List the categories in which the user has a specific capability.
$list = []; $list = [];
// Initialize parent if needed. // Initialize parent if needed.
@ -221,7 +221,7 @@ class courseservice extends \external_api {
return new \external_multiple_structure(static::map_category_structure(true)); return new \external_multiple_structure(static::map_category_structure(true));
} }
public static function list_used_categories($operation='edit') { public static function list_used_categories($operation = 'edit') {
global $DB; global $DB;
if ($operation == "edit") { if ($operation == "edit") {
$capability = self::CAP_EDIT; $capability = self::CAP_EDIT;
@ -255,7 +255,7 @@ class courseservice extends \external_api {
return $list; return $list;
} }
public static function list_accessible_categories_with_usage($operation='edit') { public static function list_accessible_categories_with_usage($operation = 'edit') {
global $DB; global $DB;
if ($operation == "edit") { if ($operation == "edit") {
$capability = self::CAP_EDIT; $capability = self::CAP_EDIT;
@ -306,7 +306,7 @@ class courseservice extends \external_api {
} }
public static function scan_grade_progress_returns() { public static function scan_grade_progress_returns() {
return gradingscanner::structure(VALUE_REQUIRED); return gradingscanner::structure(VALUE_REQUIRED);
} }
public static function scan_grade_progress($gradeitemid, $studyplanid) { public static function scan_grade_progress($gradeitemid, $studyplanid) {
@ -390,7 +390,9 @@ class courseservice extends \external_api {
// Get the connected users. // Get the connected users.
$students = associationservice::all_associated($studyplanid); $students = associationservice::all_associated($studyplanid);
// Just get the user ids. // Just get the user ids.
$studentids = array_map(function ($a) { return $a["id"];}, $students); $studentids = array_map(function ($a) {
return $a["id"];
}, $students);
return [ return [
"total" => count($studentids), "total" => count($studentids),

View File

@ -183,7 +183,7 @@ class gradeinfo {
return(false); return(false);
} }
public static function editor_structure($value=VALUE_REQUIRED) { public static function editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'grade_item id'), "id" => new \external_value(PARAM_INT, 'grade_item id'),
"cmid" => new \external_value(PARAM_INT, 'course module id'), "cmid" => new \external_value(PARAM_INT, 'course module id'),
@ -222,7 +222,7 @@ class gradeinfo {
return $model; return $model;
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'grade_item id'), "id" => new \external_value(PARAM_INT, 'grade_item id'),
"cmid" => new \external_value(PARAM_INT, 'course module id'), "cmid" => new \external_value(PARAM_INT, 'course module id'),
@ -293,7 +293,7 @@ class gradeinfo {
public static function import(studyitem $item, array $model) { public static function import(studyitem $item, array $model) {
if ($item->type() == studyitem::COURSE) { if ($item->type() == studyitem::COURSE) {
$courseid = $item->courseid(); $courseid = $item->courseid();
$gradeitems= grade_item::fetch_all(['itemtype' => 'mod', 'courseid' => $courseid]); $gradeitems = grade_item::fetch_all(['itemtype' => 'mod', 'courseid' => $courseid]);
foreach ($gradeitems as $gi) { foreach ($gradeitems as $gi) {
$giname = empty($outcome) ? $gi->itemname : $outcome->name; $giname = empty($outcome) ? $gi->itemname : $outcome->name;
$gitype = $gi->itemmodule; $gitype = $gi->itemmodule;
@ -314,7 +314,7 @@ class gradeinfo {
} }
} }
public static function list_course_gradables($course, studyitem $studyitem=null) { public static function list_course_gradables($course, studyitem $studyitem = null) {
$list = []; $list = [];
if (method_exists("\course_modinfo", "get_array_of_activities")) { if (method_exists("\course_modinfo", "get_array_of_activities")) {
@ -325,7 +325,7 @@ class gradeinfo {
} }
foreach ($activities as $act) { foreach ($activities as $act) {
if ($act->visible) { if ($act->visible) {
$gradeitems= grade_item::fetch_all(['itemtype' => 'mod', $gradeitems = grade_item::fetch_all(['itemtype' => 'mod',
'itemmodule' => $act->mod, 'itemmodule' => $act->mod,
'iteminstance' => $act->id, 'iteminstance' => $act->id,
'courseid' => $course->id]); 'courseid' => $course->id]);
@ -376,7 +376,7 @@ class gradeinfo {
return $list; return $list;
} }
public static function include_grade(int $gradeid, int $itemid, bool $include, bool $required=false) { public static function include_grade(int $gradeid, int $itemid, bool $include, bool $required = false) {
global $DB; global $DB;
$table = 'local_treestudyplan_gradeinc'; $table = 'local_treestudyplan_gradeinc';
if ($include) { if ($include) {

View File

@ -79,7 +79,7 @@ class gradingscanner {
return $this->pending_cache[$userid]; return $this->pending_cache[$userid];
} }
public static function structure($value=VALUE_OPTIONAL) { public static function structure($value = VALUE_OPTIONAL) {
return new \external_single_structure([ return new \external_single_structure([
"ungraded" => new \external_value(PARAM_INT, 'number of ungraded submissions'), "ungraded" => new \external_value(PARAM_INT, 'number of ungraded submissions'),
"completed" => new \external_value(PARAM_INT, 'number of completed students'), "completed" => new \external_value(PARAM_INT, 'number of completed students'),

View File

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

View File

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

View File

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

View File

@ -21,7 +21,6 @@
*/ */
namespace local_treestudyplan\local; namespace local_treestudyplan\local;
defined('MOODLE_INTERNAL') || die();
use Exception; use Exception;
@ -136,7 +135,7 @@ class gradegenerator {
$results = []; $results = [];
$gaveup = false; $gaveup = false;
for ($i=0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$r = new \stdClass; $r = new \stdClass;
if ($gaveup) { if ($gaveup) {
$r->done = !$gaveup; $r->done = !$gaveup;
@ -169,12 +168,12 @@ class gradegenerator {
public function generate($student, $skill, array $gradeinfos ) { public function generate($student, $skill, array $gradeinfos ) {
global $DB; global $DB;
$table ="local_treestudyplan_gradecfg"; $table = "local_treestudyplan_gradecfg";
$rlist = []; $rlist = [];
$gen = $this->generateraw($student, $skill, count($gradeinfos)); $gen = $this->generateraw($student, $skill, count($gradeinfos));
for ($i=0; $i < count($gradeinfos); $i++) { for ($i = 0; $i < count($gradeinfos); $i++) {
$g = $gradeinfos[$i]; $g = $gradeinfos[$i];
$gi = $g->getGradeitem(); $gi = $g->getGradeitem();
$gr = $gen[$i]; $gr = $gen[$i];

View File

@ -61,7 +61,7 @@ class webservicehelper {
* @param \core_course_category $parent The parent category to use as a scanning base. Used internally. * @param \core_course_category $parent The parent category to use as a scanning base. Used internally.
* @return boolean * @return boolean
*/ */
public static function has_capability_in_any_category($capability, \core_course_category $parent=null) { public static function has_capability_in_any_category($capability, \core_course_category $parent = null) {
// List the categories in which the user has a specific capability. // List the categories in which the user has a specific capability.
$list = []; $list = [];
@ -101,7 +101,7 @@ class webservicehelper {
* @param bool $validate Validate the context before checking capabilities * @param bool $validate Validate the context before checking capabilities
* @throws \webservice_access_exception If none of the capabilities provided are given to the current user * @throws \webservice_access_exception If none of the capabilities provided are given to the current user
*/ */
public static function require_capabilities($capability, $context=null, $validate=true) { public static function require_capabilities($capability, $context = null, $validate = true) {
if ($validate) { if ($validate) {
\external_api::validate_context($context); \external_api::validate_context($context);
} }

View File

@ -21,7 +21,6 @@
*/ */
namespace local_treestudyplan\local\ungradedscanners; namespace local_treestudyplan\local\ungradedscanners;
defined('MOODLE_INTERNAL') || die();
class assign_scanner extends scanner_base { class assign_scanner extends scanner_base {
@ -51,7 +50,7 @@ class assign_scanner extends scanner_base {
return $DB->get_fieldset_sql($sql); return $DB->get_fieldset_sql($sql);
} }
public function count_ungraded($courseuserids=[]) { public function count_ungraded($courseuserids = []) {
$ungraded = $this->get_ungraded_submissions(); $ungraded = $this->get_ungraded_submissions();
if (count($courseuserids) > 0) { if (count($courseuserids) > 0) {
@ -60,7 +59,7 @@ class assign_scanner extends scanner_base {
return count($ungraded); return count($ungraded);
} }
public function count_graded($courseuserids=[]) { public function count_graded($courseuserids = []) {
$ungraded = $this->get_ungraded_submissions(); $ungraded = $this->get_ungraded_submissions();
$graded = $this->get_graded_users(); $graded = $this->get_graded_users();

View File

@ -21,7 +21,6 @@
*/ */
namespace local_treestudyplan\local\ungradedscanners; namespace local_treestudyplan\local\ungradedscanners;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/question/engine/states.php'); // For reading question state. require_once($CFG->dirroot.'/question/engine/states.php'); // For reading question state.
@ -55,7 +54,7 @@ class quiz_scanner extends scanner_base {
return array_keys($submissions); return array_keys($submissions);
} }
public function count_ungraded($courseuserids=[]) { public function count_ungraded($courseuserids = []) {
$ungraded = $this->get_ungraded_submissions(); $ungraded = $this->get_ungraded_submissions();
if (count($courseuserids) > 0) { if (count($courseuserids) > 0) {
$ungraded = array_intersect($ungraded, $courseuserids); $ungraded = array_intersect($ungraded, $courseuserids);
@ -63,7 +62,7 @@ class quiz_scanner extends scanner_base {
return count($ungraded); return count($ungraded);
} }
public function count_graded($courseuserids=[]) { public function count_graded($courseuserids = []) {
// Count all users who submitted one or more finished tests. // Count all users who submitted one or more finished tests.
global $DB; global $DB;
$sql = "SELECT DISTINCT g.userid $sql = "SELECT DISTINCT g.userid

View File

@ -21,7 +21,6 @@
*/ */
namespace local_treestudyplan\local\ungradedscanners; namespace local_treestudyplan\local\ungradedscanners;
defined('MOODLE_INTERNAL') || die();
use \grade_item; use \grade_item;
@ -32,9 +31,9 @@ abstract class scanner_base {
$this->gi = $gi; $this->gi = $gi;
} }
abstract public function count_ungraded($courseuserids=[]); abstract public function count_ungraded($courseuserids = []);
abstract public function count_graded($courseuserids=[]); abstract public function count_graded($courseuserids = []);
abstract public function has_ungraded_submission($userid); abstract public function has_ungraded_submission($userid);

View File

@ -107,7 +107,7 @@ class period {
if (!array_key_exists($page->id(), self::$PAGECACHE)) { if (!array_key_exists($page->id(), self::$PAGECACHE)) {
$periods = []; $periods = [];
// Find and add the periods to an array with the period sequence as a key. // Find and add the periods to an array with the period sequence as a key.
for ($i=1; $i <= $page->periods(); $i++) { for ($i = 1; $i <= $page->periods(); $i++) {
$period = self::find($page, $i); $period = self::find($page, $i);
$periods[$i] = $period; $periods[$i] = $period;
} }
@ -160,7 +160,7 @@ class period {
} }
} }
public static function structure($value=VALUE_REQUIRED) { public static function structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of period'), "id" => new \external_value(PARAM_INT, 'id of period'),
"fullname" => new \external_value(PARAM_TEXT, 'Full name of period'), "fullname" => new \external_value(PARAM_TEXT, 'Full name of period'),
@ -235,7 +235,7 @@ class period {
return success::success(); return success::success();
} }
public static function page_structure($value=VALUE_REQUIRED) { public static function page_structure($value = VALUE_REQUIRED) {
return new \external_multiple_structure(self::structure(), "The periods in the page", $value); return new \external_multiple_structure(self::structure(), "The periods in the page", $value);
} }

View File

@ -21,7 +21,6 @@
*/ */
namespace local_treestudyplan\privacy; namespace local_treestudyplan\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\collection; use core_privacy\local\metadata\collection;
use \core_privacy\local\request\userlist; 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 { class reportinvite_form extends moodleform {
// Add elements to form. // Add elements to form.
const GOALS_EDITOR_OPTIONS = array('trusttext' => true, 'subdirs' => true, 'maxfiles' => 0, 'maxbytes' => 5*1024*1025);
public function definition() { public function definition() {
global $CFG; 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->addElement('hidden', 'add', 0);
$mform->setType('add', PARAM_ALPHANUM); $mform->setType('add', PARAM_ALPHANUM);
@ -61,11 +59,6 @@ class reportinvite_form extends moodleform {
return array(); return array();
} }
public function set_data($data) {
parent::set_data($data);
}
public function get_data() { public function get_data() {
global $DB, $USER; global $DB, $USER;
@ -87,14 +80,14 @@ class reportinvite_form extends moodleform {
do { do {
$length = 20; $length = 20;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters); $characterslength = strlen($characters);
$randomkey = ''; $randomkey = '';
for ($i = 0; $i < $length; $i++) { 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. // Double check that the key is unique before inserting.
} while($DB->record_exists_select("local_treestudyplan_invit", } while ($DB->record_exists_select("local_treestudyplan_invit",
$DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"),
['invitekey' => $randomkey])); ['invitekey' => $randomkey]));

View File

@ -214,7 +214,7 @@ class studentstudyplanservice extends \external_api {
); );
} }
public static function get_own_studyplan($id=null) { public static function get_own_studyplan($id = null) {
global $USER; global $USER;
// Validate this call in the system context. // Validate this call in the system context.
@ -258,7 +258,7 @@ class studentstudyplanservice extends \external_api {
); );
} }
public static function get_teaching_studyplans($id=null) { public static function get_teaching_studyplans($id = null) {
global $CFG, $DB, $USER; global $CFG, $DB, $USER;
$userid = $USER->id; $userid = $USER->id;

View File

@ -98,7 +98,7 @@ class studyitem {
return is_numeric($id) && $DB->record_exists(self::TABLE, array('id' => $id)); return is_numeric($id) && $DB->record_exists(self::TABLE, array('id' => $id));
} }
public static function editor_structure($value=VALUE_REQUIRED) { public static function editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of study item'), "id" => new \external_value(PARAM_INT, 'id of study item'),
"type" => new \external_value(PARAM_TEXT, 'shortname of study item'), "type" => new \external_value(PARAM_TEXT, 'shortname of study item'),
@ -206,7 +206,7 @@ class studyitem {
} }
public static function add($fields, $import=false) { public static function add($fields, $import = false) {
global $DB; global $DB;
$addable = ['line_id', 'type', 'layer', 'conditions', 'slot', $addable = ['line_id', 'type', 'layer', 'conditions', 'slot',
'competency_id', 'course_id', 'badge_id', 'continuation_id', 'span']; 'competency_id', 'course_id', 'badge_id', 'continuation_id', 'span'];
@ -253,7 +253,7 @@ class studyitem {
} }
} }
public function delete($force=false) { public function delete($force = false) {
global $DB; global $DB;
// Check if this item is referenced in a START item. // Check if this item is referenced in a START item.
@ -312,7 +312,7 @@ class studyitem {
return $list; return $list;
} }
private static function link_structure($value=VALUE_REQUIRED) { private static function link_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of study item'), "id" => new \external_value(PARAM_INT, 'id of study item'),
"type" => new \external_value(PARAM_TEXT, 'type of study item'), "type" => new \external_value(PARAM_TEXT, 'type of study item'),
@ -336,7 +336,7 @@ class studyitem {
]; ];
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of study item'), "id" => new \external_value(PARAM_INT, 'id of study item'),
"type" => new \external_value(PARAM_TEXT, 'type of study item'), "type" => new \external_value(PARAM_TEXT, 'type of study item'),

View File

@ -37,7 +37,7 @@ class studyitemconnection {
$this->id = $r->id; $this->id = $r->id;
} }
public static function structure($value=VALUE_REQUIRED) { public static function structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
'id' => new \external_value(PARAM_INT, 'id of connection'), 'id' => new \external_value(PARAM_INT, 'id of connection'),
'from_id' => new \external_value(PARAM_INT, 'id of start item'), 'from_id' => new \external_value(PARAM_INT, 'id of start item'),

View File

@ -90,7 +90,7 @@ class studyline {
return $this->r->shortname; return $this->r->shortname;
} }
public static function editor_structure($value=VALUE_REQUIRED) { public static function editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyline'), "id" => new \external_value(PARAM_INT, 'id of studyline'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'), "name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
@ -140,7 +140,7 @@ class studyline {
$numslots = max($this->page->periods(), $maxslot +1); $numslots = max($this->page->periods(), $maxslot +1);
// Create the required amount of slots. // Create the required amount of slots.
for ($i=0; $i < $numslots+1; $i++) { for ($i = 0; $i < $numslots+1; $i++) {
if ($mode == "export") { if ($mode == "export") {
// Export mode does not separate between filter or competency type, since that is determined automatically. // Export mode does not separate between filter or competency type, since that is determined automatically.
$slots = []; $slots = [];
@ -254,7 +254,7 @@ class studyline {
return $list; return $list;
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyline'), "id" => new \external_value(PARAM_INT, 'id of studyline'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'), "name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
@ -294,7 +294,7 @@ class studyline {
$numslots = max($this->page->periods(), $maxslot +1); $numslots = max($this->page->periods(), $maxslot +1);
// Create the required amount of slots. // Create the required amount of slots.
for ($i=0; $i < $numslots+1; $i++) { for ($i = 0; $i < $numslots+1; $i++) {
if ($i > 0) { if ($i > 0) {
$slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []]; $slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []];
} else { } else {
@ -356,7 +356,7 @@ class studyline {
public function import_studyitems($model, &$itemtranslation, &$connections) { public function import_studyitems($model, &$itemtranslation, &$connections) {
global $DB; global $DB;
foreach ($model as $slot=> $slotmodel) { foreach ($model as $slot => $slotmodel) {
$courselayer = 0; $courselayer = 0;
$filterlayer = 0; $filterlayer = 0;
foreach ($slotmodel as $itemmodel) { foreach ($slotmodel as $itemmodel) {

View File

@ -95,7 +95,7 @@ class studyplan {
return $this->context; return $this->context;
} }
public static function simple_structure($value=VALUE_REQUIRED) { public static function simple_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
@ -130,7 +130,7 @@ class studyplan {
]; ];
} }
public static function editor_structure($value=VALUE_REQUIRED) { public static function editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
@ -193,7 +193,7 @@ class studyplan {
return $model; return $model;
} }
public static function add($fields, $bare=false) { public static function add($fields, $bare = false) {
global $CFG, $DB; global $CFG, $DB;
$addable = ['name', 'shortname', 'description', 'idnumber', 'context_id', 'aggregation', 'aggregation_config']; $addable = ['name', 'shortname', 'description', 'idnumber', 'context_id', 'aggregation', 'aggregation_config'];
@ -276,7 +276,7 @@ class studyplan {
return $this; return $this;
} }
public function delete($force=false) { public function delete($force = false) {
global $DB; global $DB;
if ($force) { if ($force) {
@ -294,7 +294,7 @@ class studyplan {
} }
} }
public static function find_all($contextid=-1) { public static function find_all($contextid = -1) {
global $DB, $USER; global $DB, $USER;
$list = []; $list = [];
@ -443,7 +443,7 @@ class studyplan {
} }
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
@ -482,7 +482,7 @@ class studyplan {
public function duplicate($name, $shortname) { public function duplicate($name, $shortname) {
// First duplicate the studyplan structure. // First duplicate the studyplan structure.
$newplan =studyplan::add([ $newplan = studyplan::add([
'name' => $name, 'name' => $name,
'shortname' => $shortname, 'shortname' => $shortname,
'description' => $this->r->description, 'description' => $this->r->description,
@ -535,7 +535,7 @@ class studyplan {
return $pages; return $pages;
} }
public static function import_studyplan($content, $format="application/json", $contextid=1) { public static function import_studyplan($content, $format = "application/json", $contextid = 1) {
if ($format != "application/json") { if ($format != "application/json") {
return false; return false;
} }
@ -555,12 +555,12 @@ class studyplan {
return $plan->import_pages_model($content["studyplan"]["pages"]); return $plan->import_pages_model($content["studyplan"]["pages"]);
} else { } else {
error_log("Invalid format and type: {$content['type']} version {$content['version']}"); debugging("Invalid format and type: {$content['type']} version {$content['version']}");
return false; return false;
} }
} }
public function import_pages($content, $format="application/json") { public function import_pages($content, $format = "application/json") {
if ($format != "application/json") { if ($format != "application/json") {
return false; return false;
} }

View File

@ -87,7 +87,7 @@ class studyplanpage {
} }
public static function simple_structure($value=VALUE_REQUIRED) { public static function simple_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan page'), "id" => new \external_value(PARAM_INT, 'id of studyplan page'),
"fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'),
@ -113,7 +113,7 @@ class studyplanpage {
]; ];
} }
public static function editor_structure($value=VALUE_REQUIRED) { public static function editor_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'),
@ -193,7 +193,7 @@ class studyplanpage {
return $this; return $this;
} }
public function delete($force=false) { public function delete($force = false) {
global $DB; global $DB;
if ($force) { if ($force) {
@ -211,7 +211,7 @@ class studyplanpage {
} }
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value = VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan page'), "id" => new \external_value(PARAM_INT, 'id of studyplan page'),
"fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'),
@ -432,7 +432,7 @@ class studyplanpage {
return $lines; return $lines;
} }
public function import_periods($content, $format="application/json") { public function import_periods($content, $format = "application/json") {
if ($format != "application/json") { if ($format != "application/json") {
return false; return false;
} }
@ -446,7 +446,7 @@ class studyplanpage {
} }
} }
public function import_studylines($content, $format="application/json") { public function import_studylines($content, $format = "application/json") {
if ($format != "application/json") { if ($format != "application/json") {
return false; return false;
} }

View File

@ -143,7 +143,7 @@ class studyplanservice extends \external_api {
} }
public static function add_studyplan($name, $shortname, $idnumber, $description, $periods, public static function add_studyplan($name, $shortname, $idnumber, $description, $periods,
$startdate, $enddate, $aggregation="bistate", $aggregationconfig='', $contextid=0) { $startdate, $enddate, $aggregation = "bistate", $aggregationconfig = '', $contextid = 0) {
// Check if we have the proper rights for the requested context. // Check if we have the proper rights for the requested context.
$context = webservicehelper::find_context($contextid); $context = webservicehelper::find_context($contextid);
webservicehelper::require_capabilities(self::CAP_EDIT, $context); webservicehelper::require_capabilities(self::CAP_EDIT, $context);
@ -190,7 +190,7 @@ class studyplanservice extends \external_api {
} }
public static function edit_studyplan($id, $name, $shortname, $idnumber, $description, $periods, $startdate, public static function edit_studyplan($id, $name, $shortname, $idnumber, $description, $periods, $startdate,
$enddate, $aggregation="bistate", $aggregationconfig='', $contextid=0) { $enddate, $aggregation = "bistate", $aggregationconfig = '', $contextid = 0) {
// Validate access in the intended context. // Validate access in the intended context.
$context = webservicehelper::find_context($contextid); $context = webservicehelper::find_context($contextid);
// Do not validate the context in this case, just check the permissions. // Do not validate the context in this case, just check the permissions.
@ -231,7 +231,7 @@ class studyplanservice extends \external_api {
return success::structure(); return success::structure();
} }
public static function delete_studyplan($id, $force=false) { public static function delete_studyplan($id, $force = false) {
$o = studyplan::findById($id); $o = studyplan::findById($id);
// Validate if the requesting user has the right to edit the plan in it's current context. // Validate if the requesting user has the right to edit the plan in it's current context.
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
@ -360,13 +360,13 @@ class studyplanservice extends \external_api {
return studyline::reorder($resequence)->model(); return studyline::reorder($resequence)->model();
} }
/*********************************** /***********************************
* STUDYITEM FUNCTIONS * STUDYITEM FUNCTIONS
***********************************/ ***********************************/
/************************ /************************
* * * *
* get_studyitem * * get_studyitem *
* * * *
************************/ ************************/
@ -413,7 +413,7 @@ class studyplanservice extends \external_api {
return studyitem::editor_structure(); return studyitem::editor_structure();
} }
public static function add_studyitem($lineid, $type, $details, $slot=-1, $layer=0) { public static function add_studyitem($lineid, $type, $details, $slot = -1, $layer = 0) {
webservicehelper::require_capabilities(self::CAP_EDIT, studyline::findById($lineid)->context()); webservicehelper::require_capabilities(self::CAP_EDIT, studyline::findById($lineid)->context());
$o = studyitem::add([ $o = studyitem::add([
@ -447,7 +447,7 @@ class studyplanservice extends \external_api {
return studyitem::editor_structure(); return studyitem::editor_structure();
} }
public static function edit_studyitem($id, $conditions, $continuationid=false) { public static function edit_studyitem($id, $conditions, $continuationid = false) {
$o = studyitem::findById($id); $o = studyitem::findById($id);
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
@ -589,12 +589,10 @@ class studyplanservice extends \external_api {
$result = []; $result = [];
$badges = badges_get_badges(BADGE_TYPE_SITE, "timemodified"); $badges = badges_get_badges(BADGE_TYPE_SITE, "timemodified");
foreach ($badges as $badge) { foreach ($badges as $badge) {
// TODO: Add config option to list only active badges. // TODO: Add config option to list only active badges.
// if ($badge->is_active()) {. $result[] = (new badgeinfo($badge))->editor_model();
$result[] = (new badgeinfo($badge))->editor_model();
// }.
// TODO: Include course badges somehow... Just site badges is not enough. // TODO: Include course badges somehow... Just site badges is not enough.
} }
return $result; return $result;
@ -620,7 +618,7 @@ class studyplanservice extends \external_api {
return success::structure(); return success::structure();
} }
public static function include_grade($gradeid, $itemid, $include, $required=false) { public static function include_grade($gradeid, $itemid, $include, $required = false) {
global $USER; global $USER;
// Find related course and course context. // Find related course and course context.
@ -742,7 +740,7 @@ class studyplanservice extends \external_api {
$fieldname = "grade"; $fieldname = "grade";
if ($result && $gi->itemtype == "mod" && $dbman->table_exists($tablename)) { if ($result && $gi->itemtype == "mod" && $dbman->table_exists($tablename)) {
if ($dbman->field_exists($tablename, $fieldname)) { if ($dbman->field_exists($tablename, $fieldname)) {
$gradevalue = intval(0-($scale->id)); $gradevalue = intval(0 - ($scale->id));
try { try {
$DB->set_field($tablename, $fieldname, $gradevalue, ["id" => $gi->iteminstance]); $DB->set_field($tablename, $fieldname, $gradevalue, ["id" => $gi->iteminstance]);
} catch (\dml_exception $x) { } catch (\dml_exception $x) {
@ -809,9 +807,9 @@ class studyplanservice extends \external_api {
} }
/**************************** /****************************
* * * *
* disable_autoenddate * * disable_autoenddate *
* * * *
****************************/ ****************************/
@ -894,7 +892,7 @@ class studyplanservice extends \external_api {
return studyplan::export_structure(); return studyplan::export_structure();
} }
public static function export_plan($studyplanid, $format="json") { public static function export_plan($studyplanid, $format = "json") {
try { try {
// Validate permissions. // Validate permissions.
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context()); webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
@ -951,7 +949,7 @@ class studyplanservice extends \external_api {
return success::structure(); return success::structure();
} }
public static function import_plan($content, $format="application/json", $contextid=1) { public static function import_plan($content, $format = "application/json", $contextid = 1) {
try { try {
// Validate import context. // Validate import context.
@ -977,7 +975,7 @@ class studyplanservice extends \external_api {
return success::structure(); return success::structure();
} }
public static function import_studylines($studyplanid, $content, $format="application/json") { public static function import_studylines($studyplanid, $content, $format = "application/json") {
try { try {
$plan = studyplan::findById($studyplanid); $plan = studyplan::findById($studyplanid);
@ -1041,9 +1039,9 @@ class studyplanservice extends \external_api {
foreach (explode("&", $formdata) as $pair) { foreach (explode("&", $formdata) as $pair) {
$p = explode("=", $pair, 2); $p = explode("=", $pair, 2);
$k = urldecode($p[0]); $k = urldecode($p[0]);
$v = (count($p)>1) ? urldecode($p[1]) : ""; $v = (count($p) > 1) ? urldecode($p[1]) : "";
if (strpos($k, "[") > 0 && strpos($k, "]") == strlen($k) -1) { if (strpos($k, "[") > 0 && strpos($k, "]") == strlen($k) - 1) {
// Its a bracketet field, like filename[text] which should be separated and put into a named array. // Its a bracketet field, like filename[text] which should be separated and put into a named array.
list($k, $h) = explode("[", $k, 2); list($k, $h) = explode("[", $k, 2);
if (strlen($k) > 0 && strlen($h) > 1) { if (strlen($k) > 0 && strlen($h) > 1) {
@ -1053,7 +1051,7 @@ class studyplanservice extends \external_api {
} }
$_POST[$k][$h] = $v; $_POST[$k][$h] = $v;
} }
}else { } else {
$_POST[$k] = $v; $_POST[$k] = $v;
} }
} }
@ -1077,54 +1075,54 @@ class studyplanservice extends \external_api {
* * * *
************************/ ************************/
public static function edit_period_parameters() { public static function edit_period_parameters() {
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of study item'), "id" => new \external_value(PARAM_INT, 'id of study item'),
"fullname" => new \external_value(PARAM_TEXT, 'Full name of period'), "fullname" => new \external_value(PARAM_TEXT, 'Full name of period'),
"shortname" => new \external_value(PARAM_TEXT, 'Short name of period'), "shortname" => new \external_value(PARAM_TEXT, 'Short name of period'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of period'), "startdate" => new \external_value(PARAM_TEXT, 'start date of period'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of period'), "enddate" => new \external_value(PARAM_TEXT, 'end date of period'),
]); ]);
} }
public static function edit_period_returns() { public static function edit_period_returns() {
return period::structure(); return period::structure();
} }
public static function edit_period($id, $fullname, $shortname, $startdate, $enddate) { public static function edit_period($id, $fullname, $shortname, $startdate, $enddate) {
$p = period::findById($id); $p = period::findById($id);
webservicehelper::require_capabilities(self::CAP_EDIT, $p->page()->studyplan()->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $p->page()->studyplan()->context());
$p->edit([ $p->edit([
'fullname' => $fullname, 'fullname' => $fullname,
'shortname' => $shortname, 'shortname' => $shortname,
'startdate' => $startdate, 'startdate' => $startdate,
'enddate' => $enddate, 'enddate' => $enddate,
]); ]);
return $p->model(); return $p->model();
} }
/************************ /************************
* * * *
* Change course timing * * Change course timing *
* * * *
************************/ ************************/
public static function course_period_timing_parameters() { public static function course_period_timing_parameters() {
return new \external_function_parameters( [ return new \external_function_parameters( [
"period_id" => new \external_value(PARAM_INT, 'Period number within page'), "period_id" => new \external_value(PARAM_INT, 'Period number within page'),
"course_id" => new \external_value(PARAM_INT, 'Id of course to adjust dates for'), "course_id" => new \external_value(PARAM_INT, 'Id of course to adjust dates for'),
"span" => new \external_value(PARAM_INT, 'Period span (default 1)', VALUE_DEFAULT), "span" => new \external_value(PARAM_INT, 'Period span (default 1)', VALUE_DEFAULT),
]); ]);
} }
public static function course_period_timing_returns() { public static function course_period_timing_returns() {
return courseinfo::editor_structure(); return courseinfo::editor_structure();
} }
public static function course_period_timing($periodid, $courseid, $span=1) { public static function course_period_timing($periodid, $courseid, $span = 1) {
global $DB; global $DB;
$period = period::findById($periodid); $period = period::findById($periodid);
$periodnr = $period->period(); $periodnr = $period->period();
@ -1175,27 +1173,27 @@ class studyplanservice extends \external_api {
// Probably should return a nice message. // Probably should return a nice message.
throw new \webservice_access_exception("You do not have date change permissions on this course"); throw new \webservice_access_exception("You do not have date change permissions on this course");
} }
} }
public static function set_studyitem_span_parameters() { public static function set_studyitem_span_parameters() {
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of study item'), "id" => new \external_value(PARAM_INT, 'id of study item'),
"span" => new \external_value(PARAM_INT, 'span of item'), "span" => new \external_value(PARAM_INT, 'span of item'),
]); ]);
} }
public static function set_studyitem_span_returns() { public static function set_studyitem_span_returns() {
return studyitem::editor_structure(); return studyitem::editor_structure();
} }
public static function set_studyitem_span($id, $span=null) { public static function set_studyitem_span($id, $span = null) {
$o = studyitem::findById($id); $o = studyitem::findById($id);
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
$config = [ 'span' => $span]; $config = [ 'span' => $span];
$o->edit($config); $o->edit($config);
return $o->editor_model(); return $o->editor_model();
} }
} }

View File

@ -21,17 +21,16 @@
*/ */
namespace local_treestudyplan; namespace local_treestudyplan;
defined('MOODLE_INTERNAL') || die();
class success { class success {
private $success; private $success;
private $msg; private $msg;
public static function success($msg="") { public static function success($msg = "") {
return new self(true, $msg); return new self(true, $msg);
} }
public static function fail($msg="") { public static function fail($msg = "") {
return new self(false, $msg); return new self(false, $msg);
} }

View File

@ -28,7 +28,7 @@ use local_treestudyplan\studyplan;
use local_treestudyplan\cascadecohortsync; use local_treestudyplan\cascadecohortsync;
use local_treestudyplan\cascadeusersync; use local_treestudyplan\cascadeusersync;
class autocohortsync extends \core\task\scheduled_task { class autocohortsync extends \core\task\scheduled_task {
/** /**
* Return the task's name as shown in admin screens. * Return the task's name as shown in admin screens.

View File

@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/externallib.php'); require_once($CFG->dirroot.'/course/externallib.php');
use local_treestudyplan\teachingfinder; use local_treestudyplan\teachingfinder;
class refreshteacherlist extends \core\task\scheduled_task { class refreshteacherlist extends \core\task\scheduled_task {
const CACHE_TIME = 4 * 60 * 60; // 2 hours. const CACHE_TIME = 4 * 60 * 60; // 2 hours.
/** /**

View File

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

View File

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

View File

@ -19,6 +19,7 @@
* @copyright 2023 P.M. Kuipers * @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die();
$capabilities = [ $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 * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die();
$services = [ $services = [
"Competency listing" => [ "Competency listing" => [
'functions' => [ 'functions' => [
@ -571,7 +573,7 @@ $functions = [
'ajax' => true, 'ajax' => true,
'loginrequired' => true, 'loginrequired' => true,
], ],
'local_treestudyplan_set_studyitem_span' => [ // Web service function name. 'local_treestudyplan_set_studyitem_span' => [ // Web service function name.
'classname' => '\local_treestudyplan\studyplanservice', // Class containing the external function. 'classname' => '\local_treestudyplan\studyplanservice', // Class containing the external function.
'methodname' => 'set_studyitem_span', // External function name. 'methodname' => 'set_studyitem_span', // External function name.
'description' => 'Change the span of a course item', 'description' => 'Change the span of a course item',

View File

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

View File

@ -311,7 +311,7 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
$plans->close(); $plans->close();
} }
/** /*******
* Finalize studyline table to drop studyplan_id field and have page id be a non-nullable and foreign key * 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. // Launch add key page_id-id.
$dbman->add_key($table, $key); $dbman->add_key($table, $key);
/*** /*******
* Create Period table and make a period record for all studyplan periods * Create Period table and make a period record for all studyplan periods
*/ */
@ -368,20 +368,20 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
// Make a best guess for the periods based on the specified period for the plan and the . // Make a best guess for the periods based on the specified period for the plan and the .
$pcount = $r->periods; $pcount = $r->periods;
$ystart = strtotime($r->startdate)+0; $ystart = strtotime($r->startdate) + 0;
$yend = strtotime($r->enddate)+0; $yend = strtotime($r->enddate) + 0;
if ($yend < $ystart) { if ($yend < $ystart) {
// If no end time is given, assume a year duration for period calculations. // If no end time is given, assume a year duration for period calculations.
$ydelta = (365*24*60*60)/$pcount; $ydelta = (365 * 24 * 60 * 60) / $pcount;
} else { } else {
$ydelta = $yend - $ystart; $ydelta = $yend - $ystart;
} }
$ptime = $ydelta / $pcount; $ptime = $ydelta / $pcount;
for ($i=0; $i < $pcount; $i++) { for ($i = 0; $i < $pcount; $i++) {
$pnum = $i+1; $pnum = $i + 1;
$pstart = $ystart + ($i*$ptime); $pstart = $ystart + ($i * $ptime);
$pend = ($pstart + $ptime)-(24*60*60); // Minus one day. $pend = ($pstart + $ptime) - (24 * 60 * 60); // Minus one day.
$o = [ "page_id" => $r->id, $o = [ "page_id" => $r->id,
"period" => $pnum, "period" => $pnum,

View File

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

View File

@ -41,14 +41,13 @@ if ($categoryid > 0) {
$studyplancontext = context::instance_by_id($contextid); $studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) { if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
$categoryid = $studyplancontext->instanceid; $categoryid = $studyplancontext->instanceid;
} else } else {
{
$studyplancontext = $systemcontext; $studyplancontext = $systemcontext;
} }
} else { } else {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("edit"); $availablecontexts = courseservice::list_accessible_categories_with_usage("edit");
$contextid=1; // Fallback to system context. $contextid = 1; // Fallback to system context.
foreach ($availablecontexts as $ctx) { foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) { if ($ctx->count > 0) {
$contextid = $ctx->ctxid; $contextid = $ctx->ctxid;
@ -82,7 +81,7 @@ $PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$stu
$catlist = courseservice::list_accessible_categories_with_usage("edit"); $catlist = courseservice::list_accessible_categories_with_usage("edit");
// Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param = null, $plugin = 'local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }

View File

@ -20,24 +20,16 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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. require_once("../../config.php");
$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->libdir.'/weblib.php');
require_once($CFG->dirroot.'/grade/querylib.php'); require_once($CFG->dirroot.'/grade/querylib.php');
use local_treestudyplan; use local_treestudyplan;
$INVITEDURL = "/local/treestudyplan/invited.php"; $invitedurl = "/local/treestudyplan/invited.php";
// Admin_externalpage_setup('major');.
$systemcontext = context_system::instance(); $systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/invitations.php", array()); $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/page-invitemanager', 'init');
$PAGE->requires->js_call_amd('local_treestudyplan/buttonlinks', '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); $sent = optional_param('sent', '', PARAM_INT);
if (!empty($sent)) { if (!empty($sent)) {
$invite = $DB->get_record('local_treestudyplan_invit', array('id' => $sent)); $invite = $DB->get_record('local_treestudyplan_invit', array('id' => $sent));
@ -78,7 +70,7 @@ print "</thead>";
print "<tbody>"; print "<tbody>";
if (count($invites) > 0) { if (count($invites) > 0) {
foreach ($invites as $invite) { foreach ($invites as $invite) {
$testlink = $INVITEDURL."?key={$invite->invitekey}"; $testlink = $invitedurl."?key={$invite->invitekey}";
print "<tr data-id='{$invite->id}'>"; print "<tr data-id='{$invite->id}'>";
print "<td data-field='name'>{$invite->name}</td>"; print "<td data-field='name'>{$invite->name}</td>";
print "<td data-field='email'>{$invite->email}</td>"; print "<td data-field='email'>{$invite->email}</td>";

View File

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

38
lib.php
View File

@ -20,17 +20,19 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once($CFG->dirroot.'/course/modlib.php'); defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/modlib.php');
use local_treestudyplan\local\helpers\webservicehelper; use local_treestudyplan\local\helpers\webservicehelper;
use \local_treestudyplan\studyplan; use \local_treestudyplan\studyplan;
defined('MOODLE_INTERNAL') || die();
function local_treestudyplan_unit_get_editor_options($context) { function local_treestudyplan_unit_get_editor_options($context) {
global $CFG; global $CFG;
return ['subdirs' => 1, return ['subdirs' => 1,
'maxbytes' => $CFG->maxbytes, 'maxbytes' => $CFG->maxbytes,
'maxfiles' =>-1, 'changeformat' => 1, 'maxfiles' => -1,
'changeformat' => 1,
'context' => $context, 'context' => $context,
'noclean' => 1, 'noclean' => 1,
'trusttext' => 0]; '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). 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. We will add all the hrefs that should be hidden to this variable below.
*/ */
$hideprimary_hrefs = []; $hideprimaryhrefs = [];
if ($USER->id > 1) { if ($USER->id > 1) {
// Don't show if user is not logged in (id == 0) or is guest user (id == 1). // Don't show if user is not logged in (id == 0) or is guest user (id == 1).
@ -74,7 +76,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
new pix_icon("myreport", '', 'local_treestudyplan') new pix_icon("myreport", '', 'local_treestudyplan')
); );
$node->showinflatnavigation = true; $node->showinflatnavigation = true;
$node->showinsecondarynavigation=true; $node->showinsecondarynavigation = true;
// Create invitenode node. // Create invitenode node.
$invitenode = navigation_node::create( $invitenode = navigation_node::create(
@ -90,7 +92,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$navigation->add_node($node, 'mycourses'); $navigation->add_node($node, 'mycourses');
} else { } else {
$hideprimary_hrefs[] = "/local/treestudyplan/myreport.php"; $hideprimaryhrefs[] = "/local/treestudyplan/myreport.php";
} }
if ( has_capability('local/treestudyplan:viewuserreports', context_system::instance()) if ( has_capability('local/treestudyplan:viewuserreports', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports')) { || webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports')) {
@ -103,10 +105,10 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
new pix_icon("viewplans", '', 'local_treestudyplan') new pix_icon("viewplans", '', 'local_treestudyplan')
); );
$node->showinflatnavigation = true; $node->showinflatnavigation = true;
$node->showinsecondarynavigation=true; $node->showinsecondarynavigation = true;
$navigation->add_node($node, 'mycourses'); $navigation->add_node($node, 'mycourses');
} else { } else {
$hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php"; $hideprimaryhrefs[] = "/local/treestudyplan/view-plan.php";
} }
if ( has_capability('local/treestudyplan:editstudyplan', context_system::instance()) if ( has_capability('local/treestudyplan:editstudyplan', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan') || webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan')
@ -120,15 +122,15 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
new pix_icon("viewplans", '', 'local_treestudyplan') new pix_icon("viewplans", '', 'local_treestudyplan')
); );
$node->showinflatnavigation = true; $node->showinflatnavigation = true;
$node->showinsecondarynavigation=true; $node->showinsecondarynavigation = true;
$navigation->add_node($node, 'mycourses'); $navigation->add_node($node, 'mycourses');
} else { } else {
$hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php"; $hideprimaryhrefs[] = "/local/treestudyplan/edit-plan.php";
} }
} else { } else {
$hideprimary_hrefs[] = "/local/treestudyplan/myreport.php"; $hideprimaryhrefs[] = "/local/treestudyplan/myreport.php";
$hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php"; $hideprimaryhrefs[] = "/local/treestudyplan/edit-plan.php";
$hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php"; $hideprimaryhrefs[] = "/local/treestudyplan/view-plan.php";
} }
// Create invitenode node. // Create invitenode node.
$invitenode = navigation_node::create( $invitenode = navigation_node::create(
@ -143,7 +145,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$navigation->add_node($invitenode, 'mycourses'); $navigation->add_node($invitenode, 'mycourses');
// Now using some javascript magic, we'll hide the links that are not accessible. // 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,9 +277,11 @@ function local_treestudyplan_get_cohort_path($cohort) {
$cohortcontext = context::instance_by_id($cohort->contextid); $cohortcontext = context::instance_by_id($cohort->contextid);
if ($cohortcontext && $cohortcontext->id != SYSCONTEXTID) { if ($cohortcontext && $cohortcontext->id != SYSCONTEXTID) {
$ctxpath = array_map( $ctxpath = array_map(
function($ctx) { return $ctx->get_context_name(false);}, function($ctx) {
return $ctx->get_context_name(false);
},
$cohortcontext->get_parent_contexts(true) $cohortcontext->get_parent_contexts(true)
); );
array_pop($ctxpath); // Pop system context off the list. array_pop($ctxpath); // Pop system context off the list.
$ctxpath = array_reverse($ctxpath); $ctxpath = array_reverse($ctxpath);
$ctxpath[] = $cohort->name; $ctxpath[] = $cohort->name;
@ -313,7 +317,7 @@ function local_treestudyplan_output_fragment_mod_edit_form($args) {
if (file_exists($modmoodleform)) { if (file_exists($modmoodleform)) {
require_once($modmoodleform); require_once($modmoodleform);
} else { } else {
print_error('noformdesc'); throw new \moodle_exception('noformdesc', 'local_treestudyplan');;
} }
$mformclassname = 'mod_'.$module->name.'_mod_form'; $mformclassname = 'mod_'.$module->name.'_mod_form';

View File

@ -42,7 +42,7 @@ $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devs
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init'); $PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init');
// Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param = null, $plugin = 'local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }

View File

@ -50,7 +50,7 @@ $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devs
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$teachermode ? 'teaching' : 'myreport']); $PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$teachermode ? 'teaching' : 'myreport']);
// Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param = null, $plugin = 'local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }

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,14 +41,13 @@ if ($categoryid > 0) {
$studyplancontext = context::instance_by_id($contextid); $studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) { if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
$categoryid = $studyplancontext->instanceid; $categoryid = $studyplancontext->instanceid;
} else } else {
{
$studyplancontext = $systemcontext; $studyplancontext = $systemcontext;
} }
} else { } else {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("view"); $availablecontexts = courseservice::list_accessible_categories_with_usage("view");
$contextid=1; // Fallback to system context. $contextid = 1; // Fallback to system context.
foreach ($availablecontexts as $ctx) { foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) { if ($ctx->count > 0) {
$contextid = $ctx->ctxid; $contextid = $ctx->ctxid;
@ -80,7 +79,7 @@ $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devs
$PAGE->requires->js_call_amd('local_treestudyplan/page-view-plan', 'init', [$studyplancontext->id, $categoryid]); $PAGE->requires->js_call_amd('local_treestudyplan/page-view-plan', 'init', [$studyplancontext->id, $categoryid]);
// Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param = null, $plugin = 'local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }