Moodle code style fixes part 5

This commit is contained in:
PMKuipers 2023-08-25 10:41:56 +02:00
parent e694cefde3
commit 4305438d15
49 changed files with 441 additions and 624 deletions

View File

@ -29,7 +29,6 @@ $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); require_capability('local/treestudyplan:configure', $systemcontext);
$PAGE->requires->js_call_amd('local_treestudyplan/cfg-grades', 'init'); $PAGE->requires->js_call_amd('local_treestudyplan/cfg-grades', 'init');
const GRADECFG_TABLE = "local_treestudyplan_gradecfg"; const GRADECFG_TABLE = "local_treestudyplan_gradecfg";
@ -69,7 +68,6 @@ if ($_POST["action"] == "update") {
$DB->update_record(GRADECFG_TABLE, $scalecfg); $DB->update_record(GRADECFG_TABLE, $scalecfg);
} }
} else { } else {
$scalecfg = (object)[ "scale_id" => $scale->id, ]; $scalecfg = (object)[ "scale_id" => $scale->id, ];
$requireinsert = false; $requireinsert = false;
@ -141,7 +139,6 @@ if ($_POST["action"] == "update") {
} }
// Process all available scales and load the current configuration for it. // Process all available scales and load the current configuration for it.
$data = []; $data = [];
foreach ($scales as $scale) { foreach ($scales as $scale) {
@ -189,7 +186,6 @@ foreach ($scales as $scale) {
$data[] = $row; $data[] = $row;
} }
print html_writer::start_tag("form", ["method" => "post", ]); print html_writer::start_tag("form", ["method" => "post", ]);
print html_writer::tag("input", null, ['name' => "action", 'value' => 'update', 'type' => 'hidden']); print html_writer::tag("input", null, ['name' => "action", 'value' => 'update', 'type' => 'hidden']);
@ -205,24 +201,40 @@ $table->head[] = get_string('min_completed', 'local_treestudyplan');
print $OUTPUT->heading(get_string('cfg_grades_desc_head', 'local_treestudyplan')); print $OUTPUT->heading(get_string('cfg_grades_desc_head', 'local_treestudyplan'));
print html_writer::tag('p', get_string('cfg_grades_desc', 'local_treestudyplan')); print html_writer::tag('p', get_string('cfg_grades_desc', 'local_treestudyplan'));
print $OUTPUT->heading(get_string('cfg_grades_scales', 'local_treestudyplan')); print $OUTPUT->heading(get_string('cfg_grades_scales', 'local_treestudyplan'));
print html_writer::tag('div', html_writer::table($table), ['class'=>'flexible-wrap']); print html_writer::tag('div', html_writer::table($table), ['class' => 'flexible-wrap']);
$data = []; $data = [];
foreach ($gradecfgs as $g) { foreach ($gradecfgs as $g) {
$row = []; $row = [];
$row[] = $g->grade_points; $row[] = $g->grade_points;
$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}_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', ]); $row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_delete", 'type' => 'checkbox', ]);
$data[] = $row; $data[] = $row;
} }
$row = []; $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,
$row[] = html_writer::tag("input", null, ['name' => "g_new_min_completed", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']); [ '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_completed",
'value' => '',
'type' => 'text',
"class" => "float",
'autocomplete' => 'off']);
$data[] = $row; $data[] = $row;
$table = new html_table(); $table = new html_table();
$table->id = ""; $table->id = "";
$table->attributes['class'] = 'generaltable m-roomtable'; $table->attributes['class'] = 'generaltable m-roomtable';
@ -233,9 +245,8 @@ $table->head[] = get_string('grade_points', 'local_treestudyplan');
$table->head[] = get_string('min_completed', 'local_treestudyplan'); $table->head[] = get_string('min_completed', 'local_treestudyplan');
$table->head[] = get_string('delete', ); $table->head[] = get_string('delete', );
print $OUTPUT->heading(get_string('cfg_grades_grades', 'local_treestudyplan')); print $OUTPUT->heading(get_string('cfg_grades_grades', 'local_treestudyplan'));
print html_writer::tag('div', html_writer::table($table), ['class'=>'flexible-wrap']); print html_writer::tag('div', html_writer::table($table), ['class' => 'flexible-wrap']);
print html_writer::tag("input", null, ['value' => get_string("save"), 'type' => 'submit', "class" => "btn btn-primary"]); print html_writer::tag("input", null, ['value' => get_string("save"), 'type' => 'submit', "class" => "btn btn-primary"]);
print html_writer::end_tag("form"); print html_writer::end_tag("form");

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan; namespace local_treestudyplan;
require_once($CFG->libdir.'/externallib.php'); require_once($CFG->libdir.'/externallib.php');
@ -43,9 +42,9 @@ abstract class aggregator {
// 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. // And this is faster than any dynamic method.
return [ return [
"core", # use moodle core completion "core", // Use moodle core completion.
"bistate", "bistate",
"tristate", # deprecated "tristate", // Deprecated.
]; ];
} }
@ -61,8 +60,7 @@ abstract class aggregator {
public static function createOrDefault($mod, $configstr) { public static function createOrDefault($mod, $configstr) {
try { try {
return self::create($mod, $configstr); return self::create($mod, $configstr);
} } catch (\ValueError $x) {
catch(\ValueError $x) {
return self::create(self::FALLBACK, ""); return self::create(self::FALLBACK, "");
} }
} }
@ -71,7 +69,8 @@ abstract class aggregator {
$this->initialize($configstr); $this->initialize($configstr);
} }
protected function initialize($configstr) {} protected function initialize($configstr) {
}
public abstract function needSelectGradables(); public abstract function needSelectGradables();
public abstract function isDeprecated(); public abstract function isDeprecated();
@ -125,7 +124,7 @@ abstract class aggregator {
$list = []; $list = [];
foreach (self::list() as $agid) { 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[] = [ $list[] = [
'id' => $agid, 'id' => $agid,
'name' => get_string("{$agid}_aggregator_title", "local_treestudyplan"), 'name' => get_string("{$agid}_aggregator_title", "local_treestudyplan"),
@ -136,6 +135,4 @@ abstract class aggregator {
return $list; return $list;
} }
} }

View File

@ -26,8 +26,7 @@ use local_treestudyplan\local\helpers\webservicehelper;
require_once($CFG->libdir.'/externallib.php'); require_once($CFG->libdir.'/externallib.php');
class associationservice extends \external_api class associationservice extends \external_api {
{
const CAP_EDIT = "local/treestudyplan:editstudyplan"; const CAP_EDIT = "local/treestudyplan:editstudyplan";
const CAP_VIEW = "local/treestudyplan:viewuserreports"; const CAP_VIEW = "local/treestudyplan:viewuserreports";
@ -96,9 +95,7 @@ class associationservice extends \external_api
} }
public static function list_cohort_parameters() {
public static function list_cohort_parameters()
{
return new \external_function_parameters( [ return new \external_function_parameters( [
'like' => new \external_value(PARAM_TEXT, 'search text', VALUE_OPTIONAL), 'like' => new \external_value(PARAM_TEXT, 'search text', VALUE_OPTIONAL),
'exclude_id' => new \external_value(PARAM_INT, 'exclude members of this studyplan', VALUE_OPTIONAL), 'exclude_id' => new \external_value(PARAM_INT, 'exclude members of this studyplan', VALUE_OPTIONAL),
@ -106,14 +103,12 @@ class associationservice extends \external_api
] ); ] );
} }
public static function list_cohort_returns() public static function list_cohort_returns() {
{
return new \external_multiple_structure(self::cohort_structure()); return new \external_multiple_structure(self::cohort_structure());
} }
// Actual functions. // Actual functions.
public static function list_cohort($like='', $excludeid=null, $contextid=1) public static function list_cohort($like='', $excludeid=null, $contextid=1) {
{
global $CFG, $DB; global $CFG, $DB;
// Only allow this if the user has the right to edit in this context. // Only allow this if the user has the right to edit in this context.
@ -124,13 +119,14 @@ class associationservice extends \external_api
$params = ["pattern_nm" => $pattern, "pattern_id" => $pattern, ]; $params = ["pattern_nm" => $pattern, "pattern_id" => $pattern, ];
$sql = "SELECT c.* from {cohort} c LEFT JOIN {local_treestudyplan_cohort} j ON c.id = j.cohort_id"; $sql = "SELECT c.* from {cohort} c LEFT JOIN {local_treestudyplan_cohort} j ON c.id = j.cohort_id";
$sql .= " WHERE c.visible = 1 AND(name LIKE :pattern_nm OR idnumber LIKE :pattern_id)"; $sql .= " WHERE c.visible = 1 AND(name LIKE :pattern_nm OR idnumber LIKE :pattern_id)";
if (isset($excludeid) && is_numeric($excludeid)) { if (isset($excludeid) && is_numeric($excludeid)) {
$sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)"; $sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)";
$params['exclude_id'] = $excludeid; $params['exclude_id'] = $excludeid;
} }
if ($contextid > 1) { // system context returns all cohorts, including system cohorts. if ($contextid > 1) {
// System context returns all cohorts, including system cohorts.
// Otherwise, . // Otherwise, .
$sql .= " AND contextid = :context_id"; $sql .= " AND contextid = :context_id";
$params['context_id'] = $contextid; $params['context_id'] = $contextid;
@ -145,8 +141,7 @@ class associationservice extends \external_api
return $cohorts; return $cohorts;
} }
public static function find_user_parameters() public static function find_user_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
'like' => new \external_value(PARAM_TEXT, 'search text'), 'like' => new \external_value(PARAM_TEXT, 'search text'),
'exclude_id' => new \external_value(PARAM_INT, 'exclude members of this studyplan', VALUE_OPTIONAL), 'exclude_id' => new \external_value(PARAM_INT, 'exclude members of this studyplan', VALUE_OPTIONAL),
@ -154,14 +149,12 @@ class associationservice extends \external_api
] ); ] );
} }
public static function find_user_returns() public static function find_user_returns() {
{
return new \external_multiple_structure(self::user_structure()); return new \external_multiple_structure(self::user_structure());
} }
// Actual functions. // Actual functions.
public static function find_user($like, $excludeid=null, $contextid=1) public static function find_user($like, $excludeid=null, $contextid=1) {
{
global $CFG, $DB; global $CFG, $DB;
// Only allow this if the user has the right to edit in this context (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).
@ -173,7 +166,7 @@ class associationservice extends \external_api
"pattern_ln" => $pattern, "pattern_ln" => $pattern,
"pattern_un" => $pattern, "pattern_un" => $pattern,
]; ];
$sql = "SELECT u.* from {user} u LEFT JOIN {local_treestudyplan_user} j ON u.id = j.user_id"; $sql = "SELECT u.* from {user} u LEFT JOIN {local_treestudyplan_user} j ON u.id = j.user_id";
$sql .= " WHERE u.deleted != 1 AND (firstname LIKE :pattern_fn OR lastname LIKE :pattern_ln OR username LIKE :pattern_un)"; $sql .= " WHERE u.deleted != 1 AND (firstname LIKE :pattern_fn OR lastname LIKE :pattern_ln OR username LIKE :pattern_un)";
if (isset($excludeid) && is_numeric($excludeid)) { if (isset($excludeid) && is_numeric($excludeid)) {
$sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)"; $sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)";
@ -191,16 +184,14 @@ class associationservice extends \external_api
return $users; return $users;
} }
public static function connect_cohort_parameters() public static function connect_cohort_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
"cohort_id" => new \external_value(PARAM_INT, 'id of cohort to link', VALUE_OPTIONAL), "cohort_id" => new \external_value(PARAM_INT, 'id of cohort to link', VALUE_OPTIONAL),
] ); ] );
} }
public static function connect_cohort_returns() public static function connect_cohort_returns() {
{
return new \external_single_structure([ return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'), "success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'), "msg" => new \external_value(PARAM_TEXT, 'message'),
@ -208,8 +199,7 @@ class associationservice extends \external_api
} }
// Actual functions. // Actual functions.
public static function connect_cohort($studyplanid, $cohortid) public static function connect_cohort($studyplanid, $cohortid) {
{
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
@ -222,24 +212,22 @@ class associationservice extends \external_api
]); ]);
$studyplan->mark_csync_changed(); $studyplan->mark_csync_changed();
return ['success' => true, 'msg'=>'Cohort connected']; return ['success' => true, 'msg' => 'Cohort connected'];
} else { } else {
return ['success' => true, 'msg'=>'Cohort already connected']; return ['success' => true, 'msg' => 'Cohort already connected'];
} }
} }
public static function disconnect_cohort_parameters() public static function disconnect_cohort_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
"cohort_id" => new \external_value(PARAM_INT, 'id of cohort to link', VALUE_OPTIONAL), "cohort_id" => new \external_value(PARAM_INT, 'id of cohort to link', VALUE_OPTIONAL),
] ); ] );
} }
public static function disconnect_cohort_returns() public static function disconnect_cohort_returns() {
{
return new \external_single_structure([ return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'), "success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'), "msg" => new \external_value(PARAM_TEXT, 'message'),
@ -247,8 +235,7 @@ class associationservice extends \external_api
} }
// Actual functions. // Actual functions.
public static function disconnect_cohort($studyplanid, $cohortid) public static function disconnect_cohort($studyplanid, $cohortid) {
{
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
@ -262,23 +249,21 @@ class associationservice extends \external_api
$studyplan->mark_csync_changed(); $studyplan->mark_csync_changed();
return ['success' => true, 'msg'=>'Cohort Disconnected']; return ['success' => true, 'msg' => 'Cohort Disconnected'];
} else { } else {
return ['success' => true, 'msg'=>'Connection does not exist']; return ['success' => true, 'msg' => 'Connection does not exist'];
} }
} }
public static function connect_user_parameters() public static function connect_user_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
"user_id" => new \external_value(PARAM_INT, 'id of user to link', VALUE_OPTIONAL), "user_id" => new \external_value(PARAM_INT, 'id of user to link', VALUE_OPTIONAL),
] ); ] );
} }
public static function connect_user_returns() public static function connect_user_returns() {
{
return new \external_single_structure([ return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'), "success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'), "msg" => new \external_value(PARAM_TEXT, 'message'),
@ -286,8 +271,7 @@ class associationservice extends \external_api
} }
// Actual functions. // Actual functions.
public static function connect_user($studyplanid, $userid) public static function connect_user($studyplanid, $userid) {
{
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
@ -300,23 +284,21 @@ class associationservice extends \external_api
]); ]);
$studyplan->mark_csync_changed(); $studyplan->mark_csync_changed();
return ['success' => true, 'msg'=>'Cohort connected']; return ['success' => true, 'msg' => 'Cohort connected'];
} else { } else {
return ['success' => true, 'msg'=>'Cohort already connected']; return ['success' => true, 'msg' => 'Cohort already connected'];
} }
} }
public static function disconnect_user_parameters() public static function disconnect_user_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
"user_id" => new \external_value(PARAM_INT, 'id of user to link', VALUE_OPTIONAL), "user_id" => new \external_value(PARAM_INT, 'id of user to link', VALUE_OPTIONAL),
] ); ] );
} }
public static function disconnect_user_returns() public static function disconnect_user_returns() {
{
return new \external_single_structure([ return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'), "success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'), "msg" => new \external_value(PARAM_TEXT, 'message'),
@ -324,8 +306,7 @@ class associationservice extends \external_api
} }
// Actual functions. // Actual functions.
public static function disconnect_user($studyplanid, $userid) public static function disconnect_user($studyplanid, $userid) {
{
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
@ -338,27 +319,24 @@ class associationservice extends \external_api
$studyplan->mark_csync_changed(); $studyplan->mark_csync_changed();
return ['success' => true, 'msg'=>'User Disconnected']; return ['success' => true, 'msg' => 'User Disconnected'];
} else { } else {
return ['success' => true, 'msg'=>'Connection does not exist']; return ['success' => true, 'msg' => 'Connection does not exist'];
} }
} }
public static function associated_users_parameters() public static function associated_users_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
] ); ] );
} }
public static function associated_users_returns() public static function associated_users_returns() {
{
return new \external_multiple_structure(self::user_structure()); return new \external_multiple_structure(self::user_structure());
} }
// Actual functions. // Actual functions.
public static function associated_users($studyplanid) public static function associated_users($studyplanid) {
{
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
@ -376,21 +354,18 @@ class associationservice extends \external_api
return $users; return $users;
} }
public static function associated_cohorts_parameters() public static function associated_cohorts_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
] ); ] );
} }
public static function associated_cohorts_returns() public static function associated_cohorts_returns() {
{
return new \external_multiple_structure(self::cohort_structure()); return new \external_multiple_structure(self::cohort_structure());
} }
// Actual functions. // Actual functions.
public static function associated_cohorts($studyplanid) public static function associated_cohorts($studyplanid) {
{
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
@ -406,39 +381,34 @@ class associationservice extends \external_api
return $cohorts; return $cohorts;
} }
public static function all_associated_parameters() {
public static function all_associated_parameters()
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
] ); ] );
} }
public static function all_associated_returns() public static function all_associated_returns() {
{
return new \external_multiple_structure(self::user_structure()); return new \external_multiple_structure(self::user_structure());
} }
// Actual functions. // Actual functions.
public static function all_associated($studyplanid) public static function all_associated($studyplanid) {
{
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
$users = []; $users = [];
// SQL JOIN script selecting all users that have a cohort linked to this studyplan . // SQL JOIN script selecting all users that have a cohort linked to this studyplan .
// Or are directly linked. // Or are directly linked.
$sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email $sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email"
FROM {user} u ."FROM {user} u"
LEFT JOIN {cohort_members} cm ON u.id = cm.userid ."LEFT JOIN {cohort_members} cm ON u.id = cm.userid"
LEFT JOIN {local_treestudyplan_cohort} tc ON cm.cohortid = tc.cohort_id ."LEFT JOIN {local_treestudyplan_cohort} tc ON cm.cohortid = tc.cohort_id"
LEFT JOIN {local_treestudyplan_user} tu ON u.id = tu.user_id ."LEFT JOIN {local_treestudyplan_user} tu ON u.id = tu.user_id"
WHERE tc.studyplan_id = {$studyplanid} ."WHERE tc.studyplan_id = {$studyplan->id()}"
OR tu.studyplan_id = {$studyplanid} ."OR tu.studyplan_id = {$studyplan->id()}"
ORDER BY u.lastname, u.firstname"; ."ORDER BY u.lastname, u.firstname";
$rs = $DB->get_recordset_sql($sql); $rs = $DB->get_recordset_sql($sql);
foreach ($rs as $u) { foreach ($rs as $u) {
@ -464,25 +434,22 @@ class associationservice extends \external_api
$sortln_b = $b['lastname']; $sortln_b = $b['lastname'];
} }
$cmp= $sortln_a <=> $sortln_b; $cmp= $sortln_a <=> $sortln_b;
return ($cmp != 0)?$cmp:$a['firstname'] <=> $b['firstname']; return ($cmp != 0) ? $cmp : $a['firstname'] <=> $b['firstname'];
}); });
} }
public static function cascade_cohortsync_parameters() public static function cascade_cohortsync_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
] ); ] );
} }
public static function cascade_cohortsync_returns() public static function cascade_cohortsync_returns() {
{
return success::structure(); return success::structure();
} }
// Actual functions. // Actual functions.
public static function cascade_cohortsync($studyplanid) public static function cascade_cohortsync($studyplanid) {
{
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
@ -501,6 +468,4 @@ class associationservice extends \external_api
} }

View File

