Moodle code style fixes completed
This commit is contained in:
parent
f8fd27528a
commit
cbc2c0e7ca
|
@ -124,8 +124,8 @@ class associationservice extends \external_api {
|
|||
|
||||
$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 .= " WHERE c.visible = 1 AND(name LIKE :pattern_nm OR idnumber LIKE :pattern_id)";
|
||||
$sql = "SELECT c.* from {cohort} c LEFT JOIN {local_treestudyplan_cohort} j ON c.id = j.cohort_id
|
||||
WHERE c.visible = 1 AND(name LIKE :pattern_nm OR idnumber LIKE :pattern_id)";
|
||||
if (isset($excludeid) && is_numeric($excludeid)) {
|
||||
$sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)";
|
||||
$params['exclude_id'] = $excludeid;
|
||||
|
@ -171,8 +171,8 @@ class associationservice extends \external_api {
|
|||
"pattern_ln" => $pattern,
|
||||
"pattern_un" => $pattern,
|
||||
];
|
||||
$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 = "SELECT u.* from {user} u LEFT JOIN {local_treestudyplan_user} j ON u.id = j.user_id
|
||||
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)) {
|
||||
$sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)";
|
||||
$params['exclude_id'] = $excludeid;
|
||||
|
@ -207,7 +207,7 @@ class associationservice extends \external_api {
|
|||
public static function connect_cohort($studyplanid, $cohortid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
|
||||
|
||||
if (!$DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplanid, 'cohort_id' => $cohortid])) {
|
||||
|
@ -243,7 +243,7 @@ class associationservice extends \external_api {
|
|||
public static function disconnect_cohort($studyplanid, $cohortid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
|
||||
|
||||
if ($DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplanid, 'cohort_id' => $cohortid])) {
|
||||
|
@ -279,7 +279,7 @@ class associationservice extends \external_api {
|
|||
public static function connect_user($studyplanid, $userid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
|
||||
|
||||
if (!$DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplanid, 'user_id' => $userid])) {
|
||||
|
@ -313,7 +313,7 @@ class associationservice extends \external_api {
|
|||
// Actual functions.
|
||||
public static function disconnect_user($studyplanid, $userid) {
|
||||
global $CFG, $DB;
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
|
||||
|
||||
if ($DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplanid, 'user_id' => $userid])) {
|
||||
|
@ -343,11 +343,11 @@ class associationservice extends \external_api {
|
|||
// Actual functions.
|
||||
public static function associated_users($studyplanid) {
|
||||
global $CFG, $DB;
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
|
||||
|
||||
$sql = "SELECT DISTINCT u.* FROM {user} u INNER JOIN {local_treestudyplan_user} j ON j.user_id = u.id";
|
||||
$sql .= " WHERE j.studyplan_id = :studyplan_id";
|
||||
$sql = "SELECT DISTINCT u.* FROM {user} u INNER JOIN {local_treestudyplan_user} j ON j.user_id = u.id
|
||||
WHERE j.studyplan_id = :studyplan_id";
|
||||
$rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]);
|
||||
|
||||
$users = [];
|
||||
|
@ -372,11 +372,11 @@ class associationservice extends \external_api {
|
|||
// Actual functions.
|
||||
public static function associated_cohorts($studyplanid) {
|
||||
global $CFG, $DB;
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
|
||||
|
||||
$sql = "SELECT DISTINCT c.* FROM {cohort} c INNER JOIN {local_treestudyplan_cohort} j ON j.cohort_id = c.id";
|
||||
$sql .= " WHERE j.studyplan_id = :studyplan_id";
|
||||
$sql = "SELECT DISTINCT c.* FROM {cohort} c INNER JOIN {local_treestudyplan_cohort} j ON j.cohort_id = c.id
|
||||
WHERE j.studyplan_id = :studyplan_id";
|
||||
$rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]);
|
||||
$cohorts = [];
|
||||
foreach ($rs as $c) {
|
||||
|
@ -400,20 +400,20 @@ class associationservice extends \external_api {
|
|||
public static function all_associated($studyplanid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
|
||||
|
||||
$users = [];
|
||||
// SQL JOIN script selecting all users that have a cohort linked to this studyplan .
|
||||
// Or are directly linked.
|
||||
$sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email"
|
||||
."FROM {user} u"
|
||||
."LEFT JOIN {cohort_members} cm ON u.id = cm.userid"
|
||||
."LEFT JOIN {local_treestudyplan_cohort} tc ON cm.cohortid = tc.cohort_id"
|
||||
."LEFT JOIN {local_treestudyplan_user} tu ON u.id = tu.user_id"
|
||||
."WHERE tc.studyplan_id = {$studyplan->id()}"
|
||||
."OR tu.studyplan_id = {$studyplan->id()}"
|
||||
."ORDER BY u.lastname, u.firstname";
|
||||
$sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email
|
||||
FROM {user} u
|
||||
LEFT JOIN {cohort_members} cm ON u.id = cm.userid
|
||||
LEFT JOIN {local_treestudyplan_cohort} tc ON cm.cohortid = tc.cohort_id
|
||||
LEFT JOIN {local_treestudyplan_user} tu ON u.id = tu.user_id
|
||||
WHERE tc.studyplan_id = {$studyplan->id()}
|
||||
OR tu.studyplan_id = {$studyplan->id()}
|
||||
ORDER BY u.lastname, u.firstname";
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
|
||||
foreach ($rs as $u) {
|
||||
|
@ -455,7 +455,7 @@ class associationservice extends \external_api {
|
|||
|
||||
// Actual functions.
|
||||
public static function cascade_cohortsync($studyplanid) {
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
|
||||
|
||||
$enroller = new cascadecohortsync($studyplan);
|
||||
|
|
|
@ -51,13 +51,28 @@ class corecompletioninfo {
|
|||
}
|
||||
|
||||
public static function completiontypes() {
|
||||
global $COMPLETION_CRITERIA_TYPES;
|
||||
/* Just return the keys of the global array COMPLETION_CRITERIA_TYPES,
|
||||
/* While it is tempting to use the global array COMPLETION_CRITERIA_TYPES,
|
||||
so we don't have to manually add any completion types if moodle decides to add a few.
|
||||
Unfortunately, the global variable breaks the moodle coding standard...
|
||||
We can just as easily add the list here manually, since adding a completion type
|
||||
requires adding code to this page anyway.
|
||||
And this way we can keep the moodle code style checker happy.
|
||||
(Moodle will probably refator that part of the code anyway in the future, without
|
||||
taking effects of this plugin into account :)
|
||||
|
||||
Array declaration based completion/criteria/completion_criteria.php:85 where the global
|
||||
COMPLETION_CRITERIA_TYPES iw/was defined.
|
||||
*/
|
||||
if (!isset(self::$completiontypes)) {
|
||||
self::$completiontypes = \array_keys($COMPLETION_CRITERIA_TYPES);
|
||||
self::$completiontypes = [
|
||||
COMPLETION_CRITERIA_TYPE_SELF => 'self',
|
||||
COMPLETION_CRITERIA_TYPE_DATE => 'date',
|
||||
COMPLETION_CRITERIA_TYPE_UNENROL => 'unenrol',
|
||||
COMPLETION_CRITERIA_TYPE_ACTIVITY => 'activity',
|
||||
COMPLETION_CRITERIA_TYPE_DURATION => 'duration',
|
||||
COMPLETION_CRITERIA_TYPE_GRADE => 'grade',
|
||||
COMPLETION_CRITERIA_TYPE_ROLE => 'role',
|
||||
COMPLETION_CRITERIA_TYPE_COURSE => 'course',
|
||||
];
|
||||
}
|
||||
return self::$completiontypes;
|
||||
}
|
||||
|
@ -192,10 +207,11 @@ class corecompletioninfo {
|
|||
];
|
||||
|
||||
foreach ($criterias as $criteria) {
|
||||
// Unfortunately, we cannot easily get the criteria details with get_details() without having a .
|
||||
// User completion object involved, so'we'll have to retrieve the details per completion type.
|
||||
// See moodle/completion/criteria/completion_criteria_*.php::get_details() for the code that is.
|
||||
// In the code below is based on.
|
||||
/* Unfortunately, we cannot easily get the criteria details with get_details() without having a
|
||||
user completion object involved, so'we'll have to retrieve the details per completion type.
|
||||
See moodle/completion/criteria/completion_criteria_*.php::get_details() for the code that
|
||||
the code below is based on.
|
||||
*/
|
||||
|
||||
if ($type == COMPLETION_CRITERIA_TYPE_SELF) {
|
||||
$details = [
|
||||
|
|
|
@ -71,12 +71,12 @@ class courseinfo {
|
|||
return static::$contentitems;
|
||||
}
|
||||
|
||||
protected function amTeacher() {
|
||||
protected function am_teacher() {
|
||||
global $USER;
|
||||
return is_enrolled($this->coursecontext, $USER, 'mod/assign:grade');
|
||||
}
|
||||
|
||||
protected function iCanSelectGradables($userid = -1) {
|
||||
protected function i_can_select_gradables($userid = -1) {
|
||||
global $USER, $DB;
|
||||
if ($userid <= 0) {
|
||||
$usr = $USER;
|
||||
|
@ -217,9 +217,9 @@ class courseinfo {
|
|||
'timing' => $timing,
|
||||
'startdate' => date("Y-m-d", $this->course->startdate, ),
|
||||
'enddate' => date("Y-m-d", $this->course->enddate),
|
||||
'amteacher' => $this->amTeacher(),
|
||||
'amteacher' => $this->am_teacher(),
|
||||
'canupdatecourse' => \has_capability("moodle/course:update", $this->coursecontext),
|
||||
'canselectgradables' => $this->iCanSelectGradables(),
|
||||
'canselectgradables' => $this->i_can_select_gradables(),
|
||||
'tag' => "Editormodel",
|
||||
'grades' => [],
|
||||
];
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
// This file is part of the Studyplan plugin for Moodle
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
|
||||
/**
|
||||
*
|
||||
* @package local_treestudyplan
|
||||
* @copyright 2023 P.M. Kuipers
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace local_treestudyplan;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/externallib.php');
|
||||
require_once($CFG->libdir.'/modinfolib.php');
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
|
||||
use core_course\local\repository\caching_content_item_readonly_repository;
|
||||
use core_course\local\repository\content_item_readonly_repository;
|
||||
use \grade_item;
|
||||
|
||||
class coursemoduleinfo {
|
||||
private $id;
|
||||
private $cm;
|
||||
private $cminfo;
|
||||
private $dbrecord;
|
||||
|
||||
public function __construct($id) {
|
||||
global $DB;
|
||||
// Determine the icon for the associated activity.
|
||||
$this->id = $id;
|
||||
$this->cm = $DB->get_record("course_modules", ["id" => $id]);
|
||||
$this->cm_info = \cm_info::create($this->cm);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return $this->cm_info->name;
|
||||
}
|
||||
|
||||
public function setTitle($value) {
|
||||
$this->cm_info->set_name($value);
|
||||
// TODO: Actually save this after setting the cminfo.
|
||||
}
|
||||
|
||||
}
|
|
@ -312,7 +312,7 @@ class courseservice extends \external_api {
|
|||
public static function scan_grade_progress($gradeitemid, $studyplanid) {
|
||||
global $DB;
|
||||
// Verify access to the study plan.
|
||||
$o = studyplan::findById($studyplanid);
|
||||
$o = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_VIEW, $o->context());
|
||||
|
||||
// Retrieve grade item.
|
||||
|
@ -345,7 +345,7 @@ class courseservice extends \external_api {
|
|||
public static function scan_completion_progress($criteriaid, $studyplanid, $courseid) {
|
||||
global $DB;
|
||||
// Verify access to the study plan.
|
||||
$o = studyplan::findById($studyplanid);
|
||||
$o = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_VIEW, $o->context());
|
||||
|
||||
$crit = \completion_criteria::fetch(["id" => $criteriaid]);
|
||||
|
@ -375,7 +375,7 @@ class courseservice extends \external_api {
|
|||
public static function scan_badge_progress($badgeid, $studyplanid) {
|
||||
global $DB;
|
||||
// Check access to the study plan.
|
||||
$o = studyplan::findById($studyplanid);
|
||||
$o = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_VIEW, $o->context());
|
||||
|
||||
// Validate that badge is linked to studyplan.
|
||||
|
|
|
@ -57,7 +57,7 @@ class gradeinfo {
|
|||
|
||||
private static $sections = [];
|
||||
|
||||
protected static function getSectionSequence($sectionid) {
|
||||
protected static function get_sectionsequence($sectionid) {
|
||||
global $DB;
|
||||
if (!array_key_exists($sectionid, self::$sections)) {
|
||||
self::$sections[$sectionid] = explode(", ", $DB->get_field("course_sections", "sequence", ["id" => $sectionid]));
|
||||
|
@ -65,15 +65,15 @@ class gradeinfo {
|
|||
return self::$sections[$sectionid];
|
||||
}
|
||||
|
||||
public function getGradeitem() {
|
||||
public function get_gradeitem() {
|
||||
return $this->gradeitem;
|
||||
}
|
||||
|
||||
public function getGradingscanner() {
|
||||
public function get_gradingscanner() {
|
||||
return $this->gradingscanner;
|
||||
}
|
||||
|
||||
public function getScale() {
|
||||
public function get_scale() {
|
||||
return $this->scale;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ class gradeinfo {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static function getCourseContextById($id) {
|
||||
public static function get_coursecontext_by_id($id) {
|
||||
$gi = grade_item::fetch(["id" => $id]);
|
||||
if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
|
||||
throw new \InvalidArgumentException ("Grade {$id} not found in database");
|
||||
|
@ -131,7 +131,7 @@ class gradeinfo {
|
|||
// Sort by position in course.
|
||||
// .
|
||||
$this->section = $cminfo->sectionnum;
|
||||
$ssequence = self::getSectionSequence($cminfo->section);
|
||||
$ssequence = self::get_sectionsequence($cminfo->section);
|
||||
$this->sectionorder = array_search($cminfo->id, $ssequence);
|
||||
|
||||
$this->link = "/mod/{$gi->itemmodule}/view.php?id={$cminfo->id}";
|
||||
|
@ -336,6 +336,8 @@ class gradeinfo {
|
|||
$gradable = new static($gi->id, $studyitem);
|
||||
$list[] = $gradable;
|
||||
} catch (\InvalidArgumentException $x) {
|
||||
// Pass and do not add to the list if an error occurs.
|
||||
$gradable = null; // Clean up gradable variable.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -391,7 +393,7 @@ class gradeinfo {
|
|||
'studyitem_id' => $itemid,
|
||||
'grade_item_id' => $gradeid,
|
||||
'include' => 1,
|
||||
'required' => boolval($required)?1:0]
|
||||
'required' => boolval($required) ? 1 : 0 ]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -79,7 +79,7 @@ class gradingscanner {
|
|||
return $this->pending_cache[$userid];
|
||||
}
|
||||
|
||||
public static function structure($value = VALUE_OPTIONAL) {
|
||||
public static function structure($value =VALUE_OPTIONAL) {
|
||||
return new \external_single_structure([
|
||||
"ungraded" => new \external_value(PARAM_INT, 'number of ungraded submissions'),
|
||||
"completed" => new \external_value(PARAM_INT, 'number of completed students'),
|
||||
|
@ -102,9 +102,7 @@ class gradingscanner {
|
|||
$ungraded++;
|
||||
} else {
|
||||
$grade = $this->gi->get_final($userid);
|
||||
if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) {
|
||||
// Skip.
|
||||
} else {
|
||||
if ( (!empty($grade->finalgrade)) && is_numeric($grade->finalgrade)) {
|
||||
// Compare grade to minimum grade.
|
||||
if ($this->grade_passed($grade)) {
|
||||
$completedpass++;
|
||||
|
|
|
@ -30,14 +30,22 @@ use \local_treestudyplan\debug;
|
|||
|
||||
class bistate_aggregator extends \local_treestudyplan\aggregator {
|
||||
public const DEPRECATED = false;
|
||||
private const DEFAULT_CONDITION = "50";
|
||||
|
||||
private $threshexcellent = 1.0; // Minimum fraction that must be completed to aggregate as excellent (usually 1.0).
|
||||
private $threshgood = 0.8; // Minimum fraction that must be completed to aggregate as good.
|
||||
private $threshcompleted = 0.66; // Minimum fraction that must be completed to aggregate as completed.
|
||||
private $usefailed = true; // Support failed completion yes/no.
|
||||
private $threshprogress = 0.33; // Minimum fraction that must be failed to aggregate as failed instead of progress.
|
||||
private $acceptpending_as_submitted = false; // Also count ungraded but submitted .
|
||||
private $agcfg = null;
|
||||
|
||||
private function cfg() {
|
||||
if (empty($this->agcfg)) {
|
||||
$this->agcfg = (object)[
|
||||
'thresh_excellent' => 1.0, // Minimum fraction that must be completed to aggregate as excellent (usually 1.0).
|
||||
'thresh_good' => 0.8, // Minimum fraction that must be completed to aggregate as good.
|
||||
'thresh_completed' => 0.66, // Minimum fraction that must be completed to aggregate as completed.
|
||||
'use_failed' => true, // Support failed completion yes/no.
|
||||
'thresh_progress' => 0.33, // Deprecated!
|
||||
'accept_pending_as_submitted' => false, // Also count ungraded but submitted .
|
||||
];
|
||||
}
|
||||
return $this->agcfg;
|
||||
}
|
||||
|
||||
public function __construct($configstr) {
|
||||
// Allow public constructor for testing purposes.
|
||||
|
@ -50,11 +58,11 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress", ] as $key) {
|
||||
$val = intval(get_config('local_treestudyplan', "bistate_{$key}"));
|
||||
if ($val >= 0 && $val <= 100) {
|
||||
$this->$key = floatval($val)/100;
|
||||
$this->cfg()->$key = floatval($val) / 100;
|
||||
}
|
||||
}
|
||||
foreach (["use_failed", "accept_pending_as_submitted"] as $key) {
|
||||
$this->$key = boolval(get_config('local_treestudyplan', "bistate_{$key}"));
|
||||
$this->cfg()->$key = boolval(get_config('local_treestudyplan', "bistate_{$key}"));
|
||||
}
|
||||
|
||||
// Next, decode json.
|
||||
|
@ -66,13 +74,13 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
if (array_key_exists($key, $config)) {
|
||||
$val = $config[$key];
|
||||
if ($val >= 0 && $val <= 100) {
|
||||
$this->$key = floatval($val)/100;
|
||||
$this->cfg()->$key = floatval($val) / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (["use_failed", "accept_pending_as_submitted"] as $key) {
|
||||
if (array_key_exists($key, $config)) {
|
||||
$this->$key = boolval($config[$key]);
|
||||
$this->cfg()->$key = boolval($config[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,12 +89,12 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
// Return active configuration model.
|
||||
public function config_string() {
|
||||
return json_encode([
|
||||
"thresh_excellent" => 100*$this->thresh_excellent,
|
||||
"thresh_good" => 100*$this->thresh_good,
|
||||
"thresh_completed" => 100*$this->thresh_completed,
|
||||
"thresh_progress" => 100*$this->thresh_progress,
|
||||
"use_failed" => $this->use_failed,
|
||||
"accept_pending_as_submitted" => $this->accept_pending_as_submitted,
|
||||
"thresh_excellent" => 100 * $this->cfg()->thresh_excellent,
|
||||
"thresh_good" => 100 * $this->cfg()->thresh_good,
|
||||
"thresh_completed" => 100 * $this->cfg()->thresh_completed,
|
||||
"thresh_progress" => 100 * $this->cfg()->thresh_progress,
|
||||
"use_failed" => $this->cfg()->use_failed,
|
||||
"accept_pending_as_submitted" => $this->cfg()->accept_pending_as_submitted,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -124,21 +132,21 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
$totalrequired = 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) {
|
||||
|
||||
$completed += ($c >= completion::COMPLETED) ? 1 : 0;
|
||||
$progress += ($c >= $MINPROGRESS) ? 1 : 0;
|
||||
$progress += ($c >= $minprogress) ? 1 : 0;
|
||||
$failed += ($c <= completion::FAILED) ? 1 : 0;
|
||||
}
|
||||
$started = $progress + $failed;
|
||||
$allrequiredmet = ($requiredmet >= $totalrequired);
|
||||
|
||||
$fractioncompleted = ($total >0) ? (floatval($completed)/floatval($total)) : 0.0;
|
||||
$fractionprogress = ($total >0) ? (floatval($progress)/floatval($total)) : 0.0;
|
||||
$fractionfailed = ($total >0) ? (floatval($failed)/floatval($total)) : 0.0;
|
||||
$fractionstarted = ($total >0) ? (floatval($started)/floatval($total)) : 0.0;
|
||||
$fractioncompleted = ($total > 0) ? (floatval($completed) / floatval($total)) : 0.0;
|
||||
$fractionprogress = ($total > 0) ? (floatval($progress) / floatval($total)) : 0.0;
|
||||
$fractionfailed = ($total > 0) ? (floatval($failed) / floatval($total)) : 0.0;
|
||||
$fractionstarted = ($total > 0) ? (floatval($started) / floatval($total)) : 0.0;
|
||||
|
||||
if ($total == 0) {
|
||||
return completion::INCOMPLETE;
|
||||
|
@ -217,7 +225,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
public function grade_completion(gradeinfo $gradeinfo, $userid) {
|
||||
global $DB;
|
||||
$table = "local_treestudyplan_gradecfg";
|
||||
$gradeitem = $gradeinfo->getGradeitem();
|
||||
$gradeitem = $gradeinfo->get_gradeitem();
|
||||
$grade = $gradeitem->get_final($userid);
|
||||
$course = \get_course($gradeitem->courseid); // Fetch course from cache.
|
||||
$coursefinished = ($course->enddate) ? ($course->enddate < time()) : false;
|
||||
|
@ -231,7 +239,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
|
||||
// Since we want old results to be visible until a pending item was graded, we only use this state here.
|
||||
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model.
|
||||
if ($gradeinfo->getGradingscanner()->pending($userid)) {
|
||||
if ($gradeinfo->get_gradingscanner()->pending($userid)) {
|
||||
return completion::PENDING;
|
||||
} else {
|
||||
return completion::INCOMPLETE;
|
||||
|
@ -240,7 +248,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
$grade = $gradeitem->get_final($userid);
|
||||
// First determine if we have a grade_config for this scale or this maximum grade.
|
||||
$finalgrade = $grade->finalgrade;
|
||||
$scale = $gradeinfo->getScale();
|
||||
$scale = $gradeinfo->get_scale();
|
||||
if ( isset($scale)) {
|
||||
$gradecfg = $DB->get_record($table, ["scale_id" => $scale->id]);
|
||||
} else if ($gradeitem->grademin == 0) {
|
||||
|
|
|
@ -31,7 +31,16 @@ use \local_treestudyplan\debug;
|
|||
|
||||
class core_aggregator extends \local_treestudyplan\aggregator {
|
||||
public const DEPRECATED = false;
|
||||
private $acceptpending_as_submitted = false; // Also count ungraded but submitted .
|
||||
private $agcfg = null;
|
||||
|
||||
private function cfg() {
|
||||
if (empty($this->agcfg)) {
|
||||
$this->agcfg = (object)[
|
||||
'accept_pending_as_submitted' => false, // Also count ungraded but submitted .
|
||||
];
|
||||
}
|
||||
return $this->agcfg;
|
||||
}
|
||||
|
||||
public function __construct($configstr) {
|
||||
// Allow public constructor for testing purposes.
|
||||
|
@ -41,7 +50,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
protected function initialize($configstr) {
|
||||
// First initialize with the defaults.
|
||||
foreach (["accept_pending_as_submitted"] as $key) {
|
||||
$this->$key = boolval(get_config('local_treestudyplan', "bistate_{$key}"));
|
||||
$this->cfg()->$key = boolval(get_config('local_treestudyplan', "bistate_{$key}"));
|
||||
}
|
||||
|
||||
// Next, decode json.
|
||||
|
@ -51,7 +60,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
// Copy all valid config settings to this item.
|
||||
foreach (["accept_pending_as_submitted"] as $key) {
|
||||
if (array_key_exists($key, $config)) {
|
||||
$this->$key = boolval($config[$key]);
|
||||
$this->cfg()->$key = boolval($config[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +69,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
// Return active configuration model.
|
||||
public function config_string() {
|
||||
return json_encode([
|
||||
"accept_pending_as_submitted" => $this->accept_pending_as_submitted,
|
||||
"accept_pending_as_submitted" => $this->cfg()->accept_pending_as_submitted,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -97,11 +106,11 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
*/
|
||||
|
||||
public function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid) {
|
||||
// Retrieve the core completion info from the core.
|
||||
$course = $courseinfo->course();
|
||||
$completion = new \completion_info($course);
|
||||
// Retrieve the core completion info from the core.
|
||||
$course = $courseinfo->course();
|
||||
$completion = new \completion_info($course);
|
||||
|
||||
if ($completion->is_enabled() && $completion->is_tracked_user($userid)) {
|
||||
if ($completion->is_enabled() && $completion->is_tracked_user($userid)) {
|
||||
if ($completion->is_course_complete($userid)) {
|
||||
// Now, the trick is to determine what constitutes excellent and good completion....
|
||||
// TODO: Determine excellent and maybe good completion.
|
||||
|
@ -174,7 +183,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
public function grade_completion(gradeinfo $gradeinfo, $userid) {
|
||||
global $DB;
|
||||
$table = "local_treestudyplan_gradecfg";
|
||||
$gradeitem = $gradeinfo->getGradeitem();
|
||||
$gradeitem = $gradeinfo->get_gradeitem();
|
||||
$grade = $gradeitem->get_final($userid);
|
||||
|
||||
if (empty($grade)) {
|
||||
|
@ -186,7 +195,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
|
||||
// Since we want old results to be visible until a pending item was graded, we only use this state here.
|
||||
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model.
|
||||
if ($gradeinfo->getGradingscanner()->pending($userid)) {
|
||||
if ($gradeinfo->get_gradingscanner()->pending($userid)) {
|
||||
return completion::PENDING;
|
||||
} else {
|
||||
return completion::INCOMPLETE;
|
||||
|
@ -195,7 +204,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
$grade = $gradeitem->get_final($userid);
|
||||
// First determine if we have a grade_config for this scale or this maximum grade.
|
||||
$finalgrade = $grade->finalgrade;
|
||||
$scale = $gradeinfo->getScale();
|
||||
$scale = $gradeinfo->get_scale();
|
||||
if ( isset($scale)) {
|
||||
$gradecfg = $DB->get_record($table, ["scale_id" => $scale->id]);
|
||||
} else if ($gradeitem->grademin == 0) {
|
||||
|
|
|
@ -51,15 +51,15 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
$cexcellent = 0;
|
||||
$cprogress = 0;
|
||||
$cpending = 0;
|
||||
$count = sizeof($a);
|
||||
$count = count($a);
|
||||
|
||||
if ($count > 0) {
|
||||
|
||||
foreach ($a as $c) {
|
||||
$cprogress += ($c>=completion::PROGRESS) ? 1 : 0;
|
||||
$ccompleted += ($c>=completion::COMPLETED) ? 1 : 0;
|
||||
$cexcellent += ($c>=completion::EXCELLENT) ? 1 : 0;
|
||||
$cpending += ($c>=completion::PENDING) ? 1 : 0;
|
||||
$cprogress += ($c >= completion::PROGRESS) ? 1 : 0;
|
||||
$ccompleted += ($c >= completion::COMPLETED) ? 1 : 0;
|
||||
$cexcellent += ($c >= completion::EXCELLENT) ? 1 : 0;
|
||||
$cpending += ($c >= completion::PENDING) ? 1 : 0;
|
||||
}
|
||||
|
||||
$required = [
|
||||
|
@ -116,7 +116,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
|
||||
public function grade_completion(gradeinfo $gradeinfo, $userid) {
|
||||
global $DB;
|
||||
$gradeitem = $gradeinfo->getGradeitem();
|
||||
$gradeitem = $gradeinfo->get_gradeitem();
|
||||
$grade = $gradeitem->get_final($userid);
|
||||
|
||||
if (empty($grade)) {
|
||||
|
@ -128,7 +128,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
|
||||
// Since we want old results to be visible until a pending item was graded, we only use this state here.
|
||||
// Pending items are otherwise expressly indicated by the "pendingsubmission" field in the user model.
|
||||
if ($gradeinfo->getGradingscanner()->pending($userid)) {
|
||||
if ($gradeinfo->get_gradingscanner()->pending($userid)) {
|
||||
return completion::PENDING;
|
||||
} else {
|
||||
return completion::INCOMPLETE;
|
||||
|
@ -136,7 +136,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
|
||||
} else {
|
||||
$finalgrade = $grade->finalgrade;
|
||||
$scale = $gradeinfo->getScale();
|
||||
$scale = $gradeinfo->get_scale();
|
||||
|
||||
if ($gradeitem->gradepass > 0) {
|
||||
// Base completion off of gradepass (if set).
|
||||
|
|
|
@ -91,7 +91,7 @@ class gradegenerator {
|
|||
return shell_exec("/usr/games/fortune -n 160 -e disclaimer literature science pratchett wisdom education");
|
||||
} else {
|
||||
// Get a random loremipsum string.
|
||||
return self::$loremipsum[rand(0, count(self::$loremipsum)-1)];
|
||||
return self::$loremipsum[rand(0, count(self::$loremipsum) - 1)];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ class gradegenerator {
|
|||
}
|
||||
|
||||
// Below is mostly just for reference in the json file.
|
||||
public function addUserNameInfo(string $student, $firstname, $lastname) {
|
||||
public function add_username_info(string $student, $firstname, $lastname) {
|
||||
$this->addstudent($student);
|
||||
$this->table[$student]["firstname"] = $firstname;
|
||||
$this->table[$student]["lastname"] = $lastname;
|
||||
|
@ -175,7 +175,7 @@ class gradegenerator {
|
|||
|
||||
for ($i = 0; $i < count($gradeinfos); $i++) {
|
||||
$g = $gradeinfos[$i];
|
||||
$gi = $g->getGradeitem();
|
||||
$gi = $g->get_gradeitem();
|
||||
$gr = $gen[$i];
|
||||
|
||||
// First get the configured interpretation for this scale or grade.
|
||||
|
@ -196,7 +196,7 @@ class gradegenerator {
|
|||
$grade = 0;
|
||||
$r = (object)["gi" => $g, "grade" => $grade, "fb" => "" ];
|
||||
} 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 ];
|
||||
} else {
|
||||
// COMPLETED.
|
||||
|
@ -216,11 +216,11 @@ class gradegenerator {
|
|||
} else if ($gi->gradepass > 0) {
|
||||
if (!$gr->done) {
|
||||
// INCOMPLETe or FAILED.
|
||||
$grade = rand(0, $gi->gradepass/2);
|
||||
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>($grade > 0) ? $gr->fb : "" ];
|
||||
$grade = rand(0, $gi->gradepass / 2);
|
||||
$r = (object)["gi" => $g, "grade" => $grade, "fb" => ($grade > 0) ? $gr->fb : "" ];
|
||||
} else if (!$gr->result) {
|
||||
// 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 {
|
||||
// COMPLETED.
|
||||
$r = (object)["gi" => $g, "grade" => rand( $gi->gradepass, $gi->grademax ), "fb" => $gr->fb ];
|
||||
|
@ -238,21 +238,21 @@ class gradegenerator {
|
|||
$grade = rand(0, round($range * 0.35) - 1);
|
||||
$r = (object)[
|
||||
"gi" => $g,
|
||||
"grade" => $gi->grademin+$grade,
|
||||
"fb" =>($grade > 0) ? $gr->fb : ""
|
||||
"grade" => $gi->grademin + $grade,
|
||||
"fb" => ($grade > 0) ? $gr->fb : ""
|
||||
];
|
||||
} else if (!$gr->result) {
|
||||
// PROGRESS.
|
||||
$r = (object)[
|
||||
"gi" => $g,
|
||||
"grade" => $gi->grademin+rand(round($range * 0.35), round($range * 0.55) - 1 ),
|
||||
"grade" => $gi->grademin + rand(round($range * 0.35), round($range * 0.55) - 1 ),
|
||||
"fb" => $gr->fb
|
||||
];
|
||||
} else {
|
||||
// COMPLETED.
|
||||
$r = (object)[
|
||||
"gi" => $g,
|
||||
"grade" => $gi->grademin+rand(round($range * 0.55) , $range ),
|
||||
"grade" => $gi->grademin + rand(round($range * 0.55) , $range ),
|
||||
"fb" => $gr->fb
|
||||
];
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ class gradegenerator {
|
|||
public function getstats($student) {
|
||||
return $this->table[$student];
|
||||
}
|
||||
public function serialize(): ?string{
|
||||
public function serialize(): ?string {
|
||||
return json_encode([
|
||||
"table" => $this->table], JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
@ -280,12 +280,12 @@ class gradegenerator {
|
|||
$this->table = $o["table"];
|
||||
}
|
||||
|
||||
public function toFile(string $filename) {
|
||||
public function to_file(string $filename) {
|
||||
$filename = self::expand_tilde($filename);
|
||||
file_put_contents($filename, $this->serialize());
|
||||
}
|
||||
|
||||
public function fromFile(string $filename) {
|
||||
public function from_file(string $filename) {
|
||||
$filename = self::expand_tilde($filename);
|
||||
if (file_exists($filename)) {
|
||||
try {
|
||||
|
|
|
@ -118,7 +118,7 @@ class webservicehelper {
|
|||
* @return \context The found context by id
|
||||
* @throws \InvalidArgumentException When the context is not found
|
||||
*/
|
||||
public static function find_context($contextid): \context{
|
||||
public static function find_context($contextid): \context {
|
||||
if (isset($contextid) && is_int($contextid) && $contextid > 0) {
|
||||
|
||||
if (!in_array($contextid, self::$validatedcontexts)) {
|
||||
|
|
|
@ -27,15 +27,15 @@ class assign_scanner extends scanner_base {
|
|||
protected function get_ungraded_submissions() {
|
||||
global $DB;
|
||||
$sql = "SELECT DISTINCT asgn_sub.userid
|
||||
FROM {assign_submission} asgn_sub
|
||||
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
|
||||
asgn_sub.attemptnumber = ag.attemptnumber
|
||||
WHERE a.id = {$this->gi->iteminstance}
|
||||
FROM {assign_submission} asgn_sub
|
||||
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 asgn_sub.attemptnumber = ag.attemptnumber
|
||||
WHERE a.id = {$this->gi->iteminstance}
|
||||
AND asgn_sub.status = 'submitted'
|
||||
AND asgn_sub.userid > 0
|
||||
AND a.grade <> 0 AND (ag.id IS NULL OR asgn_sub.timemodified >= ag.timemodified)
|
||||
";
|
||||
";
|
||||
|
||||
return $DB->get_fieldset_sql($sql);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class assign_scanner extends scanner_base {
|
|||
FROM {grade_grades} g
|
||||
LEFT JOIN {grade_items} gi on g.itemid = gi.id
|
||||
WHERE gi.itemmodule = 'assign' AND gi.iteminstance = {$this->gi->iteminstance}
|
||||
AND g.finalgrade IS NOT NULL"; // MAy turn out to be needed, dunno.
|
||||
AND g.finalgrade IS NOT NULL"; // MAy turn out to be needed, dunno.
|
||||
return $DB->get_fieldset_sql($sql);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
namespace local_treestudyplan\local\ungradedscanners;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->dirroot.'/question/engine/states.php'); // For reading question state.
|
||||
|
||||
class quiz_scanner extends scanner_base {
|
||||
|
@ -31,20 +32,20 @@ class quiz_scanner extends scanner_base {
|
|||
global $DB;
|
||||
|
||||
// First find all question attempts that need grading.
|
||||
$sql = "SELECT qza.id as submissionid, qza.userid as userid,"
|
||||
. "qas.questionattemptid as attempt_id, qas.sequencenumber as sequencenumber "
|
||||
. "FROM {question_attempt_steps} qas "
|
||||
. "JOIN {question_attempts} qna ON qas.questionattemptid = qna.id "
|
||||
. "JOIN {quiz_attempts} qza ON qna.questionusageid = qza.uniqueid "
|
||||
. "WHERE qas.state = 'needsgrading' AND qza.quiz = {$this->gi->iteminstance}";
|
||||
$sql = "SELECT qza.id as submissionid, qza.userid as userid,
|
||||
qas.questionattemptid as attempt_id, qas.sequencenumber as sequencenumber
|
||||
FROM {question_attempt_steps} qas
|
||||
JOIN {question_attempts} qna ON qas.questionattemptid = qna.id
|
||||
JOIN {quiz_attempts} qza ON qna.questionusageid = qza.uniqueid
|
||||
WHERE qas.state = 'needsgrading' AND qza.quiz = {$this->gi->iteminstance}";
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
$submissions = [];
|
||||
foreach ($rs as $r) {
|
||||
// Now, check if .
|
||||
$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);
|
||||
if ($r->sequencenumber == $max) {
|
||||
$submissions[$r->userid] = true; // Set array index based on user id, to avoid checking if value is in array.
|
||||
|
|
|
@ -27,8 +27,8 @@ require_once($CFG->libdir.'/externallib.php');
|
|||
|
||||
class period {
|
||||
const TABLE = "local_treestudyplan_period";
|
||||
private static $CACHE = [];
|
||||
private static $PAGECACHE = [];
|
||||
private static $cache = [];
|
||||
private static $pagecache = [];
|
||||
|
||||
private $r; // Holds database record.
|
||||
private $id;
|
||||
|
@ -39,17 +39,17 @@ class period {
|
|||
}
|
||||
|
||||
// Cache constructors to avoid multiple creation events in one session.
|
||||
public static function findById($id): self {
|
||||
if (!array_key_exists($id, self::$CACHE)) {
|
||||
self::$CACHE[$id] = new self($id);
|
||||
public static function find_by_id($id): self {
|
||||
if (!array_key_exists($id, self::$cache)) {
|
||||
self::$cache[$id] = new self($id);
|
||||
}
|
||||
return self::$CACHE[$id];
|
||||
return self::$cache[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a period by page and period number [1..$page->periods()]
|
||||
*/
|
||||
public static function find(studyplanpage $page, $periodnr): self{
|
||||
public static function find(studyplanpage $page, $periodnr): self {
|
||||
global $DB;
|
||||
if ($periodnr < 1) {
|
||||
// Clamp period index .
|
||||
|
@ -57,7 +57,7 @@ class period {
|
|||
}
|
||||
try {
|
||||
$id = $DB->get_field(self::TABLE, "id", ["page_id" => $page->id(), "period" => $periodnr], MUST_EXIST);
|
||||
$period = self::findById($id);
|
||||
$period = self::find_by_id($id);
|
||||
} catch (\dml_missing_record_exception $x) {
|
||||
// Period does not exist - create one ...
|
||||
// Make a best guess estimate of the start and end date, based on surrounding periods,.
|
||||
|
@ -73,19 +73,19 @@ class period {
|
|||
try {
|
||||
// Check if we have a previous period to glance the end date of as a reference.
|
||||
$startdate = $DB->get_field(self::TABLE, "enddate",
|
||||
["page_id" => $page->id(), "period" => $periodnr-1], MUST_EXIST);
|
||||
$pstart = strtotime($startdate)+(24*60*60); // Add one day.
|
||||
["page_id" => $page->id(), "period" => $periodnr - 1], MUST_EXIST);
|
||||
$pstart = strtotime($startdate) + (24 * 60 * 60); // Add one day.
|
||||
} catch (\dml_missing_record_exception $x2) {
|
||||
// If not, do a fair guess.
|
||||
$pstart = $ystart + (($periodnr-1)*$ptime);
|
||||
$pstart = $ystart + (($periodnr - 1) * $ptime);
|
||||
}
|
||||
try {
|
||||
// Check if we have a next period to glance the start date of as a reference.
|
||||
$enddate = $DB->get_field(self::TABLE, "startdate",
|
||||
["page_id" => $page->id(), "period" => $periodnr+1], MUST_EXIST);
|
||||
$pstart = strtotime($enddate)-(24*60*60); // Subtract one day.
|
||||
} catch (\dml_missing_record_exception $x2) {
|
||||
// If not, do a fair guess.
|
||||
$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.
|
||||
} catch (\dml_missing_record_exception $x) {
|
||||
// If not, do a fair guess.
|
||||
$pend = $pstart + $ptime;
|
||||
}
|
||||
|
||||
|
@ -103,24 +103,24 @@ class period {
|
|||
}
|
||||
|
||||
// Cache constructors to avoid multiple creation events in one session.
|
||||
public static function findForPage(studyplanpage $page): array {
|
||||
if (!array_key_exists($page->id(), self::$PAGECACHE)) {
|
||||
public static function find_for_page(studyplanpage $page): array {
|
||||
if (!array_key_exists($page->id(), self::$pagecache)) {
|
||||
$periods = [];
|
||||
// Find and add the periods to an array with the period sequence as a key.
|
||||
for ($i = 1; $i <= $page->periods(); $i++) {
|
||||
$period = self::find($page, $i);
|
||||
$periods[$i] = $period;
|
||||
}
|
||||
self::$PAGECACHE[$page->id()] = $periods;
|
||||
self::$pagecache[$page->id()] = $periods;
|
||||
}
|
||||
return self::$PAGECACHE[$page->id()];
|
||||
return self::$pagecache[$page->id()];
|
||||
}
|
||||
|
||||
private function __construct($id) {
|
||||
global $DB;
|
||||
$this->id = $id;
|
||||
$this->r = $DB->get_record(self::TABLE, ['id' => $id]);
|
||||
$this->page = studyplanpage::findById($this->r->page_id);
|
||||
$this->page = studyplanpage::find_by_id($this->r->page_id);
|
||||
}
|
||||
|
||||
public function id() {
|
||||
|
@ -184,7 +184,7 @@ class period {
|
|||
|
||||
/**
|
||||
* Do not use directly to add periods, unless performing import
|
||||
* The static find() and findForPage() functions create the period if needed
|
||||
* The static find() and find_for_page() functions create the period if needed
|
||||
*/
|
||||
public static function add($fields) {
|
||||
global $DB;
|
||||
|
@ -208,8 +208,8 @@ class period {
|
|||
}
|
||||
}
|
||||
$id = $DB->insert_record(self::TABLE, $info);
|
||||
unset(self::$PAGECACHE[$fields['page_id']]); // Invalidate the cache for this page.
|
||||
return self::findById($id); // Make sure the new page is immediately cached.
|
||||
unset(self::$pagecache[$fields['page_id']]); // Invalidate the cache for this page.
|
||||
return self::find_by_id($id); // Make sure the new page is immediately cached.
|
||||
}
|
||||
|
||||
public function edit($fields) {
|
||||
|
@ -224,14 +224,14 @@ class period {
|
|||
$DB->update_record(self::TABLE, $info);
|
||||
// Reload record after edit.
|
||||
$this->r = $DB->get_record(self::TABLE, ['id' => $this->id], "*", MUST_EXIST);
|
||||
unset(self::$PAGECACHE[$this->r->page_id]); // Invalidate the cache for this page.
|
||||
unset(self::$pagecache[$this->r->page_id]); // Invalidate the cache for this page.
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
global $DB;
|
||||
$DB->delete_records(self::TABLE, ['id' => $this->id]);
|
||||
unset(self::$PAGECACHE[$this->r->page_id]); // Invalidate the cache for this page.
|
||||
unset(self::$pagecache[$this->r->page_id]); // Invalidate the cache for this page.
|
||||
return success::success();
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ class period {
|
|||
|
||||
public static function page_model(studyplanpage $page) {
|
||||
$model = [];
|
||||
foreach (self::findForPage($page) as $p) {
|
||||
foreach (self::find_for_page($page) as $p) {
|
||||
$model[] = $p->model();
|
||||
}
|
||||
return $model;
|
||||
|
|
|
@ -35,9 +35,8 @@ use tool_dataprivacy\context_instance;
|
|||
|
||||
class provider implements \core_privacy\local\metadata\provider,
|
||||
\core_privacy\local\request\plugin\provider,
|
||||
\core_privacy\local\request\core_userlist_provider
|
||||
{
|
||||
/**
|
||||
\core_privacy\local\request\core_userlist_provider {
|
||||
/**
|
||||
* Get the language string identifier with the component's language
|
||||
* file to explain why this plugin stores no data.
|
||||
*
|
||||
|
@ -121,11 +120,10 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
static::export_studyplan_data_for_user($r);
|
||||
}
|
||||
} else if ($context->contextlevel == CONTEXT_COURSECAT) {
|
||||
// Export studyplan associations.
|
||||
// Export studyplan associations.
|
||||
$sql = "SELECT * FROM {local_treestudyplan} s
|
||||
INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id
|
||||
WHERE ( a.user_id = :userid AND s.context_id = :contextid)
|
||||
";
|
||||
WHERE ( a.user_id = :userid AND s.context_id = :contextid)";
|
||||
$records = $DB->get_records_sql($sql, ["userid" => $user->id, "contextid" => $context->id]);
|
||||
foreach ($records as $r) {
|
||||
static::export_studyplan_data_for_user($r);
|
||||
|
@ -193,10 +191,10 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
foreach ($contextlist->get_contexts() as $context) {
|
||||
|
||||
if ($context->contextlevel == CONTEXT_SYSTEM) {
|
||||
$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))";
|
||||
$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))";
|
||||
$planids = $DB->get_fieldset_sql($sql, ["contextid" => $context->id, "userid" => $user->id]);
|
||||
|
||||
foreach ($planids as $planid) {
|
||||
|
@ -282,10 +280,10 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
}
|
||||
|
||||
// Now delete the studyplan associations if relevant.
|
||||
if (count($planids) >0 && count($users) >0) {
|
||||
if (count($planids) > 0 && count($users) > 0) {
|
||||
|
||||
list($planinsql, $planinputparams) = $DB->get_in_or_equal($planids, SQL_PARAMS_NAMED, 'plan');
|
||||
$params = $userinparams+$planinputparams;
|
||||
$params = $userinparams + $planinputparams;
|
||||
$sql = "user_id {$userinsql} and studyplan_id {$planinsql}";
|
||||
$DB->delete_records_select('local_treestudyplan_user', $sql, $params);
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ class reportinvite_form extends moodleform {
|
|||
$characterslength = strlen($characters);
|
||||
$randomkey = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomkey .= $characters[rand(0, $characterslength - 1)];
|
||||
$randomkey .= $characters[rand(0, $characterslength - 1)];
|
||||
}
|
||||
|
||||
// Double check that the key is unique before inserting.
|
||||
|
|
|
@ -57,7 +57,7 @@ class studentstudyplanservice extends \external_api {
|
|||
foreach ($studyplans as $studyplan) {
|
||||
// Only include studyplans in the context the user has permissions for.
|
||||
if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) {
|
||||
$list[] =$studyplan->simple_model();
|
||||
$list[] = $studyplan->simple_model();
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
|
@ -115,7 +115,7 @@ class studentstudyplanservice extends \external_api {
|
|||
public static function get_user_studyplan($userid, $studyplanid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$studyplan = studyplan::findById($studyplanid);
|
||||
$studyplan = studyplan::find_by_id($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_VIEWOTHER, $studyplan->context());
|
||||
|
||||
if ($studyplan->has_linked_user($userid)) {
|
||||
|
@ -191,7 +191,7 @@ class studentstudyplanservice extends \external_api {
|
|||
$list = [];
|
||||
$studyplans = studyplan::find_for_user($userid);
|
||||
foreach ($studyplans as $studyplan) {
|
||||
$list[] =$studyplan->simple_model();
|
||||
$list[] = $studyplan->simple_model();
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class studyitem {
|
|||
|
||||
public const TABLE = "local_treestudyplan_item";
|
||||
|
||||
private static $STUDYITEMCACHE = [];
|
||||
private static $studyitemcache = [];
|
||||
private $r; // Holds database record.
|
||||
private $id;
|
||||
|
||||
|
@ -57,11 +57,11 @@ class studyitem {
|
|||
return $this->r->conditions;
|
||||
}
|
||||
|
||||
public static function findById($id): self {
|
||||
if (!array_key_exists($id, self::$STUDYITEMCACHE)) {
|
||||
self::$STUDYITEMCACHE[$id] = new self($id);
|
||||
public static function find_by_id($id): self {
|
||||
if (!array_key_exists($id, self::$studyitemcache)) {
|
||||
self::$studyitemcache[$id] = new self($id);
|
||||
}
|
||||
return self::$STUDYITEMCACHE[$id];
|
||||
return self::$studyitemcache[$id];
|
||||
}
|
||||
|
||||
public function __construct($id) {
|
||||
|
@ -69,7 +69,7 @@ class studyitem {
|
|||
$this->id = $id;
|
||||
$this->r = $DB->get_record(self::TABLE, ['id' => $id], "*", MUST_EXIST);
|
||||
|
||||
$this->studyline = studyline::findById($this->r->line_id);
|
||||
$this->studyline = studyline::find_by_id($this->r->line_id);
|
||||
$this->aggregator = $this->studyline()->studyplan()->aggregator();
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ class studyitem {
|
|||
|
||||
$model = [
|
||||
'id' => $this->r->id, // Id is needed in export model because of link references.
|
||||
'type' => $this->isValid() ? $this->r->type : self::INVALID,
|
||||
'type' => $this->valid() ? $this->r->type : self::INVALID,
|
||||
'conditions' => $this->r->conditions,
|
||||
'slot' => $this->r->slot,
|
||||
'layer' => $this->r->layer,
|
||||
|
@ -217,7 +217,7 @@ class studyitem {
|
|||
}
|
||||
}
|
||||
$id = $DB->insert_record(self::TABLE, $info);
|
||||
$item = self::findById($id);
|
||||
$item = self::find_by_id($id);
|
||||
if ($item->type() == self::COURSE) {
|
||||
// Signal the studyplan that a course has been added so it can be marked for csync cascading.
|
||||
$item->studyline()->studyplan()->mark_csync_changed();
|
||||
|
@ -242,7 +242,7 @@ class studyitem {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function isValid() {
|
||||
public function valid() {
|
||||
// Check if referenced courses, badges and/or competencies still exist.
|
||||
if ($this->r->type == static::COURSE) {
|
||||
return courseinfo::exists($this->r->course_id);
|
||||
|
@ -306,7 +306,7 @@ class studyitem {
|
|||
$list = [];
|
||||
$ids = $DB->get_fieldset_select(self::TABLE, "id", "line_id = :line_id ORDER BY layer", ['line_id' => $line->id()]);
|
||||
foreach ($ids as $id) {
|
||||
$item = self::findById($id, $line);
|
||||
$item = self::find_by_id($id, $line);
|
||||
$list[] = $item;
|
||||
}
|
||||
return $list;
|
||||
|
@ -380,7 +380,7 @@ class studyitem {
|
|||
|
||||
// Add continuation_info if available.
|
||||
if (self::exists($this->r->continuation_id)) {
|
||||
$citem = self::findById($this->r->continuation_id);
|
||||
$citem = self::find_by_id($this->r->continuation_id);
|
||||
$model['continuation'] = $citem->link_model($userid);
|
||||
}
|
||||
|
||||
|
@ -414,16 +414,16 @@ class studyitem {
|
|||
private function completion($userid) {
|
||||
global $DB;
|
||||
|
||||
if ($this->isValid()) {
|
||||
if ($this->valid()) {
|
||||
if (strtolower($this->r->type) == 'course') {
|
||||
// Determine competency by competency completion.
|
||||
$courseinfo = $this->getcourseinfo();
|
||||
return $this->aggregator->aggregate_course($courseinfo, $this, $userid);
|
||||
} else if (strtolower($this->r->type) =='start') {
|
||||
} else if (strtolower($this->r->type) == 'start') {
|
||||
// Does not need to use aggregator.
|
||||
// Either true, or the completion of the reference.
|
||||
if (self::exists($this->r->continuation_id)) {
|
||||
$citem = self::findById($this->r->continuation_id);
|
||||
$citem = self::find_by_id($this->r->continuation_id);
|
||||
return $citem->completion($userid);
|
||||
} else {
|
||||
return completion::COMPLETED;
|
||||
|
@ -434,11 +434,11 @@ class studyitem {
|
|||
// Retrieve incoming connections.
|
||||
$incoming = $DB->get_records(studyitemconnection::TABLE, ['to_id' => $this->r->id]);
|
||||
foreach ($incoming as $conn) {
|
||||
$item = self::findById($conn->from_id);
|
||||
$item = self::find_by_id($conn->from_id);
|
||||
$incompleted[] = $item->completion($userid);
|
||||
}
|
||||
return $this->aggregator->aggregate_junction($incompleted, $this, $userid);
|
||||
} else if (strtolower($this->r->type) =='badge') {
|
||||
} else if (strtolower($this->r->type) == 'badge') {
|
||||
global $DB;
|
||||
// Badge awarded.
|
||||
if (badgeinfo::exists($this->r->badge_id)) {
|
||||
|
@ -486,12 +486,12 @@ class studyitem {
|
|||
$fields->line_id = $newline->id();
|
||||
// Create new record with the new data.
|
||||
$id = $DB->insert_record(self::TABLE, (array)$fields);
|
||||
$new = self::findById($id, $newline);
|
||||
$new = self::find_by_id($id, $newline);
|
||||
|
||||
// Copy the grading info if relevant.
|
||||
$gradables = gradeinfo::list_studyitem_gradables($this);
|
||||
foreach ($gradables as $g) {
|
||||
gradeinfo::include_grade($g->getGradeitem()->id, $new->id(), true);
|
||||
gradeinfo::include_grade($g->get_gradeitem()->id, $new->id(), true);
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
|
|
|
@ -50,11 +50,11 @@ class studyitemconnection {
|
|||
}
|
||||
|
||||
public function from_item() {
|
||||
return studyitem::findById($this->r->from_id);
|
||||
return studyitem::find_by_id($this->r->from_id);
|
||||
}
|
||||
|
||||
public function to_item() {
|
||||
return studyitem::findById($this->r->to_id);
|
||||
return studyitem::find_by_id($this->r->to_id);
|
||||
}
|
||||
|
||||
public function from_id() {
|
||||
|
|
|
@ -45,7 +45,7 @@ class studyline {
|
|||
|
||||
public const TABLE = "local_treestudyplan_line";
|
||||
|
||||
private static $STUDYLINECACHE = [];
|
||||
private static $studylinecache = [];
|
||||
|
||||
private $r; // Holds database record.
|
||||
private $id;
|
||||
|
@ -64,18 +64,18 @@ class studyline {
|
|||
return $this->page;
|
||||
}
|
||||
|
||||
public static function findById($id): self {
|
||||
if (!array_key_exists($id, self::$STUDYLINECACHE)) {
|
||||
self::$STUDYLINECACHE[$id] = new self($id);
|
||||
public static function find_by_id($id): self {
|
||||
if (!array_key_exists($id, self::$studylinecache)) {
|
||||
self::$studylinecache[$id] = new self($id);
|
||||
}
|
||||
return self::$STUDYLINECACHE[$id];
|
||||
return self::$studylinecache[$id];
|
||||
}
|
||||
|
||||
private function __construct($id) {
|
||||
global $DB;
|
||||
$this->id = $id;
|
||||
$this->r = $DB->get_record(self::TABLE, ['id' => $id]);
|
||||
$this->page = studyplanpage::findById($this->r->page_id);
|
||||
$this->page = studyplanpage::find_by_id($this->r->page_id);
|
||||
$this->studyplan = $this->page->studyplan();
|
||||
}
|
||||
|
||||
|
@ -137,10 +137,10 @@ class studyline {
|
|||
// Make sure there are enought slots to account for them.
|
||||
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
|
||||
$maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
|
||||
$numslots = max($this->page->periods(), $maxslot +1);
|
||||
$numslots = max($this->page->periods(), $maxslot + 1);
|
||||
|
||||
// Create the required amount of slots.
|
||||
for ($i = 0; $i < $numslots+1; $i++) {
|
||||
for ($i = 0; $i < $numslots + 1; $i++) {
|
||||
if ($mode == "export") {
|
||||
// Export mode does not separate between filter or competency type, since that is determined automatically.
|
||||
$slots = [];
|
||||
|
@ -187,14 +187,14 @@ class studyline {
|
|||
$pageid = $fields['page_id'];
|
||||
$sqmax = $DB->get_field_select(self::TABLE, "MAX(sequence)", "page_id = :page_id", ['page_id' => $pageid]);
|
||||
$addable = ['page_id', 'name', 'shortname', 'color'];
|
||||
$info = ['sequence' => $sqmax+1];
|
||||
$info = ['sequence' => $sqmax + 1];
|
||||
foreach ($addable as $f) {
|
||||
if (array_key_exists($f, $fields)) {
|
||||
$info[$f] = $fields[$f];
|
||||
}
|
||||
}
|
||||
$id = $DB->insert_record(self::TABLE, $info);
|
||||
return self::findById($id);
|
||||
return self::find_by_id($id);
|
||||
}
|
||||
|
||||
public function edit($fields) {
|
||||
|
@ -249,7 +249,7 @@ class studyline {
|
|||
$ids = $DB->get_fieldset_select(self::TABLE, "id", "page_id = :page_id ORDER BY sequence",
|
||||
['page_id' => $page->id()]);
|
||||
foreach ($ids as $id) {
|
||||
$list[] = self::findById($id);
|
||||
$list[] = self::find_by_id($id);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
@ -291,10 +291,10 @@ class studyline {
|
|||
// Make sure there are enought slots to account for them.
|
||||
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
|
||||
$maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
|
||||
$numslots = max($this->page->periods(), $maxslot +1);
|
||||
$numslots = max($this->page->periods(), $maxslot + 1);
|
||||
|
||||
// Create the required amount of slots.
|
||||
for ($i = 0; $i < $numslots+1; $i++) {
|
||||
for ($i = 0; $i < $numslots + 1; $i++) {
|
||||
if ($i > 0) {
|
||||
$slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []];
|
||||
} else {
|
||||
|
@ -305,7 +305,7 @@ class studyline {
|
|||
|
||||
$children = studyitem::find_studyline_children($this);
|
||||
foreach ($children as $c) {
|
||||
if ($c->isValid()) {
|
||||
if ($c->valid()) {
|
||||
$slotset = null;
|
||||
if ($c->slot() > 0) {
|
||||
if (in_array($c->type(), self::COMPETENCY_TYPES)) {
|
||||
|
@ -336,7 +336,7 @@ class studyline {
|
|||
$fields->studyplan_id = $newstudyplan->id();
|
||||
// Create new record with the new data.
|
||||
$id = $DB->insert_record(self::TABLE, (array)$fields);
|
||||
$new = self::findById($id);
|
||||
$new = self::find_by_id($id);
|
||||
|
||||
// Next copy all the study items for this studyline.
|
||||
// And record the original and copy id's in the $translation array.
|
||||
|
@ -363,7 +363,7 @@ class studyline {
|
|||
if ($itemmodel["type"] == "course") {
|
||||
$itemmodel["layer"] = $courselayer;
|
||||
$courselayer++;
|
||||
}else {
|
||||
} else {
|
||||
$itemmodel["layer"] = $filterlayer;
|
||||
$filterlayer++;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ require_once($CFG->libdir.'/externallib.php');
|
|||
class studyplan {
|
||||
|
||||
const TABLE = "local_treestudyplan";
|
||||
private static $STUDYPLANCACHE = [];
|
||||
private static $studyplancache = [];
|
||||
|
||||
private $r; // Holds database record.
|
||||
private $id;
|
||||
|
@ -42,11 +42,11 @@ class studyplan {
|
|||
}
|
||||
|
||||
// Cache constructors to avoid multiple creation events in one session.
|
||||
public static function findById($id): self {
|
||||
if (!array_key_exists($id, self::$STUDYPLANCACHE)) {
|
||||
self::$STUDYPLANCACHE[$id] = new self($id);
|
||||
public static function find_by_id($id): self {
|
||||
if (!array_key_exists($id, self::$studyplancache)) {
|
||||
self::$studyplancache[$id] = new self($id);
|
||||
}
|
||||
return self::$STUDYPLANCACHE[$id];
|
||||
return self::$studyplancache[$id];
|
||||
}
|
||||
|
||||
private function __construct($id) {
|
||||
|
@ -82,7 +82,7 @@ class studyplan {
|
|||
/**
|
||||
* Return the context this studyplan is associated to
|
||||
*/
|
||||
public function context(): \context{
|
||||
public function context(): \context {
|
||||
if (!isset($this->context)) {
|
||||
try {
|
||||
$this->context = contextinfo::by_id($this->r->context_id)->context;
|
||||
|
@ -183,7 +183,7 @@ class studyplan {
|
|||
// Get a list of available scales.
|
||||
$scales = array_map( function($scale) {
|
||||
return [ "id" => $scale->id, "name" => $scale->name, ];
|
||||
}, \grade_scale::fetch_all(array('courseid' => 0)) );
|
||||
}, \grade_scale::fetch_all(['courseid' => 0]) );
|
||||
|
||||
$model['advanced']['force_scales'] = [
|
||||
'scales' => $scales,
|
||||
|
@ -204,7 +204,7 @@ class studyplan {
|
|||
}
|
||||
}
|
||||
$id = $DB->insert_record(self::TABLE, $info);
|
||||
$plan = self::findById($id); // Make sure the new studyplan is immediately cached.
|
||||
$plan = self::find_by_id($id); // Make sure the new studyplan is immediately cached.
|
||||
|
||||
// Start temporary skräpp code.
|
||||
// Add a single page and copy the names.This keeps the data sane until the upgrade to .
|
||||
|
@ -264,7 +264,7 @@ class studyplan {
|
|||
if (array_key_exists($f, $fields)) {
|
||||
if ($f == "name") {
|
||||
$pageinfo["fullname"] = $fields[$f];
|
||||
}else {
|
||||
} else {
|
||||
$pageinfo[$f] = $fields[$f];
|
||||
}
|
||||
}
|
||||
|
@ -311,12 +311,12 @@ class studyplan {
|
|||
}
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$list[] = studyplan::findById($id);
|
||||
$list[] = self::find_by_id($id);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function find_by_shortname($shortname, $contextid = 0): array{
|
||||
public static function find_by_shortname($shortname, $contextid = 0): array {
|
||||
global $DB;
|
||||
$list = [];
|
||||
|
||||
|
@ -326,7 +326,7 @@ class studyplan {
|
|||
}
|
||||
$ids = $DB->get_fieldset_select(self::TABLE, "id", $where, ["shortname" => $shortname, "contextid" => $contextid]);
|
||||
foreach ($ids as $id) {
|
||||
$list[] = studyplan::findById($id);
|
||||
$list[] = self::find_by_id($id);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
@ -338,20 +338,20 @@ class studyplan {
|
|||
INNER JOIN {local_treestudyplan_cohort} j ON j.studyplan_id = s.id
|
||||
INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid
|
||||
WHERE cm.userid = :userid";
|
||||
$cohortplan_ids = $DB->get_fieldset_sql($sql, ['userid' => $userid]);
|
||||
$cohortplanids = $DB->get_fieldset_sql($sql, ['userid' => $userid]);
|
||||
|
||||
$sql = "SELECT s.id FROM {local_treestudyplan} s
|
||||
INNER JOIN {local_treestudyplan_user} j ON j.studyplan_id = s.id
|
||||
WHERE j.user_id = :userid";
|
||||
$userplan_ids = $DB->get_fieldset_sql($sql, ['userid' => $userid]);
|
||||
$userplanids = $DB->get_fieldset_sql($sql, ['userid' => $userid]);
|
||||
|
||||
$plans = [];
|
||||
foreach ($cohortplan_ids as $id) {
|
||||
$plans[$id] = self::findById($id);
|
||||
foreach ($cohortplanids as $id) {
|
||||
$plans[$id] = self::find_by_id($id);
|
||||
}
|
||||
foreach ($userplan_ids as $id) {
|
||||
foreach ($userplanids as $id) {
|
||||
if (!array_key_exists($id, $plans)) {
|
||||
$plans[$id] = self::findById($id);
|
||||
$plans[$id] = self::find_by_id($id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,7 +394,7 @@ class studyplan {
|
|||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retrieve the user id's of the users linked to this studyplan.
|
||||
* @return array of int (User Id)
|
||||
*/
|
||||
|
@ -475,14 +475,14 @@ class studyplan {
|
|||
}
|
||||
|
||||
public static function duplicate_plan($planid, $name, $shortname) {
|
||||
$ori = self::findById($planid);
|
||||
$ori = self::find_by_id($planid);
|
||||
$new = $ori->duplicate($name, $shortname);
|
||||
return $new->simple_model();
|
||||
}
|
||||
|
||||
public function duplicate($name, $shortname) {
|
||||
// First duplicate the studyplan structure.
|
||||
$newplan = studyplan::add([
|
||||
$newplan = self::add([
|
||||
'name' => $name,
|
||||
'shortname' => $shortname,
|
||||
'description' => $this->r->description,
|
||||
|
|
|
@ -28,7 +28,7 @@ require_once($CFG->libdir.'/externallib.php');
|
|||
class studyplanpage {
|
||||
|
||||
const TABLE = "local_treestudyplan_page";
|
||||
private static $CACHE = [];
|
||||
private static $cache = [];
|
||||
|
||||
private $r; // Holds database record.
|
||||
private $id;
|
||||
|
@ -39,18 +39,18 @@ class studyplanpage {
|
|||
}
|
||||
|
||||
// Cache constructors to avoid multiple creation events in one session.
|
||||
public static function findById($id): self {
|
||||
if (!array_key_exists($id, self::$CACHE)) {
|
||||
self::$CACHE[$id] = new self($id);
|
||||
public static function find_by_id($id): self {
|
||||
if (!array_key_exists($id, self::$cache)) {
|
||||
self::$cache[$id] = new self($id);
|
||||
}
|
||||
return self::$CACHE[$id];
|
||||
return self::$cache[$id];
|
||||
}
|
||||
|
||||
private function __construct($id) {
|
||||
global $DB;
|
||||
$this->id = $id;
|
||||
$this->r = $DB->get_record(self::TABLE, ['id' => $id]);
|
||||
$this->studyplan = studyplan::findById($this->r->studyplan_id);
|
||||
$this->studyplan = studyplan::find_by_id($this->r->studyplan_id);
|
||||
}
|
||||
|
||||
public function id() {
|
||||
|
@ -170,7 +170,7 @@ class studyplanpage {
|
|||
}
|
||||
|
||||
$id = $DB->insert_record(self::TABLE, $info);
|
||||
return self::findById($id); // Make sure the new page is immediately cached.
|
||||
return self::find_by_id($id); // Make sure the new page is immediately cached.
|
||||
}
|
||||
|
||||
public function edit($fields) {
|
||||
|
@ -252,20 +252,20 @@ class studyplanpage {
|
|||
$ids = $DB->get_fieldset_select(self::TABLE, "id", "studyplan_id = :plan_id ORDER BY startdate",
|
||||
['plan_id' => $plan->id()]);
|
||||
foreach ($ids as $id) {
|
||||
$list[] = self::findById($id);
|
||||
$list[] = self::find_by_id($id);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function duplicate_page($pageid, $name, $shortname) {
|
||||
$ori = self::findById($pageid);
|
||||
$ori = self::find_by_id($pageid);
|
||||
$new = $ori->duplicate($name, $shortname);
|
||||
return $new->simple_model();
|
||||
}
|
||||
|
||||
public function duplicate($newstudyplan) {
|
||||
// First duplicate the studyplan structure.
|
||||
$new = studyplanpage::add([
|
||||
$new = self::add([
|
||||
'studyplan_id' => $newstudyplan->id(),
|
||||
'fullname' => $this->r->fullname,
|
||||
'shortname' => $this->r->shortname,
|
||||
|
@ -316,7 +316,7 @@ class studyplanpage {
|
|||
}
|
||||
|
||||
public function export_page_csv() {
|
||||
$plist = period::findForPage($this);
|
||||
$plist = period::find_for_page($this);
|
||||
|
||||
$model = $this->editor_model();
|
||||
|
||||
|
@ -473,7 +473,7 @@ class studyplanpage {
|
|||
}
|
||||
|
||||
public function import_periods_model($model) {
|
||||
$periods = period::findForPage($this);
|
||||
$periods = period::find_for_page($this);
|
||||
foreach ($model as $pmodel) {
|
||||
$pi = $pmodel["period"];
|
||||
if (array_key_exists($pi, $periods)) {
|
||||
|
|
|
@ -86,7 +86,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function get_studyplan_map($id) {
|
||||
if (isset($id) && $id > 0) {
|
||||
$studyplan = studyplan::findById($id);
|
||||
$studyplan = studyplan::find_by_id($id);
|
||||
webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $studyplan->context());
|
||||
return $studyplan->editor_model();
|
||||
} else {
|
||||
|
@ -112,7 +112,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function get_studyline_map($id) {
|
||||
|
||||
$o = studyline::findById($id);
|
||||
$o = studyline::find_by_id($id);
|
||||
webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $o->context());
|
||||
return $o->editor_model();
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ class studyplanservice extends \external_api {
|
|||
// Do not validate the context in this case, just check the permissions.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $context, false);
|
||||
|
||||
$o = studyplan::findById($id);
|
||||
$o = studyplan::find_by_id($id);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
|
||||
$o->edit([
|
||||
|
@ -232,7 +232,7 @@ class studyplanservice extends \external_api {
|
|||
}
|
||||
|
||||
public static function delete_studyplan($id, $force = false) {
|
||||
$o = studyplan::findById($id);
|
||||
$o = studyplan::find_by_id($id);
|
||||
// Validate if the requesting user has the right to edit the plan in it's current context.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
return $o->delete(!!$force)->model();
|
||||
|
@ -260,7 +260,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function add_studyline($pageid, $name, $shortname, $color, $sequence) {
|
||||
// Validate if the requesting user has the right to edit the plan in it's current context.
|
||||
$page = studyplanpage::findById($pageid);
|
||||
$page = studyplanpage::find_by_id($pageid);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $page->studyplan()->context());
|
||||
|
||||
$o = studyline::add([
|
||||
|
@ -293,7 +293,7 @@ class studyplanservice extends \external_api {
|
|||
}
|
||||
|
||||
public static function edit_studyline($id, $name, $shortname, $color) {
|
||||
$o = studyline::findById($id);
|
||||
$o = studyline::find_by_id($id);
|
||||
// Validate if the requesting user has the right to edit the plan in it's current context.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
|
||||
|
@ -322,7 +322,7 @@ class studyplanservice extends \external_api {
|
|||
}
|
||||
|
||||
public static function delete_studyline($id) {
|
||||
$o = studyline::findById($id);
|
||||
$o = studyline::find_by_id($id);
|
||||
// Validate if the requesting user has the right to edit the plan in it's current context.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
return $o->delete()->model();
|
||||
|
@ -353,7 +353,7 @@ class studyplanservice extends \external_api {
|
|||
public static function reorder_studylines($resequence) {
|
||||
// Validate if the requesting user has the right to edit the lines in it's current context.
|
||||
foreach ($resequence as $sq) {
|
||||
$o = studyline::findById(($sq['id']));
|
||||
$o = studyline::find_by_id(($sq['id']));
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
}
|
||||
|
||||
|
@ -381,7 +381,7 @@ class studyplanservice extends \external_api {
|
|||
}
|
||||
|
||||
public static function get_studyitem($id) {
|
||||
$o = studyitem::findById($id);
|
||||
$o = studyitem::find_by_id($id);
|
||||
webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $o->context());
|
||||
return $o->editor_model();
|
||||
|
||||
|
@ -414,7 +414,7 @@ class studyplanservice extends \external_api {
|
|||
}
|
||||
|
||||
public static function add_studyitem($lineid, $type, $details, $slot = -1, $layer = 0) {
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyline::findById($lineid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyline::find_by_id($lineid)->context());
|
||||
|
||||
$o = studyitem::add([
|
||||
'line_id' => $lineid,
|
||||
|
@ -449,7 +449,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function edit_studyitem($id, $conditions, $continuationid = false) {
|
||||
|
||||
$o = studyitem::findById($id);
|
||||
$o = studyitem::find_by_id($id);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
|
||||
$config = [
|
||||
|
@ -490,7 +490,7 @@ class studyplanservice extends \external_api {
|
|||
public static function reorder_studyitems($resequence) {
|
||||
// Check for permissions to modify the studyplan.
|
||||
foreach ($resequence as $sq) {
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById(($sq['id']))->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::find_by_id(($sq['id']))->context());
|
||||
}
|
||||
|
||||
return studyitem::reorder($resequence)->model();
|
||||
|
@ -513,7 +513,7 @@ class studyplanservice extends \external_api {
|
|||
}
|
||||
|
||||
public static function delete_studyitem($id) {
|
||||
$o = studyitem::findById($id);
|
||||
$o = studyitem::find_by_id($id);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
|
||||
return $o->delete()->model();
|
||||
|
@ -538,8 +538,8 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function connect_studyitems($fromid, $toid) {
|
||||
// Validate permissions.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($fromid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($toid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::find_by_id($fromid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::find_by_id($toid)->context());
|
||||
|
||||
$o = studyitemconnection::connect($fromid, $toid);
|
||||
return $o->model();
|
||||
|
@ -564,8 +564,8 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function disconnect_studyitems($fromid, $toid) {
|
||||
// Validate permissions.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($fromid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($toid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::find_by_id($fromid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::find_by_id($toid)->context());
|
||||
return studyitemconnection::disconnect($fromid, $toid)->model();
|
||||
}
|
||||
|
||||
|
@ -622,12 +622,12 @@ class studyplanservice extends \external_api {
|
|||
global $USER;
|
||||
|
||||
// Find related course and course context.
|
||||
$coursecontext = gradeinfo::getCourseContextById($gradeid);
|
||||
$coursecontext = gradeinfo::get_coursecontext_by_id($gradeid);
|
||||
// Do sanity checks.
|
||||
\external_api::validate_context($coursecontext);
|
||||
|
||||
// Check correct capabilities.
|
||||
if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($itemid)->context()) ||
|
||||
if (has_capability('local/treestudyplan:editstudyplan', studyitem::find_by_id($itemid)->context()) ||
|
||||
is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) {
|
||||
return gradeinfo::include_grade($gradeid, $itemid, $include, $required)->model();
|
||||
} else {
|
||||
|
@ -684,7 +684,7 @@ class studyplanservice extends \external_api {
|
|||
$dbman = $DB->get_manager();
|
||||
|
||||
// Validate permissions.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::find_by_id($studyplanid)->context());
|
||||
|
||||
$list = [];
|
||||
// Check if scaleid is valid.
|
||||
|
@ -705,13 +705,13 @@ class studyplanservice extends \external_api {
|
|||
|
||||
foreach ($records as $itemr) {
|
||||
$studyitem = new studyitem($itemr->id);
|
||||
if ($studyitem->isValid() && $studyitem->type() == studyitem::COURSE) {
|
||||
if ($studyitem->valid() && $studyitem->type() == studyitem::COURSE) {
|
||||
$courseinfo = $studyitem->getcourseinfo();
|
||||
$gradables = gradeinfo::list_studyitem_gradables($studyitem);
|
||||
|
||||
$gradelist = [];
|
||||
foreach ($gradables as $g) {
|
||||
$gi = $g->getGradeItem();
|
||||
$gi = $g->get_gradeitem();
|
||||
|
||||
// Only change items that do not yet have grades.
|
||||
// Otherwise we will need to implement grade recalculations and it is not worth the trouble. .
|
||||
|
@ -827,7 +827,7 @@ class studyplanservice extends \external_api {
|
|||
global $DB;
|
||||
|
||||
// Validate permissions.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::find_by_id($studyplanid)->context());
|
||||
|
||||
// Find studyline id's.
|
||||
$studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]);
|
||||
|
@ -837,7 +837,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
foreach ($records as $itemr) {
|
||||
$studyitem = new studyitem($itemr->id);
|
||||
if ($studyitem->isValid() && $studyitem->type() == studyitem::COURSE) {
|
||||
if ($studyitem->valid() && $studyitem->type() == studyitem::COURSE) {
|
||||
$record = $DB->get_record("course_format_options",
|
||||
["courseid" => $studyitem->courseid(), "name" => "automaticenddate"]);
|
||||
if ($record && $record->value) {
|
||||
|
@ -870,7 +870,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function duplicate_plan($studyplanid, $name, $shortname) {
|
||||
// Validate permissions.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::find_by_id($studyplanid)->context());
|
||||
|
||||
return studyplan::duplicate_plan($studyplanid, $name, $shortname);
|
||||
}
|
||||
|
@ -895,9 +895,9 @@ class studyplanservice extends \external_api {
|
|||
public static function export_plan($studyplanid, $format = "json") {
|
||||
try {
|
||||
// Validate permissions.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::find_by_id($studyplanid)->context());
|
||||
|
||||
$plan = studyplan::findById($studyplanid);
|
||||
$plan = studyplan::find_by_id($studyplanid);
|
||||
if ($format == "csv") {
|
||||
// FIXME: Make sure this webservice function gets called for the page instead of the studyplan.
|
||||
return $plan->pages()[0]->export_page_csv();
|
||||
|
@ -923,8 +923,8 @@ class studyplanservice extends \external_api {
|
|||
$systemcontext = webservicehelper::system_context();
|
||||
|
||||
try {
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
|
||||
$plan = studyplan::findById($studyplanid);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::find_by_id($studyplanid)->context());
|
||||
$plan = studyplan::find_by_id($studyplanid);
|
||||
// FIXME: Make sure this gets called for the page instead of the studyplan.
|
||||
return $plan->pages()[0]->export_studylines();
|
||||
} catch (\webservice_access_exception $x) {
|
||||
|
@ -978,7 +978,7 @@ class studyplanservice extends \external_api {
|
|||
public static function import_studylines($studyplanid, $content, $format = "application/json") {
|
||||
|
||||
try {
|
||||
$plan = studyplan::findById($studyplanid);
|
||||
$plan = studyplan::find_by_id($studyplanid);
|
||||
// Validate import context.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $plan->context());
|
||||
|
||||
|
@ -1091,7 +1091,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function edit_period($id, $fullname, $shortname, $startdate, $enddate) {
|
||||
|
||||
$p = period::findById($id);
|
||||
$p = period::find_by_id($id);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $p->page()->studyplan()->context());
|
||||
|
||||
$p->edit([
|
||||
|
@ -1124,7 +1124,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
public static function course_period_timing($periodid, $courseid, $span = 1) {
|
||||
global $DB;
|
||||
$period = period::findById($periodid);
|
||||
$period = period::find_by_id($periodid);
|
||||
$periodnr = $period->period();
|
||||
$page = $period->page();
|
||||
// Check for studyplan edit permissions.
|
||||
|
@ -1135,7 +1135,7 @@ class studyplanservice extends \external_api {
|
|||
if (webservicehelper::has_capabilities("moodle/course:update", $coursecontext)) {
|
||||
|
||||
// Get the proper list of all the periods for this page.
|
||||
$periods = period::findForPage($page);
|
||||
$periods = period::find_for_page($page);
|
||||
|
||||
$pstart = $periods[$periodnr];
|
||||
|
||||
|
@ -1187,7 +1187,7 @@ class studyplanservice extends \external_api {
|
|||
}
|
||||
|
||||
public static function set_studyitem_span($id, $span = null) {
|
||||
$o = studyitem::findById($id);
|
||||
$o = studyitem::find_by_id($id);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
|
||||
$config = [ 'span' => $span];
|
||||
|
|
|
@ -37,7 +37,7 @@ class teachingfinder {
|
|||
}
|
||||
$list = [];
|
||||
foreach ($records as $r) {
|
||||
$list[] = studyplan::findById($r->studyplan_id);
|
||||
$list[] = studyplan::find_by_id($r->studyplan_id);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class teachingfinder {
|
|||
// First find all active study plans.
|
||||
|
||||
$sql = "SELECT p.id FROM {local_treestudyplan_page} p
|
||||
WHERE startdate <= NOW() and enddate >= NOW()";
|
||||
WHERE startdate <= NOW() and enddate >= NOW()";
|
||||
$pageids = $DB->get_fieldset_sql($sql, []);
|
||||
|
||||
// Then parse them to see if the user has the grading permission in any of them .
|
||||
|
@ -102,7 +102,7 @@ class teachingfinder {
|
|||
|
||||
public static function get_update_time($teacherid): int {
|
||||
global $DB;
|
||||
$r = $DB->get_field_sql("SELECT MIN(update_time)FROM {".self::TABLE."} WHERE teacher_id=:teacher_id",
|
||||
$r = $DB->get_field_sql("SELECT MIN(update_time) FROM {".self::TABLE."} WHERE teacher_id=:teacher_id",
|
||||
["teacher_id" => $teacherid]);
|
||||
return (int)($r->update_time);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ if (!empty($options["all"])) {
|
|||
}
|
||||
|
||||
$generator = new gradegenerator();
|
||||
$generator->fromFile($options["file"]);
|
||||
$generator->from_file($options["file"]);
|
||||
|
||||
cli_writeln(count($plans)." studyplans found:");
|
||||
foreach ($plans as $plan) {
|
||||
|
@ -80,7 +80,7 @@ foreach ($plans as $plan) {
|
|||
$users = $plan->find_linked_users();
|
||||
foreach ($users as $u) {
|
||||
$generator->addstudent($u->username);
|
||||
$generator->addUserNameInfo($u->username, $u->firstname, $u->lastname);
|
||||
$generator->add_username_info($u->username, $u->firstname, $u->lastname);
|
||||
cli_writeln(" - {$u->firstname} {$u->lastname} / {$u->username}");
|
||||
}
|
||||
|
||||
|
@ -96,4 +96,4 @@ foreach ($plans as $plan) {
|
|||
}
|
||||
}
|
||||
|
||||
$generator->toFile($options["file"]);
|
||||
$generator->to_file($options["file"]);
|
||||
|
|
|
@ -97,7 +97,7 @@ if (!empty($options["all"])) {
|
|||
}
|
||||
|
||||
$generator = new gradegenerator();
|
||||
$generator->fromFile($options["file"]);
|
||||
$generator->from_file($options["file"]);
|
||||
|
||||
$assignments = [];
|
||||
|
||||
|
@ -125,7 +125,7 @@ foreach ($plans as $plan) {
|
|||
$gen = $generator->generate($u->username, $line->shortname(), $gradables);
|
||||
foreach ($gen as $gg) {
|
||||
$g = $gg->gi;
|
||||
$gi = $g->getGradeitem();
|
||||
$gi = $g->get_gradeitem();
|
||||
|
||||
$name = $gi->itemname;
|
||||
$grade = $gg->gradetext;
|
||||
|
@ -184,4 +184,4 @@ foreach ($plans as $plan) {
|
|||
}
|
||||
}
|
||||
|
||||
$generator->toFile($options["file"]);
|
||||
$generator->to_file($options["file"]);
|
||||
|
|
Loading…
Reference in New Issue
Block a user