Moodle code style fixes part 1

This commit is contained in:
PMKuipers 2023-08-24 23:02:41 +02:00
parent ab8a3c6f84
commit 1a3df05195
63 changed files with 4467 additions and 3885 deletions

View File

@ -1,13 +1,35 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('CLI_SCRIPT', true);
require_once("../../config.php");
$plugin = new stdClass;
include('version.php');
require_once('version.php');
$a = explode("_", $plugin->component, 2);
$plugin->type = $a[0];
$plugin->name = $a[1];
$exclude_paths = [
"build", // dir for build zip files
$excludepaths = [
"build", // Dir for build zip files.
"build/*",
"build.*",
"vuemode.sh",
@ -19,16 +41,16 @@ $exclude_paths = [
"*.zip",
];
// Determine some paths
// Determine some paths.
$wd = realpath(dirname(__FILE__));
$parent = dirname($wd);
$plugindirname = basename($wd);
$builddir = $wd."/"."build";
$zipname = $builddir."/"."{$plugin->name}-{$plugin->version}.zip";
// create the exclude line
// Create the exclude line.
$exclude = "-x ";
foreach($exclude_paths as $x){
foreach ($excludepaths as $x) {
$exclude .= "'{$plugindirname}/{$x}' ";
}

View File

@ -1,12 +1,32 @@
<?php
require_once("../../config.php");
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->libdir.'/adminlib.php');
admin_externalpage_setup("local_treestudyplan_gradeconfig");
$systemcontext = context_system::instance();
// Check if user has capability to manage this
// Check if user has capability to manage this.
require_capability('local/treestudyplan:configure', $systemcontext);
@ -30,9 +50,8 @@ foreach($mappings as $cfg){
print $OUTPUT->header();
if ($_POST["action"] == "update") {
// First loop through the scales to see which need to be updated
foreach($scales as $scale)
{
// First loop through the scales to see which need to be updated.
foreach ($scales as $scale) {
if (array_key_exists($scale->id, $scale_cfgs)) {
$scalecfg = $scale_cfgs[$scale->id];
@ -64,14 +83,14 @@ if($_POST["action"] == "update"){
}
}
if ($requireinsert) {
// Insert into database and add to the list of scale configs
// Insert into database and add to the list of scale configs.
$id = $DB->insert_record(GRADECFG_TABLE, $scalecfg);
$scalecfg = $DB->get_record(GRADECFG_TABLE, ['id' => $id]);
$scale_cfgs[$id] = $scalecfg;
}
}
}
// Now, loop through the gradepoints to parse
// Now, loop through the gradepoints to parse .
$deletelist = [];
foreach ($grade_cfgs as $gradecfg) {
$deletekey = "g_{$gradecfg->grade_points}_delete";
@ -88,7 +107,7 @@ if($_POST["action"] == "update"){
}
}
$DB->update_record(GRADECFG_TABLE, $gradecfg);
// reload to ensure proper rounding is done
// reload to ensure proper rounding is done.
$grade_cfgs[$gradecfg->grade_points] = $DB->get_record(GRADECFG_TABLE, ['id' => $gradecfg->id]);
}
}
@ -98,7 +117,7 @@ if($_POST["action"] == "update"){
}
unset($deletelist);
// And add an optionally existing new gradepoint setting
// And add an optionally existing new gradepoint setting.
if (array_key_exists("g_new_gradepoints", $_POST) && !empty($_POST["g_new_gradepoints"]) && is_numeric($_POST["g_new_gradepoints"]) ) {
$gp = intval($_POST["g_new_gradepoints"]);
if (!array_key_exists($gp, $grade_cfgs)) {
@ -112,9 +131,9 @@ if($_POST["action"] == "update"){
}
}
if ($requireinsert) {
// Insert into database and add to the list of grade configs
// Insert into database and add to the list of grade configs.
$id = $DB->insert_record(GRADECFG_TABLE, $gradecfg);
// reload to ensure proper rounding is done
// reload to ensure proper rounding is done.
$gradecfg = $DB->get_record(GRADECFG_TABLE, ['id' => $id]);
$grade_cfgs[$id] = $gradecfg;
}
@ -127,8 +146,7 @@ if($_POST["action"] == "update"){
//process all available scales and load the current configuration for it.
$data = [];
foreach($scales as $scale)
{
foreach ($scales as $scale) {
$scale->load_items();
$scalecfg = null;
if (array_key_exists($scale->id, $scale_cfgs)) {
@ -147,7 +165,7 @@ foreach($scales as $scale)
$options_completed = html_writer::tag("option", get_string('select_scaleitem', 'local_treestudyplan'), $attrs_c);
$options_progress = html_writer::tag("option", get_string('select_scaleitem', 'local_treestudyplan'), $attrs_p);
$key = 1; // Start counting by one, as used in sum aggregations
$key = 1; // Start counting by one, as used in sum aggregations.
foreach ($scale->scale_items as $value) {
$attrs_c = ["value" => $key];
@ -168,7 +186,7 @@ foreach($scales as $scale)
$row = [];
$row[] = $scale->name;
//$row[] = html_writer::tag("select", $options_progress, ['name' => "s_{$scale->id}_min_progress",'autocomplete' => 'off']) ;
//$row[] = html_writer::tag("select", $options_progress, ['name' => "s_{$scale->id}_min_progress", 'autocomplete' => 'off']) ;.
$row[] = html_writer::tag("select", $options_completed, ['name' => "s_{$scale->id}_min_completed", 'autocomplete' => 'off']) ;
$data[] = $row;
}
@ -181,11 +199,11 @@ $table = new html_table();
$table->id = "";
$table->attributes['class'] = 'generaltable m-roomtable';
$table->tablealign = 'center';
$table->summary = '';//get_string('uploadtimetable_preview', 'local_chronotable');
$table->summary = '';//get_string('uploadtimetable_preview', 'local_chronotable');.
$table->head = [];
$table->data = $data;
$table->head[] = get_string('scale');
//$table->head[] = get_string('min_progress', 'local_treestudyplan');
//$table->head[] = get_string('min_progress', 'local_treestudyplan');.
$table->head[] = get_string('min_completed', 'local_treestudyplan');
print $OUTPUT->heading(get_string('cfg_grades_desc_head', 'local_treestudyplan'));
@ -197,7 +215,7 @@ $data = [];
foreach ($grade_cfgs as $g) {
$row = [];
$row[] = $g->grade_points;
// $row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_min_progress", 'value' => "{$g->min_progress}", 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;
// $row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_min_progress", 'value' => "{$g->min_progress}", 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;.
$row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_min_completed", 'value' => "{$g->min_completed}", 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;
$row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_delete", 'type' => 'checkbox', ]) ;
$data[] = $row;
@ -205,7 +223,7 @@ foreach($grade_cfgs as $g){
$row = [];
$row[] = html_writer::tag("input", null, ['name' => "g_new_gradepoints", 'value' => '', 'type' => 'number', 'min' => '0', 'pattern' => '/d+', 'step' => '1', 'autocomplete' => 'off']);
//$row[] = html_writer::tag("input", null, ['name' => "g_new_min_progress", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;
//$row[] = html_writer::tag("input", null, ['name' => "g_new_min_progress", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;.
$row[] = html_writer::tag("input", null, ['name' => "g_new_min_completed", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;
$data[] = $row;
@ -215,11 +233,11 @@ $table = new html_table();
$table->id = "";
$table->attributes['class'] = 'generaltable m-roomtable';
$table->tablealign = 'center';
$table->summary = '';//get_string('uploadtimetable_preview', 'local_chronotable');
$table->summary = '';//get_string('uploadtimetable_preview', 'local_chronotable');.
$table->head = [];
$table->data = $data;
$table->head[] = get_string('grade_points', 'local_treestudyplan');
//$table->head[] = get_string('min_progress', 'local_treestudyplan');
//$table->head[] = get_string('min_progress', 'local_treestudyplan');.
$table->head[] = get_string('min_completed', 'local_treestudyplan');
$table->head[] = get_string('delete', );

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -19,7 +40,7 @@ abstract class aggregator {
}
public static function list() {
// static list, since we'd need to implement a lot of static data for new aggregation methods anyway
// static list, since we'd need to implement a lot of static data for new aggregation methods anyway.
// and this is faster than any dynamic method.
return [
"core", # use moodle core completion
@ -59,19 +80,19 @@ abstract class aggregator {
public abstract function grade_completion(gradeinfo $gradeinfo, $userid);
// Aggregation method makes use of "required grades" in a course/module
// Aggregation method makes use of "required grades" in a course/module.
public abstract function useRequiredGrades();
// Aggregation method makes use of
// Aggregation method makes use of .
public abstract function useItemConditions();
// Whether the aggregation method uses core_completion, or treestudyplan custom completion
// Whether the aggregation method uses core_completion, or treestudyplan custom completion.
public function usecorecompletioninfo() {
return false;
}
// Parameter editing functions - override in child class to implement parameter config for aggregation
// Parameter editing functions - override in child class to implement parameter config for aggregation.
// Return the current configuration string
// Return the current configuration string.
public function config_string() {
return "";
}
@ -104,7 +125,7 @@ abstract class aggregator {
$list = [];
foreach (self::list() as $agid) {
$a = self::create($agid,""); // create new one with empty config string
$a = self::create($agid, ""); // create new one with empty config string.
$list[] = [
'id' => $agid,
'name' => get_string("{$agid}_aggregator_title", "local_treestudyplan"),

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
use local_treestudyplan\local\helpers\webservicehelper;
@ -90,12 +111,12 @@ class associationservice extends \external_api
return new \external_multiple_structure(self::cohort_structure());
}
// Actual functions
// Actual functions.
public static function list_cohort($like='', $exclude_id=null, $context_id=1)
{
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.
$context = webservicehelper::find_context($context_id);
webservicehelper::require_capabilities(self::CAP_EDIT, $context);
@ -109,8 +130,8 @@ class associationservice extends \external_api
$sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)";
$params['exclude_id'] = $exclude_id;
}
if($context_id > 1){ // system context returns all cohorts, including system cohorts
// otherwise,
if ($context_id > 1) { // system context returns all cohorts, including system cohorts.
// otherwise, .
$sql .= " AND contextid = :context_id";
$params['context_id'] = $context_id;
}
@ -138,12 +159,12 @@ class associationservice extends \external_api
return new \external_multiple_structure(self::user_structure());
}
// Actual functions
// Actual functions.
public static function find_user($like, $exclude_id=null, $context_id=1)
{
global $CFG, $DB;
// Only allow this if the user has the right to edit in this context (using system rights would make things more confusing)
// Only allow this if the user has the right to edit in this context (using system rights would make things more confusing).
$context = webservicehelper::find_context($context_id);
webservicehelper::require_capabilities(self::CAP_EDIT, $context);
@ -186,7 +207,7 @@ class associationservice extends \external_api
]);
}
// Actual functions
// Actual functions.
public static function connect_cohort($studyplan_id, $cohort_id)
{
global $CFG, $DB;
@ -194,8 +215,7 @@ class associationservice extends \external_api
$studyplan = studyplan::findById($studyplan_id);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
if(!$DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplan_id, 'cohort_id' => $cohort_id]))
{
if (!$DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplan_id, 'cohort_id' => $cohort_id])) {
$id = $DB->insert_record('local_treestudyplan_cohort', [
'studyplan_id' => $studyplan_id,
'cohort_id' => $cohort_id,
@ -226,7 +246,7 @@ class associationservice extends \external_api
]);
}
// Actual functions
// Actual functions.
public static function disconnect_cohort($studyplan_id, $cohort_id)
{
global $CFG, $DB;
@ -234,8 +254,7 @@ class associationservice extends \external_api
$studyplan = studyplan::findById($studyplan_id);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
if($DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplan_id, 'cohort_id' => $cohort_id]))
{
if ($DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplan_id, 'cohort_id' => $cohort_id])) {
$DB->delete_records('local_treestudyplan_cohort', [
'studyplan_id' => $studyplan_id,
'cohort_id' => $cohort_id,
@ -266,7 +285,7 @@ class associationservice extends \external_api
]);
}
// Actual functions
// Actual functions.
public static function connect_user($studyplan_id, $user_id)
{
global $CFG, $DB;
@ -274,8 +293,7 @@ class associationservice extends \external_api
$studyplan = studyplan::findById($studyplan_id);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
if(!$DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplan_id, 'user_id' => $user_id]))
{
if (!$DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplan_id, 'user_id' => $user_id])) {
$id = $DB->insert_record('local_treestudyplan_user', [
'studyplan_id' => $studyplan_id,
'user_id' => $user_id,
@ -305,15 +323,14 @@ class associationservice extends \external_api
]);
}
// Actual functions
// Actual functions.
public static function disconnect_user($studyplan_id, $user_id)
{
global $CFG, $DB;
$studyplan = studyplan::findById($studyplan_id);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
if($DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplan_id, 'user_id' => $user_id]))
{
if ($DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplan_id, 'user_id' => $user_id])) {
$DB->delete_records('local_treestudyplan_user', [
'studyplan_id' => $studyplan_id,
'user_id' => $user_id,
@ -339,7 +356,7 @@ class associationservice extends \external_api
return new \external_multiple_structure(self::user_structure());
}
// Actual functions
// Actual functions.
public static function associated_users($studyplan_id)
{
global $CFG, $DB;
@ -351,8 +368,7 @@ class associationservice extends \external_api
$rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplan_id]);
$users = [];
foreach($rs as $u)
{
foreach ($rs as $u) {
$users[] = self::make_user_model($u);
}
$rs->close();
@ -372,7 +388,7 @@ class associationservice extends \external_api
return new \external_multiple_structure(self::cohort_structure());
}
// Actual functions
// Actual functions.
public static function associated_cohorts($studyplan_id)
{
global $CFG, $DB;
@ -383,8 +399,7 @@ class associationservice extends \external_api
$sql .= " WHERE j.studyplan_id = :studyplan_id";
$rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplan_id]);
$cohorts = [];
foreach($rs as $c)
{
foreach ($rs as $c) {
$cohorts[] = self::make_cohort_model($c);
}
$rs->close();
@ -404,7 +419,7 @@ class associationservice extends \external_api
return new \external_multiple_structure(self::user_structure());
}
// Actual functions
// Actual functions.
public static function all_associated($studyplan_id)
{
global $CFG, $DB;
@ -414,8 +429,8 @@ class associationservice extends \external_api
$users = [];
// SQL JOIN script selecting all users that have a cohort linked to this studyplan
// or are directly linked
// SQL JOIN script selecting all users that have a cohort linked to this studyplan .
// or are directly linked.
$sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email
FROM {user} u
LEFT JOIN {cohort_members} cm ON u.id = cm.userid
@ -426,8 +441,7 @@ class associationservice extends \external_api
ORDER BY u.lastname, u.firstname";
$rs = $DB->get_recordset_sql($sql);
foreach($rs as $u)
{
foreach ($rs as $u) {
$users[] = self::make_user_model($u);
}
$rs->close();
@ -466,7 +480,7 @@ class associationservice extends \external_api
return success::structure();
}
// Actual functions
// Actual functions.
public static function cascade_cohortsync($studyplan_id)
{
$studyplan = studyplan::findById($studyplan_id);
@ -479,7 +493,7 @@ class associationservice extends \external_api
$userenroller = new cascadeusersync($studyplan);
$userenroller->sync();
}
$studyplan->clear_csync_changed(); // Clear the csync required flag
$studyplan->clear_csync_changed(); // Clear the csync required flag.
return success::success()->model();

View File

@ -1,9 +1,30 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
class badgeinfo {
private $badge; // Holds database record
private $badge; // Holds database record.
private const STATUSINFO = [
BADGE_STATUS_INACTIVE => 'inactive',
@ -17,7 +38,7 @@ class badgeinfo {
BADGE_STATUS_ACTIVE => 0,
BADGE_STATUS_INACTIVE_LOCKED => 1,
BADGE_STATUS_ACTIVE_LOCKED => 1,
BADGE_STATUS_ARCHIVED => 1, // We don't want to edit archived badges anyway....
BADGE_STATUS_ARCHIVED => 1, // We don't want to edit archived badges anyway.... .
];
public function __construct(\core_badges\badge $badge) {
@ -55,8 +76,7 @@ class badgeinfo {
], "Badge info", $value);
}
public function editor_model(array $studentlist=null)
{
public function editor_model(array $studentlist=null) {
$context = ($this->badge->type == BADGE_TYPE_SITE) ? \context_system::instance() : \context_course::instance($this->badge->courseid);
// If the user is viewing another user's badge and doesn't have the right capability return only part of the data.
@ -75,7 +95,7 @@ class badgeinfo {
'imageurl' => \moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $this->badge->id, '/', 'f1')->out(false),
];
// Add badge issue stats if a studentlist is attached to the request
// Add badge issue stats if a studentlist is attached to the request.
if (!empty($studentlist) && is_array($studentlist)) {
$model['studentcount'] = count($studentlist);
$model['issuedcount'] = $this->count_issued($studentlist);
@ -84,8 +104,7 @@ class badgeinfo {
return $model;
}
public static function user_structure($value=VALUE_REQUIRED)
{
public static function user_structure($value=VALUE_REQUIRED) {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of badge'),
"infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL),
@ -101,8 +120,7 @@ class badgeinfo {
], "Badge info", $value);
}
public function user_model($userid)
{
public function user_model($userid) {
global $DB;
$context = ($this->badge->type == BADGE_TYPE_SITE) ? \context_system::instance() : \context_course::instance($this->badge->courseid);

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -25,7 +46,7 @@ class cascadecohortsync {
}
static function uploadenrolmentmethods_get_group($courseid, $groupname) {
// Function shamelessly copied from tool/uploadenrolmentmethods/locallib.php
// Function shamelessly copied from tool/uploadenrolmentmethods/locallib.php.
global $DB, $CFG;
require_once($CFG->dirroot.'/group/lib.php');
@ -57,19 +78,19 @@ class cascadecohortsync {
*/
$enrol = \enrol_get_plugin(self::METHOD);
// Find the courses that need to be synced to the associated cohorts
// Find the courses that need to be synced to the associated cohorts.
$courseids = $this->studyplan->get_linked_course_ids();
// And find the cohorts that are linked to this studyplan.
$cohortids = $this->studyplan->get_linked_cohort_ids();
// Next, for each course that is linked:
// Next, for each course that is linked:.
foreach ($courseids as $courseid) {
$course = \get_course($courseid);
//\mtrace("Processing Course {$courseid} {$course->shortname}");
// first create any nonexistent links
//\mtrace("Processing Course {$courseid} {$course->shortname}");.
// first create any nonexistent links.
foreach ($cohortids as $cohortid) {
$cohort = $DB->get_record('cohort', ['id'=>$cohortid]);
//\mtrace("Processing cohort {$cohortid} {$cohort->shortname}");
//\mtrace("Processing cohort {$cohortid} {$cohort->shortname}");.
$instanceparams = [
'courseid' => $courseid,
@ -84,20 +105,20 @@ class cascadecohortsync {
'roleid' => get_config("local_treestudyplan", "csync_roleid"),
];
// Create group:
// Create group: .
// 1: check if a link exists
// If not, make it (maybe use some of the custom text to list the studyplans involved)
// 1: check if a link exists.
// If not, make it (maybe use some of the custom text to list the studyplans involved).
if ($instance = $DB->get_record('enrol', $instanceparams)) {
//\mtrace("Instance exists");
// it already exists
// check if this studyplan is already referenced in customtext4 in json format
//\mtrace("Instance exists");.
// it already exists.
// check if this studyplan is already referenced in customtext4 in json format.
//TODO: Check this code - Maybe add option to not remember manually added stuff
//TODO: Check this code - Maybe add option to not remember manually added stuff .
$plans = json_decode($instance->customtext4);
if ($plans == false || !is_array(($plans))) {
// If the data was not an array (null or garbled), count it as manually added
// This will prevent it's deletion upon
// If the data was not an array (null or garbled), count it as manually added.
// This will prevent it's deletion upon.
if (get_config("local_treestudyplan", "csync_remember_manual_csync")) {
$plans = ["manual"];
} else {
@ -105,61 +126,61 @@ class cascadecohortsync {
}
}
if (!in_array($this->studyplanid , $plans)) {
// if not, add it to the reference
//\mtrace("Adding this plan to the list");
// if not, add it to the reference.
//\mtrace("Adding this plan to the list");.
$plans[] = (int)($this->studyplanid);
$enrol->update_instance($instance, (object)["customtext4"=>json_encode($plans)]);
}
} else {
//\mtrace("New instance should be made");
//\mtrace("New instance should be made");.
// If method members should be added to a group, create it or get its ID.
if (get_config("local_treestudyplan", "csync_creategroup")) {
// Make or get new new cohort group - but only on creating of instances
// Make or get new new cohort group - but only on creating of instances.
$groupname = $cohort->name." ".strtolower(\get_string('defaultgroupname', 'core_group'));
//\mtrace("Adding group {$groupname} for this method");
// and make sure the
//\mtrace("Adding group {$groupname} for this method");.
// and make sure the .
$instancenewparams['customint2'] = self::uploadenrolmentmethods_get_group($courseid, $groupname);
}
if ($instanceid = $enrol->add_instance($course, $instancenewparams)) {
// also record the (as of yet only) studyplans id requiring this association
// in the customtext4 field in json format
//\mtrace("Instance ({$instanceid} created. Updateing instance with studyplan id");
// also record the (as of yet only) studyplans id requiring this association.
// in the customtext4 field in json format.
//\mtrace("Instance ({$instanceid} created. Updateing instance with studyplan id");.
$instance = $DB->get_record('enrol', array('id' => $instanceid));
$enrol->update_instance($instance, (object)["customtext4"=>json_encode([(int)($this->studyplanid)])]);
//\mtrace("Synchronize the enrolment");
//\mtrace("Synchronize the enrolment");.
// Successfully added a valid new instance, so now instantiate it.
// First synchronise the enrolment.
$cohorttrace = new \null_progress_trace();
$result = enrol_cohort_sync($cohorttrace, $cohortid);
if ($result > 0) {
//\mtrace("Error during 'enrol_cohort_sync': code {$result}");
//\mtrace("Error during 'enrol_cohort_sync': code {$result}");.
}
$cohorttrace->finished();
} else {
// Instance not added for some reason, so report an error somewhere
// (or not)
//\mtrace("Error - instance not added for some reason");
// Instance not added for some reason, so report an error somewhere.
// (or not).
//\mtrace("Error - instance not added for some reason");.
}
}
}
// 2: Check if there are cohort links for this studyplan in this course that should be removed
// A: Check if there are cohort links that are no longer related to this studyplan
// 2: Check if there are cohort links for this studyplan in this course that should be removed.
// A: Check if there are cohort links that are no longer related to this studyplan.
// B: Check if these links are valid through another studyplan...
// If no one uses the link anymore, deactivate it...
// INFO: This does not remove the sync from courses that are unlinked from a studplan. But maybe we do not want that anyway
// since it is generally a good idea to keep student access to courses available
// INFO: This does not remove the sync from courses that are unlinked from a studplan. But maybe we do not want that anyway.
// since it is generally a good idea to keep student access to courses available .
if (get_config("local_treestudyplan", "csync_autoremove")) {
// Only try the autoremove if the option is enabled
//\mtrace("Autoremove scan for course {$courseid} {$course->shortname}");
// find all cohort syncs for this course
// Only try the autoremove if the option is enabled.
//\mtrace("Autoremove scan for course {$courseid} {$course->shortname}");.
// find all cohort syncs for this course.
$searchparams = [
'courseid' => $courseid,
'enrol' => self::METHOD,
@ -168,27 +189,27 @@ class cascadecohortsync {
$records = $DB->get_records("enrol", $searchparams);
foreach ($records as $instance) {
if(!empty($instance->customtext4)){ // only check the records that have studyplan information in the customtext4 field
// first check if the cohort is not one of the cohort id's we have associated
if (!empty($instance->customtext4)) { // only check the records that have studyplan information in the customtext4 field.
// first check if the cohort is not one of the cohort id's we have associated.
if (!in_array($instance->customint1, $cohortids)) {
//\mtrace("Found cohort sync instance that is not currently liked to the studyplan: {$instance->id}");
// So it may or may not need to be removed
//\mtrace("Found cohort sync instance that is not currently liked to the studyplan: {$instance->id}");.
// So it may or may not need to be removed.
$plans = json_decode($instance->customtext4);
if ($plans !== null && is_array($plans)) {
//if a valid array is not returned, better leave it be, we don't want to mess with it
// otherwise, check if we should remove it
//if a valid array is not returned, better leave it be, we don't want to mess with it.
// otherwise, check if we should remove it.
if (in_array($this->studyplanid, $plans)) {
//\mtrace("Found this studyplan in the id list - removing from list");
//if this plan was referenced before
// first remove the link
//\mtrace("Found this studyplan in the id list - removing from list");.
//if this plan was referenced before.
// first remove the link.
$fplans = self::array_remove_value($plans, $this->studyplanid);
if (count($fplans) == 0) {
// delete the sync if there are no studyplan references left
//\mtrace("No references are left, removing instance");
// delete the sync if there are no studyplan references left.
//\mtrace("No references are left, removing instance");.
$enrol->delete_instance($instance);
} else {
// otherwise just update the references so this studyplan is no longer linked
//\mtrace("Still references left in the list, updating list...");
// otherwise just update the references so this studyplan is no longer linked.
//\mtrace("Still references left in the list, updating list...");.
$enrol->update_instance($instance, (object)["customtext4"=>json_encode($fplans)]);
}
}
@ -198,6 +219,6 @@ class cascadecohortsync {
}
}
}
//\mtrace("Cascading complete");
//\mtrace("Cascading complete");.
}
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -25,26 +46,26 @@ class cascadeusersync {
*/
$enrol = \enrol_get_plugin(self::METHOD);
// Find the courses that need to be synced to the associated cohorts
// Find the courses that need to be synced to the associated cohorts.
$courseids = $this->studyplan->get_linked_course_ids();
// And find the users that are linked to this studyplan.
$userids = $this->studyplan->get_linked_user_ids();
// Get the roleid to use for synchronizations
// Get the roleid to use for synchronizations.
$roleid = get_config("local_treestudyplan", "csync_roleid");
// Next, for each course that is linked:
// Next, for each course that is linked:.
foreach ($courseids as $courseid) {
$course = \get_course($courseid);
if (count($userids) > 0) {
// Get the manual enrol instance for this course
// Get the manual enrol instance for this course.
$instanceparams = ['courseid' => $courseid, 'enrol' => 'manual'];
if (!($instance = $DB->get_record('enrol', $instanceparams))) {
if ($instanceid = $enrol->add_default_instance($course)) {
$instance = $DB->get_record('enrol', array('id' => $instanceid));
}
else {
// Instance not added for some reason, so report an error somewhere
// (or not)
// Instance not added for some reason, so report an error somewhere.
// (or not).
$instance = null;
}
}
@ -57,7 +78,7 @@ class cascadeusersync {
}
// We do not do any autoremoval for user syncs, to avoid students losing access to the course data
// We do not do any autoremoval for user syncs, to avoid students losing access to the course data.
}
}

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -37,13 +57,13 @@ class completion {
}
public static function count_states(array $states) {
// initialize result array
// initialize result array.
$statecount = [];
foreach (array_keys(self::LABELS) as $key) {
$statecount[$key] = 0;
}
// process all states in array and increment relevant counter for each one
// process all states in array and increment relevant counter for each one.
foreach ($states as $c) {
if (array_key_exists($c, $statecount)) {
$statecount[$c] += 1;

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -44,18 +64,16 @@ class completionscanner
$this->completioninfo = new \completion_info($course);
// Find a related scanner if the type is an activity type
// Find a related scanner if the type is an activity type.
if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
// First find the course module
// First find the course module.
$this->cm = $this->modinfo->get_cm($crit->moduleinstance);
$gi = grade_item::fetch(['itemtype' => 'mod', 'itemmodule' => $this->cm->modname, 'iteminstance' => $this->cm->instance, 'courseid' => $this->courseid]);
if($gi !== false)
{
// Grade none items should not be relevant
// Note that the grade status is probably only relevant if the item has not yet received a completion, but has been submitted
if(($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE))
{
// If it's a relevant grade type, initialize a scanner if possible
if ($gi !== false) {
// Grade none items should not be relevant.
// Note that the grade status is probably only relevant if the item has not yet received a completion, but has been submitted.
if (($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE)) {
// If it's a relevant grade type, initialize a scanner if possible.
$this->gi = $gi;
if (self::supported($gi->itemmodule)) {
$scannerclass = "\local_treestudyplan\\local\ungradedscanners\\{$gi->itemmodule}_scanner";
@ -91,7 +109,7 @@ class completionscanner
public function model() {
// get completion info
// get completion info.
$students = self::get_course_students($this->courseid);
$completed = 0;
$ungraded = 0;
@ -99,13 +117,13 @@ class completionscanner
$completed_fail = 0;
foreach ($students as $userid) {
if ($this->pending($userid)) {
// First check if the completion needs grading
// First check if the completion needs grading.
$ungraded++;
} else {
$completion = $this->completioninfo->get_user_completion($userid, $this->crit);
if ($this->crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
// If it's an activity completion, add all the relevant activities as sub-items
// If it's an activity completion, add all the relevant activities as sub-items.
$completion_status = $this->completioninfo->get_grade_completion($this->cm, $userid);
if ($completion_status == COMPLETION_COMPLETE_PASS) {

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -29,7 +49,7 @@ class corecompletioninfo {
static public function completiontypes() {
global $COMPLETION_CRITERIA_TYPES;
// Just return the keys of the global array COMPLETION_CRITERIA_TYPES, so we don't have to manually
// Just return the keys of the global array COMPLETION_CRITERIA_TYPES, so we don't have to manually.
// add any completion types....
return \array_keys($COMPLETION_CRITERIA_TYPES);
}
@ -40,13 +60,13 @@ class corecompletioninfo {
*/
static public function completion_handle($completion) {
if (empty(self::$COMPLETION_HANDLES)) {
// Cache the translation table, to avoid overhead
// Cache the translation table, to avoid overhead.
self::$COMPLETION_HANDLES = [
COMPLETION_INCOMPLETE => "incomplete",
COMPLETION_COMPLETE => "complete",
COMPLETION_COMPLETE_PASS => "complete-pass",
COMPLETION_COMPLETE_FAIL => "complete-fail",
COMPLETION_COMPLETE_FAIL_HIDDEN => "complete-fail"]; // the front end won't differentiate between hidden or not
COMPLETION_COMPLETE_FAIL_HIDDEN => "complete-fail"]; // the front end won't differentiate between hidden or not.
}
return self::$COMPLETION_HANDLES[$completion] ?? "undefined";
}
@ -138,21 +158,20 @@ class corecompletioninfo {
global $DB, $CFG, $COMPLETION_CRITERIA_TYPES;
$conditions = [];
$aggregation = "all"; // default
$aggregation = "all"; // default.
$info = [
"conditions" => $conditions,
"aggregation" => self::aggregation_handle($this->completion->get_aggregation_method()),
"enabled" => $this->completion->is_enabled()
];
// Check if completion tracking is enabled for this course - otherwise, revert to defaults
if($this->completion->is_enabled())
{
// Check if completion tracking is enabled for this course - otherwise, revert to defaults .
if ($this->completion->is_enabled()) {
$aggregation = $this->completion->get_aggregation_method();
// Loop through all condition types to see if they are applicable
// Loop through all condition types to see if they are applicable.
foreach (self::completiontypes() as $type) {
$criterias = $this->completion->get_criteria($type); // Returns array of relevant criteria items
if(count($criterias) > 0 ) // Only take it into account if the criteria count is > 0
$criterias = $this->completion->get_criteria($type); // Returns array of relevant criteria items.
if (count($criterias) > 0 ) // Only take it into account if the criteria count is > 0.
{
$cinfo = [
"type" => $COMPLETION_CRITERIA_TYPES[$type],
@ -162,10 +181,10 @@ class corecompletioninfo {
];
foreach ($criterias as $criteria) {
// Unfortunately, we cannot easily get the criteria details with get_details() without having a
// user completion object involved, so'we'll have to retrieve the details per completion type
// See moodle/completion/criteria/completion_criteria_*.php::get_details() for the code that is
// in the code below is based on
// Unfortunately, we cannot easily get the criteria details with get_details() without having a .
// user completion object involved, so'we'll have to retrieve the details per completion type.
// See moodle/completion/criteria/completion_criteria_*.php::get_details() for the code that is.
// in the code below is based on.
if ($type == COMPLETION_CRITERIA_TYPE_SELF) {
$details = [
@ -195,8 +214,8 @@ class corecompletioninfo {
$cm = $this->modinfo->get_cm($criteria->moduleinstance);
$details = [
"type" => $criteria->get_title(),
"criteria" => "", // Will be built in a moment by code copied from completion_criteria_activity.php
"requirement" => "", // Will be built momentarily by code copied from completion_criteria_activity.php
"criteria" => "", // Will be built in a moment by code copied from completion_criteria_activity.php.
"requirement" => "", // Will be built momentarily by code copied from completion_criteria_activity.php.
"status" => "",
];
if ($cm->has_view()) {
@ -204,7 +223,7 @@ class corecompletioninfo {
} else {
$details['criteria'] = $cm->get_formatted_name();
}
// Build requirements
// Build requirements.
$details['requirement'] = array();
if ($cm->completion == COMPLETION_TRACKING_MANUAL) {
@ -239,7 +258,7 @@ class corecompletioninfo {
$details = [
"type" => get_string('coursegrade', 'completion'),
"criteria" => get_string('graderequired', 'completion'),
// TODO: convert to selected representation (letter, percentage, etc)
// TODO: convert to selected representation (letter, percentage, etc).
"requirement" => get_string('graderequired', 'completion').": ".format_float($criteria->gradepass, 1),
"status" => "",
];
@ -265,7 +284,7 @@ class corecompletioninfo {
"status" => "",
];
} else {
// Moodle added a criteria type
// Moodle added a criteria type.
$details = [
"type" => "",
"criteria" => "",
@ -307,7 +326,7 @@ class corecompletioninfo {
if ($typeaggregation == COMPLETION_AGGREGATION_ALL) {
return $completed >= $count;
}
else { // COMPLETION_AGGREGATION_ANY
else { // COMPLETION_AGGREGATION_ANY.
return $completed > 1;
}
@ -327,13 +346,12 @@ class corecompletioninfo {
"tracked" => $this->completion->is_tracked_user($userid),
];
// Check if completion tracking is enabled for this course - otherwise, revert to defaults
if($this->completion->is_enabled() && $this->completion->is_tracked_user($userid))
{
// Check if completion tracking is enabled for this course - otherwise, revert to defaults .
if ($this->completion->is_enabled() && $this->completion->is_tracked_user($userid)) {
$anypending = false;
// Loop through all conditions to see if they are applicable
// Loop through all conditions to see if they are applicable.
foreach (self::completiontypes() as $type) {
// Get the main completion for this type
// Get the main completion for this type.
$completions = $this->completion->get_completions($userid, $type);
if (count($completions) > 0) {
$typeaggregation = $this->completion->get_aggregation_method($type);
@ -352,32 +370,32 @@ class corecompletioninfo {
$criteria = $completion->get_criteria();
if ($completion->is_complete()) {
$progress += 1; // Add a point to the progress counter
$progress += 1; // Add a point to the progress counter.
}
$iinfo = [
"id" => $criteria->id,
"title" => $criteria->get_title_detailed(),
"details" => $criteria->get_details($completion),
"completed" => $completion->is_complete(), // Make sure to override for activi
"completed" => $completion->is_complete(), // Make sure to override for activi.
"status" => self::completion_handle($completion->is_complete()?COMPLETION_COMPLETE:COMPLETION_INCOMPLETE),
];
if ($type == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$cm = $this->modinfo->get_cm($criteria->moduleinstance);
// If it's an activity completion, add all the relevant activities as sub-items
// If it's an activity completion, add all the relevant activities as sub-items.
$completion_status = $this->completion->get_grade_completion($cm, $userid);
$iinfo['status'] = self::completion_handle($completion_status);
// Re-evaluate the completed value, to make sure COMPLETE_FAIL doesn't creep in as completed
// Re-evaluate the completed value, to make sure COMPLETE_FAIL doesn't creep in as completed.
$iinfo['completed'] = in_array($completion_status, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]);
// Determine the grade (retrieve from grade item, not from completion)
// Determine the grade (retrieve from grade item, not from completion).
$grade = $this->get_grade($cm, $userid);
$iinfo['grade'] = $grade->grade;
$iinfo['feedback'] = $grade->feedback;
$iinfo['pending'] = $grade->pending;
$anypending = $anypending || $grade->pending;
// Overwrite the status with progress if something has been graded, or is pending
// Overwrite the status with progress if something has been graded, or is pending.
if ($completion_status != COMPLETION_INCOMPLETE || $anypending) {
if ($cinfo["status"] == "incomplete") {
$cinfo["status"] = "progress";
@ -386,7 +404,7 @@ class corecompletioninfo {
}
else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) {
// Make sure we provide the current course grade
// Make sure we provide the current course grade.
$iinfo['grade'] = floatval($iinfo['details']['status']);
if ($iinfo["grade"] > 0) {
$iinfo["grade"] = format_float($iinfo["grade"], 1). "/".format_float(floatval($iinfo['details']['requirement']));
@ -396,19 +414,19 @@ class corecompletioninfo {
}
}
}
// finally add the item to the items list
// finally add the item to the items list.
$cinfo["items"][] = $iinfo;
}
// Set the count and progress stats based on the Type's aggregation style
// Set the count and progress stats based on the Type's aggregation style.
if ($typeaggregation == COMPLETION_AGGREGATION_ALL) {
// Count and Progress amount to the sum of items
// Count and Progress amount to the sum of items.
$cinfo["count"] = count($cinfo["items"]);
$cinfo["progress"] = $progress;
}
else { //$typeaggregation == COMPLETION_AGGREGATION_ANY
// Count and progress are either 1 or 0, since any of the items
// complete's the type
else { //$typeaggregation == COMPLETION_AGGREGATION_ANY.
// Count and progress are either 1 or 0, since any of the items.
// complete's the type.
$cinfo["count"] = (count($cinfo["items"]) > 0)?1:0;
$cinfo["progress"] = ($progress>0)?1:0;
}
@ -427,32 +445,30 @@ class corecompletioninfo {
* @return stdClass|null object containing 'grade' and optional 'feedback' attribute
*/
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',
'itemmodule' => $cm->modname,
'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.
if($gi)
{
// Only the following types of grade yield a result
if(($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE))
{
if ($gi) {
// Only the following types of grade yield a result.
if (($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE)) {
$scale = $gi->load_scale();
$grade = (object)$gi->get_final($userid); // Get the grade for the specified user
$grade = (object)$gi->get_final($userid); // Get the grade for the specified user.
$result = new \stdClass;
// Check if the final grade is available and numeric (safety check)
// Check if the final grade is available and numeric (safety check).
if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) {
// convert scale grades to corresponding scale name
// convert scale grades to corresponding scale name.
if (isset($scale)) {
// get scale value
// get scale value.
$result->grade = $scale->get_nearest_item($grade->finalgrade);
}
else
{
// round final grade to 1 decimal point
// round final grade to 1 decimal point.
$result->grade = round($grade->finalgrade, 1);
}
@ -460,7 +476,7 @@ class corecompletioninfo {
$result->pending = (new gradingscanner($gi))->pending($userid);
}
else {
$result->grade = "-"; // Activity is gradable, but user did not receive a grade yet
$result->grade = "-"; // Activity is gradable, but user did not receive a grade yet.
$result->feedback = null;
$result->pending = false;
}
@ -468,7 +484,7 @@ class corecompletioninfo {
}
}
return null; // Activity cannot be graded (Shouldn't be happening, but still....)
return null; // Activity cannot be graded (Shouldn't be happening, but still....).
}
/**
@ -476,38 +492,36 @@ class corecompletioninfo {
* @return stdClass|null object containing 'grade' and optional 'feedback' attribute
*/
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',
'iteminstance' => $this->course->id,
'courseid' => $this->course->id]);
if($gi)
{
// Only the following types of grade yield a result
if(($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE))
{
if ($gi) {
// Only the following types of grade yield a result.
if (($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE)) {
$scale = $gi->load_scale();
$grade = $gi->get_final($userid); // Get the grade for the specified user
// Check if the final grade is available and numeric (safety check)
$grade = $gi->get_final($userid); // Get the grade for the specified user.
// Check if the final grade is available and numeric (safety check).
if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) {
// convert scale grades to corresponding scale name
// convert scale grades to corresponding scale name.
if (isset($scale)) {
// get scale value
// get scale value.
return $scale->get_nearest_item($grade->finalgrade);
}
else
{
// round final grade to 1 decimal point
// round final grade to 1 decimal point.
return round($grade->finalgrade, 1);
}
}
else {
return "-"; // User did not receive a grade yet for this course
return "-"; // User did not receive a grade yet for this course.
}
}
}
return null; // Course cannot be graded (Shouldn't be happening, but still....)
return null; // Course cannot be graded (Shouldn't be happening, but still....).
}
@ -534,18 +548,18 @@ class corecompletioninfo {
$count = count($completions);
$completed = 0;
// Before we check how many modules have been completed see if the course has completed.
// Before we check how many modules have been completed see if the course has completed. .
if ($this->completion->is_course_complete($userid)) {
$completed = $count;
}
else {
// count all completions, but treat
// count all completions, but treat .
foreach ($completions as $completion) {
$crit = $completion->get_criteria();
if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
// get the cm data object
// get the cm data object.
$cm = $this->modinfo->get_cm($crit->moduleinstance);
// retrieve data for this object
// retrieve data for this object.
$data = $this->completion->get_data($cm, false, $userid);
// Count complete, but failed as incomplete too...
if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) {
@ -591,12 +605,12 @@ class corecompletioninfo {
$aggregation = $this->completion->get_aggregation_method();
$critcount = [];
// Before we check how many modules have been completed see if the course has completed.
// count all completions, but treat
// Before we check how many modules have been completed see if the course has completed. .
// count all completions, but treat .
foreach ($completions as $completion) {
$crit = $completion->get_criteria();
// Make a new object for the type if it's not already there
// Make a new object for the type if it's not already there.
$type = $crit->criteriatype;
if (!array_key_exists($type, $critcount)) {
$critcount[$type] = new \stdClass;
@ -604,14 +618,14 @@ class corecompletioninfo {
$critcount[$type]->completed = 0;
$critcount[$type]->aggregation = $this->completion->get_aggregation_method($type);
}
// Get a reference to the counter object for this type
// Get a reference to the counter object for this type.
$typecount =& $critcount[$type];
$typecount->count += 1;
if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
// get the cm data object
// get the cm data object.
$cm = $this->modinfo->get_cm($crit->moduleinstance);
// retrieve data for this object
// retrieve data for this object.
$data = $this->completion->get_data($cm, false, $userid);
// Count complete, but failed as incomplete too...
if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) {
@ -627,15 +641,15 @@ class corecompletioninfo {
}
}
// Now that we have all completions sorted by type, we can be smart about how to do the count
// Now that we have all completions sorted by type, we can be smart about how to do the count.
$count = 0;
$completed = 0;
$completion_percentage = 0;
foreach ($critcount as $c) {
// Take only types that are actually present into account
// Take only types that are actually present into account.
if ($c->count > 0) {
// If the aggregation for the type is ANY, reduce the count to 1 for this type
// And adjust the progress accordingly (check if any have been completed or not)
// If the aggregation for the type is ANY, reduce the count to 1 for this type.
// And adjust the progress accordingly (check if any have been completed or not).
if ($c->aggregation == COMPLETION_AGGREGATION_ALL) {
$ct = $c->count;
$cmpl = $c->completed;
@ -644,8 +658,8 @@ class corecompletioninfo {
$ct = 1;
$cmpl = ($c->completed > 0)?1:0;
}
// if ANY completion for the types, count only the criteria type with the highest completion percentage -
// Overwrite data if current type is more complete
// if ANY completion for the types, count only the criteria type with the highest completion percentage -.
// Overwrite data if current type is more complete.
if ($aggregation == COMPLETION_AGGREGATION_ANY) {
$pct = $cmpl/$ct;
if ($pct > $completion_percentage) {
@ -654,11 +668,11 @@ class corecompletioninfo {
$completion_percentage = $pct;
}
}
// if ALL completion for the types, add the count for this type to that of the others
// if ALL completion for the types, add the count for this type to that of the others.
else {
$count += $ct;
$completed += $cmpl;
// Don't really care about recalculating completion percentage every round in this case
// Don't really care about recalculating completion percentage every round in this case.
}
}
}

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -29,7 +49,7 @@ class courseinfo {
}
public function course() {
return $this->course; // php arrays are assigned by copy
return $this->course; // php arrays are assigned by copy.
}
public function course_context() {
@ -97,10 +117,8 @@ class courseinfo {
public static function coursetiming($course) {
$now = time();
if($now > $course->startdate)
{
if($course->enddate > 0 && $now > $course->enddate)
{
if ($now > $course->startdate) {
if ($course->enddate > 0 && $now > $course->enddate) {
return "past";
}
else {
@ -137,7 +155,7 @@ class courseinfo {
}
}
}
// Fallback to shortname when the specified display field fails, since shortname is never empty
// Fallback to shortname when the specified display field fails, since shortname is never empty.
return $this->course->shortname;
}

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -17,11 +37,11 @@ class coursemoduleinfo {
public function __construct($id) {
global $DB;
// Determine the icon for the associated activity
// Determine the icon for the associated activity.
$this->id = $id;
$this->cm = $DB->get_record("course_modules", ["id" => $id]);
$this->cm_info = \cm_info::create($this->cm);
// $this->db_record = $DB->get_record($this->cm_info->modname,["id" => $this->cm_info->instance]);
// $this->db_record = $DB->get_record($this->cm_info->modname, ["id" => $this->cm_info->instance]);.
}
public function getTitle() {
@ -30,7 +50,7 @@ class coursemoduleinfo {
public function setTitle($value) {
$this->cm_info->set_name($value);
// TODO: Actually save this after setting the cminfo
// TODO: Actually save this after setting the cminfo.
}
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -31,8 +52,7 @@ class courseservice extends \external_api
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 = [
"id" => new \external_value(PARAM_INT, 'course category id'),
"context_id" => new \external_value(PARAM_INT, 'course category context id'),
@ -54,16 +74,16 @@ class courseservice extends \external_api
$root = \core_course_category::get($root_id);
$context = $root->get_context();
// Make sure the user has access to the context for editing purposes
// Make sure the user has access to the context for editing purposes.
webservicehelper::require_capabilities(self::CAP_EDIT, $context);
// Determine top categories from provided context
// Determine top categories from provided context.
if ($root->id == 0) {
// on the system level, determine the user's topmost allowed catecories
// on the system level, determine the user's topmost allowed catecories.
$user_top = \core_course_category::user_top();
if ($user_top->id == 0) { // top category..
$children = $root->get_children(); // returns a list of çore_course_category, let it overwrite $children
$children = $root->get_children(); // returns a list of çore_course_category, let it overwrite $children.
} else {
$children = [$user_top];
}
@ -98,7 +118,7 @@ class courseservice extends \external_api
global $DB;
$catcontext = $cat->get_context();
$ctx_info = new contextinfo($catcontext);
$children = $cat->get_children(); // only shows children visible to the current user
$children = $cat->get_children(); // only shows children visible to the current user.
$courses = $cat->get_courses();
$model = [
"id" => $cat->id,
@ -108,8 +128,7 @@ class courseservice extends \external_api
"hascourses" => !empty($courses),
];
if(!$lazy)
{
if (!$lazy) {
$model["courses"] = [];
foreach ($courses as $course) {
$courseinfo = new courseinfo($course->id);
@ -141,7 +160,7 @@ class courseservice extends \external_api
{
if ($operation == "edit") {
$capability = self::CAP_EDIT;
} else { // $operation == "view" || default
} else { // $operation == "view" || default.
$capability = self::CAP_VIEW;
}
@ -157,9 +176,9 @@ class courseservice extends \external_api
}
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 = [];
// initialize parent if needed
// initialize parent if needed.
if ($parent == null) {
$parent = \core_course_category::user_top();
if (has_capability($capability, $parent->get_context())) {
@ -169,11 +188,11 @@ class courseservice extends \external_api
$children = $parent->get_children();
foreach ($children as $child) {
// Check if we should add this category
// Check if we should add this category.
if (has_capability($capability, $child->get_context())) {
$list[] = $child;
// For optimization purposes, we include all its children now, since they will have inherited the permission
// #PREMATURE_OPTIMIZATION ???
// For optimization purposes, we include all its children now, since they will have inherited the permission.
// #PREMATURE_OPTIMIZATION ???.
$list = array_merge($list, self::recursive_child_categories($child));
} else {
if ($child->get_children_count() > 0) {
@ -214,7 +233,7 @@ class courseservice extends \external_api
global $DB;
if ($operation == "edit") {
$capability = self::CAP_EDIT;
} else { // $operation == "view" || default
} else { // $operation == "view" || default.
$capability = self::CAP_VIEW;
}
$context_ids = [];
@ -226,8 +245,8 @@ class courseservice extends \external_api
$rs->close();
// Now filter the categories that the user has acces to by the used context id's
// (That should filter out irrelevant stuff)
// Now filter the categories that the user has acces to by the used context id's.
// (That should filter out irrelevant stuff).
$cats = static::categories_by_capability($capability);
$list = [];
@ -249,10 +268,10 @@ class courseservice extends \external_api
global $DB;
if ($operation == "edit") {
$capability = self::CAP_EDIT;
} else { // $operation == "view" || default
} else { // $operation == "view" || default.
$capability = self::CAP_VIEW;
}
// retrieve context ids used
// retrieve context ids used.
$context_ids = [];
$rs = $DB->get_recordset_sql("SELECT DISTINCT context_id, COUNT(*) as num FROM {local_treestudyplan}
GROUP BY context_id");
@ -261,8 +280,8 @@ class courseservice extends \external_api
}
$rs->close();
// Now filter the categories that the user has acces to by the used context id's
// (That should filter out irrelevant stuff)
// Now filter the categories that the user has acces to by the used context id's.
// (That should filter out irrelevant stuff).
$cats = static::categories_by_capability($capability);
$list = [];
@ -288,8 +307,7 @@ class courseservice extends \external_api
*
**************************************/
public static function scan_grade_progress_parameters()
{
public static function scan_grade_progress_parameters() {
return new \external_function_parameters( [
"gradeitemid" => new \external_value(PARAM_INT, 'Grade item ID to scan progress for', VALUE_DEFAULT),
"studyplanid" => new \external_value(PARAM_INT, 'Study plan id to check progress in', VALUE_DEFAULT),
@ -297,22 +315,20 @@ class courseservice extends \external_api
]);
}
public static function scan_grade_progress_returns()
{
public static function scan_grade_progress_returns() {
return gradingscanner::structure(VALUE_REQUIRED);
}
public static function scan_grade_progress($gradeitemid, $studyplanid)
{
public static function scan_grade_progress($gradeitemid, $studyplanid) {
global $DB;
// Verify access to the study plan
// Verify access to the study plan.
$o = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $o->context());
// Retrieve grade item
// Retrieve grade item.
$gi = \grade_item::fetch(["id" => $gradeitemid]);
// Validate course is linked to studyplan
// Validate course is linked to studyplan.
$courseid = $gi->courseid;
if (!$o->course_linked($courseid)) {
throw new \webservice_access_exception("Course {$courseid} linked to grade item {$gradeitemid} is not linked to studyplan {$o->id()}");
@ -340,7 +356,7 @@ class courseservice extends \external_api
public static function scan_completion_progress($criteriaid, $studyplanid, $courseid)
{
global $DB;
// Verify access to the study plan
// Verify access to the study plan.
$o = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $o->context());
@ -371,22 +387,22 @@ class courseservice extends \external_api
public static function scan_badge_progress($badgeid, $studyplanid)
{
global $DB;
// Check access to the study plan
// Check access to the study plan.
$o = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $o->context());
// Validate that badge is linked to studyplan
// Validate that badge is linked to studyplan.
if (!$o->badge_linked($badgeid)) {
throw new \webservice_access_exception("Badge {$badgeid} is not linked to studyplan {$o->id()}");
}
// Get badge info
// Get badge info.
$badge = new \core_badges\badge($badgeid);
$badgeinfo = new badgeinfo($badge);
// get the connected users
// get the connected users.
$students = associationservice::all_associated($studyplanid);
// Just get the user ids
// Just get the user ids.
$studentids = array_map(function ($a) { return $a["id"];}, $students);
return [

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -77,8 +97,7 @@ class gradeinfo {
public static function getCourseContextById($id) {
$gi = grade_item::fetch(["id" => $id]);
if(!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance))
{
if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
throw new \InvalidArgumentException ("Grade {$id} not found in database". print_r($gi, true));
}
return \context_course::instance($gi->courseid);;
@ -89,18 +108,17 @@ class gradeinfo {
$this->studyitem = $studyitem;
$gi = grade_item::fetch(["id" => $id]);
if(!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance))
{
if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
throw new \InvalidArgumentException ("Grade {$id} not found in database". print_r($gi, true));
}
$this->id = $id;
$this->gradeitem = $gi;
// Determine the icon for the associated activity
// Determine the icon for the associated activity.
$contentitem = static::get_contentitem($gi->itemmodule);
$this->icon = empty($contentitem)?"":$contentitem->get_icon();
// Determine a link to the associated activity
// Determine a link to the associated activity.
if ($gi->itemtype != "mod" || empty($gi->itemmodule) || empty($gi->iteminstance)) {
$this->link = "";
$this->cmid = 0;
@ -110,8 +128,8 @@ class gradeinfo {
else {
list($c, $cminfo) = get_course_and_cm_from_instance($gi->iteminstance, $gi->itemmodule);
$this->cmid = $cminfo->id;
// sort by position in course
//
// sort by position in course.
// .
$this->section = $cminfo->sectionnum;
$ssequence = self::getSectionSequence($cminfo->section);
$this->sectionorder = array_search($cminfo->id, $ssequence);
@ -144,7 +162,7 @@ class gradeinfo {
public function is_selected() {
global $DB;
if ($this->studyitem) {
// Check if selected for this studyitem
// Check if selected for this studyitem.
$r = $DB->get_record('local_treestudyplan_gradeinc', ['studyitem_id' => $this->studyitem->id(), 'grade_item_id'=> $this->gradeitem->id]);
if ($r && $r->include) {
return(true);
@ -156,7 +174,7 @@ class gradeinfo {
public function is_required() {
global $DB;
if ($this->studyitem) {
// Check if selected for this studyitem
// Check if selected for this studyitem.
$r = $DB->get_record('local_treestudyplan_gradeinc', ['studyitem_id' => $this->studyitem->id(), 'grade_item_id'=> $this->gradeitem->id]);
if ($r && $r->include && $r->required) {
return(true);
@ -224,7 +242,7 @@ class gradeinfo {
public function user_model($userid) {
global $DB;
$grade = $this->gradeitem->get_final($userid);
// convert scale grades to corresponding scale name
// convert scale grades to corresponding scale name.
if (!empty($grade)) {
if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) {
$finalgrade = "-";
@ -242,7 +260,7 @@ class gradeinfo {
$finalgrade = "-";
}
// retrieve the aggregator and determine completion
// retrieve the aggregator and determine completion.
if (!isset($this->studyitem)) {
throw new \UnexpectedValueException("Study item not set (null) for gradeinfo in report mode");
}
@ -285,7 +303,7 @@ class gradeinfo {
$gi_type = $gi->itemmodule;
if ($gi_name == $model["name"] && $gi_type == $model["type"]) {
// we have a match
// we have a match.
if (!isset($model["selected"])) { $model["selected"] = true;}
if (!isset($model["required"])) { $model["required"] = false;}
if ($model["selected"] || $model["required"]) {
@ -302,19 +320,15 @@ class gradeinfo {
if (method_exists("\course_modinfo", "get_array_of_activities")) {
$activities = \course_modinfo::get_array_of_activities($course);
} else {
// Deprecated in Moodle 4.0+, but not yet available in Moodle 3.11
// Deprecated in Moodle 4.0+, but not yet available in Moodle 3.11.
$activities = get_array_of_activities($course->id);
}
foreach($activities as $act)
{
if($act->visible)
{
foreach ($activities as $act) {
if ($act->visible) {
$gradeitems= grade_item::fetch_all(['itemtype' => 'mod', 'itemmodule' => $act->mod, 'iteminstance' => $act->id, 'courseid' => $course->id]);
if(!empty($gradeitems))
{
if (!empty($gradeitems)) {
foreach ($gradeitems as $gi) {
if(($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE))
{
if (($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE)) {
try {
$gradable = new static($gi->id, $studyitem);
$list[] = $gradable;
@ -333,8 +347,7 @@ class gradeinfo {
return $list;
}
public static function list_studyitem_gradables(studyitem $studyitem)
{
public static function list_studyitem_gradables(studyitem $studyitem) {
global $DB;
$table = 'local_treestudyplan_gradeinc';
$list = [];
@ -347,8 +360,8 @@ class gradeinfo {
}
}
catch(\InvalidArgumentException $x) {
// on InvalidArgumentException, the grade_item id can no longer be found
// Remove the link to avoid database record hogging
// on InvalidArgumentException, the grade_item id can no longer be found.
// Remove the link to avoid database record hogging.
$DB->delete_records($table, ['id' => $r->id]);
}
}
@ -365,7 +378,7 @@ class gradeinfo {
global $DB;
$table = 'local_treestudyplan_gradeinc';
if ($include) {
// make sure a record exits
// make sure a record exits.
$r = $DB->get_record($table, ['studyitem_id' => $item_id, 'grade_item_id' => $grade_id]);
if ($r) {
$r->include = 1;
@ -380,7 +393,7 @@ class gradeinfo {
);
}
} else {
// remove if it should not be included
// remove if it should not be included.
$r = $DB->get_record($table, ['studyitem_id' => $item_id, 'grade_item_id' => $grade_id]);
if ($r) {
$DB->delete_records($table, ['id' => $r->id]);

View File

@ -1,13 +1,33 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
use \grade_item;
// $gi->courseid,
// $gi->itemmodule,
// $gi->iteminstance
// $gi->courseid, .
// $gi->itemmodule, .
// $gi->iteminstance.
class gradingscanner
{
private static $mod_supported = [];
@ -73,7 +93,7 @@ class gradingscanner
}
public function model() {
// Upda
// Upda.
$students = self::get_course_students($this->courseid);
$completed = 0;
$ungraded = 0;
@ -81,16 +101,16 @@ class gradingscanner
$completed_fail = 0;
foreach ($students as $userid) {
if ($this->pending($userid)) {
// First check if the completion needs grading
// First check if the completion needs grading.
$ungraded++;
} else {
$grade = $this->gi->get_final($userid);
if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) {
//skip
//skip.
}
else
{
//compare grade to minimum grade
//compare grade to minimum grade.
if ($this->grade_passed($grade)) {
$completed_pass++;
} else {
@ -110,18 +130,17 @@ class gradingscanner
}
// Function copied from bistate aggregator to avoid reference mazes
// Function copied from bistate aggregator to avoid reference mazes.
private function grade_passed($grade) {
global $DB;
$table = "local_treestudyplan_gradecfg";
// first determine if we have a grade_config for this scale or this maximum grade
// first determine if we have a grade_config for this scale or this maximum grade.
$finalgrade = $grade->finalgrade;
$scale = $this->gi->load_scale();
if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
}
else if($this->gi->grademin == 0)
{
else if ($this->gi->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$this->gi->grademax]);
}
else
@ -129,12 +148,11 @@ class gradingscanner
$gradecfg = null;
}
// for point grades, a provided grade pass overrides the defaults in the gradeconfig
// for scales, the configuration in the gradeconfig is leading
// for point grades, a provided grade pass overrides the defaults in the gradeconfig.
// for scales, the configuration in the gradeconfig is leading.
if($gradecfg && (isset($scale) || $this->gi->gradepass == 0))
{
// if so, we need to know if the grade is
if ($gradecfg && (isset($scale) || $this->gi->gradepass == 0)) {
// if so, we need to know if the grade is .
if ($finalgrade >= $gradecfg->min_completed) {
return true;
}
@ -142,8 +160,7 @@ class gradingscanner
return false;
}
}
else if($this->gi->gradepass > 0)
{
else if ($this->gi->gradepass > 0) {
$range = floatval($this->gi->grademax - $this->gi->grademin);
// if no gradeconfig and gradepass is set, use that one to determine config.
if ($finalgrade >= $this->gi->gradepass) {
@ -154,9 +171,9 @@ class gradingscanner
}
}
else {
// Blind assumptions if nothing is provided
// over 55% of range is completed
// if range >= 3 and failed is enabled, assume that this means failed
// Blind assumptions if nothing is provided.
// over 55% of range is completed.
// if range >= 3 and failed is enabled, assume that this means failed.
$g = floatval($finalgrade - $this->gi->grademin);
$range = floatval($this->gi->grademax - $this->gi->grademin);
$score = $g / $range;

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\aggregators;
@ -12,25 +33,24 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
public const DEPRECATED = false;
private const DEFAULT_CONDITION = "50";
private $thresh_excellent = 1.0; // Minimum fraction that must be completed to aggregate as excellent (usually 1.0)
private $thresh_good = 0.8; // Minimum fraction that must be completed to aggregate as good
private $thresh_completed = 0.66; // Minimum fraction that must be completed to aggregate as completed
private $use_failed = True; // Support failed completion yes/no
private $thresh_progress = 0.33; // Minimum fraction that must be failed to aggregate as failed instead of progress
private $accept_pending_as_submitted = False; // Also count ungraded but submitted
private $thresh_excellent = 1.0; // Minimum fraction that must be completed to aggregate as excellent (usually 1.0).
private $thresh_good = 0.8; // Minimum fraction that must be completed to aggregate as good.
private $thresh_completed = 0.66; // Minimum fraction that must be completed to aggregate as completed.
private $use_failed = True; // Support failed completion yes/no.
private $thresh_progress = 0.33; // Minimum fraction that must be failed to aggregate as failed instead of progress.
private $accept_pending_as_submitted = False; // Also count ungraded but submitted .
public function __construct($configstr) {
// allow public constructor for testing purposes
// allow public constructor for testing purposes.
$this->initialize($configstr);
}
protected function initialize($configstr) {
// First initialize with the defaults
// First initialize with the defaults.
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress", ] as $key) {
$val = intval(get_config('local_treestudyplan', "bistate_{$key}"));
if($val >= 0 && $val <= 100)
{
if ($val >= 0 && $val <= 100) {
$this->$key = floatval($val)/100;
}
}
@ -38,16 +58,15 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$this->$key = boolval(get_config('local_treestudyplan', "bistate_{$key}"));
}
// Next, decode json
// Next, decode json.
$config = \json_decode($configstr, true);
if (is_array($config)) {
// copy all valid config settings to this item
// copy all valid config settings to this item.
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress", ] as $key) {
if (array_key_exists($key, $config)) {
$val = $config[$key];
if($val >= 0 && $val <= 100)
{
if ($val >= 0 && $val <= 100) {
$this->$key = floatval($val)/100;
}
}
@ -62,7 +81,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
}
}
// Return active configuration model
// Return active configuration model.
public function config_string() {
return json_encode([
"thresh_excellent" => 100*$this->thresh_excellent,
@ -81,16 +100,16 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_binary_goals(array $completions, array $required = []) {
// function is public to allow access for the testing code
// function is public to allow access for the testing code.
// return te following conditions
// Possible states:
// - completion::EXCELLENT - At least $thresh_excellent fraction of goals are complete and all required goals are met
// - completion::GOOD - At least $thresh_good fraction of goals are complete and all required goals are met
// - completion::COMPLETED - At least $thresh_complete fraction of goals are completed and all required goals are met
// - completion::FAILED - At least $thresh_progress fraction of goals is not failed
// - completion::INCOMPLETE - No goals have been started
// - completion::PROGRESS - All other states
// return te following conditions.
// Possible states:.
// - completion::EXCELLENT - At least $thresh_excellent fraction of goals are complete and all required goals are met.
// - completion::GOOD - At least $thresh_good fraction of goals are complete and all required goals are met.
// - completion::COMPLETED - At least $thresh_complete fraction of goals are completed and all required goals are met.
// - completion::FAILED - At least $thresh_progress fraction of goals is not failed.
// - completion::INCOMPLETE - No goals have been started.
// - completion::PROGRESS - All other states.
$total = count($completions);
@ -148,13 +167,13 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
foreach (gradeinfo::list_studyitem_gradables($studyitem) as $gi) {
$completions[] = $this->grade_completion($gi, $userid);
if ($gi->is_required()) {
// if it's a required grade
// also add it's index in the completion list to the list of required grades
// if it's a required grade .
// also add it's index in the completion list to the list of required grades .
$required[] = count($completions) - 1;
}
}
// Combine the aquired completions into one
// Combine the aquired completions into one.
$result = self::aggregate_binary_goals($completions, $required);
if ($this->use_failed && $result == completion::PROGRESS && $coursefinished) {
return completion::FAILED;
@ -166,15 +185,15 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_junction(array $completion, studyitem $studyitem = null, $userid = 0) {
// Aggregate multiple incoming states into one junction or finish.
// Possible states:
// - completion::EXCELLENT - All incoming states are excellent
// - completion::GOOD - All incoming states are at least good
// - completion::COMPLETED - All incoming states are at least completed
// - completion::FAILED - All incoming states are failed
// - completion::INCOMPLETE - All incoming states are incomplete
// - completion::PROGRESS - All other states
// Possible states:.
// - completion::EXCELLENT - All incoming states are excellent.
// - completion::GOOD - All incoming states are at least good.
// - completion::COMPLETED - All incoming states are at least completed.
// - completion::FAILED - All incoming states are failed.
// - completion::INCOMPLETE - All incoming states are incomplete.
// - completion::PROGRESS - All other states.
// First count all states
// First count all states.
$statecount = completion::count_states($completion);
$total = count($completion);
@ -203,20 +222,19 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$table = "local_treestudyplan_gradecfg";
$gradeitem = $gradeinfo->getGradeitem();
$grade = $gradeitem->get_final($userid);
$course = \get_course($gradeitem->courseid); // Fetch course from cache
$course = \get_course($gradeitem->courseid); // Fetch course from cache.
$coursefinished = ($course->enddate)?($course->enddate < time()):false;
if (empty($grade)) {
return completion::INCOMPLETE;
}
else if($grade->finalgrade === NULL)
{
// on assignments, grade NULL means a submission has not yet been graded,
// but on quizes this can also mean a quiz might have been started
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items
else if ($grade->finalgrade === NULL) {
// on assignments, grade NULL means a submission has not yet been graded,.
// but on quizes this can also mean a quiz might have been started.
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
// Since we want old results to be visible until a pending item was graded, we only use this state here.
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model.
if ($gradeinfo->getGradingscanner()->pending($userid)) {
return completion::PENDING;
} else {
@ -225,14 +243,13 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
}
else {
$grade = $gradeitem->get_final($userid);
// first determine if we have a grade_config for this scale or this maximum grade
// first determine if we have a grade_config for this scale or this maximum grade.
$finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale();
if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
}
else if($gradeitem->grademin == 0)
{
else if ($gradeitem->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]);
}
else
@ -240,34 +257,30 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$gradecfg = null;
}
// for point grades, a provided grade pass overrides the defaults in the gradeconfig
// for scales, the configuration in the gradeconfig is leading
// for point grades, a provided grade pass overrides the defaults in the gradeconfig.
// for scales, the configuration in the gradeconfig is leading.
if($gradecfg && (isset($scale) || $gradeitem->gradepass == 0))
{
// if so, we need to know if the grade is
if ($gradecfg && (isset($scale) || $gradeitem->gradepass == 0)) {
// if so, we need to know if the grade is .
if ($finalgrade >= $gradecfg->min_completed) {
// return completed if completed
// return completed if completed.
return completion::COMPLETED;
}
else if($this->use_failed && $coursefinished)
{
// return failed if failed is enabled and the grade is less than the minimum grade for progress
else if ($this->use_failed && $coursefinished) {
// return failed if failed is enabled and the grade is less than the minimum grade for progress.
return completion::FAILED;
}
else {
return completion::PROGRESS;
}
}
else if($gradeitem->gradepass > 0)
{
else if ($gradeitem->gradepass > 0) {
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
// if no gradeconfig and gradepass is set, use that one to determine config.
if ($finalgrade >= $gradeitem->gradepass) {
return completion::COMPLETED;
}
else if($this->use_failed && $coursefinished)
{
else if ($this->use_failed && $coursefinished) {
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
return completion::FAILED;
}
@ -276,9 +289,9 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
}
}
else {
// Blind assumptions if nothing is provided
// over 55% of range is completed
// if range >= 3 and failed is enabled, assume that this means failed
// Blind assumptions if nothing is provided.
// over 55% of range is completed.
// if range >= 3 and failed is enabled, assume that this means failed.
$g = floatval($finalgrade - $gradeitem->grademin);
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
$score = $g / $range;
@ -286,8 +299,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
if ($score > 0.55) {
return completion::COMPLETED;
}
else if($this->use_failed && $coursefinished)
{
else if ($this->use_failed && $coursefinished) {
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
return completion::FAILED;
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\aggregators;
@ -11,24 +32,24 @@ use \local_treestudyplan\debug;
class core_aggregator extends \local_treestudyplan\aggregator {
public const DEPRECATED = false;
private $accept_pending_as_submitted = False; // Also count ungraded but submitted
private $accept_pending_as_submitted = False; // Also count ungraded but submitted .
public function __construct($configstr) {
// allow public constructor for testing purposes
// allow public constructor for testing purposes.
$this->initialize($configstr);
}
protected function initialize($configstr) {
// First initialize with the defaults
// First initialize with the defaults.
foreach (["accept_pending_as_submitted"] as $key) {
$this->$key = boolval(get_config('local_treestudyplan', "bistate_{$key}"));
}
// Next, decode json
// Next, decode json.
$config = \json_decode($configstr, true);
if (is_array($config)) {
// copy all valid config settings to this item
// copy all valid config settings to this item.
foreach (["accept_pending_as_submitted"] as $key) {
if (array_key_exists($key, $config)) {
$this->$key = boolval($config[$key]);
@ -39,7 +60,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
}
}
// Return active configuration model
// Return active configuration model.
public function config_string() {
return json_encode([
"accept_pending_as_submitted" => $this->accept_pending_as_submitted,
@ -69,36 +90,36 @@ class core_aggregator extends \local_treestudyplan\aggregator {
*/
public function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid) {
// Retrieve the core completion info from the core
// Retrieve the core completion info from the core.
$course = $courseinfo->course();
$completion = new \completion_info($course);
if ($completion->is_enabled() && $completion->is_tracked_user($userid)) {
if ($completion->is_course_complete($userid)) {
// Now, the trick is to determine what constitutes excellent and good completion....
// TODO: Determine excellent and maybe good completion
// TODO: Determine excellent and maybe good completion.
// Option: Use course end grade to determine that...
// Probably needs a config value in the aggregator....
return completion::COMPLETED;
} else {
// Check if the course is over or not, if it is over, display failed
// Else, return PROGRESS
// Check if the course is over or not, if it is over, display failed.
// Else, return PROGRESS.
// Retrieve timing through courseinfo
// Retrieve timing through courseinfo .
$timing = courseinfo::coursetiming($course);
// Not met and time is passed, means FAILED
// Not met and time is passed, means FAILED.
if ($timing == "past") {
return completion::FAILED;
}
else {
// Check if any of the requirements are being met?
// Check if any of the requirements are being met?.
$completions = $completion->get_completions($userid);
foreach ($completions as $c) {
if ($c->is_complete()) {
// If so, return progress
// If so, return progress.
return completion::PROGRESS;
}
}
@ -113,15 +134,15 @@ class core_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_junction(array $completion, studyitem $studyitem = null, $userid = 0) {
// Aggregate multiple incoming states into one junction or finish.
// Possible states:
// - completion::EXCELLENT - All incoming states are excellent
// - completion::GOOD - All incoming states are at least good
// - completion::COMPLETED - All incoming states are at least completed
// - completion::FAILED - All incoming states are failed
// - completion::INCOMPLETE - All incoming states are incomplete
// - completion::PROGRESS - All other states
// Possible states:.
// - completion::EXCELLENT - All incoming states are excellent.
// - completion::GOOD - All incoming states are at least good.
// - completion::COMPLETED - All incoming states are at least completed.
// - completion::FAILED - All incoming states are failed.
// - completion::INCOMPLETE - All incoming states are incomplete.
// - completion::PROGRESS - All other states.
// First count all states
// First count all states.
$statecount = completion::count_states($completion);
$total = count($completion);
@ -146,7 +167,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
}
// CORE COMPLETION DOESN'T REALLY USE THE FUNCTIONS BELOW
// CORE COMPLETION DOESN'T REALLY USE THE FUNCTIONS BELOW.
// AGGREGATORS ARE GOING TO BE DEPRECATED ANYWAY... but used in legacy parts of this plugin.
public function grade_completion(gradeinfo $gradeinfo, $userid) {
@ -158,14 +179,13 @@ class core_aggregator extends \local_treestudyplan\aggregator {
if (empty($grade)) {
return completion::INCOMPLETE;
}
else if($grade->finalgrade === NULL)
{
// on assignments, grade NULL means a submission has not yet been graded,
// but on quizes this can also mean a quiz might have been started
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items
else if ($grade->finalgrade === NULL) {
// on assignments, grade NULL means a submission has not yet been graded,.
// but on quizes this can also mean a quiz might have been started.
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
// Since we want old results to be visible until a pending item was graded, we only use this state here.
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model.
if ($gradeinfo->getGradingscanner()->pending($userid)) {
return completion::PENDING;
} else {
@ -174,14 +194,13 @@ class core_aggregator extends \local_treestudyplan\aggregator {
}
else {
$grade = $gradeitem->get_final($userid);
// first determine if we have a grade_config for this scale or this maximum grade
// first determine if we have a grade_config for this scale or this maximum grade.
$finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale();
if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
}
else if($gradeitem->grademin == 0)
{
else if ($gradeitem->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]);
}
else
@ -189,34 +208,30 @@ class core_aggregator extends \local_treestudyplan\aggregator {
$gradecfg = null;
}
// for point grades, a provided grade pass overrides the defaults in the gradeconfig
// for scales, the configuration in the gradeconfig is leading
// for point grades, a provided grade pass overrides the defaults in the gradeconfig.
// for scales, the configuration in the gradeconfig is leading.
if($gradecfg && (isset($scale) || $gradeitem->gradepass == 0))
{
// if so, we need to know if the grade is
if ($gradecfg && (isset($scale) || $gradeitem->gradepass == 0)) {
// if so, we need to know if the grade is .
if ($finalgrade >= $gradecfg->min_completed) {
// return completed if completed
// return completed if completed.
return completion::COMPLETED;
}
else if($this->use_failed && $finalgrade < $gradecfg->min_progress)
{
// return failed if failed is enabled and the grade is less than the minimum grade for progress
else if ($this->use_failed && $finalgrade < $gradecfg->min_progress) {
// return failed if failed is enabled and the grade is less than the minimum grade for progress.
return completion::FAILED;
}
else {
return completion::PROGRESS;
}
}
else if($gradeitem->gradepass > 0)
{
else if ($gradeitem->gradepass > 0) {
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
// if no gradeconfig and gradepass is set, use that one to determine config.
if ($finalgrade >= $gradeitem->gradepass) {
return completion::COMPLETED;
}
else if($this->use_failed && $gradeitem->gradepass >= 3 && $range >= 3 && $finalgrade == 1)
{
else if ($this->use_failed && $gradeitem->gradepass >= 3 && $range >= 3 && $finalgrade == 1) {
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
return completion::FAILED;
}
@ -225,9 +240,9 @@ class core_aggregator extends \local_treestudyplan\aggregator {
}
}
else {
// Blind assumptions if nothing is provided
// over 55% of range is completed
// if range >= 3 and failed is enabled, assume that this means failed
// Blind assumptions if nothing is provided.
// over 55% of range is completed.
// if range >= 3 and failed is enabled, assume that this means failed.
$g = floatval($finalgrade - $gradeitem->grademin);
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
$score = $g / $range;
@ -235,8 +250,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
if ($score > 0.55) {
return completion::COMPLETED;
}
else if($this->use_failed && $range >= 3 && $finalgrade == 1)
{
else if ($this->use_failed && $range >= 3 && $finalgrade == 1) {
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
return completion::FAILED;
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\aggregators;
@ -18,15 +39,14 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
protected function aggregate_completion(array $a, $condition = "50") {
if (in_array($condition, ['ALL', '67', '50', 'ANY'])) {
// condition is one of the valid conditions
// condition is one of the valid conditions.
$c_completed = 0;
$c_excellent = 0;
$c_progress = 0;
$c_pending = 0;
$count = sizeof($a);
if($count > 0)
{
if ($count > 0) {
foreach ($a as $c) {
$c_progress += ($c>=completion::PROGRESS)?1:0;
@ -47,8 +67,8 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
} else if ($c_completed >= $required) {
return completion::COMPLETED;
} else {
// Return PROGRESS if one or more completions are COMPLETED or EXCELLENT, but the aggregation margin is not met
// state PROGRESS will not carry on if aggregations are chained
// Return PROGRESS if one or more completions are COMPLETED or EXCELLENT, but the aggregation margin is not met.
// state PROGRESS will not carry on if aggregations are chained.
if ($c_progress > 0) {
return completion::PROGRESS;
}
@ -66,7 +86,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
}
else
{
// indeterminable, return null
// indeterminable, return null.
return null;
}
}
@ -86,7 +106,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_junction(array $completion, studyitem $studyitem, $userid) {
$completed = self::aggregate_completion($completion, $studyitem->conditions());
// if null result (conditions are unknown/null) - default to ALL
// if null result (conditions are unknown/null) - default to ALL.
return isset($completed)?$completed:(self::aggregate_completion($completion, 'ALL'));
}
@ -98,14 +118,13 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
if (empty($grade)) {
return completion::INCOMPLETE;
}
else if($grade->finalgrade === NULL)
{
// on assignments, grade NULL means a submission has not yet been graded,
// but on quizes this can also mean a quiz might have been started
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items
else if ($grade->finalgrade === NULL) {
// on assignments, grade NULL means a submission has not yet been graded,.
// but on quizes this can also mean a quiz might have been started.
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
// Since we want old results to be visible until a pending item was graded, we only use this state here.
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model.
if ($gradeinfo->getGradingscanner()->pending($userid)) {
return completion::PENDING;
} else {
@ -117,11 +136,10 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
$finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale();
if($gradeitem->gradepass > 0)
{
// Base completion off of gradepass (if set)
if ($gradeitem->gradepass > 0) {
// Base completion off of gradepass (if set).
if ($gradeitem->grademax > $gradeitem->gradepass && $finalgrade >= $gradeitem->grademax) {
// If gradepass is configured
// If gradepass is configured .
return completion::EXCELLENT;
}
else if ($finalgrade >= $gradeitem->gradepass) {
@ -132,9 +150,9 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
}
}
else {
// Blind assumptions:
// over 55% of range is completed
// over 85% of range is excellent
// Blind assumptions:.
// over 55% of range is completed.
// over 85% of range is excellent.
$g = floatval($finalgrade - $gradeitem->grademin);
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
$score = $g / $range;

View File

@ -1,4 +1,26 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local;
use Exception;
@ -66,10 +88,10 @@ class gradegenerator {
private function generatedfeedback() {
if (file_exists("/usr/games/fortune")) {
// get a fortune if it is available
// get a fortune if it is available.
return shell_exec("/usr/games/fortune -n 160 -e disclaimer literature science pratchett wisdom education");
} else {
// get a random loremipsum string
// get a random loremipsum string.
return self::$loremipsum[rand(0, count(self::$loremipsum)-1)];
}
}
@ -101,15 +123,14 @@ class gradegenerator {
}
}
// Below is mostly just for reference in the json file
// Below is mostly just for reference in the json file.
public function addUserNameInfo(string $student, $firstname, $lastname) {
$this->addstudent($student);
$this->table[$student]["firstname"] = $firstname;
$this->table[$student]["lastname"] = $lastname;
}
public function generateraw($student,$skill, $count )
{
public function generateraw($student, $skill, $count ) {
$this->addskill($student, $skill);
$int = $this->table[$student]["skills"][$skill]["intelligence"];
$end = $this->table[$student]["skills"][$skill]["endurance"];
@ -121,24 +142,24 @@ class gradegenerator {
if ($gaveup) {
$r->done = !$gaveup;
} else {
$r->done = (rand(0, $end) > 20); // Determine if the assignment was done
$r->done = (rand(0, $end) > 20); // Determine if the assignment was done.
}
if ($r->done) {
$score = rand(0, $int) ;
$r->result = ($score > 20); // determine if the assignment was successful
$r->result = ($score > 20); // determine if the assignment was successful.
if (!$r->result) {
$r->failed = !($score > 10);
}
} else {
$r->result = false; // make sure a result property is always there
$r->result = false; // make sure a result property is always there.
$r->failed = true;
}
// Aways generate a little feedback
// Aways generate a little feedback.
$r->fb = $this->generatedfeedback();
$results[] = $r;
if (!$gaveup && $i >= 3) {
// There is a slight chance the students with low endurance for this course will stop with this course's work entirely
// There is a slight chance the students with low endurance for this course will stop with this course's work entirely.
$gaveup = (rand(0, $end) < 15);
}
}
@ -157,13 +178,12 @@ class gradegenerator {
$gi = $g->getGradeitem();
$gr = $gen[$i];
// First get the configured interpretation for this scale or grade
// First get the configured interpretation for this scale or grade.
$scale = $gi->load_scale();
if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
}
else if($gi->grademin == 0)
{
else if ($gi->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gi->grademax]);
}
else
@ -171,13 +191,12 @@ class gradegenerator {
$gradecfg = null;
}
// next generate the grade
if($gradecfg)
{
// next generate the grade.
if ($gradecfg) {
if (!$gr->done) {
// INCOMPLETE
// fair chance of teacher forgetting to set incomplete to "no evidence"
$grade = 0;// $grade = (rand(0,100) > 15)?max(1, $gradecfg->min_progress-1):"0";
// INCOMPLETE.
// fair chance of teacher forgetting to set incomplete to "no evidence".
$grade = 0;// $grade = (rand(0, 100) > 15)?max(1, $gradecfg->min_progress-1):"0";.
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>"" ];
}
else if (!$gr->result) {
@ -185,7 +204,7 @@ class gradegenerator {
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>$gr->fb ];
}
else{
// COMPLETED
// COMPLETED.
$r = (object)["gi" => $g, "grade" => rand( $gradecfg->min_completed, $gi->grademax ), "fb" =>$gr->fb ];
}
@ -200,41 +219,40 @@ class gradegenerator {
}
}
else if($gi->gradepass > 0)
{
else if ($gi->gradepass > 0) {
if (!$gr->done) {
// INCOMPLETe or FAILED
// INCOMPLETe or FAILED.
$grade = rand(0, $gi->gradepass/2);
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>($grade > 0)?$gr->fb:"" ];
}
else if (!$gr->result) {
//PROGRESS
//PROGRESS.
$r = (object)["gi" => $g, "grade" => rand( round($gi->gradepass/2), $gi->gradepass -1 ), "fb" =>$gr->fb ];
}
else{
// COMPLETED
// COMPLETED.
$r = (object)["gi" => $g, "grade" => rand( $gi->gradepass, $gi->grademax ), "fb" =>$gr->fb ];
}
$r->gradetext = $r->grade;
}
else {
// Blind assumptions if nothing is provided
// over 55% of range is completed
// under 35% is not done
// Blind assumptions if nothing is provided.
// over 55% of range is completed.
// under 35% is not done.
$range = floatval($gi->grademax - $gi->grademin);
if (!$gr->done) {
// INCOMPLETe or FAILED
// INCOMPLETe or FAILED.
$grade = rand(0, round($range * 0.35) - 1);
$r = (object)["gi" => $g, "grade" => $gi->grademin+$grade, "fb" =>($grade > 0)?$gr->fb:"" ];
}
else if (!$gr->result) {
//PROGRESS
//PROGRESS.
$r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.35), round($range * 0.55) - 1 ), "fb" =>$gr->fb ];
}
else{
// COMPLETED
// COMPLETED.
$r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.55) , $range ), "fb" =>$gr->fb ];
}
@ -274,13 +292,12 @@ class gradegenerator {
$this->unserialize($json);
} catch(Exception $x) {
cli_problem("ERROR loading from file");
throw $x; // Throw X up again to show the output
throw $x; // Throw X up again to show the output.
}
}
}
private static function expand_tilde($path)
{
private static function expand_tilde($path) {
if (function_exists('posix_getuid') && strpos($path, '~') !== false) {
$info = posix_getpwuid(posix_getuid());
$path = str_replace('~', $info['dir'], $path);

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\helpers;
@ -10,20 +31,18 @@ class debugger {
private $tag;
private $enabled = false;
public function __construct($filename,$tag)
{
public function __construct($filename, $tag) {
global $CFG;
$this->fname = $filename;
$this->tag = $tag;
// assume debug environment if cachejs is false
// assume debug environment if cachejs is false.
$this->enabled = (isset($CFG->cachejs) && $CFG->cachejs == false);
}
public function dump($object,string $tag="")
{
public function dump($object, string $tag="") {
if (strlen($tag) > 0) {
$tag .= ":\n";
}
@ -31,8 +50,7 @@ class debugger {
}
public function write($str)
{
public function write($str) {
$this->writeblock($str);
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\helpers;
require_once($CFG->dirroot.'/webservice/lib.php');
@ -24,7 +45,7 @@ class webservicehelper {
}
if (is_array($capability)) {
//TODO: replace this by accesslib function \has_any_capability()
//TODO: replace this by accesslib function \has_any_capability().
foreach ($capability as $cap) {
if (has_capability($cap, $context)) {
return true;
@ -44,9 +65,9 @@ class webservicehelper {
*/
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 = [];
// initialize parent if needed
// initialize parent if needed.
if ($parent == null) {
$parent = \core_course_category::user_top();
if (has_capability($capability, $parent->get_context())) {
@ -55,16 +76,16 @@ class webservicehelper {
}
$children = $parent->get_children();
// Since the change for a category permission is greatest at the lower levels,
// we scan in two stages, to focus the search more on the lower levels instead of diving deep into the first category
// Stage one (surface check): check all children for the capability
// Since the change for a category permission is greatest at the lower levels,.
// we scan in two stages, to focus the search more on the lower levels instead of diving deep into the first category.
// Stage one (surface check): check all children for the capability.
foreach ($children as $child) {
// Check if we should add this category
// Check if we should add this category.
if (has_capability($capability, $child->get_context())) {
return true;
}
}
// Stage two (deep dive): recurse into the child categories
// Stage two (deep dive): recurse into the child categories.
foreach ($children as $child) {
if ($child->get_children_count() > 0) {
if (self::has_capability_in_any_category($capability, $child)) {
@ -105,16 +126,16 @@ class webservicehelper {
$context = \context::instance_by_id($contextid);
}
catch(\dml_missing_record_exception $x) {
throw new \InvalidArgumentException("Context {$contextid} not available"); // Just throw it up again. catch is included here to make sure we know it throws this exception
throw new \InvalidArgumentException("Context {$contextid} not available"); // Just throw it up again. catch is included here to make sure we know it throws this exception.
}
// Validate the found context
// Validate the found context.
\external_api::validate_context($context);
self::$validated_contexts[$contextid] = $context;
}
return self::$validated_contexts[$contextid];
}
else{
return static::system_context(); // This function ensures the system context is validated just once this call
return static::system_context(); // This function ensures the system context is validated just once this call.
}
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\ungradedscanners;
@ -7,7 +28,7 @@ class assign_scanner extends scanner_base {
protected function get_ungraded_submissions() {
global $DB;
//SELECT asgn_sub.id as submissionid, a.id as instanceid, asgn_sub.userid as userid, asgn_sub.timemodified as timesubmitted, asgn_sub.attemptnumber , a.maxattempts
//SELECT asgn_sub.id as submissionid, a.id as instanceid, asgn_sub.userid as userid, asgn_sub.timemodified as timesubmitted, asgn_sub.attemptnumber , a.maxattempts.
$sql = "SELECT DISTINCT asgn_sub.userid
FROM {assign_submission} asgn_sub
JOIN {assign} a ON a.id = asgn_sub.assignment
@ -28,7 +49,7 @@ class assign_scanner extends scanner_base {
FROM {grade_grades} g
LEFT JOIN {grade_items} gi on g.itemid = gi.id
WHERE gi.itemmodule = 'assign' AND gi.iteminstance = {$this->gi->iteminstance}
AND g.finalgrade IS NOT NULL"; // MAy turn out to be needed, dunno
AND g.finalgrade IS NOT NULL"; // MAy turn out to be needed, dunno.
return $DB->get_fieldset_sql($sql);
}
@ -51,14 +72,13 @@ class assign_scanner extends scanner_base {
$graded = array_intersect($graded, $course_userids);
}
// determine how many id's have a grade, but also an ungraded submission
// determine how many id's have a grade, but also an ungraded submission.
$dual = array_intersect($ungraded, $graded);
// subtract those from the graded count
// subtract those from the graded count.
return count($graded) - count($dual);
}
public function has_ungraded_submission($userid)
{
public function has_ungraded_submission($userid) {
$ungraded = $this->get_ungraded_submissions();
return in_array($userid, $ungraded);
}

View File

@ -1,17 +1,38 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\ungradedscanners;
require_once($CFG->dirroot.'/question/engine/states.php'); // for reading question state
require_once($CFG->dirroot.'/question/engine/states.php'); // for reading question state.
class quiz_scanner extends scanner_base {
protected function get_ungraded_submissions() {
// count all users who have one or more questions that still need grading
// count all users who have one or more questions that still need grading.
global $DB;
// First find all question attempts that need grading
// First find all question attempts that need grading.
$sql = "SELECT qza.id as submissionid, qza.userid as userid, qas.questionattemptid as attempt_id, qas.sequencenumber as sequencenumber
FROM {question_attempt_steps} qas
JOIN {question_attempts} qna ON qas.questionattemptid = qna.id
@ -21,11 +42,11 @@ class quiz_scanner extends scanner_base {
$rs = $DB->get_recordset_sql($sql);
$submissions = [];
foreach ($rs as $r) {
// Now, check if
// Now, check if .
$maxstate_sql = "SELECT MAX(qas.sequencenumber) FROM {question_attempt_steps} qas WHERE qas.questionattemptid = {$r->attempt_id}";
$max = $DB->get_field_sql($maxstate_sql);
if ($r->sequencenumber == $max) {
$submissions[$r->userid] = true; // set array index based on user id, to avoid checking if value is in array
$submissions[$r->userid] = true; // set array index based on user id, to avoid checking if value is in array.
}
}
$rs->close();
@ -47,7 +68,7 @@ class quiz_scanner extends scanner_base {
FROM {grade_grades} g
LEFT JOIN {grade_items} gi on g.itemid = gi.id
WHERE gi.itemmodule = 'quiz' AND gi.iteminstance = {$this->gi->iteminstance}
AND g.finalgrade IS NOT NULL"; // MAy turn out to be needed, dunno
AND g.finalgrade IS NOT NULL"; // MAy turn out to be needed, dunno.
$graded = $DB->get_fieldset_sql($sql);
@ -58,8 +79,7 @@ class quiz_scanner extends scanner_base {
return count($graded);
}
public function has_ungraded_submission($userid)
{
public function has_ungraded_submission($userid) {
$ungraded = $this->get_ungraded_submissions();
return in_array($userid, $ungraded);
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\ungradedscanners;
use \grade_item;

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -9,7 +30,7 @@ class period {
private static $PAGECACHE = [];
private $r; // Holds database record
private $r; // Holds database record.
private $id;
private $page;
@ -31,7 +52,7 @@ class period {
public static function find(studyplanpage $page, $periodnr): self{
global $DB;
if ($periodnr < 1) {
// Clamp period index
// Clamp period index .
$periodnr = 1;
}
try{
@ -39,34 +60,34 @@ class period {
$period = self::findById($id);
} catch(\dml_missing_record_exception $x) {
// Period does not exist - create one ...
// Make a best guess estimate of the start and end date, based on surrounding periods,
// or specified duration of the page and the sequence of the periods
// Make a best guess estimate of the start and end date, based on surrounding periods,.
// or specified duration of the page and the sequence of the periods .
$pcount = $page->periods();
$ystart = $page->startdate()->getTimestamp();
$yend = $page->enddate()->getTimestamp();
// Estimate the period's timing to make a reasonable first guess
// Estimate the period's timing to make a reasonable first guess.
$ydelta = $yend - $ystart;
$ptime = $ydelta / $pcount;
try{
// Check if we have a previous period to glance the end date of as a reference
// Check if we have a previous period to glance the end date of as a reference.
$startdate = $DB->get_field(self::TABLE, "enddate", ["page_id"=>$page->id(), "period" => $periodnr-1], MUST_EXIST);
$pstart = strtotime($startdate)+(24*60*60); // Add one day
$pstart = strtotime($startdate)+(24*60*60); // Add one day.
} catch(\dml_missing_record_exception $x2) {
// If not, do a fair guess
// If not, do a fair guess.
$pstart = $ystart + (($periodnr-1)*$ptime);
}
try{
// Check if we have a next period to glance the start date of as a reference
// Check if we have a next period to glance the start date of as a reference.
$enddate = $DB->get_field(self::TABLE, "startdate", ["page_id"=>$page->id(), "period" => $periodnr+1], MUST_EXIST);
$pstart = strtotime($enddate)-(24*60*60); // subtract one day
$pstart = strtotime($enddate)-(24*60*60); // subtract one day.
} catch(\dml_missing_record_exception $x2) {
// If not, do a fair guess
// If not, do a fair guess.
$pend = $pstart + $ptime;
}
// And create the period
// And create the period.
$period = self::add([
'page_id' => $page->id(),
'period' => $periodnr,
@ -83,7 +104,7 @@ class period {
public static function findForPage(studyplanpage $page): array {
if (!array_key_exists($page->id(), self::$PAGECACHE)) {
$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++) {
$period = self::find($page, $i);
$periods[$i] = $period;
@ -133,7 +154,7 @@ class period {
return new \DateTime($this->r->enddate);
}
else{
// return a date 100 years into the future
// return a date 100 years into the future.
return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
}
}
@ -186,8 +207,8 @@ class period {
}
}
$id = $DB->insert_record(self::TABLE, $info);
unset(self::$PAGECACHE[$fields['page_id']]); // invalidate the cache for this page
return self::findById($id); // make sure the new page is immediately cached
unset(self::$PAGECACHE[$fields['page_id']]); // invalidate the cache for this page.
return self::findById($id); // make sure the new page is immediately cached.
}
public function edit($fields) {
@ -200,16 +221,16 @@ class period {
}
}
$DB->update_record(self::TABLE, $info);
//reload record after edit
//reload record after edit.
$this->r = $DB->get_record(self::TABLE, ['id' => $this->id], "*", MUST_EXIST);
unset(self::$PAGECACHE[$this->r->page_id]); // invalidate the cache for this page
unset(self::$PAGECACHE[$this->r->page_id]); // invalidate the cache for this page.
return $this;
}
public function delete() {
global $DB;
$DB->delete_records(self::TABLE, ['id' => $this->id]);
unset(self::$PAGECACHE[$this->r->page_id]); // invalidate the cache for this page
unset(self::$PAGECACHE[$this->r->page_id]); // invalidate the cache for this page.
return success::success();
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\privacy;
use core_privacy\local\metadata\collection;
@ -57,9 +78,9 @@ class provider implements \core_privacy\local\metadata\provider,
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
$contextlist = new \core_privacy\local\request\contextlist();
$contextlist->add_system_context(); // For invitations
$contextlist->add_system_context(); // For invitations.
// add contexts for linked studyplans
// add contexts for linked studyplans.
$sql = "SELECT s.context_id FROM {local_treestudyplan} s
INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id
WHERE ( a.user_id = :userid )
@ -81,7 +102,7 @@ class provider implements \core_privacy\local\metadata\provider,
$user = $contextlist->get_user();
if ($context instanceof \context_system) {
// Export invitations
// Export invitations.
$sql = "SELECT * FROM {local_treestudyplan_invit} i
WHERE ( aiuser_id = :userid )
";
@ -90,7 +111,7 @@ class provider implements \core_privacy\local\metadata\provider,
static::export_invitation_data_for_user($r);
}
// Export empty associations
// Export empty associations.
$sql = "SELECT * FROM {local_treestudyplan} s
INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id
WHERE ( a.user_id = :userid AND (s.context_id IS NULL or s.context_id = 0)
@ -100,7 +121,7 @@ class provider implements \core_privacy\local\metadata\provider,
static::export_studyplan_data_for_user($r);
}
} else if ($context->contextlevel == CONTEXT_COURSECAT) {
// Export studyplan associations
// Export studyplan associations.
$sql = "SELECT * FROM {local_treestudyplan} s
INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id
WHERE ( a.user_id = :userid AND s.context_id = :contextid)
@ -151,7 +172,7 @@ class provider implements \core_privacy\local\metadata\provider,
*/
public static function delete_data_for_all_users_in_context(\context $context) {
global $DB;
// find studyplans in context
// find studyplans in context.
if ($context->contextlevel == CONTEXT_COURSECAT) {
$sql = "SELECT s.id FROM {local_treestudyplan} WHERE ( a.user_id = :userid AND s.context_id = :contextid)";
$plan_ids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id]);
@ -183,7 +204,7 @@ class provider implements \core_privacy\local\metadata\provider,
$DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $plan_id, "user_id" => $user->id]);
}
// Also delete all invitations for this user
// Also delete all invitations for this user.
$DB->delete_records("local_treestudyplan_invit", ["user_id" => $user->id]);
} else if ($context->contextlevel == CONTEXT_COURSECAT) {
@ -207,12 +228,12 @@ class provider implements \core_privacy\local\metadata\provider,
$context = $userlist->get_context();
if ($context instanceof \context_system) {
// Add all invitations
// Add all invitations.
$sql = "SELECT i.user_id as userid
FROM {local_treestudyplan_invit} i;";
$userlist->add_from_sql('userid', $sql, []);
// also add "contextless studyplans, they are considered in system context"
// also add "contextless studyplans, they are considered in system context".
$sql = "SELECT a.user_id as userid FROM {local_treestudyplan_user} a
INNER JOIN {local_treestudyplan} s ON a.studyplan_id = s.id
WHERE ( a.context_id is NULL or a.context_id = 0)
@ -221,7 +242,7 @@ class provider implements \core_privacy\local\metadata\provider,
}
// add the links to all study plans in this context
// add the links to all study plans in this context.
$sql = "SELECT a.user_id as userid FROM {local_treestudyplan_user} a
INNER JOIN {local_treestudyplan} s ON a.studyplan_id = s.id
WHERE ( a.context_id = :contextid )
@ -244,13 +265,13 @@ class provider implements \core_privacy\local\metadata\provider,
$plan_ids = [];
if ($context->contextlevel == CONTEXT_SYSTEM) {
// Determine the relevant plan_ids for this context
// Determine the relevant plan_ids for this context.
$sql = "SELECT s.id FROM {local_treestudyplan}
WHERE ( s.context_id IS NULL OR s.context_id == 0 OR s.context_id = :contextid)) ";
$plan_ids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, ]);
// If plan ids not empty, they will be processed later
// If plan ids not empty, they will be processed later.
// Also delete all invitations for these users
// Also delete all invitations for these users.
$sql = "user_id {$userinsql}";
$DB->delete_records_select("local_treestudyplan_invit", $sql, $userinparams);
@ -258,10 +279,10 @@ class provider implements \core_privacy\local\metadata\provider,
$sql = "SELECT s.id FROM {local_treestudyplan}
WHERE (s.context_id = :contextid)";
$plan_ids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, ]);
// If plan ids not empty, they will be processed later
// If plan ids not empty, they will be processed later.
}
// Now delete the studyplan associations if relevant
// Now delete the studyplan associations if relevant.
if (count($plan_ids) >0 && count($users) >0) {
list($planinsql, $planinputparams) = $DB->get_in_or_equal($plan_ids, SQL_PARAMS_NAMED, 'plan');

View File

@ -1,16 +1,37 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("$CFG->libdir/formslib.php");
require_once("$CFG->dirroot/local/treestudyplan/lib.php");
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() {
global $CFG;
// 'code', 'revision', 'description', 'goals', 'complexity', 'points', 'studyhours'
$mform = $this->_form; // Don't forget the underscore!
// 'code', 'revision', 'description', 'goals', 'complexity', 'points', 'studyhours'.
$mform = $this->_form; // Don't forget the underscore! .
$mform->addElement('hidden', 'add', 0);
$mform->setType('add', PARAM_ALPHANUM);
@ -18,25 +39,25 @@ class reportinvite_form extends moodleform {
$mform->addElement('hidden', 'update', 0);
$mform->setType('update', PARAM_INT);
// $mform->addElement('static', 'desc_new', get_string('invite_desc_new','local_treestudyplan')); // Add elements to your form
// $mform->addElement('static', 'desc_edit', get_string('invite_desc_edit','local_treestudyplan')); // Add elements to your form
// $mform->addElement('static', 'desc_new', get_string('invite_desc_new', 'local_treestudyplan')); // Add elements to your form.
// $mform->addElement('static', 'desc_edit', get_string('invite_desc_edit', 'local_treestudyplan')); // Add elements to your form.
$mform->addElement('text', 'name', get_string('invite_name','local_treestudyplan'), array('size' => 50)); // Add elements to your form
$mform->setType('name', PARAM_NOTAGS); //Set type of element
$mform->setDefault('name', ''); //Default value
$mform->addElement('text', 'name', get_string('invite_name', 'local_treestudyplan'), array('size' => 50)); // Add elements to your form.
$mform->setType('name', PARAM_NOTAGS); //Set type of element.
$mform->setDefault('name', ''); //Default value.
$mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->addElement('text', 'email', get_string('invite_email','local_treestudyplan'), array('size' => 20)); // Add elements to your form
$mform->setType('email', PARAM_NOTAGS); //Set type of element
$mform->setDefault('email', ''); //Default value
$mform->addElement('text', 'email', get_string('invite_email', 'local_treestudyplan'), array('size' => 20)); // Add elements to your form.
$mform->setType('email', PARAM_NOTAGS); //Set type of element.
$mform->setDefault('email', ''); //Default value.
$mform->addRule('email', get_string('required'), 'required', null, 'client');
$mform->addRule('email', get_string('email'), 'email', null, 'client');
$mform->addElement('static', get_string('invite_email','local_treestudyplan') ); // Add elements to your form
$mform->addElement('static', get_string('invite_email', 'local_treestudyplan') ); // Add elements to your form.
$this->add_action_buttons();
}
//Custom validation should be added here
//Custom validation should be added here.
function validation($data, $files) {
return array();
}
@ -68,7 +89,7 @@ class reportinvite_form extends moodleform {
if (empty($data->update))
{
//create a new random key for the invite
//create a new random key for the invite.
do {
$length = 20;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
@ -78,7 +99,7 @@ class reportinvite_form extends moodleform {
$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", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $randomkey]));
$data->invitekey = $randomkey;

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -34,9 +55,8 @@ class studentstudyplanservice extends \external_api
$list = [];
$studyplans = studyplan::find_for_user($userid);
foreach($studyplans as $studyplan)
{
// only include studyplans in the context the user has permissions for
foreach ($studyplans as $studyplan) {
// only include studyplans in the context the user has permissions for.
if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) {
$list[] =$studyplan->simple_model();
}
@ -63,16 +83,14 @@ class studentstudyplanservice extends \external_api
studyplan::user_structure()
);
}
public static function get_user_studyplans($userid)
{
public static function get_user_studyplans($userid) {
global $CFG, $DB;
$studyplans = studyplan::find_for_user($userid);
$map = [];
foreach($studyplans as $studyplan)
{
// only include studyplans in the context the user has permissions for
foreach ($studyplans as $studyplan) {
// only include studyplans in the context the user has permissions for.
if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) {
$map[] = $studyplan->user_model($userid);
}
@ -99,8 +117,7 @@ class studentstudyplanservice extends \external_api
{
return studyplan::user_structure();
}
public static function get_user_studyplan($userid,$studyplanid)
{
public static function get_user_studyplan($userid, $studyplanid) {
global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid);
@ -133,8 +150,7 @@ class studentstudyplanservice extends \external_api
studyplan::user_structure()
);
}
public static function get_invited_studyplan($invitekey)
{
public static function get_invited_studyplan($invitekey) {
global $CFG, $DB;
$invite = $DB->get_record_select("local_treestudyplan_invit", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $invitekey]);
@ -143,15 +159,14 @@ class studentstudyplanservice extends \external_api
return [];
}
// Validate context now
// Validate context now.
\external_api::validate_context(\context_system::instance());
$userid = $invite->user_id;
$map = [];
$studyplans = studyplan::find_for_user($userid);
foreach($studyplans as $studyplan)
{
foreach ($studyplans as $studyplan) {
$map[] = $studyplan->user_model($userid);
}
return $map;
@ -181,8 +196,7 @@ class studentstudyplanservice extends \external_api
$list = [];
$studyplans = studyplan::find_for_user($userid);
foreach($studyplans as $studyplan)
{
foreach ($studyplans as $studyplan) {
$list[] =$studyplan->simple_model();
}
return $list;
@ -208,8 +222,7 @@ class studentstudyplanservice extends \external_api
);
}
public static function get_own_studyplan($id=null)
{
public static function get_own_studyplan($id=null) {
global $USER;
// Validate this call in the system context.
@ -256,8 +269,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;
$userid = $USER->id;

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -16,7 +37,7 @@ class studyitem {
public const TABLE = "local_treestudyplan_item";
private static $STUDYITEM_CACHE = [];
private $r; // Holds database record
private $r; // Holds database record.
private $id;
private $courseinfo = null;
@ -101,12 +122,12 @@ class studyitem {
}
private function generate_model($mode) {
// Mode parameter is used to geep this function for both editor model and export model
// (Export model results in fewer parameters on children, but is otherwise basically the same as this function)
// Mode parameter is used to geep this function for both editor model and export model.
// (Export model results in fewer parameters on children, but is otherwise basically the same as this function).
global $DB;
$model = [
'id' => $this->r->id, // Id is needed in export model because of link references
'id' => $this->r->id, // Id is needed in export model because of link references.
'type' => $this->isValid()?$this->r->type:self::INVALID,
'conditions' => $this->r->conditions,
'slot' => $this->r->slot,
@ -119,17 +140,17 @@ class studyitem {
]
];
if ($mode == "export") {
// remove slot and layer
// remove slot and layer.
unset($model["slot"]);
unset($model["layer"]);
unset($model["continuation_id"]);
$model["connections"] = []; // In export mode, connections is just an array of outgoing connections
$model["connections"] = []; // In export mode, connections is just an array of outgoing connections.
if (!isset($this->r->conditions)) {
unset($model["conditions"]);
}
}
// Add course link if available
// Add course link if available.
$ci = $this->getcourseinfo();
if (isset($ci)) {
if ($mode == "export") {
@ -139,23 +160,22 @@ class studyitem {
}
}
// Add badge info if available
if(is_numeric($this->r->badge_id) && $DB->record_exists('badge', array('id' => $this->r->badge_id)))
{
// Add badge info if available.
if (is_numeric($this->r->badge_id) && $DB->record_exists('badge', array('id' => $this->r->badge_id))) {
$badge = new \core_badges\badge($this->r->badge_id);
$badgeinfo = new badgeinfo($badge);
if ($mode == "export") {
$model['badge'] = $badgeinfo->name();
} else {
// Also supply a list of linked users, so the badgeinfo can give stats on
// the amount issued, related to this studyplan
// Also supply a list of linked users, so the badgeinfo can give stats on .
// the amount issued, related to this studyplan.
$studentids = $this->studyline()->studyplan()->find_linked_userids();
$model['badge'] = $badgeinfo->editor_model($studentids);
}
}
if ($mode == "export") {
// Also export gradables
// Also export gradables.
$gradables = gradeinfo::list_studyitem_gradables($this);
if (count($gradables) > 0) {
$model["gradables"] = [];
@ -166,7 +186,7 @@ class studyitem {
}
// Add incoming and outgoing connection info
// Add incoming and outgoing connection info.
$conn_out = studyitemconnection::find_outgoing($this->id);
if ($mode == "export") {
@ -188,8 +208,7 @@ class studyitem {
}
public static function add($fields,$import=false)
{
public static function add($fields, $import=false) {
global $DB;
$addable = ['line_id', 'type', 'layer', 'conditions', 'slot', 'competency_id', 'course_id', 'badge_id', 'continuation_id', 'span'];
$info = [ 'layer' => 0, ];
@ -201,14 +220,13 @@ class studyitem {
$id = $DB->insert_record(self::TABLE, $info);
$item = self::findById($id);
if ($item->type() == self::COURSE) {
// Signal the studyplan that a course has been added so it can be marked for csync cascading
// Signal the studyplan that a course has been added so it can be marked for csync cascading.
$item->studyline()->studyplan()->mark_csync_changed();
}
return $item;
}
public function edit($fields)
{
public function edit($fields) {
global $DB;
$editable = ['conditions', 'course_id', 'continuation_id', 'span'];
@ -220,13 +238,13 @@ class studyitem {
}
$DB->update_record(self::TABLE, $info);
//reload record after edit
//reload record after edit.
$this->r = $DB->get_record(self::TABLE, ['id' => $this->id], "*", MUST_EXIST);
return $this;
}
public function isValid() {
// Check if referenced courses, badges and/or competencies still exist
// Check if referenced courses, badges and/or competencies still exist.
if ($this->r->type == static::COURSE) {
return courseinfo::exists($this->r->course_id);
}
@ -238,13 +256,12 @@ class studyitem {
}
}
public function delete($force=false)
{
public function delete($force=false) {
global $DB;
// check if this item is referenced in a START item
// check if this item is referenced in a START item.
if ($force) {
// clear continuation id from any references to this item
// clear continuation id from any references to this item.
$records = $DB->get_records(self::TABLE, ['continuation_id' => $this->id]);
foreach ($records as $r) {
$r->continuation_id = 0;
@ -257,11 +274,11 @@ class studyitem {
}
else
{
// delete al related connections to this item
// delete al related connections to this item.
studyitemconnection::clear($this->id);
// delete all grade inclusion references to this item
// delete all grade inclusion references to this item.
$DB->delete_records("local_treestudyplan_gradeinc", ['studyitem_id' => $this->id]);
// delete the item itself
// delete the item itself.
$DB->delete_records(self::TABLE, ['id' => $this->id]);
return success::success();
@ -274,12 +291,10 @@ class studyitem {
* *
************************/
public static function reorder($resequence)
{
public static function reorder($resequence) {
global $DB;
foreach($resequence as $sq)
{
foreach ($resequence as $sq) {
$DB->update_record(self::TABLE, [
'id' => $sq['id'],
'line_id' => $sq['line_id'],
@ -291,8 +306,7 @@ class studyitem {
return success::success();
}
public static function find_studyline_children(studyline $line)
{
public static function find_studyline_children(studyline $line) {
global $DB;
$list = [];
$ids = $DB->get_fieldset_select(self::TABLE, "id", "line_id = :line_id ORDER BY layer", ['line_id' => $line->id()]);
@ -362,29 +376,26 @@ class studyitem {
]
];
// Add badge info if available
if(badgeinfo::exists($this->r->badge_id))
{
// Add badge info if available.
if (badgeinfo::exists($this->r->badge_id)) {
$badge = new \core_badges\badge($this->r->badge_id);
$badgeinfo = new badgeinfo($badge);
$model['badge'] = $badgeinfo->user_model($userid);
}
// Add continuation_info if available
if(self::exists($this->r->continuation_id))
{
// Add continuation_info if available.
if (self::exists($this->r->continuation_id)) {
$c_item = self::findById($this->r->continuation_id);
$model['continuation'] = $c_item->link_model($userid);
}
// Add course if available
if(courseinfo::exists($this->r->course_id))
{
// Add course if available.
if (courseinfo::exists($this->r->course_id)) {
$cinfo = $this->getcourseinfo();
$model['course'] = $cinfo->user_model($userid, $this->aggregator->usecorecompletioninfo());
}
// Add incoming and outgoing connection info
// Add incoming and outgoing connection info.
$conn_out = studyitemconnection::find_outgoing($this->id);
foreach ($conn_out as $c) {
$model['connections']['out'][$c->to_id()] = $c->model();
@ -398,8 +409,7 @@ class studyitem {
}
public function getcourseinfo()
{
public function getcourseinfo() {
if (empty($this->courseinfo) && courseinfo::exists($this->r->course_id)) {
$this->courseinfo = new courseinfo($this->r->course_id, $this);
}
@ -411,13 +421,13 @@ class studyitem {
if ($this->isValid()) {
if (strtolower($this->r->type) == 'course') {
// determine competency by competency completion
// determine competency by competency completion.
$courseinfo = $this->getcourseinfo();
return $this->aggregator->aggregate_course($courseinfo, $this, $userid);
}
else if (strtolower($this->r->type) =='start') {
// Does not need to use aggregator.
// Either true, or the completion of the reference
// Either true, or the completion of the reference.
if (self::exists($this->r->continuation_id)) {
$c_item = self::findById($this->r->continuation_id);
return $c_item->completion($userid);
@ -426,9 +436,9 @@ class studyitem {
}
}
else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) {
// completion of the linked items, according to the rule
// completion of the linked items, according to the rule.
$in_completed = [];
// Retrieve incoming connections
// Retrieve incoming connections.
$incoming = $DB->get_records(studyitemconnection::TABLE, ['to_id' => $this->r->id]);
foreach ($incoming as $conn) {
$item = self::findById($conn->from_id);
@ -438,13 +448,12 @@ class studyitem {
}
else if (strtolower($this->r->type) =='badge') {
global $DB;
// badge awarded
if(badgeinfo::exists($this->r->badge_id))
{
// badge awarded.
if (badgeinfo::exists($this->r->badge_id)) {
$badge = new \core_badges\badge($this->r->badge_id);
if ($badge->is_issued($userid)) {
if ($badge->can_expire()) {
// get the issued badges and check if any of them have not expired yet
// get the issued badges and check if any of them have not expired yet.
$badges_issued = $DB->get_records("badge_issued", ["badge_id" => $this->r->badge_id, "user_id" => $userid]);
$notexpired = false;
$now = time();
@ -467,31 +476,31 @@ class studyitem {
}
}
else {
// return incomplete for other types
// return incomplete for other types.
return completion::INCOMPLETE;
}
}
else {
// return incomplete for other types
// return incomplete for other types.
return completion::INCOMPLETE;
}
}
public function duplicate($new_line) {
global $DB;
// clone the database fields
// clone the database fields.
$fields = clone $this->r;
// set new line id
// set new line id.
unset($fields->id);
$fields->line_id = $new_line->id();
//create new record with the new data
//create new record with the new data.
$id = $DB->insert_record(self::TABLE, (array)$fields);
$new = self::findById($id, $new_line);
// copy the grading info if relevant
// copy the grading info if relevant.
$gradables = gradeinfo::list_studyitem_gradables($this);
foreach ($gradables as $g) {
gradeinfo::include_grade($g->getGradeitem()->id,$new,true);
gradeinfo::include_grade($g->getGradeitem()->id, $new->id(), true);
}
return $new;
}
@ -515,7 +524,7 @@ class studyitem {
$item = self::add($model, true);
if (isset($model["course_id"])) {
// attempt to import the gradables
// attempt to import the gradables.
foreach ($model["gradables"] as $gradable) {
gradeinfo::import($item, $gradable);
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -64,14 +85,12 @@ class studyitemconnection {
return $list;
}
public static function connect($from_id,$to_id)
{
public static function connect($from_id, $to_id) {
global $DB;
//check if link already exists
//check if link already exists.
if(!$DB->record_exists(self::TABLE, ['from_id' => $from_id, 'to_id' => $to_id]))
{
if (!$DB->record_exists(self::TABLE, ['from_id' => $from_id, 'to_id' => $to_id])) {
$id = $DB->insert_record(self::TABLE, [
'from_id' => $from_id,
'to_id' => $to_id,
@ -84,12 +103,10 @@ class studyitemconnection {
}
}
public static function disconnect($from_id,$to_id)
{
public static function disconnect($from_id, $to_id) {
global $DB;
if($DB->record_exists(self::TABLE, ['from_id' => $from_id, 'to_id' => $to_id]))
{
if ($DB->record_exists(self::TABLE, ['from_id' => $from_id, 'to_id' => $to_id])) {
$DB->delete_records(self::TABLE, [
'from_id' => $from_id,
'to_id' => $to_id,

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -24,7 +45,7 @@ class studyline {
private static $STUDYLINE_CACHE = [];
private $r; // Holds database record
private $r; // Holds database record.
private $id;
private $page;
private $studyplan;
@ -88,8 +109,8 @@ class studyline {
}
protected function generate_model($mode) {
// Mode parameter is used to geep this function for both editor model and export model
// (Export model results in fewer parameters on children, but is otherwise basically the same as this function)
// Mode parameter is used to geep this function for both editor model and export model.
// (Export model results in fewer parameters on children, but is otherwise basically the same as this function).
global $DB;
$model = [
@ -101,23 +122,23 @@ class studyline {
'slots' => [],
];
if ($mode == "export") {
// Id and sequence are not used in export model
// Id and sequence are not used in export model.
unset($model["id"]);
unset($model["sequence"]);
}
// TODO: Make this a little nicer
// Get the number of slots
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed,
// make sure there are enought slots to account for them
// TODO: Make this a little nicer.
// Get the number of slots.
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed, .
// make sure there are enought slots to account for them.
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
$max_slot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
$num_slots = max($this->page->periods(), $max_slot +1);
// Create the required amount of slots
// Create the required amount of slots.
for($i=0; $i < $num_slots+1; $i++) {
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 = [];
} else {
if ($i > 0) {
@ -130,8 +151,7 @@ class studyline {
}
$children = studyitem::find_studyline_children($this);
foreach($children as $c)
{
foreach ($children as $c) {
if ($mode == "export") {
$model['slots'][$c->slot()][] = $c->export_model();
} else {
@ -184,7 +204,7 @@ class studyline {
}
}
$DB->update_record(self::TABLE, $info);
//reload record after edit
//reload record after edit.
$this->r = $DB->get_record(self::TABLE, ['id' => $this->id], "*", MUST_EXIST);
return $this;
}
@ -198,7 +218,7 @@ class studyline {
$c->delete($force);
}
}
// check if this item has study items in it
// check if this item has study items in it.
if ($DB->count_records(studyitem::TABLE, ['line_id' => $this->id]) > 0) {
return success::fail('cannot delete studyline with items');
}
@ -209,12 +229,10 @@ class studyline {
}
}
public static function reorder($resequence)
{
public static function reorder($resequence) {
global $DB;
foreach($resequence as $sq)
{
foreach ($resequence as $sq) {
$DB->update_record(self::TABLE, [
'id' => $sq['id'],
'sequence' => $sq['sequence'],
@ -224,8 +242,7 @@ class studyline {
return success::success();
}
public static function find_page_children(studyplanpage $page)
{
public static function find_page_children(studyplanpage $page) {
global $DB;
$list = [];
$ids = $DB->get_fieldset_select(self::TABLE, "id", "page_id = :page_id ORDER BY sequence",
@ -253,7 +270,7 @@ class studyline {
}
public function user_model($userid) {
// TODO: Integrate this function into generate_model() for ease of maintenance
// TODO: Integrate this function into generate_model() for ease of maintenance.
global $DB;
@ -266,14 +283,14 @@ class studyline {
'slots' => [],
];
// Get the number of slots
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed,
// make sure there are enought slots to account for them
// Get the number of slots.
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed, .
// make sure there are enought slots to account for them.
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
$max_slot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
$num_slots = max($this->page->periods(), $max_slot +1);
// Create the required amount of slots
// Create the required amount of slots.
for($i=0; $i < $num_slots+1; $i++) {
if ($i > 0) {
$slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []];
@ -284,8 +301,7 @@ class studyline {
}
$children = studyitem::find_studyline_children($this);
foreach($children as $c)
{
foreach ($children as $c) {
if ($c->isValid()) {
$slotset = null;
if ($c->slot() > 0) {
@ -312,41 +328,37 @@ class studyline {
public function duplicate($new_studyplan, &$translation) {
global $DB;
// clone the database fields
// clone the database fields.
$fields = clone $this->r;
// set new studyplan id
// set new studyplan id.
unset($fields->id);
$fields->studyplan_id = $new_studyplan->id();
// create new record with the new data
// create new record with the new data.
$id = $DB->insert_record(self::TABLE, (array)$fields);
$new = self::findById($id);
// Next copy all the study items for this studyline
// and record the original and copy id's in the $translation array
// so the calling function can connect the new studyitems as required
// Next copy all the study items for this studyline.
// and record the original and copy id's in the $translation array.
// so the calling function can connect the new studyitems as required.
$children = studyitem::find_studyline_children($this);
$translation = [];
foreach($children as $c)
{
foreach ($children as $c) {
$newchild = $c->duplicate($new);
$translation[$c->id()] = $newchild->id();
}
return $new;
}
public function export_model()
{
public function export_model() {
return $this->generate_model("export");
}
public function import_studyitems($model, &$itemtranslation, &$connections) {
global $DB;
foreach($model as $slot=>$slotmodel)
{
foreach ($model as $slot=>$slotmodel) {
$courselayer = 0;
$filterlayer = 0;
foreach($slotmodel as $itemmodel)
{
foreach ($slotmodel as $itemmodel) {
if ($itemmodel["type"] == "course") {
$itemmodel["layer"] = $courselayer;
$courselayer++;

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -10,11 +31,11 @@ class studyplan {
private static $STUDYPLAN_CACHE = [];
private $r; // Holds database record
private $r; // Holds database record.
private $id;
private $aggregator;
private $context = null; // Hold context object once retrieved
private $linked_userids = null; // cache lookup of linked users (saves queries)
private $context = null; // Hold context object once retrieved.
private $linked_userids = null; // cache lookup of linked users (saves queries).
private $page_cache = null;
public function aggregator() {
@ -51,8 +72,8 @@ class studyplan {
public function pages() {
// cached version of find_studyplan_children.
// (may be premature optimization, since
// find_studyplan_children also does some caching)
// (may be premature optimization, since .
// find_studyplan_children also does some caching).
if (empty($this->page_cache)) {
$this->page_cache = studyplanpage::find_studyplan_children($this);
}
@ -68,7 +89,7 @@ class studyplan {
$this->context = contextinfo::by_id($this->r->context_id)->context;
}
catch(\dml_missing_record_exception $x) {
throw new \InvalidArgumentException("Context {$this->r->context_id} not available"); // Just throw it up again. catch is included here to make sure we know it throws this exception
throw new \InvalidArgumentException("Context {$this->r->context_id} not available"); // Just throw it up again. catch is included here to make sure we know it throws this exception.
}
}
return $this->context;
@ -148,19 +169,18 @@ class studyplan {
'pages' => [],
];
foreach($this->pages() as $p)
{
foreach ($this->pages() as $p) {
$model['pages'][] = $p->editor_model();
}
if (has_capability('local/treestudyplan:forcescales', \context_system::instance())) {
if (!array_key_exists('advanced', $model)) {
// Create advanced node if it does not exist
// Create advanced node if it does not exist.
$model['advanced'] = [];
}
// get a list of available scales
// get a list of available scales.
$scales = array_map( function($scale) {
return [ "id" => $scale->id, "name" => $scale->name, ];
}, \grade_scale::fetch_all(array('courseid'=>0)) ) ;
@ -185,14 +205,14 @@ class studyplan {
}
}
$id = $DB->insert_record(self::TABLE, $info);
$plan = self::findById($id); // make sure the new studyplan is immediately cached
$plan = self::findById($id); // make sure the new studyplan is immediately cached.
// Start temporary skräpp code
// Add a single page and copy the names.This keeps the data sane until the upgrade to
// real page management is done
// Start temporary skräpp code.
// Add a single page and copy the names.This keeps the data sane until the upgrade to .
// real page management is done.
// On import, adding an empty page messes things up for now, so we have an option to skip this....
// TODO: Remove this when proper page management is implemented
// TODO: Remove this when proper page management is implemented.
if (!$bare) {
$pageaddable = ['name', 'shortname', 'description', 'periods', 'startdate', 'enddate'];
@ -210,7 +230,7 @@ class studyplan {
$page = studyplanpage::add($pageinfo);
$plan->page_cache = [$page];
}
// End temporary skräpp code
// End temporary skräpp code.
return $plan;
}
@ -225,20 +245,20 @@ class studyplan {
}
}
$DB->update_record(self::TABLE, $info);
//reload record after edit
//reload record after edit.
$this->r = $DB->get_record(self::TABLE, ['id' => $this->id], "*", MUST_EXIST);
//reload the context...
$this->context = null;
$this->context();
// reload aggregator
// reload aggregator.
$this->aggregator = aggregator::createOrDefault($this->r->aggregation, $this->r->aggregation_config);
// Start temporary skräpp code
// TODO: Until proper page editing is implemented, copy data from studyplan to it's first page
// Start temporary skräpp code.
// TODO: Until proper page editing is implemented, copy data from studyplan to it's first page.
// This keeps the data sane until the upgrade is done.
if (count($this->pages()) == 1) {
// update the info to the page as well
// update the info to the page as well.
$page = $this->pages()[0];
$pageeditable = ['name', 'shortname', 'description', 'periods', 'startdate', 'enddate'];
$pageinfo = [];
@ -253,7 +273,7 @@ class studyplan {
}
$page->edit($pageinfo);
}
// End temporary skräpp code
// End temporary skräpp code.
return $this;
}
@ -295,8 +315,7 @@ class studyplan {
$ids = $DB->get_fieldset_select(self::TABLE, "id", $where, ["contextid" => $contextid]);
}
foreach($ids as $id)
{
foreach ($ids as $id) {
$list[] = studyplan::findById($id);
}
return $list;
@ -311,15 +330,13 @@ class studyplan {
$where .= "OR context_id IS NULL";
}
$ids = $DB->get_fieldset_select(self::TABLE, "id", $where, ["shortname"=>$shortname, "contextid" => $contextid]);
foreach($ids as $id)
{
foreach ($ids as $id) {
$list[] = studyplan::findById($id);
}
return $list;
}
public static function find_for_user($userid)
{
public static function find_for_user($userid) {
global $DB;
$sql = "SELECT s.id FROM {local_treestudyplan} s
@ -347,8 +364,7 @@ class studyplan {
}
static public function exist_for_user($userid)
{
static public function exist_for_user($userid) {
global $DB;
$count = 0;
$sql = "SELECT s.* FROM {local_treestudyplan} s
@ -392,7 +408,7 @@ class studyplan {
if ($this->linked_userids === null) {
$uids = [];
// First get directly linked userids
// First get directly linked userids.
$sql = "SELECT j.user_id FROM {local_treestudyplan_user} j
WHERE j.studyplan_id = :planid";
$ulist = $DB->get_fieldset_sql($sql, ['planid' => $this->id]);
@ -402,7 +418,7 @@ class studyplan {
$users[] = $DB->get_record("user", ["id"=>$uid]);
}
// Next het users linked though cohort
// Next het users linked though cohort.
$sql = "SELECT cm.userid FROM {local_treestudyplan_cohort} j
INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid
WHERE j.studyplan_id = :planid";
@ -457,30 +473,27 @@ class studyplan {
'aggregation_info' => $this->aggregator->basic_model(),
];
foreach($this->pages() as $p)
{
foreach ($this->pages() as $p) {
$model['pages'][] = $p->user_model($userid);
}
return $model;
}
public static function duplicate_plan($plan_id,$name,$shortname)
{
public static function duplicate_plan($plan_id, $name, $shortname) {
$ori = self::findById($plan_id);
$new = $ori->duplicate($name, $shortname);
return $new->simple_model();
}
public function duplicate($name,$shortname)
{
// First duplicate the studyplan structure
public function duplicate($name, $shortname) {
// First duplicate the studyplan structure.
$newplan =studyplan::add([
'name' => $name,
'shortname' => $shortname,
'description' => $this->r->description,
]);
// next, copy the studylines
// next, copy the studylines.
foreach ($this->pages() as $p) {
$newchild = $p->duplicate($newplan);
@ -489,16 +502,14 @@ class studyplan {
return $newplan;
}
public static function export_structure()
{
public static function export_structure() {
return new \external_single_structure([
"format" => new \external_value(PARAM_TEXT, 'format of studyplan export'),
"content"=> new \external_value(PARAM_TEXT, 'exported studyplan content'),
], 'Exported studyplan');
}
public function export_plan()
{
public function export_plan() {
$model = $this->export_model();
$json = json_encode([
"type"=>"studyplan",
@ -508,8 +519,7 @@ class studyplan {
return [ "format" => "application/json", "content" => $json];
}
public function export_model()
{
public function export_model() {
$model = [
'name' => $this->r->name,
'shortname' => $this->r->shortname,
@ -522,32 +532,29 @@ class studyplan {
return $model;
}
public function export_pages_model()
{
public function export_pages_model() {
$pages = [];
foreach($this->pages() as $p)
{
foreach ($this->pages() as $p) {
$pages[] = $p->export_model();
}
return $pages;
}
public static function import_studyplan($content,$format="application/json",$context_id=1)
{
public static function import_studyplan($content, $format="application/json", $context_id=1) {
if ($format != "application/json") { return false;}
$content = json_decode($content, true);
if ($content["type"] == "studyplan" && $content["version"] >= 2.0) {
// Make sure the aggregation_config is re-encoded as json text
// Make sure the aggregation_config is re-encoded as json text.
$content["studyplan"]["aggregation_config"] = json_encode($content["studyplan"]["aggregation_config"]);
// And make sure the context_id is set to the provided context for import
// And make sure the context_id is set to the provided context for import.
$content["studyplan"]["context_id"] = $context_id;
// Create a new plan, based on the given parameters - this is the import studyplan part
// Create a new plan, based on the given parameters - this is the import studyplan part.
$plan = self::add($content["studyplan"], true);
// Now import each page
// Now import each page.
return $plan->import_pages_model($content["studyplan"]["pages"]);
}
@ -557,17 +564,16 @@ class studyplan {
}
}
public function import_pages($content,$format="application/json")
{
public function import_pages($content, $format="application/json") {
if ($format != "application/json") { return false;}
$content = json_decode($content, true);
if ($content["version"] >= 2.0) {
if ($content["type"] == "studyplanpage") {
// import single page from a studyplanpage (wrapped in array of one page)
// import single page from a studyplanpage (wrapped in array of one page).
return $this->import_pages_model([$content["page"]]);
}
else if ($content["type"] == "studyplan") {
// Import all pages from the studyplan
// Import all pages from the studyplan.
return $this->import_pages_model($content["studyplan"]["pages"]);
}
}
@ -576,8 +582,7 @@ class studyplan {
}
}
protected function import_pages_model($model)
{
protected function import_pages_model($model) {
$this->pages(); // make sure the page cache is initialized, since we will be adding to it.
foreach ($model as $p) {
$p["studyplan_id"] = $this->id();
@ -595,7 +600,7 @@ class studyplan {
public function mark_csync_changed() {
global $DB;
$DB->update_record(self::TABLE, ['id' => $this->id, "csync_flag" => 1]);
$this->r->csync_flag = 1; //manually set it in the cache, if something unexpected happened, an exception has already been thrown anyway
$this->r->csync_flag = 1; //manually set it in the cache, if something unexpected happened, an exception has already been thrown anyway.
}
/**
@ -604,7 +609,7 @@ class studyplan {
public function clear_csync_changed() {
global $DB;
$DB->update_record(self::TABLE, ['id' => $this->id, "csync_flag" => 0]);
$this->r->csync_flag = 0; //manually set it in the cache, if something unexpected happened, an exception has already been thrown anyway
$this->r->csync_flag = 0; //manually set it in the cache, if something unexpected happened, an exception has already been thrown anyway.
}
public function has_csync_changed() {

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php');
@ -10,7 +31,7 @@ class studyplanpage {
private static $CACHE = [];
private $r; // Holds database record
private $r; // Holds database record.
private $id;
private $studyplan;
@ -62,7 +83,7 @@ class studyplanpage {
return new \DateTime($this->r->enddate);
}
else{
// return a date 100 years into the future
// return a date 100 years into the future.
return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
}
@ -124,8 +145,7 @@ class studyplanpage {
];
$children = studyline::find_page_children($this);
foreach($children as $c)
{
foreach ($children as $c) {
$model['studylines'][] = $c->editor_model();
}
return $model;
@ -152,7 +172,7 @@ class studyplanpage {
}
$id = $DB->insert_record(self::TABLE, $info);
return self::findById($id); // make sure the new page is immediately cached
return self::findById($id); // make sure the new page is immediately cached.
}
public function edit($fields) {
@ -169,7 +189,7 @@ class studyplanpage {
}
$DB->update_record(self::TABLE, $info);
//reload record after edit
//reload record after edit.
$this->r = $DB->get_record(self::TABLE, ['id' => $this->id], "*", MUST_EXIST);
return $this;
@ -224,15 +244,13 @@ class studyplanpage {
];
$children = studyline::find_page_children($this);
foreach($children as $c)
{
foreach ($children as $c) {
$model['studylines'][] = $c->user_model($userid);
}
return $model;
}
public static function find_studyplan_children(studyplan $plan)
{
public static function find_studyplan_children(studyplan $plan) {
global $DB;
$list = [];
$ids = $DB->get_fieldset_select(self::TABLE, "id", "studyplan_id = :plan_id ORDER BY startdate",
@ -243,16 +261,14 @@ class studyplanpage {
return $list;
}
public static function duplicate_page($page_id,$name,$shortname)
{
public static function duplicate_page($page_id, $name, $shortname) {
$ori = self::findById($page_id);
$new = $ori->duplicate($name, $shortname);
return $new->simple_model();
}
public function duplicate($new_studyplan)
{
// First duplicate the studyplan structure
public function duplicate($new_studyplan) {
// First duplicate the studyplan structure.
$new = studyplanpage::add([
'studyplan_id' => $new_studyplan->id(),
'fullname' => $this->r->fullname,
@ -263,7 +279,7 @@ class studyplanpage {
'enddate' => empty($this->r->enddate)?null:$this->r->enddate,
]);
// next, copy the studylines
// next, copy the studylines.
$children = studyline::find_page_children($this);
$itemtranslation = [];
@ -273,11 +289,11 @@ class studyplanpage {
$linetranslation[$c->id()] = $newchild->id();
}
// now the itemtranslation array contains all of the old child id's as keys and all of the related new ids as values
// (feature of the studyline::duplicate function)
// use this to recreate the lines in the new plan
// now the itemtranslation array contains all of the old child id's as keys and all of the related new ids as values.
// (feature of the studyline::duplicate function).
// use this to recreate the lines in the new plan.
foreach (array_keys($itemtranslation) as $item_id) {
// copy based on the outgoing connections of each item, to avoid duplicates
// copy based on the outgoing connections of each item, to avoid duplicates.
$connections = studyitemconnection::find_outgoing($item_id);
foreach ($connections as $conn) {
studyitemconnection::connect($itemtranslation[$conn->from_id], $itemtranslation[$conn->to_id]);
@ -286,16 +302,14 @@ class studyplanpage {
return $new;
}
public static function export_structure()
{
public static function export_structure() {
return new \external_single_structure([
"format" => new \external_value(PARAM_TEXT, 'format of studyplan export'),
"content"=> new \external_value(PARAM_TEXT, 'exported studyplan content'),
], 'Exported studyplan');
}
public function export_page()
{
public function export_page() {
$model = $this->export_model();
$json = json_encode([
"type"=>"studyplanpage",
@ -305,23 +319,22 @@ class studyplanpage {
return [ "format" => "application/json", "content" => $json];
}
public function export_page_csv()
{
public function export_page_csv() {
$plist = period::findForPage($this);
$model = $this->editor_model();
$periods = intval($model["periods"]);
// First line
// First line.
$csv = "\"\"";
for($i = 1; $i <= $periods; $i++) {
$name = $plist[$i]->shortname();
$csv .= ", \"{$name}\"";
}
$csv .= "\r\n";
// next, make one line per studyline
// next, make one line per studyline.
foreach ($model["studylines"] as $line) {
// determine how many fields are simultaneous in the line at maximum
// determine how many fields are simultaneous in the line at maximum.
$maxlines = 1;
for($i = 1; $i <= $periods; $i++) {
if (count($line["slots"]) > $i) {
@ -402,8 +415,7 @@ class studyplanpage {
}
public function export_model()
{
public function export_model() {
$model = [
'fullname' => $this->r->fullname,
'shortname' => $this->r->shortname,
@ -417,20 +429,17 @@ class studyplanpage {
return $model;
}
public function export_studylines_model()
{
public function export_studylines_model() {
$children = studyline::find_page_children($this);
$lines = [];
foreach($children as $c)
{
foreach ($children as $c) {
$lines[] = $c->export_model();
}
return $lines;
}
public function import_periods($content,$format="application/json")
{
public function import_periods($content, $format="application/json") {
if ($format != "application/json") { return false;}
$content = json_decode($content, true);
if ($content["type"] == "periods" && $content["version"] >= 2.0) {
@ -444,8 +453,7 @@ class studyplanpage {
}
}
public function import_studylines($content,$format="application/json")
{
public function import_studylines($content, $format="application/json") {
if ($format != "application/json") { return false;}
$content = json_decode($content, true);
if ($content["type"] == "studylines" && $content["version"] >= 2.0) {
@ -482,9 +490,8 @@ class studyplanpage {
}
}
public function import_studylines_model($model)
{
// First attempt to map each studyline model to an existing or new line
public function import_studylines_model($model) {
// First attempt to map each studyline model to an existing or new line.
$line_map = [];
foreach ($model as $ix => $linemodel) {
$line = $this->find_studyline_by_shortname($linemodel["shortname"]);
@ -492,19 +499,19 @@ class studyplanpage {
$linemodel["page_id"] = $this->id;
$line = studyline::add($linemodel);
} else {
//$line->edit($linemodel); // Update the line with the settings from the imported file
//$line->edit($linemodel); // Update the line with the settings from the imported file.
}
$line_map[$ix] = $line;
}
// next, let each study line import the study items
// next, let each study line import the study items.
$itemtranslation = [];
$connections = [];
foreach ($model as $ix => $linemodel) {
$line_map[$ix]->import_studyitems($linemodel["slots"], $itemtranslation, $connections);
}
// Finally, create the links between the study items
// Finally, create the links between the study items.
foreach ($connections as $from => $dests) {
foreach ($dests as $to) {
studyitemconnection::connect($from, $itemtranslation[$to]);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
@ -20,8 +40,7 @@ class success {
$this->msg = $msg;
}
public static function structure()
{
public static function structure() {
return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'),

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\task;
require_once($CFG->dirroot.'/course/externallib.php');
use local_treestudyplan\studyplan;
@ -25,7 +46,7 @@ class autocohortsync extends \core\task\scheduled_task {
$studyplans = studyplan::find_all();
foreach ($studyplans as $studyplan) {
// Only process studyplans that have been marked for change because
// Only process studyplans that have been marked for change because .
// a cohort change has occurred or a course has been added....
if ($studyplan->has_csync_changed()) {
\mtrace("Studyplan {$studyplan->shortname()} needs processing");

View File

@ -1,10 +1,31 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\task;
require_once($CFG->dirroot.'/course/externallib.php');
use local_treestudyplan\teachingfinder;
class refreshteacherlist extends \core\task\scheduled_task {
const CACHE_TIME = 4 * 60 * 60; // 2 hours
const CACHE_TIME = 4 * 60 * 60; // 2 hours.
/**
* Return the task's name as shown in admin screens.

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
class teachingfinder {
@ -11,7 +32,7 @@ class teachingfinder {
$records = $DB->get_records(self::TABLE, ['teacher_id' => $userid]);
if (count($records) == 0) {
// initiate a search if the cache is empty
// initiate a search if the cache is empty.
self::update_teaching_cache($userid);
$DB->get_records(self::TABLE, ['teacher_id' => $userid]);
}
@ -32,14 +53,14 @@ class teachingfinder {
global $DB;
$list = [];
// First find all active study plans
// First find all active study plans.
$sql = "SELECT p.id FROM {local_treestudyplan_page} p
WHERE startdate <= NOW() and enddate >= NOW()";
$page_ids = $DB->get_fieldset_sql($sql, []);
// then parse them to see if the user has the grading permission in any of them
// (Which would make them a teacher for all intents and purposes)
// then parse them to see if the user has the grading permission in any of them .
// (Which would make them a teacher for all intents and purposes).
foreach ($page_ids as $page_id) {
$sql = "SELECT i.course_id FROM {local_treestudyplan_item} i
@ -52,24 +73,23 @@ class teachingfinder {
$coursecontext = \context_course::instance($cid);
if (is_enrolled($coursecontext, $userid, 'mod/assign:grade')) {
$linked = true;
break; // No need to search further
break; // No need to search further.
}
}
if($linked)
{
if ($linked) {
$list[] = $page_id;
}
}
// Now, clear the database of all records for this user
// Now, clear the database of all records for this user.
$DB->delete_records(self::TABLE, ["teacher_id"=>$userid]);
// And add new records for the found studyplans
// And add new records for the found studyplans.
$now = time();
foreach ($list as $page_id) {
// Retrieve the studyplan id from the page
//TODO: Change this when page management is implemented to return the page instead of the plan
// Retrieve the studyplan id from the page.
//TODO: Change this when page management is implemented to return the page instead of the plan.
$planid = $DB->get_field("local_treestudyplan_page", "studyplan_id", ["id" => $page_id]);
$DB->insert_record(self::TABLE, ["teacher_id"=>$userid, "studyplan_id"=>$planid, "update_time"=>$now]);
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
use \local_treestudyplan\local\gradegenerator;
@ -39,7 +60,7 @@ if ($options['help']) {
cli_writeln($usage);
exit(2);
}
//cli_writeln(print_r($options,true));
//cli_writeln(print_r($options, true));.
if (empty($options['studyplan']) && empty($options["all"])) {
cli_error('Missing mandatory argument studyplan.', 2);

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
use \local_treestudyplan\local\gradegenerator;
@ -46,7 +67,7 @@ if ($options['help']) {
exit(2);
}
/////////////////////////////////
/////////////////////////////////.
$user = get_admin();
if (!$user) {
@ -65,7 +86,7 @@ login_attempt_valid($user);
complete_user_login($user);
////////////////////////////////
////////////////////////////////.
if (empty($options['studyplan']) && empty($options["all"])) {
@ -95,7 +116,7 @@ foreach($plans as $plan){
cli_writeln(" ** {$line->name()} **");
$items = studyitem::find_studyline_children($line);
foreach ($items as $item) {
if($item->type() == studyitem::COURSE) { // only handle courses for now
if ($item->type() == studyitem::COURSE) { // only handle courses for now.
$courseinfo = $item->getcourseinfo();
cli_writeln(" # {$courseinfo->shortname()}");
@ -113,14 +134,14 @@ foreach($plans as $plan){
$grade = $gg->gradetext;
cli_write (" - {$name} = {$grade}");
// Check if the item is alreaady graded for this user
// Check if the item is alreaady graded for this user.
$existing = $count = $DB->count_records_select('grade_grades', 'itemid = :gradeitemid AND finalgrade IS NOT NULL and userid = :userid',
['gradeitemid' => $gi->id, 'userid' => $u->id]);
if (!$existing) {
if ($gg->grade > 0) {
if ($gi->itemmodule == "assign") {
// If it is an assignment, submit though that interface
// If it is an assignment, submit though that interface .
list($c, $cminfo) = get_course_and_cm_from_instance($gi->iteminstance, $gi->itemmodule);
$cm_ctx = \context_module::instance($cminfo->id);
$a = new \assign($cm_ctx, $cminfo, $c);
@ -131,7 +152,7 @@ foreach($plans as $plan){
$ug->feedbacktext = nl2br( htmlspecialchars($gg->fb));
$ug->feedbackformat = FORMAT_HTML;
//print_r($ug);
//print_r($ug);.
if (!$options["dryrun"]) {
$a->update_grade($ug);
@ -142,7 +163,7 @@ foreach($plans as $plan){
}
} else {
// Otherwise, set the grade through the manual grading override
// Otherwise, set the grade through the manual grading override.
cli_writeln(" ... Cannot store");
}

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$capabilities = [

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$services = [
"Competency listing" => [
@ -36,527 +56,527 @@ $functions = [
/***************************
* Studyplan functions
***************************/
'local_treestudyplan_list_studyplans' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'list_studyplans', //external function name
'description' => 'List available studyplans', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_list_studyplans' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'list_studyplans', //external function name.
'description' => 'List available studyplans', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan, local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan, local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_studyplan_map' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'get_studyplan_map', //external function name
'description' => 'Retrieve studyplan map', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_studyplan_map' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'get_studyplan_map', //external function name.
'description' => 'Retrieve studyplan map', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan, local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan, local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_studyline_map' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'get_studyline_map', //external function name
'description' => 'Retrieve studyline map', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_studyline_map' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'get_studyline_map', //external function name.
'description' => 'Retrieve studyline map', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_add_studyplan' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'add_studyplan', //external function name
'description' => 'Add studyplan', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_add_studyplan' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'add_studyplan', //external function name.
'description' => 'Add studyplan', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_add_studyline' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'add_studyline', //external function name
'description' => 'Add studyline', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_add_studyline' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'add_studyline', //external function name.
'description' => 'Add studyline', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_edit_studyplan' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'edit_studyplan', //external function name
'description' => 'Edit studyplan', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_edit_studyplan' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'edit_studyplan', //external function name.
'description' => 'Edit studyplan', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_edit_studyline' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'edit_studyline', //external function name
'description' => 'Edit studyline', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_edit_studyline' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'edit_studyline', //external function name.
'description' => 'Edit studyline', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_delete_studyplan' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'delete_studyplan', //external function name
'description' => 'Delete studyplan', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_delete_studyplan' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'delete_studyplan', //external function name.
'description' => 'Delete studyplan', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_delete_studyline' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'delete_studyline', //external function name
'description' => 'Delete studyline', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_delete_studyline' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'delete_studyline', //external function name.
'description' => 'Delete studyline', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_reorder_studylines' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'reorder_studylines', //external function name
'description' => 'Reorder studylines', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_reorder_studylines' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'reorder_studylines', //external function name.
'description' => 'Reorder studylines', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_studyitem' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'get_studyitem', //external function name
'description' => 'Retrieve study item', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_studyitem' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'get_studyitem', //external function name.
'description' => 'Retrieve study item', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_add_studyitem' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'add_studyitem', //external function name
'description' => 'Add study item', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_add_studyitem' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'add_studyitem', //external function name.
'description' => 'Add study item', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_edit_studyitem' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'edit_studyitem', //external function name
'description' => 'Edit study item', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_edit_studyitem' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'edit_studyitem', //external function name.
'description' => 'Edit study item', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_reorder_studyitems' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'reorder_studyitems', //external function name
'description' => 'Reorder study items', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_reorder_studyitems' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'reorder_studyitems', //external function name.
'description' => 'Reorder study items', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_delete_studyitem' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'delete_studyitem', //external function name
'description' => 'Delete study item', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_delete_studyitem' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'delete_studyitem', //external function name.
'description' => 'Delete study item', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_connect_studyitems' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'connect_studyitems', //external function name
'description' => 'Connect study items', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_connect_studyitems' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'connect_studyitems', //external function name.
'description' => 'Connect study items', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_disconnect_studyitems' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'disconnect_studyitems', //external function name
'description' => 'Disconnect study items', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_disconnect_studyitems' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'disconnect_studyitems', //external function name.
'description' => 'Disconnect study items', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
/***************************
* Badge functions
***************************/
'local_treestudyplan_list_badges' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'list_badges', //external function name
'description' => 'List availabel site badges', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_list_badges' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'list_badges', //external function name.
'description' => 'List availabel site badges', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
/***************************
* Association functions
***************************/
'local_treestudyplan_list_cohort' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'list_cohort', //external function name
'description' => 'List available cohorts', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_list_cohort' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'list_cohort', //external function name.
'description' => 'List available cohorts', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_find_user' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'find_user', //external function name
'description' => 'Find user', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_find_user' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'find_user', //external function name.
'description' => 'Find user', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_connect_cohort' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'connect_cohort', //external function name
'description' => 'Connect cohort to studyplan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_connect_cohort' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'connect_cohort', //external function name.
'description' => 'Connect cohort to studyplan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_disconnect_cohort' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'disconnect_cohort', //external function name
'description' => 'Disconnect cohort from study plan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_disconnect_cohort' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'disconnect_cohort', //external function name.
'description' => 'Disconnect cohort from study plan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_connect_user' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'connect_user', //external function name
'description' => 'Connect user to study plan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_connect_user' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'connect_user', //external function name.
'description' => 'Connect user to study plan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_disconnect_user' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'disconnect_user', //external function name
'description' => 'Disconnect user from studyplan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_disconnect_user' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'disconnect_user', //external function name.
'description' => 'Disconnect user from studyplan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_associated_users' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'associated_users', //external function name
'description' => 'List users associated with a studyplan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_associated_users' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'associated_users', //external function name.
'description' => 'List users associated with a studyplan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_associated_cohorts' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'associated_cohorts', //external function name
'description' => 'List cohorts associated with a studyplan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_associated_cohorts' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'associated_cohorts', //external function name.
'description' => 'List cohorts associated with a studyplan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_list_user_studyplans' => [ //web service function name
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function
'methodname' => 'list_user_studyplans', //external function name
'description' => 'List user studyplans', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_list_user_studyplans' => [ //web service function name.
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function.
'methodname' => 'list_user_studyplans', //external function name.
'description' => 'List user studyplans', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_user_studyplans' => [ //web service function name
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function
'methodname' => 'get_user_studyplans', //external function name
'description' => 'Retrieve user studyplan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_user_studyplans' => [ //web service function name.
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function.
'methodname' => 'get_user_studyplans', //external function name.
'description' => 'Retrieve user studyplan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_user_studyplan' => [ //web service function name
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function
'methodname' => 'get_user_studyplan', //external function name
'description' => 'Retrieve user studyplan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_user_studyplan' => [ //web service function name.
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function.
'methodname' => 'get_user_studyplan', //external function name.
'description' => 'Retrieve user studyplan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_invited_studyplan' => [ //web service function name
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function
'methodname' => 'get_invited_studyplan', //external function name
'description' => 'Retrieve user studyplan based on invite', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_invited_studyplan' => [ //web service function name.
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function.
'methodname' => 'get_invited_studyplan', //external function name.
'description' => 'Retrieve user studyplan based on invite', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => '', // Advises the admin which capabilities are required
'capabilities' => '', // Advises the admin which capabilities are required.
'loginrequired' => false,
],
'local_treestudyplan_list_own_studyplans' => [ //web service function name
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function
'methodname' => 'list_own_studyplans', //external function name
'description' => 'List own studyplans', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_list_own_studyplans' => [ //web service function name.
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function.
'methodname' => 'list_own_studyplans', //external function name.
'description' => 'List own studyplans', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => '', // Advises the admin which capabilities are required
'capabilities' => '', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_own_studyplan' => [ //web service function name
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function
'methodname' => 'get_own_studyplan', //external function name
'description' => 'Retrieve own studyplan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_own_studyplan' => [ //web service function name.
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function.
'methodname' => 'get_own_studyplan', //external function name.
'description' => 'Retrieve own studyplan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => '', // Advises the admin which capabilities are required
'capabilities' => '', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_map_categories' => [ //web service function name
'classname' => '\local_treestudyplan\courseservice', //class containing the external function
'methodname' => 'map_categories', //external function name
'description' => 'List available root categories', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_map_categories' => [ //web service function name.
'classname' => '\local_treestudyplan\courseservice', //class containing the external function.
'methodname' => 'map_categories', //external function name.
'description' => 'List available root categories', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_category' => [ //web service function name
'classname' => '\local_treestudyplan\courseservice', //class containing the external function
'methodname' => 'get_category', //external function name
'description' => 'Get details for specified category', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_category' => [ //web service function name.
'classname' => '\local_treestudyplan\courseservice', //class containing the external function.
'methodname' => 'get_category', //external function name.
'description' => 'Get details for specified category', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_include_grade' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'include_grade', //external function name
'description' => 'Include gradable in result', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_include_grade' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'include_grade', //external function name.
'description' => 'Include gradable in result', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan, local/treestudyplan:selectowngradables', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan, local/treestudyplan:selectowngradables', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_all_associated' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'all_associated', //external function name
'description' => 'List associated users', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_all_associated' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'all_associated', //external function name.
'description' => 'List associated users', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_list_aggregators' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'list_aggregators', //external function name
'description' => 'List available aggregators', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_list_aggregators' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'list_aggregators', //external function name.
'description' => 'List available aggregators', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_disable_autoenddate' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'disable_autoenddate', //external function name
'description' => 'Disable automatic end dates on courses in the study plan', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_disable_autoenddate' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'disable_autoenddate', //external function name.
'description' => 'Disable automatic end dates on courses in the study plan', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:forcescales', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:forcescales', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_force_studyplan_scale' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'force_studyplan_scale', //external function name
'description' => 'Change all associated gradables to the chosen scale if possible', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_force_studyplan_scale' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'force_studyplan_scale', //external function name.
'description' => 'Change all associated gradables to the chosen scale if possible', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:forcescales', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:forcescales', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_list_scales' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'list_scales', //external function name
'description' => 'List system scales', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_list_scales' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'list_scales', //external function name.
'description' => 'List system scales', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:forcescales', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:forcescales', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_duplicate_plan' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'duplicate_plan', //external function name
'description' => 'Copy studyplan', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_duplicate_plan' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'duplicate_plan', //external function name.
'description' => 'Copy studyplan', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_export_plan' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'export_plan', //external function name
'description' => 'Export study plan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_export_plan' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'export_plan', //external function name.
'description' => 'Export study plan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_export_studylines' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'export_studylines', //external function name
'description' => 'Export study plan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_export_studylines' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'export_studylines', //external function name.
'description' => 'Export study plan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_import_plan' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'import_plan', //external function name
'description' => 'Import study plan', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_import_plan' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'import_plan', //external function name.
'description' => 'Import study plan', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_import_studylines' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'import_studylines', //external function name
'description' => 'Import study plan', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_import_studylines' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'import_studylines', //external function name.
'description' => 'Import study plan', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_edit_period' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'edit_period', //external function name
'description' => 'Edit period name and timing', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_edit_period' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'edit_period', //external function name.
'description' => 'Edit period name and timing', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_submit_cm_editform' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'submit_cm_editform', //external function name
'description' => 'Submit course module edit form', //human readable description of the web service function
'type' => 'write', //database rights of the web service function (read, write)
'local_treestudyplan_submit_cm_editform' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'submit_cm_editform', //external function name.
'description' => 'Submit course module edit form', //human readable description of the web service function.
'type' => 'write', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_get_teaching_studyplans' => [ //web service function name
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function
'methodname' => 'get_teaching_studyplans', //external function name
'description' => 'Get the studyplans I currently teach in', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_get_teaching_studyplans' => [ //web service function name.
'classname' => '\local_treestudyplan\studentstudyplanservice', //class containing the external function.
'methodname' => 'get_teaching_studyplans', //external function name.
'description' => 'Get the studyplans I currently teach in', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'loginrequired' => true,
],
'local_treestudyplan_list_accessible_categories' => [ //web service function name
'classname' => '\local_treestudyplan\courseservice', //class containing the external function
'methodname' => 'list_accessible_categories', //external function name
'description' => 'Get categories accessible to the current user', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'local_treestudyplan_list_accessible_categories' => [ //web service function name.
'classname' => '\local_treestudyplan\courseservice', //class containing the external function.
'methodname' => 'list_accessible_categories', //external function name.
'description' => 'Get categories accessible to the current user', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'ajax' => true,
'loginrequired' => true,
],
'local_treestudyplan_list_used_categories' => [ //web service function name
'classname' => '\local_treestudyplan\courseservice', //class containing the external function
'methodname' => 'list_used_categories', //external function name
'description' => 'Get categories hosting a studyplan', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'local_treestudyplan_list_used_categories' => [ //web service function name.
'classname' => '\local_treestudyplan\courseservice', //class containing the external function.
'methodname' => 'list_used_categories', //external function name.
'description' => 'Get categories hosting a studyplan', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'ajax' => true,
'loginrequired' => true,
],
'local_treestudyplan_scan_badge_progress' => [ //web service function name
'classname' => '\local_treestudyplan\courseservice', //class containing the external function
'methodname' => 'scan_badge_progress', //external function name
'description' => 'Scan progress of students in attaining badge', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'local_treestudyplan_scan_badge_progress' => [ //web service function name.
'classname' => '\local_treestudyplan\courseservice', //class containing the external function.
'methodname' => 'scan_badge_progress', //external function name.
'description' => 'Scan progress of students in attaining badge', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'ajax' => true,
'loginrequired' => true,
],
'local_treestudyplan_scan_completion_progress' => [ //web service function name
'classname' => '\local_treestudyplan\courseservice', //class containing the external function
'methodname' => 'scan_completion_progress', //external function name
'description' => 'Scan progress of students in attaining completions', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'local_treestudyplan_scan_completion_progress' => [ //web service function name.
'classname' => '\local_treestudyplan\courseservice', //class containing the external function.
'methodname' => 'scan_completion_progress', //external function name.
'description' => 'Scan progress of students in attaining completions', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'ajax' => true,
'loginrequired' => true,
],
'local_treestudyplan_scan_grade_progress' => [ //web service function name
'classname' => '\local_treestudyplan\courseservice', //class containing the external function
'methodname' => 'scan_grade_progress', //external function name
'description' => 'Scan progress of students in attaining grades', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required
'local_treestudyplan_scan_grade_progress' => [ //web service function name.
'classname' => '\local_treestudyplan\courseservice', //class containing the external function.
'methodname' => 'scan_grade_progress', //external function name.
'description' => 'Scan progress of students in attaining grades', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'capabilities' => 'local/treestudyplan:viewuserreports', // Advises the admin which capabilities are required.
'ajax' => true,
'loginrequired' => true,
],
'local_treestudyplan_cascade_cohortsync' => [ //web service function name
'classname' => '\local_treestudyplan\associationservice', //class containing the external function
'methodname' => 'cascade_cohortsync', //external function name
'description' => 'Sync cohortsync to studyplan association', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'local_treestudyplan_cascade_cohortsync' => [ //web service function name.
'classname' => '\local_treestudyplan\associationservice', //class containing the external function.
'methodname' => 'cascade_cohortsync', //external function name.
'description' => 'Sync cohortsync to studyplan association', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'ajax' => true,
'loginrequired' => true,
],
'local_treestudyplan_course_period_timing' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'course_period_timing', //external function name
'description' => 'Chenge course start and end times to match period', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'local_treestudyplan_course_period_timing' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'course_period_timing', //external function name.
'description' => 'Chenge course start and end times to match period', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'ajax' => true,
'loginrequired' => true,
],
'local_treestudyplan_set_studyitem_span' => [ //web service function name
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function
'methodname' => 'set_studyitem_span', //external function name
'description' => 'Change the span of a course item', //human readable description of the web service function
'type' => 'read', //database rights of the web service function (read, write)
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required
'local_treestudyplan_set_studyitem_span' => [ //web service function name.
'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function.
'methodname' => 'set_studyitem_span', //external function name.
'description' => 'Change the span of a course item', //human readable description of the web service function.
'type' => 'read', //database rights of the web service function (read, write).
'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required.
'ajax' => true,
'loginrequired' => true,
],

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$tasks = [
[
'classname' => 'local_treestudyplan\task\autocohortsync',

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_local_treestudyplan_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();
@ -266,7 +287,7 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
// Create a page 0 with it's data copied
// Create a page 0 with it's data copied.
$plans = $DB->get_recordset("local_treestudyplan");
foreach ($plans as $p) {
$o = [ "studyplan_id" => $p->id,
@ -279,8 +300,8 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
];
$pageid = $DB->insert_record("local_treestudyplan_page", $o);
// Now find all studyline references to the studyplan
// And update their record to reference the page instead of the plan
// Now find all studyline references to the studyplan .
// And update their record to reference the page instead of the plan.
$lines = $DB->get_recordset("local_treestudyplan_line", ["studyplan_id" => $p->id]);
foreach ($lines as $l) {
$lo = [
@ -347,16 +368,16 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
// Create a period page for all slots in the study
// Create a period page for all slots in the study.
$recordset = $DB->get_recordset("local_treestudyplan_page");
foreach ($recordset as $r) {
// 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;
$ystart = strtotime($r->startdate)+0;
$yend = strtotime($r->enddate)+0;
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;
}
else{
@ -367,7 +388,7 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
for($i=0; $i < $pcount; $i++) {
$pnum = $i+1;
$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,
"period" => $pnum,
@ -458,8 +479,8 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
if ($oldversion < 2023082100) {
// Up to version 20230821 the studyplan_id field still existed in the install.xml file
// Below code remedies that - even though this is a repeat of part of an earlier upgrade
// Up to version 20230821 the studyplan_id field still existed in the install.xml file.
// Below code remedies that - even though this is a repeat of part of an earlier upgrade.
// Define field studyplan_id to be dropped from local_treestudyplan_line.
$table = new xmldb_table('local_treestudyplan_line');

26
doc.php
View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->libdir.'/weblib.php');
@ -14,7 +35,7 @@ require_login();
$pi = $_SERVER['PATH_INFO'];
$file = $CFG->dirroot."/local/treestudyplan/doc".$pi;
// Fallback to index
// Fallback to index.
if (!file_exists($file)) {
$file = $CFG->dirroot."/local/treestudyplan/doc/index.htm";
}
@ -22,8 +43,7 @@ if(!file_exists($file)){
$mime = mime_content_type($file);
$text_types = ["text/html", "text/plain"];
if( in_array($mime,$text_types))
{
if ( in_array($mime, $text_types)) {
print $OUTPUT->header();
print file_get_contents($file);
print $OUTPUT->footer();

View File

@ -1,23 +1,32 @@
<?php
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");
}
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once("./lib.php");
require_once($CFG->libdir.'/weblib.php');
require_once($CFG->dirroot.'/local/treestudyplan/classes/reportinvite_form.php');
$add = optional_param('add', '', PARAM_ALPHANUM); // module name
$add = optional_param('add', '', PARAM_ALPHANUM); // module name.
$update = optional_param('update', 0, PARAM_INT);
$resend = optional_param('resend', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
@ -28,8 +37,7 @@ $PAGE->set_url("/local/treestudyplan/edit-invite.php");
$PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext);
if($update > 0)
{
if ($update > 0) {
$PAGE->set_title(get_string('invite_desc_edit', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invite_desc_edit', 'local_treestudyplan'));
}
@ -40,20 +48,18 @@ else
}
// Check if user has capability to manage study plan units
// Check if user has capability to manage study plan units.
require_login();
print $OUTPUT->header();
if(!empty($add))
{
if (!empty($add)) {
$data = array(
'add' => 1,
);
}
else if(!empty($update))
{
else if (!empty($update)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $update));
$data->update = $update;
if (empty($data) || $data->user_id != $USER->id)
@ -63,8 +69,7 @@ else if(!empty($update))
}
}
else if(!empty($resend))
{
else if (!empty($resend)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend));
$data->resend = $resend;
if (empty($data) || $data->user_id != $USER->id)
@ -73,7 +78,7 @@ else if(!empty($resend))
exit;
}
// Do some resending of an invitation
// Do some resending of an invitation.
local_treestudyplan_send_invite($data->id);
@ -82,8 +87,7 @@ else if(!empty($resend))
print $OUTPUT->footer();
exit;
}
else if(!empty($delete))
{
else if (!empty($delete)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete));
$data->delete = $delete;
if (empty($data) || $data->user_id != $USER->id)
@ -105,12 +109,10 @@ else {
$mform = new reportinvite_form();
$mform->set_data($data);
if($mform->is_cancelled())
{
if ($mform->is_cancelled()) {
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
}
else if ($data = $mform->get_data())
{
else if ($data = $mform->get_data()) {
if (!empty($data->update))
{
@ -128,7 +130,7 @@ else if ($data = $mform->get_data())
$id = $DB->insert_record("local_treestudyplan_invit", $data, true);
// Send invitaion mail
// Send invitaion mail.
local_treestudyplan_send_invite($id);
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$id}");

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->libdir.'/weblib.php');
@ -10,15 +31,14 @@ $systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/edit-plan.php", array());
require_login();
// Figure out the context (category or system, based on either category or context parameter)
$categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id
$contextid = optional_param('contextid', 0, PARAM_INT); // Context id
// Figure out the context (category or system, based on either category or context parameter).
$categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id.
$contextid = optional_param('contextid', 0, PARAM_INT); // Context id.
if ($categoryid > 0) {
$studyplancontext = context_coursecat::instance($categoryid);
}
elseif($contextid > 0)
{
else if ($contextid > 0) {
$studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT]))
{
@ -31,16 +51,16 @@ elseif($contextid > 0)
}
else
{
// If no context is selected, find the first available one
// If no context is selected, find the first available one.
$available_contexts = courseservice::list_accessible_categories_with_usage("edit");
$contextid=1; // fallback to system context
$contextid=1; // fallback to system context.
foreach ($available_contexts as $ctx) {
if ($ctx->count > 0) {
$contextid = $ctx->ctxid;
break;
}
}
// reload page with selected category
// reload page with selected category.
$url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]);
header('Location: '.$url->out(false), true, 302);
exit;
@ -60,7 +80,7 @@ if($studyplancontext->id > 1){
}
// Load javascripts and specific css
// Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$studyplancontext->id, $categoryid]);
@ -69,7 +89,7 @@ $PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$stu
$catlist = courseservice::list_accessible_categories_with_usage("edit");
//Local translate function
//Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param);
}

View File

@ -1,14 +1,34 @@
<?php
if(isset($_SERVER['SCRIPT_FILENAME']))
{
// If SCRIPT_FILENAME is set, use that so the symlinked directories the developmen environment uses are handled correctly
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @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
// If not, assume the cwd is not symlinked and proceed as we are used to.
require_once("../../config.php");
}
@ -19,7 +39,7 @@ use local_treestudyplan;
$INVITED_URL = "/local/treestudyplan/invited.php";
//admin_externalpage_setup('major');
//admin_externalpage_setup('major');.
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/invitations.php", array());
@ -30,14 +50,13 @@ $PAGE->set_context($systemcontext);
$PAGE->set_title(get_string('manage_invites', 'local_treestudyplan'));
$PAGE->set_heading(get_string('manage_invites', 'local_treestudyplan'));
// Load javascripts
// Load javascripts.
$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))
{
if (!empty($sent)) {
$invite = $DB->get_record('local_treestudyplan_invit', array('id' => $sent));
\core\notification::success(get_string('invite_resent_msg', 'local_treestudyplan', $invite));
@ -59,8 +78,7 @@ print "<th>&nbsp;</th>";
print "</thead>";
print "<tbody>";
if(count($invites) > 0)
{
if (count($invites) > 0) {
foreach ($invites as $invite)
{
$testlink = $INVITED_URL."?key={$invite->invitekey}";

View File

@ -1,8 +1,28 @@
<?php
// If not, assume the cwd is not symlinked and proceed as we are used to
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
//Local translate function
//Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param);
}
@ -11,14 +31,13 @@ $systemcontext = context_system::instance();
$PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext);
// See if we can get a valid user for this invited
$invitekey = optional_param('key', '', PARAM_ALPHANUM); // module name
// See if we can get a valid user for this invited.
$invitekey = optional_param('key', '', PARAM_ALPHANUM); // module name.
$PAGE->set_url("/local/treestudyplan/invited.php", array('key' => $invitekey));
$invite = $DB->get_record_select("local_treestudyplan_invit", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $invitekey]);
if(empty($invite))
{
if (empty($invite)) {
$PAGE->set_title(get_string('invalid_invitekey_title', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan'));
@ -26,7 +45,7 @@ if(empty($invite))
print $OUTPUT->header();
// render page for skill level 0 (global)
// render page for skill level 0 (global).
print "<div class='box errorbox alert alert-danger'>";
print get_string('invalid_invitekey_error', 'local_treestudyplan');
@ -38,7 +57,7 @@ if(empty($invite))
}
else
{
// Load javascripts and specific css
// Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', ['invited', $invitekey]);

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Studyplans';
$string['privacy:metadata'] = 'This plugin stores a link between users and their associated study plans. It also needs to store an email address and user provided handle, which may be a name, to send invitations to view the study plan to whomever the user chooses by email.';

View File

@ -1,4 +1,24 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Studieplannen';

83
lib.php
View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/course/modlib.php');
use local_treestudyplan\local\helpers\webservicehelper;
@ -15,30 +36,30 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$systemcontext = context_system::instance();
// Moodle 4.0-4.2 do not yet support customizing the primary navigation bar (it is a planned feature though)
// For now, go to theme settings and add the following into "Custom menu items"
// [your name for my studyplan]|/local/treestudyplan/myreport.php
// [your name for studyplan viewing]|/local/treestudyplan/view-plan.php
// [your name for studyplan managing]|/local/treestudyplan/edit-plan.php
// For example:
// Mijn studieplan|/local/treestudyplan/myreport.php
// Studieplannen|/local/treestudyplan/view-plan.php
// Studieplannen beheren|/local/treestudyplan/edit-plan.php
// Moodle 4.0-4.2 do not yet support customizing the primary navigation bar (it is a planned feature though).
// For now, go to theme settings and add the following into "Custom menu items".
// [your name for my studyplan]|/local/treestudyplan/myreport.php.
// [your name for studyplan viewing]|/local/treestudyplan/view-plan.php.
// [your name for studyplan managing]|/local/treestudyplan/edit-plan.php.
// For example:.
// Mijn studieplan|/local/treestudyplan/myreport.php.
// Studieplannen|/local/treestudyplan/view-plan.php.
// Studieplannen beheren|/local/treestudyplan/edit-plan.php.
// Using some javascript magic we'll hide the links that are not accessible
// (Since the Output API does not easily support inline style tags, adding one through Javascript is easier,
// 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
// Using some javascript magic we'll hide the links that are not accessible.
// (Since the Output API does not easily support inline style tags, adding one through Javascript is easier,.
// 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.
$hide_primary_hrefs = [];
if($USER->id > 1) // Don't show if user is not logged in (id == 0) or is guest user (id == 1)
if ($USER->id > 1) // Don't show if user is not logged in (id == 0) or is guest user (id == 1).
{
$userstudyplans = studyplan::find_for_user($USER->id);
if (!empty($userstudyplans))
{
// create studyplan node
// create studyplan node.
$node = navigation_node::create(
get_string("link_myreport", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/myreport.php", array()),
@ -50,7 +71,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$node->showinflatnavigation = true;
$node->showinsecondarynavigation=true;
// create invitenode node
// create invitenode node.
$invitenode = navigation_node::create(
get_string("manage_invites", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invitations.php", array()),
@ -111,7 +132,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$hide_primary_hrefs[] = "/local/treestudyplan/edit-plan.php";
$hide_primary_hrefs[] = "/local/treestudyplan/view-plan.php";
}
// create invitenode node
// create invitenode node.
$invitenode = navigation_node::create(
get_string("nav_invited", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invited.php", array()),
@ -124,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
// 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', [$hide_primary_hrefs]);
@ -143,7 +164,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
"local_treestudyplan_editplan",
new pix_icon("editplans", '', 'local_treestudyplan')
);
//$node->make_active();
//$node->make_active();.
}
if (has_capability('local/treestudyplan:viewuserreports', $coursecategorycontext)) {
$node = $navigation->add(
@ -154,7 +175,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
"local_treestudyplan_viewplan",
new pix_icon("viewplans", '', 'local_treestudyplan')
);
//$node->make_active();
//$node->make_active();.
}
}
@ -184,8 +205,7 @@ function local_treestudyplan_reset_fontawesome_icon_map() {
$instance->get_icon_name_map();
}
function local_treestudyplan_send_invite($inviteid)
{
function local_treestudyplan_send_invite($inviteid) {
global $DB, $USER, $CFG;
$invite = $DB->get_record("local_treestudyplan_invit", array('id' => $inviteid));
@ -226,8 +246,8 @@ function local_treestudyplan_send_invite($inviteid)
$subject = get_string('invite_mail_subject', 'local_treestudyplan', $data);
$html = "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>.
<html xmlns='http://www.w3.org/1999/xhtml'>.
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>{$subject}</title>
@ -247,8 +267,7 @@ function local_treestudyplan_send_invite($inviteid)
}
function local_treestudyplan_find_cohortmembers($cohortid)
{
function local_treestudyplan_find_cohortmembers($cohortid) {
global $DB;
// By default wherecondition retrieves all users except the deleted, not confirmed and guest.
$params = ['cohortid' => $cohortid];
@ -261,16 +280,14 @@ function local_treestudyplan_find_cohortmembers($cohortid)
return $availableusers;
}
function local_treestudyplan_get_cohort_path($cohort)
{
function local_treestudyplan_get_cohort_path($cohort) {
$cohortcontext = context::instance_by_id($cohort->contextid);
if($cohortcontext && $cohortcontext->id != SYSCONTEXTID)
{
if ($cohortcontext && $cohortcontext->id != SYSCONTEXTID) {
$ctxpath = array_map(
function($ctx) { return $ctx->get_context_name(false);},
$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[] = $cohort->name;
@ -299,8 +316,8 @@ function local_treestudyplan_output_fragment_mod_edit_form($args){
// Check the course exists.
$course = \get_course($cm->course);
// require_login
require_login($course, false, $cm); // needed to setup proper $COURSE
// require_login.
require_login($course, false, $cm); // needed to setup proper $COURSE.
list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course);

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->libdir.'/weblib.php');
@ -15,12 +36,12 @@ $PAGE->set_context($systemcontext);
$PAGE->set_title(get_string('report_invited', 'local_treestudyplan', "{$USER->firstname} {$USER->lastname}"));
$PAGE->set_heading(get_string('report_invited', 'local_treestudyplan', "{$USER->firstname} {$USER->lastname}"));
// Load javascripts and specific css
// Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init');
//Local translate function
//Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param);
}

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->libdir.'/weblib.php');
@ -23,12 +44,12 @@ if($teachermode){
$PAGE->set_heading(get_string('report_invited', 'local_treestudyplan', "{$USER->firstname} {$USER->lastname}"));
}
// Load javascripts and specific css
// Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$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') {
print get_string($str, $plugin, $param);
}

View File

@ -1,168 +0,0 @@
<?php
// 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');
require_once($CFG->dirroot.'/cohort/lib.php');
require_once($CFG->dirroot.'/cohort/locallib.php');
require_once("lib.php");
use local_treestudyplan;
//admin_externalpage_setup('major');
$systemcontext = context_system::instance();
require_login();
require_capability('local/treestudyplan:viewothercards',$systemcontext);
$PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext);
$PAGE->set_title(get_string('report_index','local_treestudyplan'));
$PAGE->set_heading(get_string('report_index','local_treestudyplan'));
// Load javascripts
//$PAGE->requires->js_call_amd('local_treestudyplan/fixlinks', 'init', ['div.tab-content']);
$PAGE->requires->js_call_amd('block_gradelevel/renderbadge', 'init');
$PAGE->requires->js_call_amd('local_treestudyplan/report', 'init');
//$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/eqstyles.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-toggle.min.css'));
$userid = null;
$studentid = optional_param('studentid', '', PARAM_INT);
$cohortid = optional_param('cohortid', '', PARAM_INT);
if(!empty($studentid)){
$PAGE->set_url("/local/treestudyplan/reports.php",array('studentid' => $studentid));
$student = $DB->get_record("user",['id' => $studentid]);
$userlist = [];
$nextstudent = null;
$prevstudent = null;
if(!empty($cohortid))
{
$cohort = $DB->get_record("cohort",['id' => $cohortid]);
$userlist = array_values(local_treestudyplan_find_cohortmembers($cohortid));
for($i = 0; $i < count($userlist); $i++)
{
if($userlist[$i]->userid == $studentid)
{
if($i > 0)
{
$prevstudent = (object)['id' => $userlist[$i - 1]->userid, 'name' => "{$userlist[$i - 1]->firstname} {$userlist[$i - 1]->lastname}"];
}
if($i < count($userlist) - 1)
{
$nextstudent = (object)['id' => $userlist[$i + 1]->userid, 'name' => "{$userlist[$i + 1]->firstname} {$userlist[$i + 1]->lastname}"];
}
break;
}
}
$cohortpath = local_treestudyplan_get_cohort_path($cohort);
$PAGE->set_title(get_string('report_invited','local_treestudyplan',"{$cohortpath}: {$student->firstname} {$student->lastname}"));
$PAGE->set_heading(get_string('report_invited','local_treestudyplan',"{$cohortpath}: {$student->firstname} {$student->lastname}"));
}
else
{
$PAGE->set_title(get_string('report_invited','local_treestudyplan',"$cohort->{$student->firstname} {$student->lastname}"));
$PAGE->set_heading(get_string('report_invited','local_treestudyplan',"{$student->firstname} {$student->lastname}"));
}
$gradewriter = new local_treestudyplan_cardwriter($studentid,true);
$badgewriter = new local_treestudyplan_badgewriter($studentid);
$calendarwriter = new local_treestudyplan_calendarwriter($studentid);
print $OUTPUT->header();
print "<div class='m-buttonbar' style='margin-bottom: 1.5em; height: 1em;'>";
if(isset($prevstudent))
{
print "<a style='float:left;' href='/local/treestudyplan/reports.php?studentid={$prevstudent->id}&cohortid={$cohortid}'><i class='fa fa-arrow-left'></i> {$prevstudent->name} </a>";
}
if(isset($nextstudent))
{
print "<a style='float:right;' href='/local/treestudyplan/reports.php?studentid={$nextstudent->id}&cohortid={$cohortid}'>{$nextstudent->name} <i class='fa fa-arrow-right'></i></a>";
}
print "</div>";
print "<ul class='nav nav-tabs' role='tablist'>";
print "<li class='nav-item'><a class='nav-link active' href='#link-report' data-toggle='tab' role='tab'>".get_string('nav_report','local_treestudyplan')."</a></li>";
print "<li class='nav-item'><a class='nav-link ' href='#link-badges' data-toggle='tab' role='tab'>".get_string('nav_badges','local_treestudyplan')."</a></li>";
print "<li class='nav-item'><a class='nav-link ' href='#link-calendar' data-toggle='tab' role='tab'>".get_string('nav_calendar','local_treestudyplan')."</a></li>";
print "</ul>";
print "<div class='tab-content mt-3'>";
print "<div class='tab-pane active' id='link-report' data-toggle='tab' role='tab'>";
print $gradewriter->render(true,false);
print "</div>";
print "<div class='tab-pane ' id='link-badges' data-toggle='tab' role='tab'>";
print $badgewriter->render();
print "</div>";
print "<div class='tab-pane' id='link-calendar' data-toggle='tab' role='tab'>";
print $calendarwriter->render();
print "</div>";
print "</div>";
print $OUTPUT->footer();
}
else {
$PAGE->set_url("/local/treestudyplan/reports.php",array());
// show student picker
$cohortlist = $DB->get_records("cohort");
$cohorts = [];
foreach($cohortlist as $c)
{
if($c->visible)
{
$cohortcontext = context::instance_by_id($c->contextid);
if($cohortcontext) // TODO: add check if user has rights in this context
{
$users = local_treestudyplan_find_cohortmembers($c->id);
$cohorts[$c->id] = (object)[
'id' => $c->id,
'cohort' => $c,
'name' => $c->name,
'path' => local_treestudyplan_get_cohort_path($c),
'users' => $users,
];
}
}
}
print $OUTPUT->header();
usort($cohorts,function($a,$b){
return $a->path <=> $b->path;
});
$regex = get_config('local_treestudyplan', 'cohortidregex');
foreach($cohorts as $c)
{
$m = [];
if(preg_match("/".$regex."/",$c->cohort->idnumber,$m) && $c->cohort->visible)
{
print "<legend class='collapse-header'><a data-toggle='collapse' class='collapsed' href='#cohort-{$c->id}' role='button'>{$c->path}</a></legend>";
print "<div id='cohort-{$c->id}' class='collapse'>";
print "<div class='card card-body'><ul class='gradecardlist'>";
foreach($c->users as $u)
{
print "<li class='gradestudent'>";
print "<a href='/local/treestudyplan/reports.php?studentid={$u->userid}&cohortid={$c->id}'>{$u->firstname} {$u->lastname}</a>";
print "</li>";
}
print "</ul>";
print "</div></div>";
}
}
print "</div>";
print $OUTPUT->footer();
}

View File

@ -1,17 +1,17 @@
<?php
// This file is part of Moodle - http://moodle.org/
// This file is part of Moodle - http://moodle.org/.
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// Moodle is free software: you can redistribute it and/or modify.
// it under the terms of the GNU General Public License as published by.
// the Free Software Foundation, either version 3 of the License, or.
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Moodle is distributed in the hope that it will be useful,.
// but WITHOUT ANY WARRANTY; without even the implied warranty of.
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the.
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// You should have received a copy of the GNU General Public License.
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
@ -19,7 +19,7 @@
*
* @package local_chronotable
* @copyright 2017 Alexander Bias, Ulm University <alexander.bias@uni-ulm.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
defined('MOODLE_INTERNAL') || die();
@ -43,7 +43,7 @@ if ($hassiteconfig) {
get_string('settingspage', 'local_treestudyplan', null, true));
// GOAL AGGREGATION SETTINGS
// GOAL AGGREGATION SETTINGS.
$page->add(new admin_setting_heading('local_treestudyplan/aggregation_heading',
get_string('setting_aggregation_heading', 'local_treestudyplan'),
get_string('settingdesc_aggregation_heading', 'local_treestudyplan')
@ -61,7 +61,7 @@ if ($hassiteconfig) {
$aggregators
));
// DISPLAY COURSE INFO SETTINGS
// DISPLAY COURSE INFO SETTINGS.
$page->add(new admin_setting_heading('local_treestudyplan/display_heading',
get_string('setting_display_heading', 'local_treestudyplan'),
get_string('settingdesc_display_heading', 'local_treestudyplan')
@ -86,7 +86,7 @@ if ($hassiteconfig) {
$displayfields
));
// BISTATE AGGREGATON DEFAULTS
// BISTATE AGGREGATON DEFAULTS.
$page->add(new admin_setting_heading('local_treestudyplan/bistate_aggregation_heading',
get_string('setting_bistate_heading', 'local_treestudyplan'),
get_string('settingdesc_bistate_heading', 'local_treestudyplan')
@ -150,48 +150,48 @@ if ($hassiteconfig) {
get_string('settingspage_csync', 'local_treestudyplan', null, true));
// Description heading
// Description heading.
$page_csync->add(new admin_setting_heading('local_treestudyplan/csync_heading',
get_string('setting_csync_heading', 'local_treestudyplan'),
get_string('settingdesc_csync_heading', 'local_treestudyplan')
));
// Enable/disable cohort sync
// Enable/disable cohort sync.
$page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_enable',
get_string('setting_csync_enable_field', 'local_treestudyplan'),
get_string('settingdesc_csync_enable_field', 'local_treestudyplan'),
false
));
// Enable/disable autoremove
// Enable/disable autoremove.
$page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_autoremove',
get_string('setting_csync_autoremove_field', 'local_treestudyplan'),
get_string('settingdesc_csync_autoremove_field', 'local_treestudyplan'),
true
));
// Enable/disable remembering previously added cohort syncs so they're not automatically deleted
// Enable/disable remembering previously added cohort syncs so they're not automatically deleted.
$page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_remember_manual_csync',
get_string('setting_csync_remember_manual_csync_field', 'local_treestudyplan'),
get_string('settingdesc_csync_remember_manual_csync_field', 'local_treestudyplan'),
true
));
// Enable/disable group creation
// Enable/disable group creation.
$page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_creategroup',
get_string('setting_csync_creategroup_field', 'local_treestudyplan'),
get_string('settingdesc_csync_creategroup_field', 'local_treestudyplan'),
true
));
// Sync users too yes/no?
// Sync users too yes/no?.
$page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_users',
get_string('setting_csync_users_field', 'local_treestudyplan'),
get_string('settingdesc_csync_users_field', 'local_treestudyplan'),
true
));
// Select csync enrol role
// Select csync enrol role.
if (!during_initial_install()) {
$options = get_default_enrol_roles(context_system::instance());
$student = get_archetype_roles('student');

View File

@ -1,182 +0,0 @@
<?php
namespace local_treestudyplan;
use \local_treestudyplan\local\aggregators\bistate_aggregator;
class bistate_aggregator_test extends \basic_testcase {
private function goalaggregation_test($configstr, $outcome, $completions,$required){
$ag = new bistate_aggregator($configstr);
// test aggregation with the required data
$result = $ag->aggregate_binary_goals($completions,$required);
// assert if the test is succesful
$this->assertEquals(completion::label($outcome),completion::label($result));
}
private function junctionaggregation_test($configstr, $outcome, $completions){
$ag = new bistate_aggregator($configstr);
// test aggregation with the minimum required data
$result = $ag->aggregate_junction($completions);
// assert if the test is succesful
$this->assertEquals(completion::label($outcome),completion::label($result));
}
public function test_goalaggregation_0() {
$this->goalaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::INCOMPLETE,
[
],
[],
);
}
public function test_goalaggregation_1() {
$this->goalaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::FAILED,
[ // completions
completion::FAILED,
completion::FAILED,
completion::FAILED,
completion::FAILED,
completion::FAILED,
],
[] // required
);
}
public function test_goalaggregation_2() {
$this->goalaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::EXCELLENT,
[
completion::COMPLETED,
completion::COMPLETED,
completion::COMPLETED,
completion::COMPLETED,
completion::COMPLETED,
],
[],
);
}
public function test_goalaggregation_3() {
$this->goalaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::INCOMPLETE,
[
completion::INCOMPLETE,
completion::INCOMPLETE,
completion::INCOMPLETE,
completion::INCOMPLETE,
completion::INCOMPLETE,
],
[],
);
}
public function test_goalaggregation_4() {
$this->goalaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::PROGRESS,
[
completion::COMPLETED,
completion::COMPLETED,
completion::COMPLETED,
completion::PROGRESS,
completion::PROGRESS,
],
[],
);
}
public function test_goalaggregation_5() {
$this->goalaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::COMPLETED,
[
completion::COMPLETED,
completion::COMPLETED,
completion::COMPLETED,
completion::COMPLETED,
completion::PROGRESS,
],
[],
);
}
public function test_goalaggregation_6() {
$this->goalaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::PROGRESS,
[
completion::PROGRESS,
completion::PROGRESS,
completion::PROGRESS,
completion::PROGRESS,
completion::INCOMPLETE,
completion::INCOMPLETE,
],
[],
);
}
public function test_junctionaggregation_0() {
$this->junctionaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::FAILED,
[
completion::FAILED,
completion::FAILED,
completion::FAILED,
completion::FAILED,
],
);
}
public function test_junctionaggregation_1() {
$this->junctionaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::INCOMPLETE,
[
completion::INCOMPLETE,
completion::INCOMPLETE,
completion::INCOMPLETE,
completion::INCOMPLETE,
],
);
}
public function test_junctionaggregation_2() {
$this->junctionaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::FAILED,
[
completion::FAILED,
completion::INCOMPLETE,
completion::INCOMPLETE,
completion::INCOMPLETE,
],
);
}
public function test_junctionaggregation_3() {
$this->junctionaggregation_test(
'{"thresh_excellent":100,"thresh_good":85,"thresh_completed":66,"thresh_progress":25,"use_failed":true,"accept_pending_as_submitted":true}',
completion::PROGRESS,
[
completion::PROGRESS,
completion::INCOMPLETE,
completion::INCOMPLETE,
completion::INCOMPLETE,
],
);
}
}

View File

@ -1,7 +1,29 @@
<?php
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494)
$plugin->version = 2023082101; // YYYYMMDDHH (year, month, day, iteration)
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11)
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
$plugin->version = 2023082101; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->dependencies = [
'theme_boost' => 2019052000,

View File

@ -1,4 +1,25 @@
<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
*
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
use \local_treestudyplan\courseservice;
@ -10,15 +31,14 @@ $systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/view-plan.php", array());
require_login();
// Figure out the context (category or system, based on either category or context parameter)
$categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id
$contextid = optional_param('contextid', 0, PARAM_INT); // Context id
// Figure out the context (category or system, based on either category or context parameter).
$categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id.
$contextid = optional_param('contextid', 0, PARAM_INT); // Context id.
if ($categoryid > 0) {
$studyplancontext = context_coursecat::instance($categoryid);
}
elseif($contextid > 0)
{
else if ($contextid > 0) {
$studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT]))
{
@ -31,16 +51,16 @@ elseif($contextid > 0)
}
else
{
// If no context is selected, find the first available one
// If no context is selected, find the first available one.
$available_contexts = courseservice::list_accessible_categories_with_usage("view");
$contextid=1; // fallback to system context
$contextid=1; // fallback to system context.
foreach ($available_contexts as $ctx) {
if ($ctx->count > 0) {
$contextid = $ctx->ctxid;
break;
}
}
// reload page with selected category
// reload page with selected category.
$url = new \moodle_url('/local/treestudyplan/view-plan.php', ["contextid" => $contextid]);
header('Location: '.$url->out(false), true, 302);
exit;
@ -59,12 +79,12 @@ if($studyplancontext->id > 1){
$PAGE->navbar->add(get_string('view_plan', 'local_treestudyplan'));
}
// Load javascripts and specific css
// Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$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') {
print get_string($str, $plugin, $param);
}