@ -69,7 +69,7 @@ class badgeinfo {
"status" => new \external_value(PARAM_TEXT, 'badge status'), "status" => new \external_value(PARAM_TEXT, 'badge status'),
"locked" => new \external_value(PARAM_TEXT, 'badge lock status'), "locked" => new \external_value(PARAM_TEXT, 'badge lock status'),
"criteria" => new \external_multiple_structure(new \external_value(PARAM_RAW, 'criteria text'), 'badge criteria', VALUE_OPTIONAL), "criteria" => new \external_multiple_structure(new \external_value(PARAM_RAW, 'criteria text'), 'badge criteria', VALUE_OPTIONAL),
"description"=> new \external_value(PARAM_TEXT, 'badge description'), "description" => new \external_value(PARAM_TEXT, 'badge description'),
"imageurl" => new \external_value(PARAM_TEXT, 'url of badge image'), "imageurl" => new \external_value(PARAM_TEXT, 'url of badge image'),
"studentcount" => new \external_value(PARAM_INT, 'number of studyplan students that can get this badge', VALUE_OPTIONAL), "studentcount" => new \external_value(PARAM_INT, 'number of studyplan students that can get this badge', VALUE_OPTIONAL),
"issuedcount" => new \external_value(PARAM_INT, 'number of studyplan students that have got this badge', VALUE_OPTIONAL), "issuedcount" => new \external_value(PARAM_INT, 'number of studyplan students that have got this badge', VALUE_OPTIONAL),
@ -110,7 +110,7 @@ class badgeinfo {
"infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL), "infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL),
"name" => new \external_value(PARAM_TEXT, 'badge name'), "name" => new \external_value(PARAM_TEXT, 'badge name'),
"criteria" => new \external_multiple_structure(new \external_value(PARAM_RAW, 'criteria text'), 'badge criteria', VALUE_OPTIONAL), "criteria" => new \external_multiple_structure(new \external_value(PARAM_RAW, 'criteria text'), 'badge criteria', VALUE_OPTIONAL),
"description"=> new \external_value(PARAM_TEXT, 'badge description'), "description" => new \external_value(PARAM_TEXT, 'badge description'),
"imageurl" => new \external_value(PARAM_TEXT, 'url of badge image'), "imageurl" => new \external_value(PARAM_TEXT, 'url of badge image'),
"issued" => new \external_value(PARAM_BOOL, 'badge is issued'), "issued" => new \external_value(PARAM_BOOL, 'badge is issued'),
"dateissued" => new \external_value(PARAM_TEXT, 'date the badge was issued', VALUE_OPTIONAL), "dateissued" => new \external_value(PARAM_TEXT, 'date the badge was issued', VALUE_OPTIONAL),
@ -124,7 +124,7 @@ class badgeinfo {
global $DB; global $DB;
$context = ($this->badge->type == BADGE_TYPE_SITE) ? \context_system::instance() : \context_course::instance($this->badge->courseid); $context = ($this->badge->type == BADGE_TYPE_SITE) ? \context_system::instance() : \context_course::instance($this->badge->courseid);
$issued = $this->badge->is_issued($userid); $issued = $this->badge->is_issued($userid);
// If the user is viewing another user's badge and doesn't have the right capability return only part of the data. // If the user is viewing another user's badge and doesn't have the right capability return only part of the data.
$criteria = []; $criteria = [];
@ -148,7 +148,7 @@ class badgeinfo {
$badge['dateexpire'] = date("Y-m-d", $issueinfo->dateexpire); $badge['dateexpire'] = date("Y-m-d", $issueinfo->dateexpire);
} }
$badge['uniquehash'] = $issueinfo->uniquehash; $badge['uniquehash'] = $issueinfo->uniquehash;
$badge['issuedlink'] = (new \moodle_url('/badges/badge.php', ['hash' => $issueinfo->uniquehash]))->out(false); $badge['issuedlink'] = (new \moodle_url('/badges/badge.php', ['hash' => $issueinfo->uniquehash]))->out(false);
} }
return $badge; return $badge;

View File

