Commit of first prototype code
This commit is contained in:
parent
029f3b6179
commit
4c777db678
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"intelephense.environment.includePaths": [
|
||||
"/srv/moodle4/moodle"
|
||||
]
|
||||
}
|
213
classes/profilefhelper.php
Normal file
213
classes/profilefhelper.php
Normal file
|
@ -0,0 +1,213 @@
|
|||
<?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/>.
|
||||
/**
|
||||
* Helper functions for web services
|
||||
* @package tool_sptoolboxmgr
|
||||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_sptoolboxmgr;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||
use \local_treestudyplan\studyplan;
|
||||
use \ValueError;
|
||||
use \stdClass;
|
||||
|
||||
/**
|
||||
* Class containing helper functions and abstraction for getting profile field information
|
||||
*/
|
||||
class profilehelper {
|
||||
static $enrollable_userids = null;
|
||||
|
||||
public static function get_enrol_values() {
|
||||
$vals = [];
|
||||
$text = get_config("tool_sptoolboxmgr","enrolvalue");
|
||||
if(strlen(trim($text)) > 0) {
|
||||
foreach ( explode("|",$text) as $v) {
|
||||
$vals[] = trim($v);
|
||||
}
|
||||
}
|
||||
return $vals;
|
||||
}
|
||||
|
||||
public static function get_userfield($id,$userid) {
|
||||
global $DB;
|
||||
$field = $DB->get_record("user_info_field",["id" => $id]);
|
||||
if ($field) {
|
||||
$userfield = profile_get_user_field($field->datatype,$id,$userid);
|
||||
return $userfield;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function enrollable_user_ids() {
|
||||
global $DB;
|
||||
if (!isset($enrollable_userids)) {
|
||||
$enrollablefield = get_config("tool_sptoolboxmgr","enrolfield");
|
||||
$enrollablevalues = self::get_enrol_values();
|
||||
[$insql, $inparams] = $DB->get_in_or_equal($enrollablevalues);
|
||||
$inparams["fieldid"] = $enrollablefield;
|
||||
$sqlwhere = "fieldid = :fieldid AND data {$insql}";
|
||||
self::$enrollable_userids = $DB->get_fieldset_select("user_info_data","userid",$sqlwhere,$inparams);
|
||||
}
|
||||
return self::$enrollable_userids;
|
||||
}
|
||||
|
||||
public static function previously_enrollable_user_ids() {
|
||||
global $DB;
|
||||
$enrollable_ids = self::enrollable_user_ids();
|
||||
[$insql, $inparams] = $DB->get_in_or_equal($enrollable_ids);
|
||||
|
||||
$sqlwhere = "enrolled = 1 AND userid NOT {$insql}";
|
||||
$userids = $DB->get_fieldset_select("tool_sptoolbox","userid",$sqlwhere,$inparams);
|
||||
return $userids;
|
||||
}
|
||||
|
||||
public static function get_coach_userid($userid) {
|
||||
global $DB;
|
||||
$coachfieldid = get_config("tool_sptoolboxmgr","coachfield");
|
||||
|
||||
$coachfield = self::get_userfield($coachfieldid,$userid);
|
||||
if (! $coachfield) {
|
||||
throw new ValueError("Coach field not set for this user");
|
||||
}
|
||||
$coachidentifier = trim($coachfield->data);
|
||||
|
||||
// First search coach by username.
|
||||
$coach = $DB->get_record("user",["userid" => $coachidentifier]);
|
||||
if (! $coach) {
|
||||
// Next search coach by email.
|
||||
$coach = $DB->get_record("user",["email" => $coachidentifier]);
|
||||
|
||||
if (! $coach) {
|
||||
// Next search coach by idnumber.
|
||||
$coach = $DB->get_record("user",["idnumber" => $coachidentifier]);
|
||||
}
|
||||
|
||||
}
|
||||
if ($coach) {
|
||||
return $coach->id;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_track_identifier($userid) {
|
||||
$trackfieldid = get_config("tool_sptoolboxmgr","trackfield");
|
||||
|
||||
$trackfield = self::get_userfield($trackfieldid,$userid);
|
||||
if (! $trackfield) {
|
||||
throw new ValueError("Track field not set for this user");
|
||||
}
|
||||
$value = trim($trackfield->data);
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function get_track_plan($track_identifier) : studyplan {
|
||||
$mapping = get_config("tool_sptoolboxmgr","trackmapping");
|
||||
if ($mapping == "shortname") {
|
||||
$plans = studyplan::find_by_shortname($track_identifier);
|
||||
} elseif ($mapping == "idnumber") {
|
||||
$plans = studyplan::find_by_idnumber($track_identifier);
|
||||
} elseif ($mapping == "name") {
|
||||
$plans = studyplan::find_by_fullname($track_identifier);
|
||||
}
|
||||
|
||||
// Return the first match
|
||||
if (count($plans) > 0) {
|
||||
return $plans[0];
|
||||
} else {
|
||||
throw new ValueError("Toolbox not found by mapping '{$mapping}': '$track_identifier'");
|
||||
}
|
||||
}
|
||||
|
||||
public static function register_changes($userid,$toolbox = null) {
|
||||
global $DB;
|
||||
|
||||
$createnew = false;
|
||||
$field = $DB->get_record("tool_sptoolboxmgr",["userid" => $userid]);
|
||||
if (! $field) {
|
||||
$createnew = true;
|
||||
$field = new \stdClass;
|
||||
$field->userid = $userid;
|
||||
}
|
||||
|
||||
$field->enrolled = in_array($userid,self::enrollable_user_ids())?1:0;
|
||||
$field->track = self::get_track_identifier($userid);
|
||||
$field->coach = self::get_coach_userid($userid);
|
||||
|
||||
if (isset($toolbox)) {
|
||||
$field->toolboxid = $toolbox->id();
|
||||
}
|
||||
|
||||
if ($createnew) {
|
||||
$DB->insert_record("tool_sptoolboxmgr",$field);
|
||||
} else {
|
||||
$DB->update_record("tool_sptoolboxmgr",$field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function check_changes($userid) {
|
||||
global $DB;
|
||||
|
||||
$o = new \stdClass;
|
||||
$o->changed = false;
|
||||
$o->validfields = true;
|
||||
$o->enrolchanged = false;
|
||||
$o->trackchanged = false;
|
||||
$o->coachchanged = false;
|
||||
$o->toolbox = null;
|
||||
|
||||
$o->track = self::get_track_identifier($userid);
|
||||
$o->coach = self::get_coach_userid($userid);
|
||||
$o->enrolled = in_array($userid,self::enrollable_user_ids())?1:0;
|
||||
|
||||
|
||||
$field = $DB->get_record("tool_sptoolboxmgr",["userid" => $userid]);
|
||||
if ($field ) {
|
||||
if ($field->enrolled != $o->enrolled) {
|
||||
$o->enrolchanged = true;
|
||||
$o->changed = true;
|
||||
}
|
||||
if ($field->track != $o->track) {
|
||||
$o->trackchanged = true;
|
||||
$o->changed = true;
|
||||
}
|
||||
if ($field->coach != $o->coach) {
|
||||
$o->coachchanged = true;
|
||||
$o->changed = true;
|
||||
}
|
||||
if ($field->toolboxid) {
|
||||
$o->toolbox = studyplan::find_by_id(($field->toolboxid));
|
||||
}
|
||||
|
||||
} else {
|
||||
$o->changed = true;
|
||||
$o->enrolchanged = true;
|
||||
$o->trackchanged = true;
|
||||
$o->coachchanged = true;
|
||||
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
}
|
173
classes/task/profilescannertask.php
Normal file
173
classes/task/profilescannertask.php
Normal file
|
@ -0,0 +1,173 @@
|
|||
<?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/>.
|
||||
/**
|
||||
* Background task to refresh the list of associaded teachers with studyplans
|
||||
* @package tool_sptoolboxmgr
|
||||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_sptoolboxmgr\task;
|
||||
|
||||
use local_treestudyplan\associationservice;
|
||||
use tool_sptoolboxmgr\profilehelper;
|
||||
use \mtrace;
|
||||
use \mtrace_exception;
|
||||
use \ValueError;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||
|
||||
/**
|
||||
* Background task to process changes in
|
||||
*/
|
||||
class profilescannertask extends \core\task\scheduled_task {
|
||||
|
||||
/**
|
||||
* Return the task's name as shown in admin screens.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return get_string('profilescannertask', 'tool_sptoolboxmgr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the task.
|
||||
*/
|
||||
public function execute() {
|
||||
global $DB;
|
||||
// We need to test for changes in the profile fields...
|
||||
|
||||
// First check the userids eligable for enrolment
|
||||
$enrollable = profilehelper::enrollable_user_ids();
|
||||
|
||||
// Next, check each of these fields for changes
|
||||
mtrace("Checking ".count($enrollable)." enrollable uids for changes ....");
|
||||
foreach ($enrollable as $uid) {
|
||||
$user = $DB->get_record("user",["id"=>$uid]);
|
||||
try {
|
||||
$changes = profilehelper::check_changes($uid);
|
||||
mtrace("Checking user {$user->username}... ".(($changes->changed)?"Has changes":"No changes"));
|
||||
|
||||
/**
|
||||
* @var studyplan
|
||||
*/
|
||||
$toolbox = null;
|
||||
if ($changes->trackchanged) {
|
||||
if ($changes->toolbox) {
|
||||
mtrace(" User changed track - removing coaches from old toolbox '{$changes->toolbox->name()}' ");
|
||||
// Remove coach from old toolbox.
|
||||
$coaches = associationservice::associated_coaches($changes->toolbox->id());
|
||||
foreach ($coaches as $coach) {
|
||||
$coach = (object)$coach; // Convert from array to object.
|
||||
associationservice::disconnect_coach($changes->toolbox->id(),$coach->id);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Create new toolbox based on new track and add coach.
|
||||
$template = profilehelper::get_track_plan($changes->track);
|
||||
|
||||
mtrace(" Created new toolbox");
|
||||
$toolbox = $template->duplicate(
|
||||
"{$user->firstname} {$user->lastname} - {$template->name()}",
|
||||
"{$user->username}-{$template->shortname()}",
|
||||
$template->context()->id,
|
||||
null,
|
||||
null
|
||||
);
|
||||
mtrace(" Creating new toolbox - Created {$toolbox->id()} - {$toolbox->name()}");
|
||||
|
||||
// Add user to toolbox.
|
||||
associationservice::connect_user($toolbox->id(),$uid);
|
||||
mtrace(" Creating new toolbox - Added user '{$user->username}' to toolbox");
|
||||
// Add new coach to toolbox.
|
||||
$coach = $DB->get_record("user", ["id"=> $changes->coach]);
|
||||
mtrace(" Creating new toolbox - adding coach '{$coach->username}' to toolbox");
|
||||
associationservice::connect_coach($toolbox->id(), $changes->coach);
|
||||
} catch (ValueError $x) {
|
||||
mtrace("Cannot find track template '{$changes->track}' for user '{$user->username}'");
|
||||
mtrace_exception($x);
|
||||
}
|
||||
} elseif ($changes->coachchanged || $changes->enrolchanged) {
|
||||
if ($changes->toolbox) { // If there is an associated toolbox. Otherwise, it should have been created above.
|
||||
$toolbox = $changes->toolbox;
|
||||
|
||||
if ($changes->coachchanged) {
|
||||
// Remove coach from old toolbox.
|
||||
$coaches = associationservice::associated_coaches($changes->toolbox->id());
|
||||
foreach ($coaches as $coach) {
|
||||
$coach = (object)$coach; // Convert from array to object.
|
||||
mtrace(" Coach changed - removing coach {$coach->username} from toolbox");
|
||||
associationservice::disconnect_coach($changes->toolbox->id(),$coach->id);
|
||||
}
|
||||
}
|
||||
// Add new coach to toolbox.
|
||||
$coach = $DB->get_record("user", ["id"=> $changes->coach]);
|
||||
mtrace(" Coach or enrol changed - (re)adding coach {$coach->username} to toolbox");
|
||||
associationservice::connect_coach($toolbox->id(), $changes->coach);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
mtrace("Registering new status");
|
||||
profilehelper::register_changes($uid,$toolbox);
|
||||
|
||||
} catch (\ValueError $x) {
|
||||
// This is thrown if any of the fields are invalid.
|
||||
|
||||
mtrace("Error retrieving fields for user {$user->username}");
|
||||
mtrace_exception($x);
|
||||
}
|
||||
}
|
||||
|
||||
// Next process the previously enrollable uids
|
||||
$prevenrollable = profilehelper::previously_enrollable_user_ids();
|
||||
|
||||
// Next, check each of these fields for changes
|
||||
mtrace("Processing ".count($prevenrollable)." previously enrollable uids for the change in enrollability");
|
||||
foreach ($enrollable as $uid) {
|
||||
try {
|
||||
$changes = profilehelper::check_changes($uid);
|
||||
mtrace("Checking user {$user->username}... ".(($changes->changed)?"Has changes":"No changes"));
|
||||
// There should be changes in the enrol now, since all of these uids are no longer eligable for an active toolbox.
|
||||
// Do not remove the old toolbox, but do remove the coach access - if
|
||||
if ($changes->enrolchanged) {
|
||||
// Remove coach from old toolbox.
|
||||
$coaches = associationservice::associated_coaches($changes->toolbox->id());
|
||||
foreach ($coaches as $coach) {
|
||||
$coach = (object)$coach; // Convert from array to object.
|
||||
mtrace(" User enrol changed - removing coach {$coach->username} from toolbox");
|
||||
associationservice::disconnect_coach($changes->toolbox->id(),$coach->id);
|
||||
}
|
||||
}
|
||||
|
||||
mtrace("Registering new status");
|
||||
profilehelper::register_changes($uid,$changes->toolbox);
|
||||
|
||||
} catch (\ValueError $x) {
|
||||
// This is thrown if any of the fields are invalid.
|
||||
|
||||
mtrace("Error retrieving fields for user {$user->username}");
|
||||
mtrace_exception($x);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
71
classes/task/updatetrackfieldtask.php
Normal file
71
classes/task/updatetrackfieldtask.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?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/>.
|
||||
/**
|
||||
* Background task to refresh the list of associaded teachers with studyplans
|
||||
* @package tool_sptoolboxmgr
|
||||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_sptoolboxmgr\task;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||
use \local_treestudyplan\studyplan;
|
||||
/**
|
||||
* Background task to process changes in
|
||||
*/
|
||||
class updatetrackfieldtask extends \core\task\scheduled_task {
|
||||
|
||||
/**
|
||||
* Return the task's name as shown in admin screens.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return get_string('updatetrackfieldtask', 'tool_sptoolboxmgr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the task.
|
||||
*/
|
||||
public function execute() {
|
||||
global $DB;
|
||||
if (get_config("tool_sptoolboxmgr","trackautofill")) {
|
||||
$fieldid = get_config("tool_sptoolboxmgr","trackfield");
|
||||
if ($fieldid > 0) {
|
||||
$field = $DB->get_record("user_info_field",["id" => $fieldid]);
|
||||
if ( $field && $field->datatype == "menu") {
|
||||
$names = [];
|
||||
$templates = studyplan::find_template();
|
||||
$mapping = get_config("tool_sptoolboxmgr","trackmapping");
|
||||
foreach ($templates as $s) {
|
||||
if ($mapping == "shortname") {
|
||||
$names[] = $s->shortname();
|
||||
} elseif ($mapping == "idnumber") {
|
||||
$names[] = $s->idnumber();
|
||||
} elseif ($mapping == "name") {
|
||||
$names[] = $s->name();
|
||||
}
|
||||
}
|
||||
|
||||
$field->param1 = implode("\n",$names);
|
||||
$DB->update_record("user_info_field",$field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Permission descriptions
|
||||
* @package block_mytreestudyplan
|
||||
* @package tool_sptoolboxmgr
|
||||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
|
21
db/install.xml
Normal file
21
db/install.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="admin/tool/sptoolboxmgr/db" VERSION="20240512" COMMENT="XMLDB file for Moodle admin/tool/sptoolboxmgr"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
<TABLES>
|
||||
<TABLE NAME="tool_sptoolboxmgr" COMMENT="Default comment for tool_sptoolboxmgr, please edit me">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="12" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="enrolled" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="track" TYPE="char" LENGTH="250" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="coach" TYPE="int" LENGTH="12" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="toolboxid" TYPE="int" LENGTH="12" NOTNULL="false" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
45
db/tasks.php
Normal file
45
db/tasks.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?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/>.
|
||||
/**
|
||||
* Background task register
|
||||
* @package tool_sptoolboxmgr
|
||||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$tasks = [
|
||||
[
|
||||
'classname' => 'tool_sptoolboxmgr\task\updatetrackfieldtask',
|
||||
'blocking' => 0,
|
||||
'minute' => '*',
|
||||
'hour' => '*',
|
||||
'day' => '*',
|
||||
'month' => '*',
|
||||
'dayofweek' => '*',
|
||||
],
|
||||
[
|
||||
'classname' => 'tool_sptoolboxmgr\task\profilescannertask',
|
||||
'blocking' => 0,
|
||||
'minute' => '*/5',
|
||||
'hour' => '*',
|
||||
'day' => '*',
|
||||
'month' => '*',
|
||||
'dayofweek' => '*',
|
||||
],
|
||||
|
||||
|
||||
];
|
87
db/upgrade.php
Normal file
87
db/upgrade.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?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/>.
|
||||
/**
|
||||
* Database upgrade script
|
||||
* @package local_treestudyplan
|
||||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Hook to upgrade database upon plugin upgrade
|
||||
* @param mixed $oldversion Version of plugin database before upgrade
|
||||
* @return bool Upgrade success status
|
||||
*
|
||||
*/
|
||||
function xmldb_tool_sptoolboxmgr_upgrade($oldversion) {
|
||||
global $DB;
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2024051201) {
|
||||
|
||||
// Define table tool_sptoolboxmgr to be created.
|
||||
$table = new xmldb_table('tool_sptoolboxmgr');
|
||||
|
||||
// Adding fields to table tool_sptoolboxmgr.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '12', null, null, null, null);
|
||||
$table->add_field('enrolled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('track', XMLDB_TYPE_CHAR, '250', null, null, null, null);
|
||||
|
||||
// Adding keys to table tool_sptoolboxmgr.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
|
||||
// Conditionally launch create table for tool_sptoolboxmgr.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Sptoolboxmgr savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2024051201, 'tool', 'sptoolboxmgr');
|
||||
}
|
||||
|
||||
if ($oldversion < 2024051202) {
|
||||
|
||||
// Define field coach to be added to tool_sptoolboxmgr.
|
||||
$table = new xmldb_table('tool_sptoolboxmgr');
|
||||
$field = new xmldb_field('coach', XMLDB_TYPE_INTEGER, '12', null, null, null, null, 'track');
|
||||
|
||||
// Conditionally launch add field coach.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Sptoolboxmgr savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2024051202, 'tool', 'sptoolboxmgr');
|
||||
}
|
||||
|
||||
if ($oldversion < 2024051203) {
|
||||
|
||||
// Define field toolboxid to be added to tool_sptoolboxmgr.
|
||||
$table = new xmldb_table('tool_sptoolboxmgr');
|
||||
$field = new xmldb_field('toolboxid', XMLDB_TYPE_INTEGER, '12', null, null, null, null, 'coach');
|
||||
|
||||
// Conditionally launch add field toolboxid.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Sptoolboxmgr savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2024051203, 'tool', 'sptoolboxmgr');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -20,6 +20,24 @@
|
|||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['pluginname'] = 'ToolboxManager (Studyplan)';
|
||||
$string['toolboxmanager'] = 'ToolboxManager';
|
||||
$string['pluginname'] = 'Toolbox manager (Studyplan)';
|
||||
$string['toolboxmanager'] = 'Toolbox manager';
|
||||
|
||||
$string['updatetrackfieldtask'] = 'Toolbox manager trajectveld updater';
|
||||
$string['profilescannertask'] = 'Toolbox manager profile scanner';
|
||||
|
||||
$string['settingspage'] = 'Toolboxmanager instellingen';
|
||||
$string['setting_enrolfield'] = 'Profielveld om inschrijving op te baseren.';
|
||||
$string['settingdesc_enrolfield'] = 'Op basis van dit profielveld wordt gekeken of een gebruiker op een toolbox moet worden ingeschreven.';
|
||||
$string['setting_enrolvalue'] = 'Waarden waarbij gebruiker op toolbox wordt ingeschreven.';
|
||||
$string['settingdesc_enrolvalue'] = 'Voer hier de waarden van het profielveld in waarbij een toolbox wordt aangemaakt (meerdere waarden scheiden met een | teken). <b>Let op: De tekst is hoofdlettergevoelig</b>';
|
||||
$string['setting_trackfield'] = 'Profielveld voor trajectkeuze.';
|
||||
$string['settingdesc_trackfield'] = 'Op basis van dit profielveld wordt bepaald welk sjabloon moet worden gebruikt.';
|
||||
$string['setting_trackmapping'] = 'Koppelveld traject met toolbox.';
|
||||
$string['settingdesc_trackmapping'] = 'Match toolbox met traject op basis van dit toolboxveld.';
|
||||
$string['setting_trackautofill'] = 'Trajectveld automatisch vullen met toolbox templates.';
|
||||
$string['settingdesc_trackautofill'] = 'Vul de opties van het trajectveld automatisch met de velden van alle beschikbare toolbox templates. <br><b>(Let op: Dit werkt alleen als het profielveld een rolmenu is en maakt gebruik van een geplande taak in Moodle.)</b>';
|
||||
$string['setting_coachfield'] = 'Profielveld voor coach';
|
||||
$string['settingdesc_coachfield'] = 'Op basis van de gebruikersnaam, idnummer, of email van een coach die in dit veld is aangegeven wordt een coach gekoppeld.';
|
||||
$string['setting_coachautofill'] = 'Coachveld automatisch vullen met beschikbare coached.';
|
||||
$string['settingdesc_coachautofill'] = 'Vul de opties van het coachveld automatisch met de gebruikersnamen van alle beschikbare coaches. <br><b>(Let op: Dit werkt alleen als het profielveld een rolmenu is en maakt gebruik van een geplande taak in Moodle.)</b>';
|
|
@ -20,6 +20,24 @@
|
|||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['pluginname'] = 'ToolboxBeheer (Studieplan)';
|
||||
$string['toolboxmanager'] = 'ToolboxBeheer';
|
||||
$string['pluginname'] = 'Toolboxmanager (Studieplan)';
|
||||
$string['toolboxmanager'] = 'Toolboxmanager';
|
||||
|
||||
$string['updatetrackfieldtask'] = 'Toolboxmanager trackfield updater';
|
||||
$string['profilescannertask'] = 'Toolboxmanager profile scanner';
|
||||
|
||||
$string['settingspage'] = 'Toolboxmanager instellingen';
|
||||
$string['setting_enrolfield'] = 'Profielveld om inschrijving op te baseren.';
|
||||
$string['settingdesc_enrolfield'] = 'Op basis van dit profielveld wordt gekeken of een gebruiker op een toolbox moet worden ingeschreven.';
|
||||
$string['setting_enrolvalue'] = 'Waarden waarbij gebruiker op toolbox wordt ingeschreven.';
|
||||
$string['settingdesc_enrolvalue'] = 'Voer hier de waarden van het profielveld in waarbij een toolbox wordt aangemaakt (meerdere waarden scheiden met een | teken). <b>Let op: De tekst is hoofdlettergevoelig</b>';
|
||||
$string['setting_trackfield'] = 'Profielveld voor trajectkeuze.';
|
||||
$string['settingdesc_trackfield'] = 'Op basis van dit profielveld wordt bepaald welk sjabloon moet worden gebruikt.';
|
||||
$string['setting_trackmapping'] = 'Koppelveld traject met toolbox.';
|
||||
$string['settingdesc_trackmapping'] = 'Match toolbox met traject op basis van dit toolboxveld.';
|
||||
$string['setting_trackautofill'] = 'Trajectveld automatisch vullen met toolbox templates.';
|
||||
$string['settingdesc_trackautofill'] = 'Vul de opties van het trajectveld automatisch met de velden van alle beschikbare toolbox templates. <br><b>(Let op: Dit werkt alleen als het profielveld een rolmenu is en maakt gebruik van een geplande taak in Moodle.)</b>';
|
||||
$string['setting_coachfield'] = 'Profielveld voor coach';
|
||||
$string['settingdesc_coachfield'] = 'Op basis van de gebruikersnaam, idnummer, of email van een coach die in dit veld is aangegeven wordt een coach gekoppeld.';
|
||||
$string['setting_coachautofill'] = 'Coachveld automatisch vullen met beschikbare coached.';
|
||||
$string['settingdesc_coachautofill'] = 'Vul de opties van het coachveld automatisch met de gebruikersnamen van alle beschikbare coaches. <br><b>(Let op: Dit werkt alleen als het profielveld een rolmenu is en maakt gebruik van een geplande taak in Moodle.)</b>';
|
24
lib.php
24
lib.php
|
@ -19,3 +19,27 @@
|
|||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use \local_treestudyplan\studyplan;
|
||||
use \local_treestudyplan\associationservice;
|
||||
/**
|
||||
* Hook to handle when a user is deleted
|
||||
* @param stdClass $user The user object that will be deleted
|
||||
*/
|
||||
function tool_sptoolboxmgr_pre_user_delete($user) {
|
||||
$userplans = studyplan::find_for_user($user->id);
|
||||
|
||||
foreach ($userplans as $uplan) {
|
||||
$uids = $uplan->find_linked_userids();
|
||||
$directuids = $uplan->get_linked_user_ids();
|
||||
if (count($uids) == 1 && $uids[0] == $user->id) {
|
||||
if(true) {
|
||||
|
||||
}
|
||||
} else {
|
||||
associationservice::disconnect_user($uplan->id(),$user->id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
119
settings.php
119
settings.php
|
@ -1,21 +1,118 @@
|
|||
<?php
|
||||
// This file is part of the Studyplan plugin for Moodle
|
||||
// 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
|
||||
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
|
||||
// You should have received a copy of the GNU General Public License.
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Settings page
|
||||
* Local plugin Settings
|
||||
*
|
||||
* @package tool_sptoolboxmgr
|
||||
* @copyright 2024 P.M. Kuipers
|
||||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
use \local_treestudyplan\debug;
|
||||
|
||||
if ($hassiteconfig) {
|
||||
|
||||
/**************************************
|
||||
*
|
||||
* Main studyplan settings
|
||||
*
|
||||
*************************************/
|
||||
|
||||
// Create admin settings category.
|
||||
$ADMIN->add('courses', new admin_category('tool_sptoolboxmgr',
|
||||
get_string('pluginname', 'tool_sptoolboxmgr', null, true)));
|
||||
|
||||
// Settings page: Root nodes.
|
||||
$page = new admin_settingpage('tool_sptoolboxmgr_settings',
|
||||
get_string('settingspage', 'tool_sptoolboxmgr', null, true));
|
||||
|
||||
|
||||
$categories = array_map('format_string', $DB->get_records_menu('user_info_category', null, 'sortorder ASC', 'id, name'));
|
||||
$profilefields = [ 0 => get_string('none', 'core')];
|
||||
|
||||
foreach ($categories as $catid => $catname) {
|
||||
$catfields = [];
|
||||
if ($fields = $DB->get_records('user_info_field', ['categoryid' => $catid], 'sortorder ASC')) {
|
||||
foreach ($fields as $field) {
|
||||
$fieldname = format_string($field->name);
|
||||
$component = 'profilefield_' . $field->datatype;
|
||||
$classname = "\\$component\\helper";
|
||||
if (class_exists($classname) && method_exists($classname, 'get_fieldname')) {
|
||||
$fieldname = $classname::get_fieldname($field->name);
|
||||
}
|
||||
$profilefields[$field->id] = "{$catname} / {$fieldname}";
|
||||
}
|
||||
}
|
||||
}
|
||||
debug::dump($profilefields);
|
||||
|
||||
$page->add(new admin_setting_configselect('tool_sptoolboxmgr/enrolfield',
|
||||
get_string('setting_enrolfield', 'tool_sptoolboxmgr'),
|
||||
get_string('settingdesc_enrolfield', 'tool_sptoolboxmgr'),
|
||||
0,
|
||||
$profilefields
|
||||
));
|
||||
|
||||
|
||||
$page->add(new admin_setting_configtext('tool_sptoolboxmgr/enrolvalue',
|
||||
get_string('setting_enrolvalue', 'tool_sptoolboxmgr'),
|
||||
get_string('settingdesc_enrolvalue', 'tool_sptoolboxmgr'),
|
||||
"",
|
||||
PARAM_RAW
|
||||
));
|
||||
|
||||
|
||||
$page->add(new admin_setting_configselect('tool_sptoolboxmgr/trackfield',
|
||||
get_string('setting_trackfield', 'tool_sptoolboxmgr'),
|
||||
get_string('settingdesc_trackfield', 'tool_sptoolboxmgr'),
|
||||
0,
|
||||
$profilefields
|
||||
));
|
||||
|
||||
$studyplanfields = ["shortname" => get_string("studyplan_shortname","local_treestudyplan"),
|
||||
"idnumber" => get_string("studyplan_idnumber","local_treestudyplan"),
|
||||
"name" => get_string("studyplan_name","local_treestudyplan"), ];
|
||||
$page->add(new admin_setting_configselect('tool_sptoolboxmgr/trackmapping',
|
||||
get_string('setting_trackmapping', 'tool_sptoolboxmgr'),
|
||||
get_string('settingdesc_trackmapping', 'tool_sptoolboxmgr'),
|
||||
"shortname",
|
||||
$studyplanfields
|
||||
));
|
||||
|
||||
|
||||
$page->add(new admin_setting_configcheckbox('tool_sptoolboxmgr/trackautofill',
|
||||
get_string('setting_trackautofill', 'tool_sptoolboxmgr'),
|
||||
get_string('settingdesc_trackautofill', 'tool_sptoolboxmgr'),
|
||||
false
|
||||
));
|
||||
|
||||
|
||||
|
||||
$page->add(new admin_setting_configselect('tool_sptoolboxmgr/coachfield',
|
||||
get_string('setting_coachfield', 'tool_sptoolboxmgr'),
|
||||
get_string('settingdesc_coachfield', 'tool_sptoolboxmgr'),
|
||||
"",
|
||||
$profilefields
|
||||
));
|
||||
|
||||
|
||||
|
||||
// Add settings page to the admin settings category.
|
||||
$ADMIN->add('tool_sptoolboxmgr', $page);
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'tool_sptoolboxmgr'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
|
||||
$plugin->version = 2024032200; // YYYYMMDDHH (year, month, day, iteration).
|
||||
$plugin->version = 2024051203; // YYYYMMDDHH (year, month, day, iteration).
|
||||
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
|
||||
|
||||
$plugin->release = "1.0.0";
|
||||
|
|
Loading…
Reference in New Issue
Block a user