@ -89,7 +89,7 @@ class cascadecohortsync {
//\mtrace("Processing Course {$courseid} {$course->shortname}");. //\mtrace("Processing Course {$courseid} {$course->shortname}");.
// First create any nonexistent links. // First create any nonexistent links.
foreach ($cohortids as $cohortid) { foreach ($cohortids as $cohortid) {
$cohort = $DB->get_record('cohort', ['id'=>$cohortid]); $cohort = $DB->get_record('cohort', ['id' => $cohortid]);
//\mtrace("Processing cohort {$cohortid} {$cohort->shortname}");. //\mtrace("Processing cohort {$cohortid} {$cohort->shortname}");.
$instanceparams = [ $instanceparams = [
@ -129,7 +129,7 @@ class cascadecohortsync {
// If not, add it to the reference. // If not, add it to the reference.
//\mtrace("Adding this plan to the list");. //\mtrace("Adding this plan to the list");.
$plans[] = (int)($this->studyplanid); $plans[] = (int)($this->studyplanid);
$enrol->update_instance($instance, (object)["customtext4"=>json_encode($plans)]); $enrol->update_instance($instance, (object)["customtext4" => json_encode($plans)]);
} }
} else { } else {
@ -149,7 +149,7 @@ class cascadecohortsync {
// In the customtext4 field in json format. // In the customtext4 field in json format.
//\mtrace("Instance ({$instanceid} created. Updateing instance with studyplan id");. //\mtrace("Instance ({$instanceid} created. Updateing instance with studyplan id");.
$instance = $DB->get_record('enrol', array('id' => $instanceid)); $instance = $DB->get_record('enrol', array('id' => $instanceid));
$enrol->update_instance($instance, (object)["customtext4"=>json_encode([(int)($this->studyplanid)])]); $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. // Successfully added a valid new instance, so now instantiate it.
@ -169,7 +169,6 @@ class cascadecohortsync {
} }
} }
// 2: Check if there are cohort links for this studyplan in this course that should be removed. // 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. // 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... // B: Check if these links are valid through another studyplan...
@ -189,7 +188,8 @@ class cascadecohortsync {
$records = $DB->get_records("enrol", $searchparams); $records = $DB->get_records("enrol", $searchparams);
foreach ($records as $instance) { foreach ($records as $instance) {
if (!empty($instance->customtext4)) { // only check the records that have studyplan information in the customtext4 field. 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. // First check if the cohort is not one of the cohort id's we have associated.
if (!in_array($instance->customint1, $cohortids)) { if (!in_array($instance->customint1, $cohortids)) {
//\mtrace("Found cohort sync instance that is not currently liked to the studyplan: {$instance->id}");. //\mtrace("Found cohort sync instance that is not currently liked to the studyplan: {$instance->id}");.
@ -210,7 +210,7 @@ class cascadecohortsync {
} else { } else {
// Otherwise just update the references so this studyplan is no longer linked. // Otherwise just update the references so this studyplan is no longer linked.
//\mtrace("Still references left in the list, updating list...");. //\mtrace("Still references left in the list, updating list...");.
$enrol->update_instance($instance, (object)["customtext4"=>json_encode($fplans)]); $enrol->update_instance($instance, (object)["customtext4" => json_encode($fplans)]);
} }
} }
} }

View File

@ -76,7 +76,6 @@ 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

@ -25,8 +25,7 @@ require_once($CFG->libdir.'/externallib.php');
use \grade_item; use \grade_item;
class completionscanner class completionscanner {
{
private static $modsupported = []; private static $modsupported = [];
private static $coursestudents = []; private static $coursestudents = [];
private $scanner = null; private $scanner = null;
@ -132,7 +131,7 @@ class completionscanner
} else if ($completionstatus == COMPLETION_COMPLETE) { } else if ($completionstatus == COMPLETION_COMPLETE) {
$completed++; $completed++;
} }
} else{ } else {
if ($completion->is_complete()) { if ($completion->is_complete()) {
$completed++; $completed++;
} }
@ -141,7 +140,6 @@ class completionscanner
} }
return [ return [
'ungraded' => $ungraded, 'ungraded' => $ungraded,
'completed' => $completed, 'completed' => $completed,

View File

@ -22,7 +22,6 @@
namespace local_treestudyplan; namespace local_treestudyplan;
class contextinfo { class contextinfo {
public $context; public $context;
public function __construct($context) { public function __construct($context) {
@ -65,5 +64,4 @@ class contextinfo {
} }

View File

@ -66,7 +66,7 @@ class corecompletioninfo {
COMPLETION_COMPLETE => "complete", COMPLETION_COMPLETE => "complete",
COMPLETION_COMPLETE_PASS => "complete-pass", COMPLETION_COMPLETE_PASS => "complete-pass",
COMPLETION_COMPLETE_FAIL => "complete-fail", 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::$COMPLETIONHANDLES[$completion] ?? "undefined"; return self::$COMPLETIONHANDLES[$completion] ?? "undefined";
} }
@ -151,14 +151,14 @@ class corecompletioninfo {
} }
private static function aggregation_handle($method) { private static function aggregation_handle($method) {
return ($method==COMPLETION_AGGREGATION_ALL)?"all":"any"; return ($method==COMPLETION_AGGREGATION_ALL) ? "all" : "any";
} }
public function editor_model() { public function editor_model() {
global $DB, $CFG, $COMPLETIONCRITERIA_TYPES; global $DB, $CFG, $COMPLETIONCRITERIA_TYPES;
$conditions = []; $conditions = [];
$aggregation = "all"; // default. $aggregation = "all"; // Default.
$info = [ $info = [
"conditions" => $conditions, "conditions" => $conditions,
"aggregation" => self::aggregation_handle($this->completion->get_aggregation_method()), "aggregation" => self::aggregation_handle($this->completion->get_aggregation_method()),
@ -304,7 +304,6 @@ class corecompletioninfo {
} }
return $info; return $info;
} }
@ -352,7 +351,7 @@ class corecompletioninfo {
"type" => $COMPLETIONCRITERIA_TYPES[$type], "type" => $COMPLETIONCRITERIA_TYPES[$type],
"aggregation" => self::aggregation_handle($typeaggregation), "aggregation" => self::aggregation_handle($typeaggregation),
"completed" => $completed, "completed" => $completed,
"status" => $completed?"complete":"incomplete", "status" => $completed ? "complete" : "incomplete",
"title" => reset($completions)->get_criteria()->get_type_title(), "title" => reset($completions)->get_criteria()->get_type_title(),
"items" => [], "items" => [],
]; ];
@ -370,7 +369,7 @@ class corecompletioninfo {
"title" => $criteria->get_title_detailed(), "title" => $criteria->get_title_detailed(),
"details" => $criteria->get_details($completion), "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), "status" => self::completion_handle($completion->is_complete() ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE),
]; ];
if ($type == COMPLETION_CRITERIA_TYPE_ACTIVITY) { if ($type == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
@ -399,7 +398,7 @@ class corecompletioninfo {
$iinfo['grade'] = floatval($iinfo['details']['status']); $iinfo['grade'] = floatval($iinfo['details']['status']);
if ($iinfo["grade"] > 0) { if ($iinfo["grade"] > 0) {
$iinfo["grade"] = format_float($iinfo["grade"], 1). "/".format_float(floatval($iinfo['details']['requirement'])); $iinfo["grade"] = format_float($iinfo["grade"], 1). "/".format_float(floatval($iinfo['details']['requirement']));
$iinfo["status"] = $completion->is_complete()?"complete-pass":"complete-fail"; $iinfo["status"] = $completion->is_complete() ? "complete-pass" : "complete-fail";
if ($cinfo["status"] == "incomplete") { if ($cinfo["status"] == "incomplete") {
$cinfo["status"] = "progress"; $cinfo["status"] = "progress";
} }
@ -457,7 +456,7 @@ class corecompletioninfo {
$result->grade = $scale->get_nearest_item($grade->finalgrade); $result->grade = $scale->get_nearest_item($grade->finalgrade);
} else { } else {
// Round final grade to 1 decimal point. // Round final grade to 1 decimal point.
$result->grade = round($grade->finalgrade, 1); $result->grade = round($grade->finalgrade, 1);
} }
$result->feedback = trim($grade->feedback); $result->feedback = trim($grade->feedback);
@ -509,7 +508,6 @@ class corecompletioninfo {
} }
/** /**
* Returns the percentage completed by a certain user, returns null if no completion data is available. * Returns the percentage completed by a certain user, returns null if no completion data is available.
* *
@ -660,10 +658,9 @@ class corecompletioninfo {
$result = new \stdClass; $result = new \stdClass;
$result->count = $count; $result->count = $count;
$result->completed = $completed; $result->completed = $completed;
$result->percentage = ($count > 0)?(($completed / $count) * 100):0; $result->percentage = ($count > 0) ? (($completed / $count) * 100) : 0;
return $result; return $result;
} }
} }

View File

@ -49,7 +49,7 @@ class courseinfo {
} }
public function course() { 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() { public function course_context() {
@ -86,7 +86,7 @@ class courseinfo {
public static function get_contentitem($name) { public static function get_contentitem($name) {
$contentitems = static::get_contentitems(); $contentitems = static::get_contentitems();
for($i = 0; $i < count($contentitems); $i++) { for ($i = 0; $i < count($contentitems); $i++) {
if ($contentitems[$i]->get_name() == $name) { if ($contentitems[$i]->get_name() == $name) {
return $contentitems[$i]; return $contentitems[$i];
} }
@ -122,7 +122,7 @@ class courseinfo {
else { else {
return "present"; return "present";
} }
} else{ } else {
return "future"; return "future";
} }
} }
@ -217,7 +217,7 @@ class courseinfo {
'enddate' => date("Y-m-d", $this->course->enddate), 'enddate' => date("Y-m-d", $this->course->enddate),
'amteacher' => $this->amTeacher(), 'amteacher' => $this->amTeacher(),
'canupdatecourse' => \has_capability("moodle/course:update", $this->coursecontext), 'canupdatecourse' => \has_capability("moodle/course:update", $this->coursecontext),
'canselectgradables' => $this->iCanSelectGradables(), 'canselectgradables' => $this->iCanSelectGradables(),
'tag' => "Editormodel", 'tag' => "Editormodel",
'grades' => [], 'grades' => [],
]; ];
@ -282,7 +282,6 @@ class courseinfo {
} }
return $info; return $info;
} }

View File

@ -29,8 +29,7 @@ use \local_treestudyplan\local\helpers\webservicehelper;
use \local_treestudyplan\completionscanner; use \local_treestudyplan\completionscanner;
use \local_treestudyplan\gradingscanner; use \local_treestudyplan\gradingscanner;
class courseservice extends \external_api class courseservice extends \external_api {
{
const CAP_EDIT = "local/treestudyplan:editstudyplan"; const CAP_EDIT = "local/treestudyplan:editstudyplan";
const CAP_VIEW = "local/treestudyplan:viewuserreports"; const CAP_VIEW = "local/treestudyplan:viewuserreports";
@ -40,15 +39,13 @@ class courseservice extends \external_api
* * * *
************************/ ************************/
public static function map_categories_parameters() public static function map_categories_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"root_id" => new \external_value(PARAM_INT, 'root category to use as base', VALUE_DEFAULT), "root_id" => new \external_value(PARAM_INT, 'root category to use as base', VALUE_DEFAULT),
] ); ] );
} }
public static function map_categories_returns() public static function map_categories_returns() {
{
return new \external_multiple_structure(static::map_category_structure(false)); return new \external_multiple_structure(static::map_category_structure(false));
} }
@ -56,10 +53,10 @@ class courseservice extends \external_api
$s = [ $s = [
"id" => new \external_value(PARAM_INT, 'course category id'), "id" => new \external_value(PARAM_INT, 'course category id'),
"context_id" => new \external_value(PARAM_INT, 'course category context id'), "context_id" => new \external_value(PARAM_INT, 'course category context id'),
"category" => contextinfo::structure(VALUE_OPTIONAL), "category" => contextinfo::structure(VALUE_OPTIONAL),
"haschildren" => new \external_value(PARAM_BOOL, 'True if the category has child categories'), "haschildren" => new \external_value(PARAM_BOOL, 'True if the category has child categories'),
"hascourses" => new \external_value(PARAM_BOOL, 'True if the category contains courses'), "hascourses" => new \external_value(PARAM_BOOL, 'True if the category contains courses'),
"studyplancount" => new \external_value(PARAM_INT, 'number of linked studyplans', VALUE_OPTIONAL), "studyplancount" => new \external_value(PARAM_INT, 'number of linked studyplans', VALUE_OPTIONAL),
]; ];
if (!$lazy > 0) { if (!$lazy > 0) {
@ -82,8 +79,9 @@ class courseservice extends \external_api
if ($root->id == 0) { 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.
$usertop = \core_course_category::user_top(); $usertop = \core_course_category::user_top();
if ($usertop->id == 0) { // top category.. if ($usertop->id == 0) {
$children = $root->get_children(); // returns a list of çore_course_category, let it overwrite $children. // Top category..
$children = $root->get_children(); // Returns a list of çore_course_category, let it overwrite $children.
} else { } else {
$children = [$usertop]; $children = [$usertop];
} }
@ -97,15 +95,13 @@ class courseservice extends \external_api
return $list; return $list;
} }
public static function get_category_parameters() public static function get_category_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of category'), "id" => new \external_value(PARAM_INT, 'id of category'),
] ); ] );
} }
public static function get_category_returns() public static function get_category_returns() {
{
return static::map_category_structure(false); return static::map_category_structure(false);
} }
@ -118,7 +114,7 @@ class courseservice extends \external_api
global $DB; global $DB;
$catcontext = $cat->get_context(); $catcontext = $cat->get_context();
$ctxinfo = new contextinfo($catcontext); $ctxinfo = 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(); $courses = $cat->get_courses();
$model = [ $model = [
"id" => $cat->id, "id" => $cat->id,
@ -144,20 +140,17 @@ class courseservice extends \external_api
return $model; return $model;
} }
public static function list_accessible_categories_parameters() public static function list_accessible_categories_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT), ] "operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT), ]
); );
} }
public static function list_accessible_categories_returns() public static function list_accessible_categories_returns() {
{
return new \external_multiple_structure(static::map_category_structure(true)); return new \external_multiple_structure(static::map_category_structure(true));
} }
public static function list_accessible_categories($operation="edit") public static function list_accessible_categories($operation="edit") {
{
if ($operation == "edit") { if ($operation == "edit") {
$capability = self::CAP_EDIT; $capability = self::CAP_EDIT;
} else { // Operation == "view" || default. } else { // Operation == "view" || default.
@ -216,20 +209,17 @@ class courseservice extends \external_api
return $list; return $list;
} }
public static function list_used_categories_parameters() public static function list_used_categories_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT), "operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT),
]); ]);
} }
public static function list_used_categories_returns() public static function list_used_categories_returns() {
{
return new \external_multiple_structure(static::map_category_structure(true)); return new \external_multiple_structure(static::map_category_structure(true));
} }
public static function list_used_categories($operation='edit') public static function list_used_categories($operation='edit') {
{
global $DB; global $DB;
if ($operation == "edit") { if ($operation == "edit") {
$capability = self::CAP_EDIT; $capability = self::CAP_EDIT;
@ -244,7 +234,6 @@ class courseservice extends \external_api
} }
$rs->close(); $rs->close();
// Now filter the categories that the user has acces to by the used context id's. // Now filter the categories that the user has acces to by the used context id's.
// (That should filter out irrelevant stuff). // (That should filter out irrelevant stuff).
$cats = static::categories_by_capability($capability); $cats = static::categories_by_capability($capability);
@ -300,7 +289,6 @@ class courseservice extends \external_api
return $list; return $list;
} }
/************************************** /**************************************
* *
* Progress scanners for teacherview * Progress scanners for teacherview
@ -338,9 +326,7 @@ class courseservice extends \external_api
return $scanner->model(); return $scanner->model();
} }
public static function scan_completion_progress_parameters() {
public static function scan_completion_progress_parameters()
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"criteriaid" => new \external_value(PARAM_INT, 'CriteriaID to scan progress for', VALUE_DEFAULT), "criteriaid" => new \external_value(PARAM_INT, 'CriteriaID to scan progress for', VALUE_DEFAULT),
"studyplanid" => new \external_value(PARAM_INT, 'Study plan id to check progress in', VALUE_DEFAULT), "studyplanid" => new \external_value(PARAM_INT, 'Study plan id to check progress in', VALUE_DEFAULT),
@ -348,13 +334,11 @@ class courseservice extends \external_api
]); ]);
} }
public static function scan_completion_progress_returns() public static function scan_completion_progress_returns() {
{
return completionscanner::structure(VALUE_REQUIRED); return completionscanner::structure(VALUE_REQUIRED);
} }
public static function scan_completion_progress($criteriaid, $studyplanid, $courseid) public static function scan_completion_progress($criteriaid, $studyplanid, $courseid) {
{
global $DB; global $DB;
// Verify access to the study plan. // Verify access to the study plan.
$o = studyplan::findById($studyplanid); $o = studyplan::findById($studyplanid);
@ -368,24 +352,21 @@ class courseservice extends \external_api
return $scanner->model(); return $scanner->model();
} }
public static function scan_badge_progress_parameters() public static function scan_badge_progress_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"badgeid" => new \external_value(PARAM_INT, 'Badge to scan progress for', VALUE_DEFAULT), "badgeid" => new \external_value(PARAM_INT, 'Badge to scan progress for', VALUE_DEFAULT),
"studyplanid" => new \external_value(PARAM_INT, 'Study plan id to limit progress search to (to determine which students to scan)', VALUE_DEFAULT), "studyplanid" => new \external_value(PARAM_INT, 'Study plan id to limit progress search to (to determine which students to scan)', VALUE_DEFAULT),
]); ]);
} }
public static function scan_badge_progress_returns() public static function scan_badge_progress_returns() {
{
return new \external_single_structure([ return new \external_single_structure([
"total" => new \external_value(PARAM_INT, 'Total number of students scanned'), "total" => new \external_value(PARAM_INT, 'Total number of students scanned'),
"issued" => new \external_value(PARAM_INT, 'Number of issued badges'), "issued" => new \external_value(PARAM_INT, 'Number of issued badges'),
]); ]);
} }
public static function scan_badge_progress($badgeid, $studyplanid) public static function scan_badge_progress($badgeid, $studyplanid) {
{
global $DB; global $DB;
// Check access to the study plan. // Check access to the study plan.
$o = studyplan::findById($studyplanid); $o = studyplan::findById($studyplanid);
@ -412,5 +393,4 @@ class courseservice extends \external_api
} }
} }

View File

@ -50,7 +50,6 @@ class gradeinfo {
private $cmid; private $cmid;
private $coursesort; private $coursesort;
private static $contentitems = null; private static $contentitems = null;
private $gradingscanner; private $gradingscanner;
@ -59,7 +58,7 @@ class gradeinfo {
protected static function getSectionSequence($sectionid) { protected static function getSectionSequence($sectionid) {
global $DB; global $DB;
if (!array_key_exists($sectionid, self::$sections)) { if (!array_key_exists($sectionid, self::$sections)) {
self::$sections[$sectionid] = explode(", ", $DB->get_field("course_sections", "sequence", ["id"=>$sectionid])); self::$sections[$sectionid] = explode(", ", $DB->get_field("course_sections", "sequence", ["id" => $sectionid]));
} }
return self::$sections[$sectionid]; return self::$sections[$sectionid];
} }
@ -87,7 +86,7 @@ class gradeinfo {
public static function get_contentitem($name) { public static function get_contentitem($name) {
$contentitems = static::get_contentitems(); $contentitems = static::get_contentitems();
for($i = 0; $i < count($contentitems); $i++) { for ($i = 0; $i < count($contentitems); $i++) {
if ($contentitems[$i]->get_name() == $name) { if ($contentitems[$i]->get_name() == $name) {
return $contentitems[$i]; return $contentitems[$i];
} }
@ -116,7 +115,7 @@ class gradeinfo {
// Determine the icon for the associated activity. // Determine the icon for the associated activity.
$contentitem = static::get_contentitem($gi->itemmodule); $contentitem = static::get_contentitem($gi->itemmodule);
$this->icon = empty($contentitem)?"":$contentitem->get_icon(); $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)) { if ($gi->itemtype != "mod" || empty($gi->itemmodule) || empty($gi->iteminstance)) {
@ -146,10 +145,10 @@ class gradeinfo {
$this->scale = $gi->load_scale(); $this->scale = $gi->load_scale();
$this->outcome = $gi->load_outcome(); $this->outcome = $gi->load_outcome();
$this->hidden = ($gi->hidden || (!empty($outcome) && $outcome->hidden))?true:false; $this->hidden = ($gi->hidden || (!empty($outcome) && $outcome->hidden)) ? true : false;
$this->name = empty($outcome)?$gi->itemname:$outcome->name; $this->name = empty($outcome) ? $gi->itemname : $outcome->name;
$this->typename = empty($contentitem)?$gi->itemmodule:$contentitem->get_title()->get_value(); $this->typename = empty($contentitem) ? $gi->itemmodule : $contentitem->get_title()->get_value();
$this->gradingscanner = new gradingscanner($gi); $this->gradingscanner = new gradingscanner($gi);
$this->coursesort = $this->section * 1000 + $this->sectionorder; $this->coursesort = $this->section * 1000 + $this->sectionorder;
@ -160,7 +159,7 @@ class gradeinfo {
global $DB; global $DB;
if ($this->studyitem) { 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]); $r = $DB->get_record('local_treestudyplan_gradeinc', ['studyitem_id' => $this->studyitem->id(), 'grade_item_id' => $this->gradeitem->id]);
if ($r && $r->include) { if ($r && $r->include) {
return(true); return(true);
} }
@ -172,7 +171,7 @@ class gradeinfo {
global $DB; global $DB;
if ($this->studyitem) { 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]); $r = $DB->get_record('local_treestudyplan_gradeinc', ['studyitem_id' => $this->studyitem->id(), 'grade_item_id' => $this->gradeitem->id]);
if ($r && $r->include && $r->required) { if ($r && $r->include && $r->required) {
return(true); return(true);
} }
@ -186,13 +185,13 @@ class gradeinfo {
"cmid" => new \external_value(PARAM_INT, 'course module id'), "cmid" => new \external_value(PARAM_INT, 'course module id'),
"name" => new \external_value(PARAM_TEXT, 'grade item name'), "name" => new \external_value(PARAM_TEXT, 'grade item name'),
"typename" => new \external_value(PARAM_TEXT, 'grade item type name'), "typename" => new \external_value(PARAM_TEXT, 'grade item type name'),
"outcome" => new \external_value(PARAM_BOOL, 'is outcome'), "outcome" => new \external_value(PARAM_BOOL, 'is outcome'),
"selected" => new \external_value(PARAM_BOOL, 'is selected for current studyitem'), "selected" => new \external_value(PARAM_BOOL, 'is selected for current studyitem'),
"icon" => new \external_value(PARAM_RAW, 'html for icon of related activity'), "icon" => new \external_value(PARAM_RAW, 'html for icon of related activity'),
"link" => new \external_value(PARAM_TEXT, 'link to related activity'), "link" => new \external_value(PARAM_TEXT, 'link to related activity'),
"gradinglink" => new \external_value(PARAM_TEXT, 'link to related activity'), "gradinglink" => new \external_value(PARAM_TEXT, 'link to related activity'),
"grading" => gradingscanner::structure(), "grading" => gradingscanner::structure(),
"required" => new \external_value(PARAM_BOOL, 'is required for current studyitem'), "required" => new \external_value(PARAM_BOOL, 'is required for current studyitem'),
], 'referenced course information', $value); ], 'referenced course information', $value);
} }
@ -207,7 +206,7 @@ class gradeinfo {
"icon" => $this->icon, "icon" => $this->icon,
"link" => $this->link, "link" => $this->link,
"gradinglink" => $this->gradinglink, "gradinglink" => $this->gradinglink,
"required" => $this->is_required(), "required" => $this->is_required(),
]; ];
// Unfortunately, lazy loading of the completion data is off, since we need the data to show study item completion... // Unfortunately, lazy loading of the completion data is off, since we need the data to show study item completion...
if ($studyitem !== null && $this->is_selected() && has_capability('local/treestudyplan:viewuserreports', $studyitem->studyline()->studyplan()->context()) if ($studyitem !== null && $this->is_selected() && has_capability('local/treestudyplan:viewuserreports', $studyitem->studyline()->studyplan()->context())
@ -217,22 +216,21 @@ class gradeinfo {
return $model; return $model;
} }
public static function user_structure($value=VALUE_REQUIRED) { public static function user_structure($value=VALUE_REQUIRED) {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'grade_item id'), "id" => new \external_value(PARAM_INT, 'grade_item id'),
"cmid" => new \external_value(PARAM_INT, 'course module id'), "cmid" => new \external_value(PARAM_INT, 'course module id'),
"name" => new \external_value(PARAM_TEXT, 'grade item name'), "name" => new \external_value(PARAM_TEXT, 'grade item name'),
"typename" => new \external_value(PARAM_TEXT, 'grade item type name'), "typename" => new \external_value(PARAM_TEXT, 'grade item type name'),
"grade" => new \external_value(PARAM_TEXT, 'is outcome'), "grade" => new \external_value(PARAM_TEXT, 'is outcome'),
"gradetype" => new \external_value(PARAM_TEXT, 'grade type (completion|grade)'), "gradetype" => new \external_value(PARAM_TEXT, 'grade type (completion|grade)'),
"feedback" => new \external_value(PARAM_RAW, 'html for feedback'), "feedback" => new \external_value(PARAM_RAW, 'html for feedback'),
"completion" => new \external_value(PARAM_TEXT, 'completion state (incomplete|progress|completed|excellent)'), "completion" => new \external_value(PARAM_TEXT, 'completion state (incomplete|progress|completed|excellent)'),
"icon" => new \external_value(PARAM_RAW, 'html for icon of related activity'), "icon" => new \external_value(PARAM_RAW, 'html for icon of related activity'),
"link" => new \external_value(PARAM_TEXT, 'link to related activity'), "link" => new \external_value(PARAM_TEXT, 'link to related activity'),
"pendingsubmission" => new \external_value(PARAM_BOOL, 'is selected for current studyitem', VALUE_OPTIONAL), "pendingsubmission" => new \external_value(PARAM_BOOL, 'is selected for current studyitem', VALUE_OPTIONAL),
"required" => new \external_value(PARAM_BOOL, 'is required for current studyitem'), "required" => new \external_value(PARAM_BOOL, 'is required for current studyitem'),
"selected" => new \external_value(PARAM_BOOL, 'is selected for current studyitem'), "selected" => new \external_value(PARAM_BOOL, 'is selected for current studyitem'),
], 'referenced course information', $value); ], 'referenced course information', $value);
} }
@ -265,13 +263,13 @@ class gradeinfo {
"name" => $this->name, "name" => $this->name,
"typename" => $this->typename, "typename" => $this->typename,
"grade" => $finalgrade, "grade" => $finalgrade,
"gradetype" => isset($this->scale)?"completion":"grade", "gradetype" => isset($this->scale) ? "completion" : "grade",
"feedback" => empty($grade)?null:$grade->feedback, "feedback" => empty($grade) ? null : $grade->feedback,
"completion" => completion::label($completion), "completion" => completion::label($completion),
"icon" => $this->icon, "icon" => $this->icon,
"link" => $this->link, "link" => $this->link,
"pendingsubmission" => $this->gradingscanner->pending($userid), "pendingsubmission" => $this->gradingscanner->pending($userid),
"required" => $this->is_required(), "required" => $this->is_required(),
"selected" => $this->is_selected(), "selected" => $this->is_selected(),
]; ];
@ -283,7 +281,7 @@ class gradeinfo {
"name" => $this->name, "name" => $this->name,
"type" => $this->gradeitem->itemmodule, "type" => $this->gradeitem->itemmodule,
"selected" => $this->is_selected(), "selected" => $this->is_selected(),
"required" => $this->is_required(), "required" => $this->is_required(),
]; ];
} }
public static function import(studyitem $item, array $model) { public static function import(studyitem $item, array $model) {
@ -291,13 +289,17 @@ class gradeinfo {
$courseid = $item->courseid(); $courseid = $item->courseid();
$gradeitems= grade_item::fetch_all(['itemtype' => 'mod', 'courseid' => $courseid]); $gradeitems= grade_item::fetch_all(['itemtype' => 'mod', 'courseid' => $courseid]);
foreach ($gradeitems as $gi) { foreach ($gradeitems as $gi) {
$giname = empty($outcome)?$gi->itemname:$outcome->name; $giname = empty($outcome) ? $gi->itemname : $outcome->name;
$gitype = $gi->itemmodule; $gitype = $gi->itemmodule;
if ($giname == $model["name"] && $gitype == $model["type"]) { if ($giname == $model["name"] && $gitype == $model["type"]) {
// We have a match. // We have a match.
if (!isset($model["selected"])) { $model["selected"] = true;} if (!isset($model["selected"])) {
if (!isset($model["required"])) { $model["required"] = false;} $model["selected"] = true;
}
if (!isset($model["required"])) {
$model["required"] = false;
}
if ($model["selected"] || $model["required"]) { if ($model["selected"] || $model["required"]) {
static::include_grade($gi->id, $item->id(), $model["selected"], $model["required"]); static::include_grade($gi->id, $item->id(), $model["selected"], $model["required"]);
} }
@ -324,8 +326,8 @@ class gradeinfo {
try { try {
$gradable = new static($gi->id, $studyitem); $gradable = new static($gi->id, $studyitem);
$list[] = $gradable; $list[] = $gradable;
} catch (\InvalidArgumentException $x) {
} }
catch(\InvalidArgumentException $x) {}
} }
} }
} }
@ -334,7 +336,7 @@ class gradeinfo {
usort($list, function($a, $b) { usort($list, function($a, $b) {
$course = $a->coursesort <=> $b->coursesort; $course = $a->coursesort <=> $b->coursesort;
return ($course != 0)?$course:$a->gradeitem->sortorder <=> $b->gradeitem->sortorder; return ($course != 0) ? $course : $a->gradeitem->sortorder <=> $b->gradeitem->sortorder;
}); });
return $list; return $list;
} }
@ -350,8 +352,7 @@ class gradeinfo {
if ($r->include || $r->required) { if ($r->include || $r->required) {
$list[] = new static($r->grade_item_id, $studyitem); $list[] = new static($r->grade_item_id, $studyitem);
} }
} } catch (\InvalidArgumentException $x) {
catch(\InvalidArgumentException $x) {
// On InvalidArgumentException, the grade_item id can no longer be found. // On InvalidArgumentException, the grade_item id can no longer be found.
// Remove the link to avoid database record hogging. // Remove the link to avoid database record hogging.
$DB->delete_records($table, ['id' => $r->id]); $DB->delete_records($table, ['id' => $r->id]);
@ -361,7 +362,7 @@ class gradeinfo {
usort($list, function($a, $b) { usort($list, function($a, $b) {
$course = $a->coursesort <=> $b->coursesort; $course = $a->coursesort <=> $b->coursesort;
return ($course != 0)?$course:$a->gradeitem->sortorder <=> $b->gradeitem->sortorder; return ($course != 0) ? $course : $a->gradeitem->sortorder <=> $b->gradeitem->sortorder;
}); });
return $list; return $list;
} }
@ -381,7 +382,7 @@ class gradeinfo {
'studyitem_id' => $itemid, 'studyitem_id' => $itemid,
'grade_item_id' => $gradeid, 'grade_item_id' => $gradeid,
'include' => 1, 'include' => 1,
'required' =>boolval($required)?1:0] 'required' => boolval($required)?1:0]
); );
} }
} else { } else {
@ -396,5 +397,4 @@ class gradeinfo {
} }
} }

View File

@ -25,8 +25,7 @@ require_once($CFG->libdir.'/externallib.php');
use \grade_item; use \grade_item;
class gradingscanner class gradingscanner {
{
private static $modsupported = []; private static $modsupported = [];
private static $coursestudents = []; private static $coursestudents = [];
private $scanner = null; private $scanner = null;
@ -132,9 +131,9 @@ class gradingscanner
$finalgrade = $grade->finalgrade; $finalgrade = $grade->finalgrade;
$scale = $this->gi->load_scale(); $scale = $this->gi->load_scale();
if ( isset($scale)) { if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); $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]); $gradecfg = $DB->get_record($table, ["grade_points" => $this->gi->grademax]);
} else { } else {
$gradecfg = null; $gradecfg = null;
} }
@ -173,5 +172,4 @@ class gradingscanner
} }
} }
} }

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local\aggregators; namespace local_treestudyplan\local\aggregators;
use \local_treestudyplan\courseinfo; use \local_treestudyplan\courseinfo;
@ -98,7 +97,6 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
public function useRequiredGrades() { return True;} public function useRequiredGrades() { return True;}
public function useItemConditions() { return False;} public function useItemConditions() { return False;}
public function aggregate_binary_goals(array $completions, array $required = []) { 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.
@ -111,7 +109,6 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
// - completion::INCOMPLETE - No goals have been started. // - completion::INCOMPLETE - No goals have been started.
// - completion::PROGRESS - All other states. // - completion::PROGRESS - All other states.
$total = count($completions); $total = count($completions);
$completed = 0; $completed = 0;
$progress = 0; $progress = 0;
@ -121,7 +118,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$totalrequired = 0; $totalrequired = 0;
$requiredmet = 0; $requiredmet = 0;
$MINPROGRESS = ($this->accept_pending_as_submitted)?completion::PENDING:completion::PROGRESS; $MINPROGRESS = ($this->accept_pending_as_submitted) ? completion::PENDING : completion::PROGRESS;
foreach ($completions as $index => $c) { foreach ($completions as $index => $c) {
@ -132,10 +129,10 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$started = $progress + $failed; $started = $progress + $failed;
$allrequiredmet = ($requiredmet >= $totalrequired); $allrequiredmet = ($requiredmet >= $totalrequired);
$fractioncompleted = ($total >0)?(floatval($completed)/floatval($total)):0.0; $fractioncompleted = ($total >0) ? (floatval($completed)/floatval($total)) : 0.0;
$fractionprogress = ($total >0)?(floatval($progress)/floatval($total)):0.0; $fractionprogress = ($total >0) ? (floatval($progress)/floatval($total)) : 0.0;
$fractionfailed = ($total >0)?(floatval($failed)/floatval($total)):0.0; $fractionfailed = ($total >0) ? (floatval($failed)/floatval($total)) : 0.0;
$fractionstarted = ($total >0)?(floatval($started)/floatval($total)):0.0; $fractionstarted = ($total >0) ? (floatval($started)/floatval($total)) : 0.0;
if ($total == 0) { if ($total == 0) {
return completion::INCOMPLETE; return completion::INCOMPLETE;
@ -155,7 +152,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid) { public function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid) {
$course = $courseinfo->course(); $course = $courseinfo->course();
$coursefinished = ($course->enddate)?($course->enddate < time()):false; $coursefinished = ($course->enddate) ? ($course->enddate < time()) : false;
// Note: studyitem condition config is not used in this aggregator. // Note: studyitem condition config is not used in this aggregator.
// Loop through all associated gradables and count the totals, completed, etc.. // Loop through all associated gradables and count the totals, completed, etc..
$completions = []; $completions = [];
@ -170,7 +167,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
} }
// Combine the aquired completions into one. // Combine the aquired completions into one.
$result = self::aggregate_binary_goals($completions, $required); $result = self::aggregate_binary_goals($completions, $required);
if ($this->use_failed && $result == completion::PROGRESS && $coursefinished) { if ($this->use_failed && $result == completion::PROGRESS && $coursefinished) {
return completion::FAILED; return completion::FAILED;
} else { } else {
@ -214,7 +211,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$gradeitem = $gradeinfo->getGradeitem(); $gradeitem = $gradeinfo->getGradeitem();
$grade = $gradeitem->get_final($userid); $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; $coursefinished = ($course->enddate) ? ($course->enddate < time()) : false;
if (empty($grade)) { if (empty($grade)) {
return completion::INCOMPLETE; return completion::INCOMPLETE;
@ -236,9 +233,9 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$finalgrade = $grade->finalgrade; $finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale(); $scale = $gradeinfo->getScale();
if ( isset($scale)) { if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); $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]); $gradecfg = $DB->get_record($table, ["grade_points" => $gradeitem->grademax]);
} else { } else {
$gradecfg = null; $gradecfg = null;
} }
@ -288,5 +285,4 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
} }
} }
} }

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local\aggregators; namespace local_treestudyplan\local\aggregators;
use \local_treestudyplan\courseinfo; use \local_treestudyplan\courseinfo;
@ -101,7 +100,6 @@ class core_aggregator extends \local_treestudyplan\aggregator {
// Option: Use course end grade to determine that... // Option: Use course end grade to determine that...
// Probably needs a config value in the aggregator.... // Probably needs a config value in the aggregator....
return completion::COMPLETED; return completion::COMPLETED;
} else { } else {
// Check if the course is over or not, if it is over, display failed. // Check if the course is over or not, if it is over, display failed.
@ -125,7 +123,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} }
} else{ } else {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} }
@ -159,7 +157,6 @@ 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. // AGGREGATORS ARE GOING TO BE DEPRECATED ANYWAY... but used in legacy parts of this plugin.
@ -189,9 +186,9 @@ class core_aggregator extends \local_treestudyplan\aggregator {
$finalgrade = $grade->finalgrade; $finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale(); $scale = $gradeinfo->getScale();
if ( isset($scale)) { if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); $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]); $gradecfg = $DB->get_record($table, ["grade_points" => $gradeitem->grademax]);
} else { } else {
$gradecfg = null; $gradecfg = null;
} }

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local\aggregators; namespace local_treestudyplan\local\aggregators;
use \local_treestudyplan\courseinfo; use \local_treestudyplan\courseinfo;
@ -102,7 +101,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_junction(array $completion, studyitem $studyitem, $userid) { public function aggregate_junction(array $completion, studyitem $studyitem, $userid) {
$completed = self::aggregate_completion($completion, $studyitem->conditions()); $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')); return isset($completed) ? $completed : (self::aggregate_completion($completion, 'ALL'));
} }
public function grade_completion(gradeinfo $gradeinfo, $userid) { public function grade_completion(gradeinfo $gradeinfo, $userid) {
@ -159,5 +158,4 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
} }
} }

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local; namespace local_treestudyplan\local;
use Exception; use Exception;
@ -96,7 +95,6 @@ class gradegenerator {
} }
} }
public function __construct() { public function __construct() {
} }
@ -137,7 +135,7 @@ class gradegenerator {
$results = []; $results = [];
$gaveup = false; $gaveup = false;
for($i=0; $i < $count; $i++) { for ($i=0; $i < $count; $i++) {
$r = new \stdClass; $r = new \stdClass;
if ($gaveup) { if ($gaveup) {
$r->done = !$gaveup; $r->done = !$gaveup;
@ -146,12 +144,12 @@ class gradegenerator {
} }
if ($r->done) { if ($r->done) {
$score = rand(0, $int); $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) { if (!$r->result) {
$r->failed = !($score > 10); $r->failed = !($score > 10);
} }
} else { } 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; $r->failed = true;
} }
// Aways generate a little feedback. // Aways generate a little feedback.
@ -173,7 +171,7 @@ class gradegenerator {
$rlist = []; $rlist = [];
$gen = $this->generateraw($student, $skill, count($gradeinfos)); $gen = $this->generateraw($student, $skill, count($gradeinfos));
for($i=0; $i < count($gradeinfos); $i++) { for ($i=0; $i < count($gradeinfos); $i++) {
$g = $gradeinfos[$i]; $g = $gradeinfos[$i];
$gi = $g->getGradeitem(); $gi = $g->getGradeitem();
$gr = $gen[$i]; $gr = $gen[$i];
@ -181,9 +179,9 @@ class gradegenerator {
// First get the configured interpretation for this scale or grade. // First get the configured interpretation for this scale or grade.
$scale = $gi->load_scale(); $scale = $gi->load_scale();
if ( isset($scale)) { if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); $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]); $gradecfg = $DB->get_record($table, ["grade_points" => $gi->grademax]);
} else { } else {
$gradecfg = null; $gradecfg = null;
} }
@ -194,13 +192,13 @@ class gradegenerator {
// INCOMPLETE. // INCOMPLETE.
// Fair chance of teacher forgetting to set incomplete to "no evidence". // Fair chance of teacher forgetting to set incomplete to "no evidence".
$grade = 0; $grade = 0;
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>"" ]; $r = (object)["gi" => $g, "grade" => $grade, "fb" => "" ];
} else if (!$gr->result) { } else if (!$gr->result) {
$grade = rand($gradecfg->min_progress, $gradecfg->min_completed -1 ); $grade = rand($gradecfg->min_progress, $gradecfg->min_completed -1 );
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => $grade, "fb" => $gr->fb ];
} else{ } else {
// COMPLETED. // COMPLETED.
$r = (object)["gi" => $g, "grade" => rand( $gradecfg->min_completed, $gi->grademax ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => rand( $gradecfg->min_completed, $gi->grademax ), "fb" => $gr->fb ];
} }
$r->gradetext = $r->grade; $r->gradetext = $r->grade;
@ -216,14 +214,14 @@ class gradegenerator {
} else if ($gi->gradepass > 0) { } else if ($gi->gradepass > 0) {
if (!$gr->done) { if (!$gr->done) {
// INCOMPLETe or FAILED. // INCOMPLETe or FAILED.
$grade = rand(0, $gi->gradepass/2); $grade = rand(0, $gi->gradepass/2);
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>($grade > 0)?$gr->fb:"" ]; $r = (object)["gi" => $g, "grade" => $grade, "fb" =>($grade > 0) ? $gr->fb : "" ];
} else if (!$gr->result) { } else if (!$gr->result) {
//PROGRESS. //PROGRESS.
$r = (object)["gi" => $g, "grade" => rand( round($gi->gradepass/2), $gi->gradepass -1 ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => rand( round($gi->gradepass/2), $gi->gradepass -1 ), "fb" => $gr->fb ];
} else{ } else {
// COMPLETED. // COMPLETED.
$r = (object)["gi" => $g, "grade" => rand( $gi->gradepass, $gi->grademax ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => rand( $gi->gradepass, $gi->grademax ), "fb" => $gr->fb ];
} }
$r->gradetext = $r->grade; $r->gradetext = $r->grade;
@ -235,14 +233,14 @@ class gradegenerator {
if (!$gr->done) { if (!$gr->done) {
// INCOMPLETe or FAILED. // INCOMPLETe or FAILED.
$grade = rand(0, round($range * 0.35) - 1); $grade = rand(0, round($range * 0.35) - 1);
$r = (object)["gi" => $g, "grade" => $gi->grademin+$grade, "fb" =>($grade > 0)?$gr->fb:"" ]; $r = (object)["gi" => $g, "grade" => $gi->grademin+$grade, "fb" =>($grade > 0) ? $gr->fb : "" ];
} else if (!$gr->result) { } 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 ]; $r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.35), round($range * 0.55) - 1 ), "fb" => $gr->fb ];
} else{ } else {
// COMPLETED. // COMPLETED.
$r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.55) , $range ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.55) , $range ), "fb" => $gr->fb ];
} }
$r->gradetext = $r->grade; $r->gradetext = $r->grade;
@ -279,7 +277,7 @@ class gradegenerator {
try { try {
$json = file_get_contents($filename); $json = file_get_contents($filename);
$this->unserialize($json); $this->unserialize($json);
} catch(Exception $x) { } catch (Exception $x) {
cli_problem("ERROR loading from file"); 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.
} }
@ -295,5 +293,4 @@ class gradegenerator {
return $path; return $path;
} }
} }

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local\helpers; namespace local_treestudyplan\local\helpers;
use DateTime; use DateTime;

View File

@ -20,11 +20,9 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local\helpers; namespace local_treestudyplan\local\helpers;
require_once($CFG->dirroot.'/webservice/lib.php'); require_once($CFG->dirroot.'/webservice/lib.php');
class webservicehelper { class webservicehelper {
/** @var \context_system */ /** @var \context_system */
private static $systemcontext = null; private static $systemcontext = null;
@ -120,11 +118,11 @@ class webservicehelper {
public static function find_context($contextid): \context{ public static function find_context($contextid): \context{
if (isset($contextid) && is_int($contextid) && $contextid > 0) { if (isset($contextid) && is_int($contextid) && $contextid > 0) {
if (!in_array($contextid, self::$validatedcontexts)) { // Cache the context and make sure it is only validated once... if (!in_array($contextid, self::$validatedcontexts)) {
// Cache the context and make sure it is only validated once...
try { try {
$context = \context::instance_by_id($contextid); $context = \context::instance_by_id($contextid);
} } catch (\dml_missing_record_exception $x) {
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.
@ -132,7 +130,7 @@ class webservicehelper {
self::$validatedcontexts[$contextid] = $context; self::$validatedcontexts[$contextid] = $context;
} }
return self::$validatedcontexts[$contextid]; return self::$validatedcontexts[$contextid];
} else{ } 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

@ -20,16 +20,14 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local\ungradedscanners; namespace local_treestudyplan\local\ungradedscanners;
class assign_scanner extends scanner_base { class assign_scanner extends scanner_base {
protected function get_ungraded_submissions() { protected function get_ungraded_submissions() {
global $DB; 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 $sql = "SELECT DISTINCT asgn_sub.userid
FROM {assign_submission} asgn_sub FROM {assign_submission} asgn_sub
JOIN {assign} a ON a.id = asgn_sub.assignment JOIN {assign} a ON a.id = asgn_sub.assignment
LEFT JOIN {assign_grades} ag ON ag.assignment = asgn_sub.assignment AND ag.userid = asgn_sub.userid AND LEFT JOIN {assign_grades} ag ON ag.assignment = asgn_sub.assignment AND ag.userid = asgn_sub.userid AND
@ -53,7 +51,6 @@ class assign_scanner extends scanner_base {
return $DB->get_fieldset_sql($sql); return $DB->get_fieldset_sql($sql);
} }
public function count_ungraded($courseuserids=[]) { public function count_ungraded($courseuserids=[]) {
$ungraded = $this->get_ungraded_submissions(); $ungraded = $this->get_ungraded_submissions();

View File

@ -20,11 +20,9 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local\ungradedscanners; 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 { class quiz_scanner extends scanner_base {
@ -46,7 +44,7 @@ class quiz_scanner extends scanner_base {
$maxstatesql = "SELECT MAX(qas.sequencenumber) FROM {question_attempt_steps} qas WHERE qas.questionattemptid = {$r->attempt_id}"; $maxstatesql = "SELECT MAX(qas.sequencenumber) FROM {question_attempt_steps} qas WHERE qas.questionattemptid = {$r->attempt_id}";
$max = $DB->get_field_sql($maxstatesql); $max = $DB->get_field_sql($maxstatesql);
if ($r->sequencenumber == $max) { 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(); $rs->close();

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\local\ungradedscanners; namespace local_treestudyplan\local\ungradedscanners;
use \grade_item; use \grade_item;

View File

@ -29,7 +29,6 @@ class period {
private static $CACHE = []; private static $CACHE = [];
private static $PAGECACHE = []; private static $PAGECACHE = [];
private $r; // Holds database record. private $r; // Holds database record.
private $id; private $id;
private $page; private $page;
@ -56,9 +55,9 @@ class period {
$periodnr = 1; $periodnr = 1;
} }
try { try {
$id = $DB->get_field(self::TABLE, "id", ["page_id"=>$page->id(), "period" => $periodnr], MUST_EXIST); $id = $DB->get_field(self::TABLE, "id", ["page_id" => $page->id(), "period" => $periodnr], MUST_EXIST);
$period = self::findById($id); $period = self::findById($id);
} catch(\dml_missing_record_exception $x) { } catch (\dml_missing_record_exception $x) {
// Period does not exist - create one ... // Period does not exist - create one ...
// Make a best guess estimate of the start and end date, based on surrounding 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 . // Or specified duration of the page and the sequence of the periods .
@ -72,17 +71,17 @@ class period {
try { 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); $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) { } catch (\dml_missing_record_exception $x2) {
// If not, do a fair guess. // If not, do a fair guess.
$pstart = $ystart + (($periodnr-1)*$ptime); $pstart = $ystart + (($periodnr-1)*$ptime);
} }
try { 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); $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) { } catch (\dml_missing_record_exception $x2) {
// If not, do a fair guess. // If not, do a fair guess.
$pend = $pstart + $ptime; $pend = $pstart + $ptime;
} }
@ -105,7 +104,7 @@ class period {
if (!array_key_exists($page->id(), self::$PAGECACHE)) { if (!array_key_exists($page->id(), self::$PAGECACHE)) {
$periods = []; $periods = [];
// Find and add the periods to an array with the period sequence as a key. // Find and add the periods to an array with the period sequence as a key.
for($i=1; $i <= $page->periods(); $i++) { for ($i=1; $i <= $page->periods(); $i++) {
$period = self::find($page, $i); $period = self::find($page, $i);
$periods[$i] = $period; $periods[$i] = $period;
} }
@ -152,7 +151,7 @@ class period {
public function enddate() { public function enddate() {
if ($this->r->enddate && strlen($this->r->enddate) > 0) { if ($this->r->enddate && strlen($this->r->enddate) > 0) {
return new \DateTime($this->r->enddate); return new \DateTime($this->r->enddate);
} else{ } 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")); return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
} }
@ -162,7 +161,7 @@ class period {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of period'), "id" => new \external_value(PARAM_INT, 'id of period'),
"fullname" => new \external_value(PARAM_TEXT, 'Full name of period'), "fullname" => new \external_value(PARAM_TEXT, 'Full name of period'),
"shortname"=> new \external_value(PARAM_TEXT, 'Short name of period'), "shortname" => new \external_value(PARAM_TEXT, 'Short name of period'),
"period" => new \external_value(PARAM_INT, 'period sequence'), "period" => new \external_value(PARAM_INT, 'period sequence'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of period'), "startdate" => new \external_value(PARAM_TEXT, 'start date of period'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of period'), "enddate" => new \external_value(PARAM_TEXT, 'end date of period'),
@ -194,7 +193,7 @@ class period {
throw new \InvalidArgumentException("parameter 'period' missing"); throw new \InvalidArgumentException("parameter 'period' missing");
} }
if ($DB->record_exists(self::TABLE, ["page_id"=>$fields["page_id"], "period"=>$fields["period"]])) { if ($DB->record_exists(self::TABLE, ["page_id" => $fields["page_id"], "period" => $fields["period"]])) {
throw new \InvalidArgumentException("record already exists for specified page and period"); throw new \InvalidArgumentException("record already exists for specified page and period");
} }
@ -206,8 +205,8 @@ class period {
} }
} }
$id = $DB->insert_record(self::TABLE, $info); $id = $DB->insert_record(self::TABLE, $info);
unset(self::$PAGECACHE[$fields['page_id']]); // invalidate the cache for this page. unset(self::$PAGECACHE[$fields['page_id']]); // Invalidate the cache for this page.
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) { public function edit($fields) {
@ -222,14 +221,14 @@ class period {
$DB->update_record(self::TABLE, $info); $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); $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; return $this;
} }
public function delete() { public function delete() {
global $DB; global $DB;
$DB->delete_records(self::TABLE, ['id' => $this->id]); $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(); return success::success();
} }

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace local_treestudyplan\privacy; namespace local_treestudyplan\privacy;
use core_privacy\local\metadata\collection; use core_privacy\local\metadata\collection;
use \core_privacy\local\request\userlist; use \core_privacy\local\request\userlist;
@ -163,7 +162,6 @@ class provider implements \core_privacy\local\metadata\provider,
} }
/** /**
* Delete all data for all users in the specified context. * Delete all data for all users in the specified context.
* Used when a context is past it's data retention period * Used when a context is past it's data retention period
@ -175,7 +173,7 @@ class provider implements \core_privacy\local\metadata\provider,
// Find studyplans in context. // Find studyplans in context.
if ($context->contextlevel == CONTEXT_COURSECAT) { if ($context->contextlevel == CONTEXT_COURSECAT) {
$sql = "SELECT s.id FROM {local_treestudyplan} WHERE ( a.user_id = :userid AND s.context_id = :contextid)"; $sql = "SELECT s.id FROM {local_treestudyplan} WHERE ( a.user_id = :userid AND s.context_id = :contextid)";
$planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id]); $planids = $DB->get_fieldset_sql($sql, ["contextid" => $context->id]);
foreach ($planids as $planid) { foreach ($planids as $planid) {
$DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid]); $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid]);
@ -194,11 +192,10 @@ class provider implements \core_privacy\local\metadata\provider,
foreach ($contextlist->get_contexts() as $context) { foreach ($contextlist->get_contexts() as $context) {
if ($context->contextlevel == CONTEXT_SYSTEM) { if ($context->contextlevel == CONTEXT_SYSTEM) {
$sql = "SELECT s.id FROM {local_treestudyplan} INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id $sql = "SELECT s.id FROM {local_treestudyplan} 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 OR s.context_id = :contextid))"; WHERE ( a.user_id = :userid AND ( s.context_id IS NULL OR s.context_id == 0 OR s.context_id = :contextid))";
$planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, "userid" => $user->id]); $planids = $DB->get_fieldset_sql($sql, ["contextid" => $context->id, "userid" => $user->id]);
foreach ($planids as $planid) { foreach ($planids as $planid) {
$DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid, "user_id" => $user->id]); $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid, "user_id" => $user->id]);
@ -210,7 +207,7 @@ class provider implements \core_privacy\local\metadata\provider,
} else if ($context->contextlevel == CONTEXT_COURSECAT) { } else if ($context->contextlevel == CONTEXT_COURSECAT) {
$sql = "SELECT s.id FROM {local_treestudyplan} INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id $sql = "SELECT s.id FROM {local_treestudyplan} INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id
WHERE ( a.user_id = :userid AND s.context_id = :contextid)"; WHERE ( a.user_id = :userid AND s.context_id = :contextid)";
$planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, "userid" => $user->id]); $planids = $DB->get_fieldset_sql($sql, ["contextid" => $context->id, "userid" => $user->id]);
foreach ($planids as $planid) { foreach ($planids as $planid) {
$DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid, "user_id" => $user->id]); $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid, "user_id" => $user->id]);
@ -268,7 +265,7 @@ class provider implements \core_privacy\local\metadata\provider,
// Determine the relevant plan_ids for this context. // Determine the relevant plan_ids for this context.
$sql = "SELECT s.id FROM {local_treestudyplan} $sql = "SELECT s.id FROM {local_treestudyplan}
WHERE ( s.context_id IS NULL OR s.context_id == 0 OR s.context_id = :contextid)) "; WHERE ( s.context_id IS NULL OR s.context_id == 0 OR s.context_id = :contextid)) ";
$planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, ]); $planids = $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.
@ -278,7 +275,7 @@ class provider implements \core_privacy\local\metadata\provider,
} else if ($context->contextlevel == CONTEXT_COURSECAT) { } else if ($context->contextlevel == CONTEXT_COURSECAT) {
$sql = "SELECT s.id FROM {local_treestudyplan} $sql = "SELECT s.id FROM {local_treestudyplan}
WHERE (s.context_id = :contextid)"; WHERE (s.context_id = :contextid)";
$planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, ]); $planids = $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.
} }

View File

@ -25,7 +25,7 @@ require_once("$CFG->dirroot/local/treestudyplan/lib.php");
class reportinvite_form extends moodleform { class reportinvite_form extends moodleform {
//Add elements to form. //Add elements to form.
const GOALS_EDITOR_OPTIONS = array('trusttext'=>true, 'subdirs'=>true, 'maxfiles'=>0, 'maxbytes'=>5*1024*1025); const GOALS_EDITOR_OPTIONS = array('trusttext' => true, 'subdirs' => true, 'maxfiles' => 0, 'maxbytes' => 5*1024*1025);
public function definition() { public function definition() {
global $CFG; global $CFG;
@ -39,7 +39,6 @@ class reportinvite_form extends moodleform {
$mform->addElement('hidden', 'update', 0); $mform->addElement('hidden', 'update', 0);
$mform->setType('update', PARAM_INT); $mform->setType('update', PARAM_INT);
$mform->addElement('text', 'name', get_string('invite_name', 'local_treestudyplan'), array('size' => 50)); // 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->setType('name', PARAM_NOTAGS); //Set type of element.
$mform->setDefault('name', ''); //Default value. $mform->setDefault('name', ''); //Default value.
@ -65,28 +64,23 @@ class reportinvite_form extends moodleform {
parent::set_data($data); parent::set_data($data);
} }
function get_data() function get_data() {
{
global $DB, $USER; global $DB, $USER;
$data = parent::get_data(); $data = parent::get_data();
if ($data != NULL) if ($data != NULL) {
{ if (empty($data->user_id)) {
if (empty($data->user_id))
{
$data->user_id = $USER->id; $data->user_id = $USER->id;
} }
if (empty($data->update)) if (empty($data->update)) {
{
$date = new DateTime("now", core_date::get_user_timezone_object()); $date = new DateTime("now", core_date::get_user_timezone_object());
$date->setTime(0, 0, 0); $date->setTime(0, 0, 0);
$data->idate = $date->getTimeStamp(); $data->idate = $date->getTimeStamp();
} }
if (empty($data->update)) if (empty($data->update)) {
{
//create a new random key for the invite. //create a new random key for the invite.
do { do {
$length = 20; $length = 20;

View File

@ -27,8 +27,7 @@ use \local_treestudyplan\local\helpers\webservicehelper;
require_once($CFG->libdir.'/badgeslib.php'); require_once($CFG->libdir.'/badgeslib.php');
class studentstudyplanservice extends \external_api class studentstudyplanservice extends \external_api {
{
const CAP_VIEWOTHER = "local/treestudyplan:viewuserreports"; const CAP_VIEWOTHER = "local/treestudyplan:viewuserreports";
/************************ /************************
* * * *
@ -36,15 +35,13 @@ class studentstudyplanservice extends \external_api
* * * *
************************/ ************************/
public static function list_user_studyplans_parameters() public static function list_user_studyplans_parameters() {
{
return new \external_function_parameters([ return new \external_function_parameters([
"userid" => new \external_value(PARAM_INT, 'id of student', VALUE_DEFAULT), "userid" => new \external_value(PARAM_INT, 'id of student', VALUE_DEFAULT),
]); ]);
} }
public static function list_user_studyplans_returns() public static function list_user_studyplans_returns() {
{
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::simple_structure() studyplan::simple_structure()
); );
@ -70,15 +67,13 @@ class studentstudyplanservice extends \external_api
* * * *
************************/ ************************/
public static function get_user_studyplans_parameters() public static function get_user_studyplans_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"userid" => new \external_value(PARAM_INT, 'id of user'), "userid" => new \external_value(PARAM_INT, 'id of user'),
] ); ] );
} }
public static function get_user_studyplans_returns() public static function get_user_studyplans_returns() {
{
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::user_structure() studyplan::user_structure()
); );
@ -105,16 +100,14 @@ class studentstudyplanservice extends \external_api
* * * *
************************/ ************************/
public static function get_user_studyplan_parameters() public static function get_user_studyplan_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"userid" => new \external_value(PARAM_INT, 'id of user'), "userid" => new \external_value(PARAM_INT, 'id of user'),
"studyplanid" => new \external_value(PARAM_INT, 'id of specific studyplan to provide'), "studyplanid" => new \external_value(PARAM_INT, 'id of specific studyplan to provide'),
] ); ] );
} }
public static function get_user_studyplan_returns() public static function get_user_studyplan_returns() {
{
return studyplan::user_structure(); return studyplan::user_structure();
} }
public static function get_user_studyplan($userid, $studyplanid) { public static function get_user_studyplan($userid, $studyplanid) {
@ -136,15 +129,13 @@ class studentstudyplanservice extends \external_api
* * * *
****************************/ ****************************/
public static function get_invited_studyplan_parameters() public static function get_invited_studyplan_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"invitekey" => new \external_value(PARAM_RAW, 'invite key'), "invitekey" => new \external_value(PARAM_RAW, 'invite key'),
] ); ] );
} }
public static function get_invited_studyplan_returns() public static function get_invited_studyplan_returns() {
{
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::user_structure() studyplan::user_structure()
); );
@ -177,13 +168,11 @@ class studentstudyplanservice extends \external_api
* * * *
************************/ ************************/
public static function list_own_studyplans_parameters() public static function list_own_studyplans_parameters() {
{
return new \external_function_parameters([]); return new \external_function_parameters([]);
} }
public static function list_own_studyplans_returns() public static function list_own_studyplans_returns() {
{
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::simple_structure() studyplan::simple_structure()
); );
@ -207,15 +196,13 @@ class studentstudyplanservice extends \external_api
* * * *
************************/ ************************/
public static function get_own_studyplan_parameters() public static function get_own_studyplan_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of specific studyplan to provide', VALUE_DEFAULT), "id" => new \external_value(PARAM_INT, 'id of specific studyplan to provide', VALUE_DEFAULT),
] ); ] );
} }
public static function get_own_studyplan_returns() public static function get_own_studyplan_returns() {
{
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::user_structure() studyplan::user_structure()
); );
@ -253,15 +240,13 @@ class studentstudyplanservice extends \external_api
* * * *
***************************/ ***************************/
public static function get_teaching_studyplans_parameters() public static function get_teaching_studyplans_parameters() {
{
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of specific studyplan to provide', VALUE_DEFAULT), "id" => new \external_value(PARAM_INT, 'id of specific studyplan to provide', VALUE_DEFAULT),
] ); ] );
} }
public static function get_teaching_studyplans_returns() public static function get_teaching_studyplans_returns() {
{
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::editor_structure() studyplan::editor_structure()
); );

View File

@ -33,7 +33,6 @@ class studyitem {
public const START = 'start'; public const START = 'start';
public const INVALID = 'invalid'; public const INVALID = 'invalid';
public const TABLE = "local_treestudyplan_item"; public const TABLE = "local_treestudyplan_item";
private static $STUDYITEMCACHE = []; private static $STUDYITEMCACHE = [];
@ -63,7 +62,6 @@ class studyitem {
return self::$STUDYITEMCACHE[$id]; return self::$STUDYITEMCACHE[$id];
} }
public function __construct($id) { public function __construct($id) {
global $DB; global $DB;
$this->id = $id; $this->id = $id;
@ -102,7 +100,7 @@ class studyitem {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of study item'), "id" => new \external_value(PARAM_INT, 'id of study item'),
"type" => new \external_value(PARAM_TEXT, 'shortname of study item'), "type" => new \external_value(PARAM_TEXT, 'shortname of study item'),
"conditions"=> new \external_value(PARAM_TEXT, 'conditions for completion'), "conditions" => new \external_value(PARAM_TEXT, 'conditions for completion'),
"slot" => new \external_value(PARAM_INT, 'slot in the study plan'), "slot" => new \external_value(PARAM_INT, 'slot in the study plan'),
"layer" => new \external_value(PARAM_INT, 'layer in the slot'), "layer" => new \external_value(PARAM_INT, 'layer in the slot'),
"span" => new \external_value(PARAM_INT, 'how many periods the item spans'), "span" => new \external_value(PARAM_INT, 'how many periods the item spans'),
@ -128,7 +126,7 @@ class studyitem {
$model = [ $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, 'type' => $this->isValid() ? $this->r->type : self::INVALID,
'conditions' => $this->r->conditions, 'conditions' => $this->r->conditions,
'slot' => $this->r->slot, 'slot' => $this->r->slot,
'layer' => $this->r->layer, 'layer' => $this->r->layer,
@ -185,7 +183,6 @@ class studyitem {
} }
} }
// Add incoming and outgoing connection info. // Add incoming and outgoing connection info.
$connout = studyitemconnection::find_outgoing($this->id); $connout = studyitemconnection::find_outgoing($this->id);
@ -455,8 +452,8 @@ class studyitem {
break; break;
} }
} }
return ($notexpired)?completion::COMPLETED:completion::INCOMPLETE; return ($notexpired) ? completion::COMPLETED : completion::INCOMPLETE;
} else{ } else {
return completion::COMPLETED; return completion::COMPLETED;
} }
} else { } else {

View File

@ -30,7 +30,6 @@ class studyitemconnection {
private $r; private $r;
private $id; private $id;
protected function __construct($r) { protected function __construct($r) {
$this->r = $r; $this->r = $r;
$this->id = $r->id; $this->id = $r->id;
@ -64,7 +63,6 @@ class studyitemconnection {
return $this->r->to_id; return $this->r->to_id;
} }
public static function find_outgoing($itemid) { public static function find_outgoing($itemid) {
global $DB; global $DB;
$list = []; $list = [];

View File

@ -92,8 +92,8 @@ class studyline {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyline'), "id" => new \external_value(PARAM_INT, 'id of studyline'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'), "name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
"shortname"=> new \external_value(PARAM_TEXT, 'idnumber of studyline'), "shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color"=> new \external_value(PARAM_TEXT, 'description of studyline'), "color" => new \external_value(PARAM_TEXT, 'description of studyline'),
"sequence" => new \external_value(PARAM_INT, 'order of studyline'), "sequence" => new \external_value(PARAM_INT, 'order of studyline'),
"slots" => new \external_multiple_structure( "slots" => new \external_multiple_structure(
new \external_single_structure([ new \external_single_structure([
@ -136,7 +136,7 @@ class studyline {
$numslots = max($this->page->periods(), $maxslot +1); $numslots = max($this->page->periods(), $maxslot +1);
// Create the required amount of slots. // Create the required amount of slots.
for($i=0; $i < $numslots+1; $i++) { for ($i=0; $i < $numslots+1; $i++) {
if ($mode == "export") { if ($mode == "export") {
// Export mode does not separate between filter or competency type, since that is determined automatically. // Export mode does not separate between filter or competency type, since that is determined automatically.
$slots = []; $slots = [];
@ -254,8 +254,8 @@ class studyline {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyline'), "id" => new \external_value(PARAM_INT, 'id of studyline'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'), "name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
"shortname"=> new \external_value(PARAM_TEXT, 'idnumber of studyline'), "shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color"=> new \external_value(PARAM_TEXT, 'description of studyline'), "color" => new \external_value(PARAM_TEXT, 'description of studyline'),
"sequence" => new \external_value(PARAM_INT, 'order of studyline'), "sequence" => new \external_value(PARAM_INT, 'order of studyline'),
"slots" => new \external_multiple_structure( "slots" => new \external_multiple_structure(
new \external_single_structure([ new \external_single_structure([
@ -288,7 +288,7 @@ class studyline {
$numslots = max($this->page->periods(), $maxslot +1); $numslots = max($this->page->periods(), $maxslot +1);
// Create the required amount of slots. // Create the required amount of slots.
for($i=0; $i < $numslots+1; $i++) { for ($i=0; $i < $numslots+1; $i++) {
if ($i > 0) { if ($i > 0) {
$slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []]; $slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []];
} else { } else {
@ -316,7 +316,6 @@ class studyline {
} }
} }
return $model; return $model;
} }
@ -351,7 +350,7 @@ class studyline {
public function import_studyitems($model, &$itemtranslation, &$connections) { public function import_studyitems($model, &$itemtranslation, &$connections) {
global $DB; global $DB;
foreach ($model as $slot=>$slotmodel) { foreach ($model as $slot=> $slotmodel) {
$courselayer = 0; $courselayer = 0;
$filterlayer = 0; $filterlayer = 0;
foreach ($slotmodel as $itemmodel) { foreach ($slotmodel as $itemmodel) {

View File

@ -26,16 +26,14 @@ require_once($CFG->libdir.'/externallib.php');
class studyplan { class studyplan {
const TABLE = "local_treestudyplan"; const TABLE = "local_treestudyplan";
private static $STUDYPLANCACHE = []; private static $STUDYPLANCACHE = [];
private $r; // Holds database record. private $r; // Holds database record.
private $id; private $id;
private $aggregator; private $aggregator;
private $context = null; // Hold context object once retrieved. private $context = null; // Hold context object once retrieved.
private $linkeduserids = null; // cache lookup of linked users (saves queries). private $linkeduserids = null; // Cache lookup of linked users (saves queries).
private $pagecache = null; private $pagecache = null;
public function aggregator() { public function aggregator() {
@ -87,8 +85,7 @@ class studyplan {
if (!isset($this->context)) { if (!isset($this->context)) {
try { try {
$this->context = contextinfo::by_id($this->r->context_id)->context; $this->context = contextinfo::by_id($this->r->context_id)->context;
} } catch (\dml_missing_record_exception $x) {
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.
} }
} }
@ -99,10 +96,10 @@ class studyplan {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'), "idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'),
"context_id" => new \external_value(PARAM_INT, 'context_id of studyplan'), "context_id" => new \external_value(PARAM_INT, 'context_id of studyplan'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan'), "description" => new \external_value(PARAM_TEXT, 'description of studyplan'),
"aggregation" => new \external_value(PARAM_TEXT, 'selected aggregator'), "aggregation" => new \external_value(PARAM_TEXT, 'selected aggregator'),
"aggregation_config" => new \external_value(PARAM_TEXT, 'config string for aggregator'), "aggregation_config" => new \external_value(PARAM_TEXT, 'config string for aggregator'),
"aggregation_info" => aggregator::basic_structure(), "aggregation_info" => aggregator::basic_structure(),
@ -134,9 +131,9 @@ class studyplan {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'), "idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan'), "description" => new \external_value(PARAM_TEXT, 'description of studyplan'),
"context_id" => new \external_value(PARAM_INT, 'context_id of studyplan'), "context_id" => new \external_value(PARAM_INT, 'context_id of studyplan'),
"aggregation" => new \external_value(PARAM_TEXT, 'selected aggregator'), "aggregation" => new \external_value(PARAM_TEXT, 'selected aggregator'),
"aggregation_config" => new \external_value(PARAM_TEXT, 'config string for aggregator'), "aggregation_config" => new \external_value(PARAM_TEXT, 'config string for aggregator'),
@ -183,14 +180,13 @@ class studyplan {
// Get a list of available scales. // Get a list of available scales.
$scales = array_map( function($scale) { $scales = array_map( function($scale) {
return [ "id" => $scale->id, "name" => $scale->name, ]; return [ "id" => $scale->id, "name" => $scale->name, ];
}, \grade_scale::fetch_all(array('courseid'=>0)) ); }, \grade_scale::fetch_all(array('courseid' => 0)) );
$model['advanced']['force_scales'] = [ $model['advanced']['force_scales'] = [
'scales' => $scales, 'scales' => $scales,
]; ];
} }
return $model; return $model;
} }
@ -205,8 +201,7 @@ class studyplan {
} }
} }
$id = $DB->insert_record(self::TABLE, $info); $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. // Start temporary skräpp code.
// Add a single page and copy the names.This keeps the data sane until the upgrade to . // Add a single page and copy the names.This keeps the data sane until the upgrade to .
@ -302,7 +297,7 @@ class studyplan {
if ($contextid <= 0) { if ($contextid <= 0) {
$ids = $DB->get_fieldset_select(self::TABLE, "id", ""); $ids = $DB->get_fieldset_select(self::TABLE, "id", "");
} else{ } else {
if ($contextid == 1) { if ($contextid == 1) {
$contextid = 1; $contextid = 1;
$where = "context_id <= :contextid OR context_id IS NULL"; $where = "context_id <= :contextid OR context_id IS NULL";
@ -326,7 +321,7 @@ class studyplan {
if ($contextid == 0) { if ($contextid == 0) {
$where .= "OR context_id IS NULL"; $where .= "OR context_id IS NULL";
} }
$ids = $DB->get_fieldset_select(self::TABLE, "id", $where, ["shortname"=>$shortname, "contextid" => $contextid]); $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); $list[] = studyplan::findById($id);
} }
@ -390,7 +385,7 @@ class studyplan {
$uids = $this->find_linked_userids(); $uids = $this->find_linked_userids();
foreach ($uids as $uid) { foreach ($uids as $uid) {
$users[] = $DB->get_record("user", ["id"=>$uid]); $users[] = $DB->get_record("user", ["id" => $uid]);
} }
return $users; return $users;
@ -412,7 +407,7 @@ class studyplan {
$uids = array_merge($uids, $ulist); $uids = array_merge($uids, $ulist);
foreach ($ulist as $uid) { foreach ($ulist as $uid) {
$users[] = $DB->get_record("user", ["id"=>$uid]); $users[] = $DB->get_record("user", ["id" => $uid]);
} }
// Next het users linked though cohort. // Next het users linked though cohort.
@ -449,9 +444,9 @@ class studyplan {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan'), "description" => new \external_value(PARAM_TEXT, 'description of studyplan'),
"idnumber"=> new \external_value(PARAM_TEXT, 'idnumber of curriculum'), "idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'),
"pages" => new \external_multiple_structure(studyplanpage::user_structure()), "pages" => new \external_multiple_structure(studyplanpage::user_structure()),
"aggregation_info" => aggregator::basic_structure(), "aggregation_info" => aggregator::basic_structure(),
], 'Studyplan with user info', $value); ], 'Studyplan with user info', $value);
@ -502,16 +497,16 @@ class studyplan {
public static function export_structure() { public static function export_structure() {
return new \external_single_structure([ return new \external_single_structure([
"format" => new \external_value(PARAM_TEXT, 'format of studyplan export'), "format" => new \external_value(PARAM_TEXT, 'format of studyplan export'),
"content"=> new \external_value(PARAM_TEXT, 'exported studyplan content'), "content" => new \external_value(PARAM_TEXT, 'exported studyplan content'),
], 'Exported studyplan'); ], 'Exported studyplan');
} }
public function export_plan() { public function export_plan() {
$model = $this->export_model(); $model = $this->export_model();
$json = json_encode([ $json = json_encode([
"type"=>"studyplan", "type" => "studyplan",
"version"=>2.0, "version" => 2.0,
"studyplan"=>$model "studyplan" => $model
], \JSON_PRETTY_PRINT); ], \JSON_PRETTY_PRINT);
return [ "format" => "application/json", "content" => $json]; return [ "format" => "application/json", "content" => $json];
} }
@ -538,7 +533,9 @@ class studyplan {
} }
public static function import_studyplan($content, $format="application/json", $contextid=1) { public static function import_studyplan($content, $format="application/json", $contextid=1) {
if ($format != "application/json") { return false;} if ($format != "application/json") {
return false;
}
$content = json_decode($content, true); $content = json_decode($content, true);
if ($content["type"] == "studyplan" && $content["version"] >= 2.0) { if ($content["type"] == "studyplan" && $content["version"] >= 2.0) {
@ -561,7 +558,9 @@ class studyplan {
} }
public function import_pages($content, $format="application/json") { public function import_pages($content, $format="application/json") {
if ($format != "application/json") { return false;} if ($format != "application/json") {
return false;
}
$content = json_decode($content, true); $content = json_decode($content, true);
if ($content["version"] >= 2.0) { if ($content["version"] >= 2.0) {
if ($content["type"] == "studyplanpage") { if ($content["type"] == "studyplanpage") {
@ -577,7 +576,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. $this->pages(); // Make sure the page cache is initialized, since we will be adding to it.
foreach ($model as $p) { foreach ($model as $p) {
$p["studyplan_id"] = $this->id(); $p["studyplan_id"] = $this->id();
$page = studyplanpage::add($p); $page = studyplanpage::add($p);
@ -607,7 +606,7 @@ class studyplan {
} }
public function has_csync_changed() { public function has_csync_changed() {
return ($this->r->csync_flag > 0)?true:false; return ($this->r->csync_flag > 0) ? true : false;
} }
/** /**
@ -624,7 +623,7 @@ class studyplan {
AND i.course_id = :courseid"; AND i.course_id = :courseid";
$count = $DB->get_field_sql($sql, ["courseid" => $courseid, "planid" => $this->id]); $count = $DB->get_field_sql($sql, ["courseid" => $courseid, "planid" => $this->id]);
return ($count > 0)?true:false; return ($count > 0) ? true : false;
} }
/** /**
@ -682,10 +681,9 @@ class studyplan {
AND i.badge_id = :badgeid"; AND i.badge_id = :badgeid";
$count = $DB->get_field_sql($sql, ["badgeid" => $badgeid, "planid" => $this->id]); $count = $DB->get_field_sql($sql, ["badgeid" => $badgeid, "planid" => $this->id]);
return ($count > 0)?true:false; return ($count > 0) ? true : false;
} }
} }

View File

@ -26,11 +26,9 @@ require_once($CFG->libdir.'/externallib.php');
class studyplanpage { class studyplanpage {
const TABLE = "local_treestudyplan_page"; const TABLE = "local_treestudyplan_page";
private static $CACHE = []; private static $CACHE = [];
private $r; // Holds database record. private $r; // Holds database record.
private $id; private $id;
private $studyplan; private $studyplan;
@ -81,7 +79,7 @@ class studyplanpage {
public function enddate() { public function enddate() {
if ($this->r->enddate && strlen($this->r->enddate) > 0) { if ($this->r->enddate && strlen($this->r->enddate) > 0) {
return new \DateTime($this->r->enddate); return new \DateTime($this->r->enddate);
} else{ } 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")); return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
} }
@ -92,9 +90,9 @@ class studyplanpage {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan page'), "id" => new \external_value(PARAM_INT, 'id of studyplan page'),
"fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan page'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan page'),
"periods" => new \external_value(PARAM_INT, 'number of periods in studyplan page'), "periods" => new \external_value(PARAM_INT, 'number of periods in studyplan page'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan page'), "description" => new \external_value(PARAM_TEXT, 'description of studyplan page'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan'), "startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'), "enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'),
"perioddesc" => period::page_structure(), "perioddesc" => period::page_structure(),
@ -118,8 +116,8 @@ class studyplanpage {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan page'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan page'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan page'), "description" => new \external_value(PARAM_TEXT, 'description of studyplan page'),
"periods" => new \external_value(PARAM_INT, 'number of periods in studyplan page'), "periods" => new \external_value(PARAM_INT, 'number of periods in studyplan page'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan page'), "startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan page'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan page'), "enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan page'),
@ -171,7 +169,7 @@ class studyplanpage {
} }
$id = $DB->insert_record(self::TABLE, $info); $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) { public function edit($fields) {
@ -216,8 +214,8 @@ class studyplanpage {
return new \external_single_structure([ return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan page'), "id" => new \external_value(PARAM_INT, 'id of studyplan page'),
"fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan page'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan page'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan page'), "description" => new \external_value(PARAM_TEXT, 'description of studyplan page'),
"periods" => new \external_value(PARAM_INT, 'number of slots in studyplan page'), "periods" => new \external_value(PARAM_INT, 'number of slots in studyplan page'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan page'), "startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan page'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan page'), "enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan page'),
@ -273,7 +271,7 @@ class studyplanpage {
'description' => $this->r->description, 'description' => $this->r->description,
'pages' => $this->r->pages, 'pages' => $this->r->pages,
'startdate' => $this->r->startdate, 'startdate' => $this->r->startdate,
'enddate' => empty($this->r->enddate)?null:$this->r->enddate, 'enddate' => empty($this->r->enddate) ? null : $this->r->enddate,
]); ]);
// Next, copy the studylines. // Next, copy the studylines.
@ -302,16 +300,16 @@ class studyplanpage {
public static function export_structure() { public static function export_structure() {
return new \external_single_structure([ return new \external_single_structure([
"format" => new \external_value(PARAM_TEXT, 'format of studyplan export'), "format" => new \external_value(PARAM_TEXT, 'format of studyplan export'),
"content"=> new \external_value(PARAM_TEXT, 'exported studyplan content'), "content" => new \external_value(PARAM_TEXT, 'exported studyplan content'),
], 'Exported studyplan'); ], 'Exported studyplan');
} }
public function export_page() { public function export_page() {
$model = $this->export_model(); $model = $this->export_model();
$json = json_encode([ $json = json_encode([
"type"=>"studyplanpage", "type" => "studyplanpage",
"version"=>2.0, "version" => 2.0,
"page"=>$model "page" => $model
], \JSON_PRETTY_PRINT); ], \JSON_PRETTY_PRINT);
return [ "format" => "application/json", "content" => $json]; return [ "format" => "application/json", "content" => $json];
} }
@ -324,7 +322,7 @@ class studyplanpage {
$periods = intval($model["periods"]); $periods = intval($model["periods"]);
// First line. // First line.
$csv = "\"\""; $csv = "\"\"";
for($i = 1; $i <= $periods; $i++) { for ($i = 1; $i <= $periods; $i++) {
$name = $plist[$i]->shortname(); $name = $plist[$i]->shortname();
$csv .= ", \"{$name}\""; $csv .= ", \"{$name}\"";
} }
@ -333,7 +331,7 @@ class studyplanpage {
foreach ($model["studylines"] as $line) { 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; $maxlines = 1;
for($i = 1; $i <= $periods; $i++) { for ($i = 1; $i <= $periods; $i++) {
if (count($line["slots"]) > $i) { if (count($line["slots"]) > $i) {
$ct = 0; $ct = 0;
foreach ($line["slots"][$i][studyline::SLOTSET_COMPETENCY] as $itm) { foreach ($line["slots"][$i][studyline::SLOTSET_COMPETENCY] as $itm) {
@ -348,9 +346,9 @@ class studyplanpage {
} }
} }
for($lct = 0; $lct < $maxlines; $lct++) { for ($lct = 0; $lct < $maxlines; $lct++) {
$csv .= "\"{$line["name"]}\""; $csv .= "\"{$line["name"]}\"";
for($i = 1; $i <= $periods; $i++) { for ($i = 1; $i <= $periods; $i++) {
$filled = false; $filled = false;
if (count($line["slots"]) > $i) { if (count($line["slots"]) > $i) {
$ct = 0; $ct = 0;
@ -365,7 +363,7 @@ class studyplanpage {
if ($g["selected"]) { if ($g["selected"]) {
if ($first) { if ($first) {
$first = false; $first = false;
} else{ } else {
$csv .= "\r\n"; $csv .= "\r\n";
} }
$csv .= "- ".str_replace('"', '\'', $g["name"]); $csv .= "- ".str_replace('"', '\'', $g["name"]);
@ -393,9 +391,9 @@ class studyplanpage {
public function export_studylines() { public function export_studylines() {
$model = $this->export_studylines_model(); $model = $this->export_studylines_model();
$json = json_encode([ $json = json_encode([
"type"=>"studylines", "type" => "studylines",
"version"=>2.0, "version" => 2.0,
"studylines"=>$model, "studylines" => $model,
], \JSON_PRETTY_PRINT); ], \JSON_PRETTY_PRINT);
return [ "format" => "application/json", "content" => $json]; return [ "format" => "application/json", "content" => $json];
} }
@ -403,14 +401,13 @@ class studyplanpage {
public function export_periods() { public function export_periods() {
$model = period::page_model($this); $model = period::page_model($this);
$json = json_encode([ $json = json_encode([
"type"=>"periods", "type" => "periods",
"version"=>2.0, "version" => 2.0,
"perioddesc"=>$model, "perioddesc" => $model,
], \JSON_PRETTY_PRINT); ], \JSON_PRETTY_PRINT);
return [ "format" => "application/json", "content" => $json]; return [ "format" => "application/json", "content" => $json];
} }
public function export_model() { public function export_model() {
$model = [ $model = [
'fullname' => $this->r->fullname, 'fullname' => $this->r->fullname,
@ -434,9 +431,10 @@ class studyplanpage {
return $lines; return $lines;
} }
public function import_periods($content, $format="application/json") { public function import_periods($content, $format="application/json") {
if ($format != "application/json") { return false;} if ($format != "application/json") {
return false;
}
$content = json_decode($content, true); $content = json_decode($content, true);
if ($content["type"] == "periods" && $content["version"] >= 2.0) { if ($content["type"] == "periods" && $content["version"] >= 2.0) {
return $this->import_periods_model($content["perioddesc"]); return $this->import_periods_model($content["perioddesc"]);
@ -448,7 +446,9 @@ class studyplanpage {
} }
public function import_studylines($content, $format="application/json") { public function import_studylines($content, $format="application/json") {
if ($format != "application/json") { return false;} if ($format != "application/json") {
return false;
}
$content = json_decode($content, true); $content = json_decode($content, true);
if ($content["type"] == "studylines" && $content["version"] >= 2.0) { if ($content["type"] == "studylines" && $content["version"] >= 2.0) {
return $this->import_studylines_model($content["studylines"]); return $this->import_studylines_model($content["studylines"]);

View File

@ -29,14 +29,11 @@ require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/course/modlib.php'); require_once($CFG->dirroot.'/course/modlib.php');
class studyplanservice extends \external_api {
class studyplanservice extends \external_api
{
const CAP_EDIT = "local/treestudyplan:editstudyplan"; const CAP_EDIT = "local/treestudyplan:editstudyplan";
const CAP_VIEW = "local/treestudyplan:viewuserreports"; const CAP_VIEW = "local/treestudyplan:viewuserreports";
/************************ /************************
* * * *
* list_studyplans * * list_studyplans *
@ -128,9 +125,9 @@ class studyplanservice extends \external_api
public static function add_studyplan_parameters() { public static function add_studyplan_parameters() {
return new \external_function_parameters( [ return new \external_function_parameters( [
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"idnumber"=> new \external_value(PARAM_TEXT, 'idnumber of studyplan'), "idnumber" => new \external_value(PARAM_TEXT, 'idnumber of studyplan'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan'), "description" => new \external_value(PARAM_TEXT, 'description of studyplan'),
"periods" => new \external_value(PARAM_INT, 'number of periods in studyplan'), "periods" => new \external_value(PARAM_INT, 'number of periods in studyplan'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan'), "startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'), "enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'),
@ -156,7 +153,7 @@ class studyplanservice extends \external_api
'description' => $description, 'description' => $description,
'periods' => $periods, 'periods' => $periods,
'startdate' => $startdate, 'startdate' => $startdate,
'enddate' => empty($enddate)?null:$enddate, 'enddate' => empty($enddate) ? null : $enddate,
'aggregation' => $aggregation, 'aggregation' => $aggregation,
'aggregation_config' => $aggregationconfig, 'aggregation_config' => $aggregationconfig,
'context_id' => $contextid, 'context_id' => $contextid,
@ -174,9 +171,9 @@ class studyplanservice extends \external_api
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of studyplan'), "id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"idnumber"=> new \external_value(PARAM_TEXT, 'idnumber of studyplan'), "idnumber" => new \external_value(PARAM_TEXT, 'idnumber of studyplan'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan'), "description" => new \external_value(PARAM_TEXT, 'description of studyplan'),
"periods" => new \external_value(PARAM_INT, 'number of periods in studyplan'), "periods" => new \external_value(PARAM_INT, 'number of periods in studyplan'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan'), "startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'), "enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'),
@ -193,7 +190,7 @@ class studyplanservice extends \external_api
public static function edit_studyplan($id, $name, $shortname, $idnumber, $description, $periods, $startdate, $enddate, $aggregation="bistate", $aggregationconfig='', $contextid=0) { public static function edit_studyplan($id, $name, $shortname, $idnumber, $description, $periods, $startdate, $enddate, $aggregation="bistate", $aggregationconfig='', $contextid=0) {
// Validate access in the intended context. // Validate access in the intended context.
$context = webservicehelper::find_context($contextid); $context = webservicehelper::find_context($contextid);
webservicehelper::require_capabilities(self::CAP_EDIT, $context, false); // do not validate the context in this case, just check the permissions. webservicehelper::require_capabilities(self::CAP_EDIT, $context, false); // Do not validate the context in this case, just check the permissions.
$o = studyplan::findById($id); $o = studyplan::findById($id);
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
@ -247,8 +244,8 @@ class studyplanservice extends \external_api
return new \external_function_parameters( [ return new \external_function_parameters( [
"page_id" => new \external_value(PARAM_INT, 'id of studyplan to add line to'), "page_id" => new \external_value(PARAM_INT, 'id of studyplan to add line to'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'), "name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
"shortname"=> new \external_value(PARAM_TEXT, 'idnumber of studyline'), "shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color"=> new \external_value(PARAM_TEXT, 'description of studyline'), "color" => new \external_value(PARAM_TEXT, 'description of studyline'),
"sequence" => new \external_value(PARAM_INT, 'sequence of studyline'), "sequence" => new \external_value(PARAM_INT, 'sequence of studyline'),
] ); ] );
} }
@ -282,8 +279,8 @@ class studyplanservice extends \external_api
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of studyline'), "id" => new \external_value(PARAM_INT, 'id of studyline'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'), "name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
"shortname"=> new \external_value(PARAM_TEXT, 'idnumber of studyline'), "shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color"=> new \external_value(PARAM_TEXT, 'description of studyline'), "color" => new \external_value(PARAM_TEXT, 'description of studyline'),
] ); ] );
} }
@ -305,7 +302,6 @@ class studyplanservice extends \external_api
} }
/************************ /************************
* * * *
* delete_studyline * * delete_studyline *
@ -381,7 +377,6 @@ class studyplanservice extends \external_api
return studyitem::editor_structure(); return studyitem::editor_structure();
} }
public static function get_studyitem($id) { public static function get_studyitem($id) {
$o = studyitem::findById($id); $o = studyitem::findById($id);
webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $o->context()); webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $o->context());
@ -400,7 +395,7 @@ class studyplanservice extends \external_api
"line_id" => new \external_value(PARAM_INT, 'id of related study line'), "line_id" => new \external_value(PARAM_INT, 'id of related study line'),
"type" => new \external_value(PARAM_TEXT, 'type of study item'), "type" => new \external_value(PARAM_TEXT, 'type of study item'),
"details" => new \external_single_structure([ "details" => new \external_single_structure([
"conditions"=> new \external_value(PARAM_TEXT, 'conditions for completion', VALUE_OPTIONAL), "conditions" => new \external_value(PARAM_TEXT, 'conditions for completion', VALUE_OPTIONAL),
"competency_id" => new \external_value(PARAM_INT, 'id of referenced competency', VALUE_OPTIONAL), "competency_id" => new \external_value(PARAM_INT, 'id of referenced competency', VALUE_OPTIONAL),
"course_id" => new \external_value(PARAM_INT, 'id of referenced course', VALUE_OPTIONAL), "course_id" => new \external_value(PARAM_INT, 'id of referenced course', VALUE_OPTIONAL),
"badge_id" => new \external_value(PARAM_INT, 'id of referenced badge', VALUE_OPTIONAL), "badge_id" => new \external_value(PARAM_INT, 'id of referenced badge', VALUE_OPTIONAL),
@ -424,10 +419,10 @@ class studyplanservice extends \external_api
//'conditions' => $conditions,. //'conditions' => $conditions,.
'slot' => $slot, 'slot' => $slot,
'layer' => $layer, 'layer' => $layer,
'competency_id' => isset($details['competency_id'])?$details['competency_id']:null, 'competency_id' => isset($details['competency_id']) ? $details['competency_id'] : null,
'course_id' => isset($details['course_id'])?$details['course_id']:null, 'course_id' => isset($details['course_id']) ? $details['course_id'] : null,
'badge_id' => isset($details['badge_id'])?$details['badge_id']:null, 'badge_id' => isset($details['badge_id']) ? $details['badge_id'] : null,
'continuation_id' => isset($details['continuation_id'])?$details['continuation_id']:null, 'continuation_id' => isset($details['continuation_id']) ? $details['continuation_id'] : null,
]); ]);
return $o->editor_model(); return $o->editor_model();
} }
@ -441,7 +436,7 @@ class studyplanservice extends \external_api
public static function edit_studyitem_parameters() { public static function edit_studyitem_parameters() {
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of study item'), "id" => new \external_value(PARAM_INT, 'id of study item'),
"conditions"=> new \external_value(PARAM_TEXT, 'conditions for completion'), "conditions" => new \external_value(PARAM_TEXT, 'conditions for completion'),
"continuation_id" => new \external_value(PARAM_INT, 'id of continued item', VALUE_DEFAULT), "continuation_id" => new \external_value(PARAM_INT, 'id of continued item', VALUE_DEFAULT),
]); ]);
} }
@ -499,7 +494,6 @@ class studyplanservice extends \external_api
return studyitem::reorder($resequence)->model(); return studyitem::reorder($resequence)->model();
} }
/************************ /************************
* * * *
* delete_studyitem * * delete_studyitem *
@ -632,7 +626,6 @@ class studyplanservice extends \external_api
// Do sanity checks. // Do sanity checks.
\external_api::validate_context($coursecontext); \external_api::validate_context($coursecontext);
// Check correct capabilities. // Check correct capabilities.
if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($itemid)->context()) || if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($itemid)->context()) ||
is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) { is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) {
@ -699,8 +692,8 @@ class studyplanservice extends \external_api
$scale->load_items(); $scale->load_items();
if ($scale) { if ($scale) {
$gradecfg = $DB->get_record("local_treestudyplan_gradecfg", ["scale_id"=>$scale->id]); $gradecfg = $DB->get_record("local_treestudyplan_gradecfg", ["scale_id" => $scale->id]);
$scalepass = ($gradecfg)?$gradecfg->min_completed:0; $scalepass = ($gradecfg) ? $gradecfg->min_completed : 0;
$scalemax = count($scale->scale_items); $scalemax = count($scale->scale_items);
// Find studyline id's. // Find studyline id's.
@ -731,10 +724,14 @@ class studyplanservice extends \external_api
$gi->gradepass = $scalepass; $gi->gradepass = $scalepass;
// Update grade_item. // Update grade_item.
$result = $gi->update("local/treestudyplan"); // update, signalling with our signature and bulkupdate. $result = $gi->update("local/treestudyplan"); // Update, signalling with our signature and bulkupdate.
$debug = ""; $debug = "";
if ($result) { $updated = "converted";} else { $updated = "error";} if ($result) {
$updated = "converted";
} else {
$updated = "error";
}
// Next update the activity's table if it has a grade field. // Next update the activity's table if it has a grade field.
// Grade is generally set to the negative scale id if it is a scale. // Grade is generally set to the negative scale id if it is a scale.
@ -745,8 +742,7 @@ class studyplanservice extends \external_api
$gradevalue = intval(0-($scale->id)); $gradevalue = intval(0-($scale->id));
try { try {
$DB->set_field($tablename, $fieldname, $gradevalue, ["id" => $gi->iteminstance]); $DB->set_field($tablename, $fieldname, $gradevalue, ["id" => $gi->iteminstance]);
} } catch (\dml_exception $x) {
catch(\dml_exception $x) {
$updated = "fail"; $updated = "fail";
$debug = strval($x); $debug = strval($x);
} }
@ -903,11 +899,10 @@ class studyplanservice extends \external_api
if ($format == "csv") { if ($format == "csv") {
// FIXME: Make sure this webservice function gets called for the page instead of the studyplan. // FIXME: Make sure this webservice function gets called for the page instead of the studyplan.
return $plan->pages()[0]->export_page_csv(); return $plan->pages()[0]->export_page_csv();
} else{ } else {
return $plan->export_plan(); return $plan->export_plan();
} }
} } catch (\webservice_access_exception $x) {
catch(\webservice_access_exception $x) {
return [ "format" => "", "content" => ""]; return [ "format" => "", "content" => ""];
} }
} }
@ -930,8 +925,7 @@ class studyplanservice extends \external_api
$plan = studyplan::findById($studyplanid); $plan = studyplan::findById($studyplanid);
// FIXME: Make sure this gets called for the page instead of the studyplan. // FIXME: Make sure this gets called for the page instead of the studyplan.
return $plan->pages()[0]->export_studylines(); return $plan->pages()[0]->export_studylines();
} } catch (\webservice_access_exception $x) {
catch(\webservice_access_exception $x) {
return [ "format" => "", "content" => ""]; return [ "format" => "", "content" => ""];
} }
} }
@ -962,8 +956,7 @@ class studyplanservice extends \external_api
$result = studyplan::import_studyplan($content, $format, $contextid); $result = studyplan::import_studyplan($content, $format, $contextid);
return (new success($result, "During study plan import"))->model(); return (new success($result, "During study plan import"))->model();
} } catch (\webservice_access_exception $x) {
catch(\webservice_access_exception $x) {
return success::fail("Access denied")->model(); return success::fail("Access denied")->model();
} }
} }
@ -990,14 +983,12 @@ class studyplanservice extends \external_api
// FIXME: Make sure this gets called for the page instead of the studyplan. // FIXME: Make sure this gets called for the page instead of the studyplan.
// Once proper page management is implemented. // Once proper page management is implemented.
$result = $plan->pages()[0]->import_studylines($content, $format); $result = $plan->pages()[0]->import_studylines($content, $format);
return ($result?success::success():success::fail())->model(); return ($result ? success::success() : success::fail())->model();
} } catch (\webservice_access_exception $x) {
catch(\webservice_access_exception $x) {
return success::fail("Access denied")->model(); return success::fail("Access denied")->model();
} }
} }
/******************************************************** /********************************************************
* * * *
* Read and write course module title and desc * * Read and write course module title and desc *
@ -1030,7 +1021,7 @@ class studyplanservice extends \external_api
// Check the course exists. // Check the course exists.
$course = \get_course($cm->course); $course = \get_course($cm->course);
// Require_login. // Require_login.
require_login($course, false, $cm); // needed to setup proper $COURSE. require_login($course, false, $cm); // Needed to setup proper $COURSE.
// Get needed info to create the correct form. // Get needed info to create the correct form.
list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course); list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course);
@ -1046,7 +1037,7 @@ class studyplanservice extends \external_api
foreach (explode("&", $formdata) as $pair) { foreach (explode("&", $formdata) as $pair) {
$p = explode("=", $pair, 2); $p = explode("=", $pair, 2);
$k = urldecode($p[0]); $k = urldecode($p[0]);
$v = (count($p)>1)?urldecode($p[1]):""; $v = (count($p)>1) ? urldecode($p[1]) : "";
if (strpos($k, "[") > 0 && strpos($k, "]") == strlen($k) -1) { if (strpos($k, "[") > 0 && strpos($k, "]") == strlen($k) -1) {
// Its a bracketet field, like filename[text] which should be separated and put into a named array. // Its a bracketet field, like filename[text] which should be separated and put into a named array.
@ -1086,7 +1077,7 @@ class studyplanservice extends \external_api
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of study item'), "id" => new \external_value(PARAM_INT, 'id of study item'),
"fullname" => new \external_value(PARAM_TEXT, 'Full name of period'), "fullname" => new \external_value(PARAM_TEXT, 'Full name of period'),
"shortname"=> new \external_value(PARAM_TEXT, 'Short name of period'), "shortname" => new \external_value(PARAM_TEXT, 'Short name of period'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of period'), "startdate" => new \external_value(PARAM_TEXT, 'start date of period'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of period'), "enddate" => new \external_value(PARAM_TEXT, 'end date of period'),
]); ]);
@ -1101,7 +1092,6 @@ class studyplanservice extends \external_api
$p = period::findById($id); $p = period::findById($id);
webservicehelper::require_capabilities(self::CAP_EDIT, $p->page()->studyplan()->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $p->page()->studyplan()->context());
$p->edit([ $p->edit([
'fullname' => $fullname, 'fullname' => $fullname,
'shortname' => $shortname, 'shortname' => $shortname,
@ -1121,8 +1111,8 @@ class studyplanservice extends \external_api
public static function course_period_timing_parameters() { public static function course_period_timing_parameters() {
return new \external_function_parameters( [ return new \external_function_parameters( [
"period_id" => new \external_value(PARAM_INT, 'Period number within page'), "period_id" => new \external_value(PARAM_INT, 'Period number within page'),
"course_id"=> new \external_value(PARAM_INT, 'Id of course to adjust dates for'), "course_id" => new \external_value(PARAM_INT, 'Id of course to adjust dates for'),
"span"=> new \external_value(PARAM_INT, 'Period span (default 1)', VALUE_DEFAULT), "span" => new \external_value(PARAM_INT, 'Period span (default 1)', VALUE_DEFAULT),
]); ]);
} }

View File

@ -22,7 +22,6 @@
namespace local_treestudyplan; namespace local_treestudyplan;
class success { class success {
private $success; private $success;
private $msg; private $msg;
@ -36,7 +35,7 @@ class success {
} }
public function __construct($success, $msg) { public function __construct($success, $msg) {
$this->success = ($success)?true:false; $this->success = ($success) ? true : false;
$this->msg = $msg; $this->msg = $msg;
} }
@ -48,7 +47,7 @@ class success {
} }
public function model() { public function model() {
return ["success" => $this->success, "msg"=> $this->msg]; return ["success" => $this->success, "msg" => $this->msg];
} }
public function successful() { public function successful() {
@ -60,5 +59,4 @@ class success {
} }
} }

View File

@ -25,7 +25,6 @@ namespace local_treestudyplan;
class teachingfinder { class teachingfinder {
const TABLE = "local_treestudyplan_teachers"; const TABLE = "local_treestudyplan_teachers";
public static function list_my_plans() { public static function list_my_plans() {
global $USER, $DB; global $USER, $DB;
$userid = $USER->id; $userid = $USER->id;
@ -43,7 +42,6 @@ class teachingfinder {
return $list; return $list;
} }
/** /**
* Find The active studyplans where the specified user is a teacher * Find The active studyplans where the specified user is a teacher
* (Has the mod/assign::grade capability in one of the linked courses) * (Has the mod/assign::grade capability in one of the linked courses)
@ -70,7 +68,7 @@ class teachingfinder {
$linked = false; $linked = false;
foreach ($courseids as $cid) { foreach ($courseids as $cid) {
$coursecontext = \context_course::instance($cid); $coursecontext = \context_course::instance($cid);
if (is_enrolled($coursecontext, $userid, 'mod/assign:grade')) { if (is_enrolled($coursecontext, $userid, 'mod/assign:grade')) {
$linked = true; $linked = true;
break; // No need to search further. break; // No need to search further.
@ -84,14 +82,14 @@ class teachingfinder {
} }
// 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]); $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(); $now = time();
foreach ($list as $pageid) { foreach ($list as $pageid) {
// Retrieve the studyplan id from the page. // Retrieve the studyplan id from the page.
//TODO: Change this when page management is implemented to return the page instead of the plan. //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" => $pageid]); $planid = $DB->get_field("local_treestudyplan_page", "studyplan_id", ["id" => $pageid]);
$DB->insert_record(self::TABLE, ["teacher_id"=>$userid, "studyplan_id"=>$planid, "update_time"=>$now]); $DB->insert_record(self::TABLE, ["teacher_id" => $userid, "studyplan_id" => $planid, "update_time" => $now]);
} }
return $list; return $list;
@ -109,5 +107,4 @@ class teachingfinder {
return (int)($r->update_time); return (int)($r->update_time);
} }
} }

View File

@ -71,7 +71,6 @@ if (!empty($options["all"])) {
$plans = studyplan::find_by_shortname($options["studyplan"]); $plans = studyplan::find_by_shortname($options["studyplan"]);
} }
$generator = new gradegenerator(); $generator = new gradegenerator();
$generator->fromFile($options["file"]); $generator->fromFile($options["file"]);

View File

@ -56,7 +56,6 @@ list($options, $unrecognised) = cli_get_params([
'd' => 'dryrun' 'd' => 'dryrun'
]); ]);
if ($unrecognised) { if ($unrecognised) {
$unrecognised = implode(PHP_EOL . ' ', $unrecognised); $unrecognised = implode(PHP_EOL . ' ', $unrecognised);
cli_error(get_string('cliunknowoption', 'core_admin', $unrecognised)); cli_error(get_string('cliunknowoption', 'core_admin', $unrecognised));
@ -85,16 +84,14 @@ $authplugin->sync_roles($user);
login_attempt_valid($user); login_attempt_valid($user);
complete_user_login($user); complete_user_login($user);
////////////////////////////////. ////////////////////////////////.
if (empty($options['studyplan']) && empty($options["all"])) { if (empty($options['studyplan']) && empty($options["all"])) {
cli_error('Missing mandatory argument studyplan.', 2); cli_error('Missing mandatory argument studyplan.', 2);
} }
if (!empty($options["all"])) { if (!empty($options["all"])) {
$plans = studyplan::find_all(); $plans = studyplan::find_all();
} else { } else {
$plans = studyplan::find_by_shortname($options["studyplan"]); $plans = studyplan::find_by_shortname($options["studyplan"]);
} }
@ -102,7 +99,6 @@ if (!empty($options["all"])) {
$generator = new gradegenerator(); $generator = new gradegenerator();
$generator->fromFile($options["file"]); $generator->fromFile($options["file"]);
$assignments = []; $assignments = [];
cli_writeln(count($plans)." studyplans found:"); cli_writeln(count($plans)." studyplans found:");
@ -116,7 +112,8 @@ foreach ($plans as $plan) {
cli_writeln(" ** {$line->name()} **"); cli_writeln(" ** {$line->name()} **");
$items = studyitem::find_studyline_children($line); $items = studyitem::find_studyline_children($line);
foreach ($items as $item) { 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(); $courseinfo = $item->getcourseinfo();
cli_writeln(" # {$courseinfo->shortname()}"); cli_writeln(" # {$courseinfo->shortname()}");

View File

@ -67,5 +67,4 @@ $capabilities = [
), ),
], ],
]; ];

View File

@ -45,7 +45,7 @@ $services = [
'local_treestudyplan_import_studyplan', 'local_treestudyplan_import_studyplan',
], ],
'requiredcapability' => 'local/treestudyplan:configure', 'requiredcapability' => 'local/treestudyplan:configure',
'shortname'=> 'local_treestudyplan_cohorts', 'shortname' => 'local_treestudyplan_cohorts',
'restrictedusers' => 0, 'restrictedusers' => 0,
'enabled' => 0, 'enabled' => 0,
'ajax' => true, 'ajax' => true,

View File

@ -49,7 +49,6 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
if ($oldversion < 2020120301) { if ($oldversion < 2020120301) {
// Define field studyitem_id to be added to local_treestudyplan_gradeinc. // Define field studyitem_id to be added to local_treestudyplan_gradeinc.
$table = new xmldb_table('local_treestudyplan_gradeinc'); $table = new xmldb_table('local_treestudyplan_gradeinc');
$field = new xmldb_field('studyitem_id', XMLDB_TYPE_INTEGER, '20', null, null, null, null, 'include'); $field = new xmldb_field('studyitem_id', XMLDB_TYPE_INTEGER, '20', null, null, null, null, 'include');
@ -64,7 +63,6 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
// Launch add key studyitem_id-id. // Launch add key studyitem_id-id.
$dbman->add_key($table, $key); $dbman->add_key($table, $key);
// Treestudyplan savepoint reached. // Treestudyplan savepoint reached.
upgrade_plugin_savepoint(true, 2020120301, 'local', 'treestudyplan'); upgrade_plugin_savepoint(true, 2020120301, 'local', 'treestudyplan');
} }
@ -156,7 +154,6 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2021082601, 'local', 'treestudyplan'); upgrade_plugin_savepoint(true, 2021082601, 'local', 'treestudyplan');
} }
if ($oldversion < 2021082700) { if ($oldversion < 2021082700) {
$table = new xmldb_table('local_treestudyplan_gradecfg'); $table = new xmldb_table('local_treestudyplan_gradecfg');
@ -262,7 +259,6 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
// Launch drop key studyplan_id-id. // Launch drop key studyplan_id-id.
$dbman->drop_key($table, $key); $dbman->drop_key($table, $key);
/****** /******
* Create the page table and copy data from treestudyplan there * Create the page table and copy data from treestudyplan there
* Also re-link the studylines to the newly created page instead of the studyplan * Also re-link the studylines to the newly created page instead of the studyplan
@ -306,7 +302,7 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
foreach ($lines as $l) { foreach ($lines as $l) {
$lo = [ $lo = [
"id" => $l->id, "id" => $l->id,
"page_id"=> $pageid, "page_id" => $pageid,
]; ];
$DB->update_record("local_treestudyplan_line", $lo); $DB->update_record("local_treestudyplan_line", $lo);
} }
@ -342,7 +338,6 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
// Launch add key page_id-id. // Launch add key page_id-id.
$dbman->add_key($table, $key); $dbman->add_key($table, $key);
/*** /***
* Create Period table and make a period record for all studyplan periods * Create Period table and make a period record for all studyplan periods
*/ */
@ -363,7 +358,6 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
$table->add_key('page_id-id', XMLDB_KEY_FOREIGN, ['page_id'], 'local_treestudyplan_page', ['id']); $table->add_key('page_id-id', XMLDB_KEY_FOREIGN, ['page_id'], 'local_treestudyplan_page', ['id']);
// Conditionally launch create table for local_treestudyplan_period. // Conditionally launch create table for local_treestudyplan_period.
if (!$dbman->table_exists($table)) { if (!$dbman->table_exists($table)) {
$dbman->create_table($table); $dbman->create_table($table);
@ -379,15 +373,15 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
if ($yend < $ystart) { if ($yend < $ystart) {
// If no end time is given, assume a year duration for period calculations. // If no end time is given, assume a year duration for period calculations.
$ydelta = (365*24*60*60)/$pcount; $ydelta = (365*24*60*60)/$pcount;
} else{ } else {
$ydelta = $yend - $ystart; $ydelta = $yend - $ystart;
} }
$ptime = $ydelta / $pcount; $ptime = $ydelta / $pcount;
for($i=0; $i < $pcount; $i++) { for ($i=0; $i < $pcount; $i++) {
$pnum = $i+1; $pnum = $i+1;
$pstart = $ystart + ($i*$ptime); $pstart = $ystart + ($i*$ptime);
$pend = ($pstart + $ptime)-(24*60*60); // minus one day. $pend = ($pstart + $ptime)-(24*60*60); // Minus one day.
$o = [ "page_id" => $r->id, $o = [ "page_id" => $r->id,
"period" => $pnum, "period" => $pnum,
@ -471,7 +465,6 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
// Treestudyplan savepoint reached. // Treestudyplan savepoint reached.
upgrade_plugin_savepoint(true, 2023080900, 'local', 'treestudyplan'); upgrade_plugin_savepoint(true, 2023080900, 'local', 'treestudyplan');
} }
@ -494,6 +487,5 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2023082100, 'local', 'treestudyplan'); upgrade_plugin_savepoint(true, 2023082100, 'local', 'treestudyplan');
} }
return true; return true;
} }

View File

@ -26,7 +26,7 @@ require_once("./lib.php");
require_once($CFG->libdir.'/weblib.php'); require_once($CFG->libdir.'/weblib.php');
require_once($CFG->dirroot.'/local/treestudyplan/classes/reportinvite_form.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); $update = optional_param('update', 0, PARAM_INT);
$resend = optional_param('resend', 0, PARAM_INT); $resend = optional_param('resend', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT); $delete = optional_param('delete', 0, PARAM_INT);
@ -45,7 +45,6 @@ if ($update > 0) {
$PAGE->set_heading(get_string('invite_desc_new', 'local_treestudyplan')); $PAGE->set_heading(get_string('invite_desc_new', 'local_treestudyplan'));
} }
// Check if user has capability to manage study plan units. // Check if user has capability to manage study plan units.
require_login(); require_login();
@ -59,8 +58,7 @@ if (!empty($add)) {
} else if (!empty($update)) { } else if (!empty($update)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $update)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $update));
$data->update = $update; $data->update = $update;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id) {
{
print_error('invalidaction'); print_error('invalidaction');
exit; exit;
} }
@ -68,25 +66,20 @@ if (!empty($add)) {
} else if (!empty($resend)) { } else if (!empty($resend)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend));
$data->resend = $resend; $data->resend = $resend;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id) {
{
print_error('invalidaction'); print_error('invalidaction');
exit; exit;
} }
// Do some resending of an invitation. // Do some resending of an invitation.
local_treestudyplan_send_invite($data->id); local_treestudyplan_send_invite($data->id);
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$resend}"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$resend}");
print $OUTPUT->footer(); print $OUTPUT->footer();
exit; exit;
} else if (!empty($delete)) { } else if (!empty($delete)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete));
$data->delete = $delete; $data->delete = $delete;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id) {
{
print_error('invalidaction'); print_error('invalidaction');
exit; exit;
} }
@ -106,20 +99,17 @@ $mform->set_data($data);
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
} else if ($data = $mform->get_data()) { } else if ($data = $mform->get_data()) {
if (!empty($data->update)) if (!empty($data->update)) {
{
$id = $data->update; $id = $data->update;
$data->id = $id; $data->id = $id;
$DB->update_record('local_treestudyplan_invit', $data); $DB->update_record('local_treestudyplan_invit', $data);
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
} }
else if (!empty($data->add)) else if (!empty($data->add)) {
{
$id = $DB->insert_record("local_treestudyplan_invit", $data, true); $id = $DB->insert_record("local_treestudyplan_invit", $data, true);
@ -128,12 +118,10 @@ if ($mform->is_cancelled()) {
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$id}"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$id}");
} }
else if (!empty($data->resend)) else if (!empty($data->resend)) {
{
} }
else if (!empty($data->delete)) else if (!empty($data->delete)) {
{
} }
else else
@ -145,13 +133,11 @@ if ($mform->is_cancelled()) {
} else { } else {
$data = null; $data = null;
if ($unitid > 0) if ($unitid > 0) {
{
} }
$mform->display(); $mform->display();
} }
print $OUTPUT->footer(); print $OUTPUT->footer();

View File

@ -39,8 +39,7 @@ if ($categoryid > 0) {
} else if ($contextid > 0) { } else if ($contextid > 0) {
$studyplancontext = context::instance_by_id($contextid); $studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
{
$categoryid = $studyplancontext->instanceid; $categoryid = $studyplancontext->instanceid;
} }
else else
@ -50,7 +49,7 @@ if ($categoryid > 0) {
} else { } else {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("edit"); $availablecontexts = courseservice::list_accessible_categories_with_usage("edit");
$contextid=1; // fallback to system context. $contextid=1; // Fallback to system context.
foreach ($availablecontexts as $ctx) { foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) { if ($ctx->count > 0) {
$contextid = $ctx->ctxid; $contextid = $ctx->ctxid;
@ -76,16 +75,13 @@ if ($studyplancontext->id > 1) {
$PAGE->navbar->add(get_string('cfg_plans', 'local_treestudyplan')); $PAGE->navbar->add(get_string('cfg_plans', '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/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.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]); $PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$studyplancontext->id, $categoryid]);
$catlist = courseservice::list_accessible_categories_with_usage("edit"); $catlist = courseservice::list_accessible_categories_with_usage("edit");
// Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
@ -94,7 +90,6 @@ function t($str, $param=null, $plugin='local_treestudyplan') {
print $OUTPUT->header(); print $OUTPUT->header();
?> ?>
<div id='root'> <div id='root'>
<div class='vue-loader' v-show='false'> <div class='vue-loader' v-show='false'>
@ -106,7 +101,7 @@ print $OUTPUT->header();
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'> <div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<b-form-select text='<?php print($contextname);?>' :value="contextid"> <b-form-select text='<?php print($contextname);?>' :value="contextid">
<b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)' <b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)'
:active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0)?'font-weight-bold':''" :active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0) ? 'font-weight-bold' : ''"
><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</b-form-select-option> ><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</b-form-select-option>
</b-form-select> </b-form-select>
</div> </div>

View File

@ -77,8 +77,7 @@ print "</thead>";
print "<tbody>"; print "<tbody>";
if (count($invites) > 0) { if (count($invites) > 0) {
foreach ($invites as $invite) foreach ($invites as $invite) {
{
$testlink = $INVITEDURL."?key={$invite->invitekey}"; $testlink = $INVITEDURL."?key={$invite->invitekey}";
print "<tr data-id='{$invite->id}'>"; print "<tr data-id='{$invite->id}'>";
print "<td data-field='name'>{$invite->name}</td>"; print "<td data-field='name'>{$invite->name}</td>";
@ -112,6 +111,4 @@ print "<a class='btn btn-info' href='/local/treestudyplan/edit-invite.php?add=tr
print $OUTPUT->footer(); print $OUTPUT->footer();

View File

@ -32,7 +32,7 @@ $PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext); $PAGE->set_context($systemcontext);
// See if we can get a valid user for this invited. // See if we can get a valid user for this invited.
$invitekey = optional_param('key', '', PARAM_ALPHANUM); // module name. $invitekey = optional_param('key', '', PARAM_ALPHANUM); // Module name.
$PAGE->set_url("/local/treestudyplan/invited.php", array('key' => $invitekey)); $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]); $invite = $DB->get_record_select("local_treestudyplan_invit", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $invitekey]);
@ -41,10 +41,8 @@ if (empty($invite)) {
$PAGE->set_title(get_string('invalid_invitekey_title', 'local_treestudyplan')); $PAGE->set_title(get_string('invalid_invitekey_title', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan')); $PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan'));
print $OUTPUT->header(); 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 "<div class='box errorbox alert alert-danger'>";

View File

@ -39,7 +39,6 @@ $string['treestudyplan:viewuserreports'] = "View study plan of others";
$string['treestudyplan:forcescales'] = 'Advanced: Allow studyplan manager to force assignment scales to setting (manual modes only)'; $string['treestudyplan:forcescales'] = 'Advanced: Allow studyplan manager to force assignment scales to setting (manual modes only)';
$string['treestudyplan:selectowngradables'] = 'Teachers can select gradables in their own courses in study plan view mode (manual modes only)'; $string['treestudyplan:selectowngradables'] = 'Teachers can select gradables in their own courses in study plan view mode (manual modes only)';
$string['report'] = 'Progress report'; $string['report'] = 'Progress report';
$string['report_invited'] = 'Progress report for {$a}'; $string['report_invited'] = 'Progress report for {$a}';
$string['report_index'] = 'View student progress reports'; $string['report_index'] = 'View student progress reports';
@ -172,8 +171,8 @@ $string['completion_incomplete'] = "Not started";
$string['completion_pending'] = "Pending review"; $string['completion_pending'] = "Pending review";
$string['completion_progress'] = "In progress"; $string['completion_progress'] = "In progress";
$string['completion_completed'] = "Completed"; $string['completion_completed'] = "Completed";
$string['completion_good'] = "Good"; $string['completion_good'] = "Good";
$string['completion_excellent'] = "Excellent"; $string['completion_excellent'] = "Excellent";
$string['completion_passed'] = "Passed"; $string['completion_passed'] = "Passed";
$string['cfg_grades'] = 'Configure grade & scale interpretation'; $string['cfg_grades'] = 'Configure grade & scale interpretation';
@ -242,7 +241,6 @@ $string['bistate_aggregator_desc'] = 'Goals are completed or not (e.g. not start
$string['core_aggregator_title'] = 'Moodle course completion'; $string['core_aggregator_title'] = 'Moodle course completion';
$string['core_aggregator_desc'] = 'Use Moodle core completion'; $string['core_aggregator_desc'] = 'Use Moodle core completion';
$string['setting_bistate_heading'] = 'Defaults for Completed + Required goalsn'; $string['setting_bistate_heading'] = 'Defaults for Completed + Required goalsn';
$string['settingdesc_bistate_heading'] = 'Set the defaults for this aggregation method'; $string['settingdesc_bistate_heading'] = 'Set the defaults for this aggregation method';

View File

@ -39,7 +39,6 @@ $string['treestudyplan:viewuserreports'] = "Studieplannen van anderen bekijken";
$string['treestudyplan:forcescales'] = 'Gevorderd: Studyplanbeheerder kan alle opdrachten in studieplan instellen op specifieke resultaatschaal (alleen handmatige modes)'; $string['treestudyplan:forcescales'] = 'Gevorderd: Studyplanbeheerder kan alle opdrachten in studieplan instellen op specifieke resultaatschaal (alleen handmatige modes)';
$string['treestudyplan:selectowngradables'] = 'Docenten kunnen in hun eigen cursussen zelf activiteiten selecteren in een studieplan (docentenweergave, alleen handmatige modes)'; $string['treestudyplan:selectowngradables'] = 'Docenten kunnen in hun eigen cursussen zelf activiteiten selecteren in een studieplan (docentenweergave, alleen handmatige modes)';
$string['report'] = 'Voortgangsrapport'; $string['report'] = 'Voortgangsrapport';
$string['report_invited'] = 'Voortgang van {$a}'; $string['report_invited'] = 'Voortgang van {$a}';
$string['report_index'] = 'Studieplannen van studenten inzien'; $string['report_index'] = 'Studieplannen van studenten inzien';
@ -175,7 +174,7 @@ $string['completion_pending'] = "Wacht op beoordelen";
$string['completion_progress'] = "In ontwikkeling"; $string['completion_progress'] = "In ontwikkeling";
$string['completion_completed'] = "Voltooid"; $string['completion_completed'] = "Voltooid";
$string['completion_good'] = "Goed"; $string['completion_good'] = "Goed";
$string['completion_excellent'] = "Uitstekend"; $string['completion_excellent'] = "Uitstekend";
$string['completion_passed'] = "Behaald"; $string['completion_passed'] = "Behaald";
$string['cfg_grades'] = 'Configureer betekenis van beoordelingen en schalen'; $string['cfg_grades'] = 'Configureer betekenis van beoordelingen en schalen';

38
lib.php
View File

@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die();
function local_treestudyplan_unit_get_editor_options($context) { function local_treestudyplan_unit_get_editor_options($context) {
global $CFG; global $CFG;
return array('subdirs'=>1, 'maxbytes'=>$CFG->maxbytes, 'maxfiles'=>-1, 'changeformat'=>1, 'context'=>$context, 'noclean'=>1, 'trusttext'=>0); return array('subdirs' => 1, 'maxbytes' => $CFG->maxbytes, 'maxfiles' =>-1, 'changeformat' => 1, 'context' => $context, 'noclean' => 1, 'trusttext' => 0);
} }
function local_treestudyplan_extend_navigation(global_navigation $navigation) { function local_treestudyplan_extend_navigation(global_navigation $navigation) {
@ -56,8 +56,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
{ {
$userstudyplans = studyplan::find_for_user($USER->id); $userstudyplans = studyplan::find_for_user($USER->id);
if (!empty($userstudyplans)) if (!empty($userstudyplans)) {
{
// Create studyplan node. // Create studyplan node.
$node = navigation_node::create( $node = navigation_node::create(
@ -83,15 +82,13 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$invitenode->showinflatnavigation = false; $invitenode->showinflatnavigation = false;
$node->add_node($invitenode); $node->add_node($invitenode);
$navigation->add_node($node, 'mycourses'); $navigation->add_node($node, 'mycourses');
} }
else { else {
$hideprimary_hrefs[] = "/local/treestudyplan/myreport.php"; $hideprimary_hrefs[] = "/local/treestudyplan/myreport.php";
} }
if ( has_capability('local/treestudyplan:viewuserreports', context_system::instance()) if ( has_capability('local/treestudyplan:viewuserreports', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports')) || webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports')) {
{
$node = navigation_node::create( $node = navigation_node::create(
get_string("link_viewplan", "local_treestudyplan"), get_string("link_viewplan", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", array()), new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", array()),
@ -109,8 +106,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
} }
if ( has_capability('local/treestudyplan:editstudyplan', context_system::instance()) if ( has_capability('local/treestudyplan:editstudyplan', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan') || webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan')
) ) {
{
$node = navigation_node::create( $node = navigation_node::create(
get_string("cfg_plans", "local_treestudyplan"), get_string("cfg_plans", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", array()), new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", array()),
@ -144,12 +140,10 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$invitenode->showinflatnavigation = false; $invitenode->showinflatnavigation = false;
$navigation->add_node($invitenode, 'mycourses'); $navigation->add_node($invitenode, 'mycourses');
// Now using some javascript magic, we'll hide the links that are not accessible. // Now using some javascript magic, we'll hide the links that are not accessible.
$PAGE->requires->js_call_amd('local_treestudyplan/primary-nav-tools', 'hide_primary', [$hideprimary_hrefs]); $PAGE->requires->js_call_amd('local_treestudyplan/primary-nav-tools', 'hide_primary', [$hideprimary_hrefs]);
} }
function local_treestudyplan_extend_navigation_category_settings($navigation, context_coursecat $coursecategorycontext) { function local_treestudyplan_extend_navigation_category_settings($navigation, context_coursecat $coursecategorycontext) {
@ -158,7 +152,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
if (has_capability('local/treestudyplan:editstudyplan', $coursecategorycontext)) { if (has_capability('local/treestudyplan:editstudyplan', $coursecategorycontext)) {
$node = $navigation->add( $node = $navigation->add(
get_string('treestudyplan:editstudyplan', "local_treestudyplan"), get_string('treestudyplan:editstudyplan', "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", ["categoryid"=>$categoryid]), new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", ["categoryid" => $categoryid]),
global_navigation::TYPE_CATEGORY, global_navigation::TYPE_CATEGORY,
null, null,
"local_treestudyplan_editplan", "local_treestudyplan_editplan",
@ -169,7 +163,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
if (has_capability('local/treestudyplan:viewuserreports', $coursecategorycontext)) { if (has_capability('local/treestudyplan:viewuserreports', $coursecategorycontext)) {
$node = $navigation->add( $node = $navigation->add(
get_string('link_viewplan', "local_treestudyplan"), get_string('link_viewplan', "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", ["categoryid"=>$categoryid]), new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", ["categoryid" => $categoryid]),
global_navigation::TYPE_CATEGORY, global_navigation::TYPE_CATEGORY,
null, null,
"local_treestudyplan_viewplan", "local_treestudyplan_viewplan",
@ -217,25 +211,21 @@ function local_treestudyplan_send_invite($inviteid) {
$invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}"; $invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}";
$data = [ 'permissions'=> '', $data = [ 'permissions' => '',
'invitee' => $invite->name, 'invitee' => $invite->name,
'sender' => "{$USER->firstname} {$USER->lastname}", 'sender' => "{$USER->firstname} {$USER->lastname}",
'link' => $invitehref]; 'link' => $invitehref];
if ($invite->allow_details || $invite->allow_calendar || $invite->allow_badges) if ($invite->allow_details || $invite->allow_calendar || $invite->allow_badges) {
{
$data['permissions'] = get_string('invite_mail_permissions', 'local_treestudyplan'); $data['permissions'] = get_string('invite_mail_permissions', 'local_treestudyplan');
$data['permissions'] .= "<ul>\n"; $data['permissions'] .= "<ul>\n";
if ($invite->allow_details ) if ($invite->allow_details ) {
{
$data['permissions'] .= "<li>".get_string('invite_allow_details', 'local_treestudyplan')."</li>\n"; $data['permissions'] .= "<li>".get_string('invite_allow_details', 'local_treestudyplan')."</li>\n";
} }
if ($invite->allow_calendar) if ($invite->allow_calendar) {
{
$data['permissions'] .= "<li>".get_string('invite_allow_calendar', 'local_treestudyplan')."</li>\n"; $data['permissions'] .= "<li>".get_string('invite_allow_calendar', 'local_treestudyplan')."</li>\n";
} }
if ($invite->allow_badges) if ($invite->allow_badges) {
{
$data['permissions'] .= "<li>".get_string('invite_allow_badges', 'local_treestudyplan')."</li>\n"; $data['permissions'] .= "<li>".get_string('invite_allow_badges', 'local_treestudyplan')."</li>\n";
} }
@ -287,7 +277,7 @@ function local_treestudyplan_get_cohort_path($cohort) {
function($ctx) { return $ctx->get_context_name(false);}, function($ctx) { return $ctx->get_context_name(false);},
$cohortcontext->get_parent_contexts(true) $cohortcontext->get_parent_contexts(true)
); );
array_pop($ctxpath); // pop system context off the list. array_pop($ctxpath); // Pop system context off the list.
$ctxpath = array_reverse($ctxpath); $ctxpath = array_reverse($ctxpath);
$ctxpath[] = $cohort->name; $ctxpath[] = $cohort->name;
@ -297,7 +287,6 @@ function local_treestudyplan_get_cohort_path($cohort) {
} }
} }
function local_treestudyplan_output_fragment_mod_edit_form($args) { function local_treestudyplan_output_fragment_mod_edit_form($args) {
global $CFG; global $CFG;
global $DB; global $DB;
@ -315,7 +304,7 @@ function local_treestudyplan_output_fragment_mod_edit_form($args) {
$course = \get_course($cm->course); $course = \get_course($cm->course);
// Require_login. // Require_login.
require_login($course, false, $cm); // needed to setup proper $COURSE. require_login($course, false, $cm); // Needed to setup proper $COURSE.
list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course); list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course);
@ -332,5 +321,4 @@ function local_treestudyplan_output_fragment_mod_edit_form($args) {
return $mform->render(); return $mform->render();
} }

View File

@ -47,7 +47,7 @@ if ($teachermode) {
// 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/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.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']); $PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$teachermode ? 'teaching' : 'myreport']);
// Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param=null, $plugin='local_treestudyplan') {
@ -55,23 +55,23 @@ function t($str, $param=null, $plugin='local_treestudyplan') {
} }
print $OUTPUT->header(); print $OUTPUT->header();
?>
<div class="m-buttonbar" style="margin-bottom: 1em; text-align: right;">
<?php if (!$teachermode) { ?>
<a class="btn btn-primary" href="invitations.php" id="manage_invites"><i class="fa fa-share"></i> <?php t('manage_invites'); ?></a>
<?php } ?>
</div>
<div id='root'>
<div class='vue-loader' v-show='false'>
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div v-cloak>
<r-report v-model="studyplans" <?php print ($teachermode?"teachermode":""); ?> ></r-report>
</div>
</div>
<?php print '<div class="m-buttonbar" style="margin-bottom: 1em; text-align: right;">';
if (!$teachermode) {
print '<a class="btn btn-primary" href="invitations.php" id="manage_invites"><i class="fa fa-share"></i>'.t('manage_invites').'</a>';
}
print "</div>";
print "<div id='root'>";
print " <div class='vue-loader' v-show='false'>";
print " <div class='spinner-border text-primary' role='status'>";
print " <span class='sr-only'>Loading...</span>";
print " </div>";
print " </div>";
print " <div v-cloak>";
print " <r-report v-model='studyplans' " . ($teachermode ? "teachermode" : "")." ></r-report>";
print " </div>";
print "</div>";
print $OUTPUT->footer(); print $OUTPUT->footer();

View File

@ -42,7 +42,6 @@ if ($hassiteconfig) {
$page = new admin_settingpage('local_treestudyplan_settings', $page = new admin_settingpage('local_treestudyplan_settings',
get_string('settingspage', 'local_treestudyplan', null, true)); get_string('settingspage', 'local_treestudyplan', null, true));
// GOAL AGGREGATION SETTINGS. // GOAL AGGREGATION SETTINGS.
$page->add(new admin_setting_heading('local_treestudyplan/aggregation_heading', $page->add(new admin_setting_heading('local_treestudyplan/aggregation_heading',
get_string('setting_aggregation_heading', 'local_treestudyplan'), get_string('setting_aggregation_heading', 'local_treestudyplan'),
@ -139,7 +138,6 @@ if ($hassiteconfig) {
get_string('cfg_plans', 'local_treestudyplan', null, true), get_string('cfg_plans', 'local_treestudyplan', null, true),
$CFG->wwwroot . '/local/treestudyplan/edit-plan.php')); $CFG->wwwroot . '/local/treestudyplan/edit-plan.php'));
/************************************** /**************************************
* *
* Settings page: Cohort sync * Settings page: Cohort sync
@ -149,7 +147,6 @@ if ($hassiteconfig) {
$pagecsync = new admin_settingpage('local_treestudyplan_settings_cohortsync', $pagecsync = new admin_settingpage('local_treestudyplan_settings_cohortsync',
get_string('settingspage_csync', 'local_treestudyplan', null, true)); get_string('settingspage_csync', 'local_treestudyplan', null, true));
// Description heading. // Description heading.
$pagecsync->add(new admin_setting_heading('local_treestudyplan/csync_heading', $pagecsync->add(new admin_setting_heading('local_treestudyplan/csync_heading',
get_string('setting_csync_heading', 'local_treestudyplan'), get_string('setting_csync_heading', 'local_treestudyplan'),

View File

@ -39,8 +39,7 @@ if ($categoryid > 0) {
} else if ($contextid > 0) { } else if ($contextid > 0) {
$studyplancontext = context::instance_by_id($contextid); $studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
{
$categoryid = $studyplancontext->instanceid; $categoryid = $studyplancontext->instanceid;
} }
else else
@ -50,7 +49,7 @@ if ($categoryid > 0) {
} else { } else {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("view"); $availablecontexts = courseservice::list_accessible_categories_with_usage("view");
$contextid=1; // fallback to system context. $contextid=1; // Fallback to system context.
foreach ($availablecontexts as $ctx) { foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) { if ($ctx->count > 0) {
$contextid = $ctx->ctxid; $contextid = $ctx->ctxid;
@ -98,7 +97,7 @@ print $OUTPUT->header();
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'> <div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<b-form-select text='<?php print($contextname);?>' :value="contextid"> <b-form-select text='<?php print($contextname);?>' :value="contextid">
<b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)' <b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)'
:active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0)?'font-weight-bold':''" :active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0) ? 'font-weight-bold' : ''"
><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</b-form-select-option> ><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</b-form-select-option>
</b-form-select> </b-form-select>
</div> </div>