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.
require_capability('local/treestudyplan:configure', $systemcontext);
$PAGE->requires->js_call_amd('local_treestudyplan/cfg-grades', 'init');
const GRADECFG_TABLE = "local_treestudyplan_gradecfg";
@ -69,7 +68,6 @@ if ($_POST["action"] == "update") {
$DB->update_record(GRADECFG_TABLE, $scalecfg);
}
} else {
$scalecfg = (object)[ "scale_id" => $scale->id, ];
$requireinsert = false;
@ -141,7 +139,6 @@ if ($_POST["action"] == "update") {
}
// Process all available scales and load the current configuration for it.
$data = [];
foreach ($scales as $scale) {
@ -189,7 +186,6 @@ foreach ($scales as $scale) {
$data[] = $row;
}
print html_writer::start_tag("form", ["method" => "post", ]);
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 html_writer::tag('p', get_string('cfg_grades_desc', '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 = [];
foreach ($gradecfgs as $g) {
$row = [];
$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', ]);
$data[] = $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, ['name' => "g_new_min_completed", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']);
$row[] = html_writer::tag("input", null,
[ 'name' => "g_new_gradepoints",
'value' => '',
'type' => 'number',
'min' => '0',
'pattern' => '/d+',
'step' => '1',
'autocomplete' => 'off']);
$row[] = html_writer::tag("input", null,
[ 'name' => "g_new_min_completed",
'value' => '',
'type' => 'text',
"class" => "float",
'autocomplete' => 'off']);
$data[] = $row;
$table = new html_table();
$table->id = "";
$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('delete', );
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::end_tag("form");

View File

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

View File

@ -26,8 +26,7 @@ use local_treestudyplan\local\helpers\webservicehelper;
require_once($CFG->libdir.'/externallib.php');
class associationservice extends \external_api
{
class associationservice extends \external_api {
const CAP_EDIT = "local/treestudyplan:editstudyplan";
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( [
'like' => new \external_value(PARAM_TEXT, 'search text', 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());
}
// 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;
// Only allow this if the user has the right to edit in this context.
@ -130,7 +125,8 @@ class associationservice extends \external_api
$sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)";
$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, .
$sql .= " AND contextid = :context_id";
$params['context_id'] = $contextid;
@ -145,8 +141,7 @@ class associationservice extends \external_api
return $cohorts;
}
public static function find_user_parameters()
{
public static function find_user_parameters() {
return new \external_function_parameters( [
'like' => new \external_value(PARAM_TEXT, 'search text'),
'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());
}
// 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;
// Only allow this if the user has the right to edit in this context (using system rights would make things more confusing).
@ -191,16 +184,14 @@ class associationservice extends \external_api
return $users;
}
public static function connect_cohort_parameters()
{
public static function connect_cohort_parameters() {
return new \external_function_parameters( [
"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),
] );
}
public static function connect_cohort_returns()
{
public static function connect_cohort_returns() {
return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'),
@ -208,8 +199,7 @@ class associationservice extends \external_api
}
// Actual functions.
public static function connect_cohort($studyplanid, $cohortid)
{
public static function connect_cohort($studyplanid, $cohortid) {
global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid);
@ -222,24 +212,22 @@ class associationservice extends \external_api
]);
$studyplan->mark_csync_changed();
return ['success' => true, 'msg'=>'Cohort connected'];
return ['success' => true, 'msg' => 'Cohort connected'];
} 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( [
"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),
] );
}
public static function disconnect_cohort_returns()
{
public static function disconnect_cohort_returns() {
return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'),
@ -247,8 +235,7 @@ class associationservice extends \external_api
}
// Actual functions.
public static function disconnect_cohort($studyplanid, $cohortid)
{
public static function disconnect_cohort($studyplanid, $cohortid) {
global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid);
@ -262,23 +249,21 @@ class associationservice extends \external_api
$studyplan->mark_csync_changed();
return ['success' => true, 'msg'=>'Cohort Disconnected'];
return ['success' => true, 'msg' => 'Cohort Disconnected'];
} 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( [
"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),
] );
}
public static function connect_user_returns()
{
public static function connect_user_returns() {
return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'),
@ -286,8 +271,7 @@ class associationservice extends \external_api
}
// Actual functions.
public static function connect_user($studyplanid, $userid)
{
public static function connect_user($studyplanid, $userid) {
global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid);
@ -300,23 +284,21 @@ class associationservice extends \external_api
]);
$studyplan->mark_csync_changed();
return ['success' => true, 'msg'=>'Cohort connected'];
return ['success' => true, 'msg' => 'Cohort connected'];
} 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( [
"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),
] );
}
public static function disconnect_user_returns()
{
public static function disconnect_user_returns() {
return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'),
@ -324,8 +306,7 @@ class associationservice extends \external_api
}
// Actual functions.
public static function disconnect_user($studyplanid, $userid)
{
public static function disconnect_user($studyplanid, $userid) {
global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
@ -338,27 +319,24 @@ class associationservice extends \external_api
$studyplan->mark_csync_changed();
return ['success' => true, 'msg'=>'User Disconnected'];
return ['success' => true, 'msg' => 'User Disconnected'];
} 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( [
"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());
}
// Actual functions.
public static function associated_users($studyplanid)
{
public static function associated_users($studyplanid) {
global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
@ -376,21 +354,18 @@ class associationservice extends \external_api
return $users;
}
public static function associated_cohorts_parameters()
{
public static function associated_cohorts_parameters() {
return new \external_function_parameters( [
"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());
}
// Actual functions.
public static function associated_cohorts($studyplanid)
{
public static function associated_cohorts($studyplanid) {
global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
@ -406,39 +381,34 @@ class associationservice extends \external_api
return $cohorts;
}
public static function all_associated_parameters()
{
public static function all_associated_parameters() {
return new \external_function_parameters( [
"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());
}
// Actual functions.
public static function all_associated($studyplanid)
{
public static function all_associated($studyplanid) {
global $CFG, $DB;
$studyplan = studyplan::findById($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 = {$studyplanid}
OR tu.studyplan_id = {$studyplanid}
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) {
@ -464,25 +434,22 @@ class associationservice extends \external_api
$sortln_b = $b['lastname'];
}
$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( [
"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();
}
// Actual functions.
public static function cascade_cohortsync($studyplanid)
{
public static function cascade_cohortsync($studyplanid) {
$studyplan = studyplan::findById($studyplanid);
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'),
"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),
"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'),
"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),
@ -110,7 +110,7 @@ class badgeinfo {
"infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL),
"name" => new \external_value(PARAM_TEXT, 'badge name'),
"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'),
"issued" => new \external_value(PARAM_BOOL, 'badge is issued'),
"dateissued" => new \external_value(PARAM_TEXT, 'date the badge was issued', VALUE_OPTIONAL),

View File

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

View File

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

View File

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

View File

@ -66,7 +66,7 @@ class corecompletioninfo {
COMPLETION_COMPLETE => "complete",
COMPLETION_COMPLETE_PASS => "complete-pass",
COMPLETION_COMPLETE_FAIL => "complete-fail",
COMPLETION_COMPLETE_FAIL_HIDDEN => "complete-fail"]; // the front end won't differentiate between hidden or not.
COMPLETION_COMPLETE_FAIL_HIDDEN => "complete-fail"]; // The front end won't differentiate between hidden or not.
}
return self::$COMPLETIONHANDLES[$completion] ?? "undefined";
}
@ -151,14 +151,14 @@ class corecompletioninfo {
}
private static function aggregation_handle($method) {
return ($method==COMPLETION_AGGREGATION_ALL)?"all":"any";
return ($method==COMPLETION_AGGREGATION_ALL) ? "all" : "any";
}
public function editor_model() {
global $DB, $CFG, $COMPLETIONCRITERIA_TYPES;
$conditions = [];
$aggregation = "all"; // default.
$aggregation = "all"; // Default.
$info = [
"conditions" => $conditions,
"aggregation" => self::aggregation_handle($this->completion->get_aggregation_method()),
@ -304,7 +304,6 @@ class corecompletioninfo {
}
return $info;
}
@ -352,7 +351,7 @@ class corecompletioninfo {
"type" => $COMPLETIONCRITERIA_TYPES[$type],
"aggregation" => self::aggregation_handle($typeaggregation),
"completed" => $completed,
"status" => $completed?"complete":"incomplete",
"status" => $completed ? "complete" : "incomplete",
"title" => reset($completions)->get_criteria()->get_type_title(),
"items" => [],
];
@ -370,7 +369,7 @@ class corecompletioninfo {
"title" => $criteria->get_title_detailed(),
"details" => $criteria->get_details($completion),
"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) {
@ -399,7 +398,7 @@ class corecompletioninfo {
$iinfo['grade'] = floatval($iinfo['details']['status']);
if ($iinfo["grade"] > 0) {
$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") {
$cinfo["status"] = "progress";
}
@ -509,7 +508,6 @@ class corecompletioninfo {
}
/**
* 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->count = $count;
$result->completed = $completed;
$result->percentage = ($count > 0)?(($completed / $count) * 100):0;
$result->percentage = ($count > 0) ? (($completed / $count) * 100) : 0;
return $result;
}
}

View File

@ -49,7 +49,7 @@ class courseinfo {
}
public function course() {
return $this->course; // php arrays are assigned by copy.
return $this->course; // Php arrays are assigned by copy.
}
public function course_context() {
@ -86,7 +86,7 @@ class courseinfo {
public static function get_contentitem($name) {
$contentitems = static::get_contentitems();
for($i = 0; $i < count($contentitems); $i++) {
for ($i = 0; $i < count($contentitems); $i++) {
if ($contentitems[$i]->get_name() == $name) {
return $contentitems[$i];
}
@ -122,7 +122,7 @@ class courseinfo {
else {
return "present";
}
} else{
} else {
return "future";
}
}
@ -282,7 +282,6 @@ class courseinfo {
}
return $info;
}

View File

@ -29,8 +29,7 @@ use \local_treestudyplan\local\helpers\webservicehelper;
use \local_treestudyplan\completionscanner;
use \local_treestudyplan\gradingscanner;
class courseservice extends \external_api
{
class courseservice extends \external_api {
const CAP_EDIT = "local/treestudyplan:editstudyplan";
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( [
"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));
}
@ -82,8 +79,9 @@ class courseservice extends \external_api
if ($root->id == 0) {
// On the system level, determine the user's topmost allowed catecories.
$usertop = \core_course_category::user_top();
if ($usertop->id == 0) { // top category..
$children = $root->get_children(); // returns a list of çore_course_category, let it overwrite $children.
if ($usertop->id == 0) {
// Top category..
$children = $root->get_children(); // Returns a list of çore_course_category, let it overwrite $children.
} else {
$children = [$usertop];
}
@ -97,15 +95,13 @@ class courseservice extends \external_api
return $list;
}
public static function get_category_parameters()
{
public static function get_category_parameters() {
return new \external_function_parameters( [
"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);
}
@ -118,7 +114,7 @@ class courseservice extends \external_api
global $DB;
$catcontext = $cat->get_context();
$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();
$model = [
"id" => $cat->id,
@ -144,20 +140,17 @@ class courseservice extends \external_api
return $model;
}
public static function list_accessible_categories_parameters()
{
public static function list_accessible_categories_parameters() {
return new \external_function_parameters( [
"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));
}
public static function list_accessible_categories($operation="edit")
{
public static function list_accessible_categories($operation="edit") {
if ($operation == "edit") {
$capability = self::CAP_EDIT;
} else { // Operation == "view" || default.
@ -216,20 +209,17 @@ class courseservice extends \external_api
return $list;
}
public static function list_used_categories_parameters()
{
public static function list_used_categories_parameters() {
return new \external_function_parameters( [
"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));
}
public static function list_used_categories($operation='edit')
{
public static function list_used_categories($operation='edit') {
global $DB;
if ($operation == "edit") {
$capability = self::CAP_EDIT;
@ -244,7 +234,6 @@ class courseservice extends \external_api
}
$rs->close();
// Now filter the categories that the user has acces to by the used context id's.
// (That should filter out irrelevant stuff).
$cats = static::categories_by_capability($capability);
@ -300,7 +289,6 @@ class courseservice extends \external_api
return $list;
}
/**************************************
*
* Progress scanners for teacherview
@ -338,9 +326,7 @@ class courseservice extends \external_api
return $scanner->model();
}
public static function scan_completion_progress_parameters()
{
public static function scan_completion_progress_parameters() {
return new \external_function_parameters( [
"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),
@ -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);
}
public static function scan_completion_progress($criteriaid, $studyplanid, $courseid)
{
public static function scan_completion_progress($criteriaid, $studyplanid, $courseid) {
global $DB;
// Verify access to the study plan.
$o = studyplan::findById($studyplanid);
@ -368,24 +352,21 @@ class courseservice extends \external_api
return $scanner->model();
}
public static function scan_badge_progress_parameters()
{
public static function scan_badge_progress_parameters() {
return new \external_function_parameters( [
"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),
]);
}
public static function scan_badge_progress_returns()
{
public static function scan_badge_progress_returns() {
return new \external_single_structure([
"total" => new \external_value(PARAM_INT, 'Total number of students scanned'),
"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;
// Check access to the study plan.
$o = studyplan::findById($studyplanid);
@ -412,5 +393,4 @@ class courseservice extends \external_api
}
}

View File

@ -50,7 +50,6 @@ class gradeinfo {
private $cmid;
private $coursesort;
private static $contentitems = null;
private $gradingscanner;
@ -59,7 +58,7 @@ class gradeinfo {
protected static function getSectionSequence($sectionid) {
global $DB;
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];
}
@ -87,7 +86,7 @@ class gradeinfo {
public static function get_contentitem($name) {
$contentitems = static::get_contentitems();
for($i = 0; $i < count($contentitems); $i++) {
for ($i = 0; $i < count($contentitems); $i++) {
if ($contentitems[$i]->get_name() == $name) {
return $contentitems[$i];
}
@ -116,7 +115,7 @@ class gradeinfo {
// Determine the icon for the associated activity.
$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.
if ($gi->itemtype != "mod" || empty($gi->itemmodule) || empty($gi->iteminstance)) {
@ -146,10 +145,10 @@ class gradeinfo {
$this->scale = $gi->load_scale();
$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->typename = empty($contentitem)?$gi->itemmodule:$contentitem->get_title()->get_value();
$this->name = empty($outcome) ? $gi->itemname : $outcome->name;
$this->typename = empty($contentitem) ? $gi->itemmodule : $contentitem->get_title()->get_value();
$this->gradingscanner = new gradingscanner($gi);
$this->coursesort = $this->section * 1000 + $this->sectionorder;
@ -160,7 +159,7 @@ class gradeinfo {
global $DB;
if ($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) {
return(true);
}
@ -172,7 +171,7 @@ class gradeinfo {
global $DB;
if ($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) {
return(true);
}
@ -217,7 +216,6 @@ class gradeinfo {
return $model;
}
public static function user_structure($value=VALUE_REQUIRED) {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'grade_item id'),
@ -265,8 +263,8 @@ class gradeinfo {
"name" => $this->name,
"typename" => $this->typename,
"grade" => $finalgrade,
"gradetype" => isset($this->scale)?"completion":"grade",
"feedback" => empty($grade)?null:$grade->feedback,
"gradetype" => isset($this->scale) ? "completion" : "grade",
"feedback" => empty($grade) ? null : $grade->feedback,
"completion" => completion::label($completion),
"icon" => $this->icon,
"link" => $this->link,
@ -291,13 +289,17 @@ class gradeinfo {
$courseid = $item->courseid();
$gradeitems= grade_item::fetch_all(['itemtype' => 'mod', 'courseid' => $courseid]);
foreach ($gradeitems as $gi) {
$giname = empty($outcome)?$gi->itemname:$outcome->name;
$giname = empty($outcome) ? $gi->itemname : $outcome->name;
$gitype = $gi->itemmodule;
if ($giname == $model["name"] && $gitype == $model["type"]) {
// We have a match.
if (!isset($model["selected"])) { $model["selected"] = true;}
if (!isset($model["required"])) { $model["required"] = false;}
if (!isset($model["selected"])) {
$model["selected"] = true;
}
if (!isset($model["required"])) {
$model["required"] = false;
}
if ($model["selected"] || $model["required"]) {
static::include_grade($gi->id, $item->id(), $model["selected"], $model["required"]);
}
@ -324,8 +326,8 @@ class gradeinfo {
try {
$gradable = new static($gi->id, $studyitem);
$list[] = $gradable;
} catch (\InvalidArgumentException $x) {
}
catch(\InvalidArgumentException $x) {}
}
}
}
@ -334,7 +336,7 @@ class gradeinfo {
usort($list, function($a, $b) {
$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;
}
@ -350,8 +352,7 @@ class gradeinfo {
if ($r->include || $r->required) {
$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.
// Remove the link to avoid database record hogging.
$DB->delete_records($table, ['id' => $r->id]);
@ -361,7 +362,7 @@ class gradeinfo {
usort($list, function($a, $b) {
$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;
}
@ -381,7 +382,7 @@ class gradeinfo {
'studyitem_id' => $itemid,
'grade_item_id' => $gradeid,
'include' => 1,
'required' =>boolval($required)?1:0]
'required' => boolval($required)?1:0]
);
}
} else {
@ -396,5 +397,4 @@ class gradeinfo {
}
}

View File

@ -25,8 +25,7 @@ require_once($CFG->libdir.'/externallib.php');
use \grade_item;
class gradingscanner
{
class gradingscanner {
private static $modsupported = [];
private static $coursestudents = [];
private $scanner = null;
@ -132,9 +131,9 @@ class gradingscanner
$finalgrade = $grade->finalgrade;
$scale = $this->gi->load_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) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$this->gi->grademax]);
$gradecfg = $DB->get_record($table, ["grade_points" => $this->gi->grademax]);
} else {
$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
*/
namespace local_treestudyplan\local\aggregators;
use \local_treestudyplan\courseinfo;
@ -98,7 +97,6 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
public function useRequiredGrades() { return True;}
public function useItemConditions() { return False;}
public function aggregate_binary_goals(array $completions, array $required = []) {
// 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::PROGRESS - All other states.
$total = count($completions);
$completed = 0;
$progress = 0;
@ -121,7 +118,7 @@ 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) {
@ -132,10 +129,10 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$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;
@ -155,7 +152,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid) {
$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.
// Loop through all associated gradables and count the totals, completed, etc..
$completions = [];
@ -214,7 +211,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$gradeitem = $gradeinfo->getGradeitem();
$grade = $gradeitem->get_final($userid);
$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)) {
return completion::INCOMPLETE;
@ -236,9 +233,9 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale();
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) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]);
$gradecfg = $DB->get_record($table, ["grade_points" => $gradeitem->grademax]);
} else {
$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
*/
namespace local_treestudyplan\local\aggregators;
use \local_treestudyplan\courseinfo;
@ -101,7 +100,6 @@ class core_aggregator extends \local_treestudyplan\aggregator {
// Option: Use course end grade to determine that...
// Probably needs a config value in the aggregator....
return completion::COMPLETED;
} else {
// Check if the course is over or not, if it is over, display failed.
@ -125,7 +123,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
return completion::INCOMPLETE;
}
}
} else{
} else {
return completion::INCOMPLETE;
}
}
@ -159,7 +157,6 @@ class core_aggregator extends \local_treestudyplan\aggregator {
}
}
// CORE COMPLETION DOESN'T REALLY USE THE FUNCTIONS BELOW.
// 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;
$scale = $gradeinfo->getScale();
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) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]);
$gradecfg = $DB->get_record($table, ["grade_points" => $gradeitem->grademax]);
} else {
$gradecfg = null;
}

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\aggregators;
use \local_treestudyplan\courseinfo;
@ -102,7 +101,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_junction(array $completion, studyitem $studyitem, $userid) {
$completed = self::aggregate_completion($completion, $studyitem->conditions());
// If null result (conditions are unknown/null) - default to ALL.
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) {
@ -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
*/
namespace local_treestudyplan\local;
use Exception;
@ -96,7 +95,6 @@ class gradegenerator {
}
}
public function __construct() {
}
@ -137,7 +135,7 @@ class gradegenerator {
$results = [];
$gaveup = false;
for($i=0; $i < $count; $i++) {
for ($i=0; $i < $count; $i++) {
$r = new \stdClass;
if ($gaveup) {
$r->done = !$gaveup;
@ -146,12 +144,12 @@ class gradegenerator {
}
if ($r->done) {
$score = rand(0, $int);
$r->result = ($score > 20); // determine if the assignment was successful.
$r->result = ($score > 20); // Determine if the assignment was successful.
if (!$r->result) {
$r->failed = !($score > 10);
}
} else {
$r->result = false; // make sure a result property is always there.
$r->result = false; // Make sure a result property is always there.
$r->failed = true;
}
// Aways generate a little feedback.
@ -173,7 +171,7 @@ class gradegenerator {
$rlist = [];
$gen = $this->generateraw($student, $skill, count($gradeinfos));
for($i=0; $i < count($gradeinfos); $i++) {
for ($i=0; $i < count($gradeinfos); $i++) {
$g = $gradeinfos[$i];
$gi = $g->getGradeitem();
$gr = $gen[$i];
@ -181,9 +179,9 @@ class gradegenerator {
// First get the configured interpretation for this scale or grade.
$scale = $gi->load_scale();
if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
$gradecfg = $DB->get_record($table, ["scale_id" => $scale->id]);
} else if ($gi->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gi->grademax]);
$gradecfg = $DB->get_record($table, ["grade_points" => $gi->grademax]);
} else {
$gradecfg = null;
}
@ -194,13 +192,13 @@ class gradegenerator {
// INCOMPLETE.
// Fair chance of teacher forgetting to set incomplete to "no evidence".
$grade = 0;
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>"" ];
$r = (object)["gi" => $g, "grade" => $grade, "fb" => "" ];
} else if (!$gr->result) {
$grade = rand($gradecfg->min_progress, $gradecfg->min_completed -1 );
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>$gr->fb ];
} else{
$r = (object)["gi" => $g, "grade" => $grade, "fb" => $gr->fb ];
} else {
// 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;
@ -217,13 +215,13 @@ class gradegenerator {
if (!$gr->done) {
// INCOMPLETe or FAILED.
$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) {
//PROGRESS.
$r = (object)["gi" => $g, "grade" => rand( round($gi->gradepass/2), $gi->gradepass -1 ), "fb" =>$gr->fb ];
} else{
$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 ];
$r = (object)["gi" => $g, "grade" => rand( $gi->gradepass, $gi->grademax ), "fb" => $gr->fb ];
}
$r->gradetext = $r->grade;
@ -236,13 +234,13 @@ class gradegenerator {
if (!$gr->done) {
// INCOMPLETe or FAILED.
$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) {
//PROGRESS.
$r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.35), round($range * 0.55) - 1 ), "fb" =>$gr->fb ];
} else{
$r = (object)["gi" => $g, "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 ), "fb" =>$gr->fb ];
$r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.55) , $range ), "fb" => $gr->fb ];
}
$r->gradetext = $r->grade;
@ -279,7 +277,7 @@ class gradegenerator {
try {
$json = file_get_contents($filename);
$this->unserialize($json);
} catch(Exception $x) {
} catch (Exception $x) {
cli_problem("ERROR loading from file");
throw $x; // Throw X up again to show the output.
}
@ -295,5 +293,4 @@ class gradegenerator {
return $path;
}
}

View File

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

View File

@ -20,11 +20,9 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\helpers;
require_once($CFG->dirroot.'/webservice/lib.php');
class webservicehelper {
/** @var \context_system */
private static $systemcontext = null;
@ -120,11 +118,11 @@ class webservicehelper {
public static function find_context($contextid): \context{
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 {
$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.
}
// Validate the found context.
@ -132,7 +130,7 @@ class webservicehelper {
self::$validatedcontexts[$contextid] = $context;
}
return self::$validatedcontexts[$contextid];
} else{
} else {
return static::system_context(); // This function ensures the system context is validated just once this call.
}
}

View File

@ -20,10 +20,8 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\ungradedscanners;
class assign_scanner extends scanner_base {
protected function get_ungraded_submissions() {
@ -53,7 +51,6 @@ class assign_scanner extends scanner_base {
return $DB->get_fieldset_sql($sql);
}
public function count_ungraded($courseuserids=[]) {
$ungraded = $this->get_ungraded_submissions();

View File

@ -20,11 +20,9 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\local\ungradedscanners;
require_once($CFG->dirroot.'/question/engine/states.php'); // for reading question state.
require_once($CFG->dirroot.'/question/engine/states.php'); // For reading question state.
class quiz_scanner extends scanner_base {
@ -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}";
$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.
$submissions[$r->userid] = true; // Set array index based on user id, to avoid checking if value is in array.
}
}
$rs->close();

View File

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

View File

@ -29,7 +29,6 @@ class period {
private static $CACHE = [];
private static $PAGECACHE = [];
private $r; // Holds database record.
private $id;
private $page;
@ -56,9 +55,9 @@ class period {
$periodnr = 1;
}
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);
} catch(\dml_missing_record_exception $x) {
} catch (\dml_missing_record_exception $x) {
// Period does not exist - create one ...
// Make a best guess estimate of the start and end date, based on surrounding periods,.
// Or specified duration of the page and the sequence of the periods .
@ -72,17 +71,17 @@ 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);
$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.
} catch(\dml_missing_record_exception $x2) {
} catch (\dml_missing_record_exception $x2) {
// If not, do a fair guess.
$pstart = $ystart + (($periodnr-1)*$ptime);
}
try {
// Check if we have a next period to glance the start date of as a reference.
$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) {
$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.
$pend = $pstart + $ptime;
}
@ -105,7 +104,7 @@ class period {
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++) {
for ($i=1; $i <= $page->periods(); $i++) {
$period = self::find($page, $i);
$periods[$i] = $period;
}
@ -152,7 +151,7 @@ class period {
public function enddate() {
if ($this->r->enddate && strlen($this->r->enddate) > 0) {
return new \DateTime($this->r->enddate);
} else{
} else {
// Return a date 100 years into the future.
return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
}
@ -162,7 +161,7 @@ class period {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id 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'),
"startdate" => new \external_value(PARAM_TEXT, 'start 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");
}
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");
}
@ -206,8 +205,8 @@ class period {
}
}
$id = $DB->insert_record(self::TABLE, $info);
unset(self::$PAGECACHE[$fields['page_id']]); // invalidate the cache for this page.
return self::findById($id); // make sure the new page is immediately cached.
unset(self::$PAGECACHE[$fields['page_id']]); // Invalidate the cache for this page.
return self::findById($id); // Make sure the new page is immediately cached.
}
public function edit($fields) {
@ -222,14 +221,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();
}

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan\privacy;
use core_privacy\local\metadata\collection;
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.
* 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.
if ($context->contextlevel == CONTEXT_COURSECAT) {
$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) {
$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) {
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))";
$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) {
$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) {
$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)";
$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) {
$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.
$sql = "SELECT s.id FROM {local_treestudyplan}
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.
// 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) {
$sql = "SELECT s.id FROM {local_treestudyplan}
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.
}

View File

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

View File

@ -27,8 +27,7 @@ use \local_treestudyplan\local\helpers\webservicehelper;
require_once($CFG->libdir.'/badgeslib.php');
class studentstudyplanservice extends \external_api
{
class studentstudyplanservice extends \external_api {
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([
"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(
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( [
"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(
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( [
"userid" => new \external_value(PARAM_INT, 'id of user'),
"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();
}
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( [
"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(
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([]);
}
public static function list_own_studyplans_returns()
{
public static function list_own_studyplans_returns() {
return new \external_multiple_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( [
"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(
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( [
"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(
studyplan::editor_structure()
);

View File

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

View File

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

View File

@ -92,8 +92,8 @@ class studyline {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyline'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
"shortname"=> new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color"=> new \external_value(PARAM_TEXT, 'description of studyline'),
"shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color" => new \external_value(PARAM_TEXT, 'description of studyline'),
"sequence" => new \external_value(PARAM_INT, 'order of studyline'),
"slots" => new \external_multiple_structure(
new \external_single_structure([
@ -136,7 +136,7 @@ class studyline {
$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 = [];
@ -254,8 +254,8 @@ class studyline {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyline'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
"shortname"=> new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color"=> new \external_value(PARAM_TEXT, 'description of studyline'),
"shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color" => new \external_value(PARAM_TEXT, 'description of studyline'),
"sequence" => new \external_value(PARAM_INT, 'order of studyline'),
"slots" => new \external_multiple_structure(
new \external_single_structure([
@ -288,7 +288,7 @@ class studyline {
$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 {
@ -316,7 +316,6 @@ class studyline {
}
}
return $model;
}
@ -351,7 +350,7 @@ class studyline {
public function import_studyitems($model, &$itemtranslation, &$connections) {
global $DB;
foreach ($model as $slot=>$slotmodel) {
foreach ($model as $slot=> $slotmodel) {
$courselayer = 0;
$filterlayer = 0;
foreach ($slotmodel as $itemmodel) {

View File

@ -26,16 +26,14 @@ require_once($CFG->libdir.'/externallib.php');
class studyplan {
const TABLE = "local_treestudyplan";
private static $STUDYPLANCACHE = [];
private $r; // Holds database record.
private $id;
private $aggregator;
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;
public function aggregator() {
@ -87,8 +85,7 @@ class studyplan {
if (!isset($this->context)) {
try {
$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.
}
}
@ -99,10 +96,10 @@ class studyplan {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id 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'),
"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_config" => new \external_value(PARAM_TEXT, 'config string for aggregator'),
"aggregation_info" => aggregator::basic_structure(),
@ -134,9 +131,9 @@ class studyplan {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id 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'),
"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'),
"aggregation" => new \external_value(PARAM_TEXT, 'selected aggregator'),
"aggregation_config" => new \external_value(PARAM_TEXT, 'config string for aggregator'),
@ -183,14 +180,13 @@ 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(array('courseid' => 0)) );
$model['advanced']['force_scales'] = [
'scales' => $scales,
];
}
return $model;
}
@ -205,8 +201,7 @@ class studyplan {
}
}
$id = $DB->insert_record(self::TABLE, $info);
$plan = self::findById($id); // make sure the new studyplan is immediately cached.
$plan = self::findById($id); // Make sure the new studyplan is immediately cached.
// Start temporary skräpp code.
// Add a single page and copy the names.This keeps the data sane until the upgrade to .
@ -302,7 +297,7 @@ class studyplan {
if ($contextid <= 0) {
$ids = $DB->get_fieldset_select(self::TABLE, "id", "");
} else{
} else {
if ($contextid == 1) {
$contextid = 1;
$where = "context_id <= :contextid OR context_id IS NULL";
@ -326,7 +321,7 @@ class studyplan {
if ($contextid == 0) {
$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) {
$list[] = studyplan::findById($id);
}
@ -390,7 +385,7 @@ class studyplan {
$uids = $this->find_linked_userids();
foreach ($uids as $uid) {
$users[] = $DB->get_record("user", ["id"=>$uid]);
$users[] = $DB->get_record("user", ["id" => $uid]);
}
return $users;
@ -412,7 +407,7 @@ class studyplan {
$uids = array_merge($uids, $ulist);
foreach ($ulist as $uid) {
$users[] = $DB->get_record("user", ["id"=>$uid]);
$users[] = $DB->get_record("user", ["id" => $uid]);
}
// Next het users linked though cohort.
@ -449,9 +444,9 @@ class studyplan {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan'),
"idnumber"=> new \external_value(PARAM_TEXT, 'idnumber of curriculum'),
"shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"description" => new \external_value(PARAM_TEXT, 'description of studyplan'),
"idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'),
"pages" => new \external_multiple_structure(studyplanpage::user_structure()),
"aggregation_info" => aggregator::basic_structure(),
], 'Studyplan with user info', $value);
@ -502,16 +497,16 @@ class studyplan {
public static function export_structure() {
return new \external_single_structure([
"format" => new \external_value(PARAM_TEXT, 'format of studyplan export'),
"content"=> new \external_value(PARAM_TEXT, 'exported studyplan content'),
"content" => new \external_value(PARAM_TEXT, 'exported studyplan content'),
], 'Exported studyplan');
}
public function export_plan() {
$model = $this->export_model();
$json = json_encode([
"type"=>"studyplan",
"version"=>2.0,
"studyplan"=>$model
"type" => "studyplan",
"version" => 2.0,
"studyplan" => $model
], \JSON_PRETTY_PRINT);
return [ "format" => "application/json", "content" => $json];
}
@ -538,7 +533,9 @@ class studyplan {
}
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);
if ($content["type"] == "studyplan" && $content["version"] >= 2.0) {
@ -561,7 +558,9 @@ class studyplan {
}
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);
if ($content["version"] >= 2.0) {
if ($content["type"] == "studyplanpage") {
@ -577,7 +576,7 @@ class studyplan {
}
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) {
$p["studyplan_id"] = $this->id();
$page = studyplanpage::add($p);
@ -607,7 +606,7 @@ class studyplan {
}
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";
$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";
$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 {
const TABLE = "local_treestudyplan_page";
private static $CACHE = [];
private $r; // Holds database record.
private $id;
private $studyplan;
@ -81,7 +79,7 @@ class studyplanpage {
public function enddate() {
if ($this->r->enddate && strlen($this->r->enddate) > 0) {
return new \DateTime($this->r->enddate);
} else{
} else {
// Return a date 100 years into the future.
return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
}
@ -92,9 +90,9 @@ class studyplanpage {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id 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'),
"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'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'),
"perioddesc" => period::page_structure(),
@ -118,8 +116,8 @@ class studyplanpage {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan'),
"fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan page'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan page'),
"shortname" => new \external_value(PARAM_TEXT, 'shortname 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'),
"startdate" => new \external_value(PARAM_TEXT, 'start 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);
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) {
@ -216,8 +214,8 @@ class studyplanpage {
return new \external_single_structure([
"id" => new \external_value(PARAM_INT, 'id of studyplan page'),
"fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan page'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan page'),
"shortname" => new \external_value(PARAM_TEXT, 'shortname 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'),
"startdate" => new \external_value(PARAM_TEXT, 'start 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,
'pages' => $this->r->pages,
'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.
@ -302,16 +300,16 @@ class studyplanpage {
public static function export_structure() {
return new \external_single_structure([
"format" => new \external_value(PARAM_TEXT, 'format of studyplan export'),
"content"=> new \external_value(PARAM_TEXT, 'exported studyplan content'),
"content" => new \external_value(PARAM_TEXT, 'exported studyplan content'),
], 'Exported studyplan');
}
public function export_page() {
$model = $this->export_model();
$json = json_encode([
"type"=>"studyplanpage",
"version"=>2.0,
"page"=>$model
"type" => "studyplanpage",
"version" => 2.0,
"page" => $model
], \JSON_PRETTY_PRINT);
return [ "format" => "application/json", "content" => $json];
}
@ -324,7 +322,7 @@ class studyplanpage {
$periods = intval($model["periods"]);
// First line.
$csv = "\"\"";
for($i = 1; $i <= $periods; $i++) {
for ($i = 1; $i <= $periods; $i++) {
$name = $plist[$i]->shortname();
$csv .= ", \"{$name}\"";
}
@ -333,7 +331,7 @@ class studyplanpage {
foreach ($model["studylines"] as $line) {
// Determine how many fields are simultaneous in the line at maximum.
$maxlines = 1;
for($i = 1; $i <= $periods; $i++) {
for ($i = 1; $i <= $periods; $i++) {
if (count($line["slots"]) > $i) {
$ct = 0;
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"]}\"";
for($i = 1; $i <= $periods; $i++) {
for ($i = 1; $i <= $periods; $i++) {
$filled = false;
if (count($line["slots"]) > $i) {
$ct = 0;
@ -365,7 +363,7 @@ class studyplanpage {
if ($g["selected"]) {
if ($first) {
$first = false;
} else{
} else {
$csv .= "\r\n";
}
$csv .= "- ".str_replace('"', '\'', $g["name"]);
@ -393,9 +391,9 @@ class studyplanpage {
public function export_studylines() {
$model = $this->export_studylines_model();
$json = json_encode([
"type"=>"studylines",
"version"=>2.0,
"studylines"=>$model,
"type" => "studylines",
"version" => 2.0,
"studylines" => $model,
], \JSON_PRETTY_PRINT);
return [ "format" => "application/json", "content" => $json];
}
@ -403,14 +401,13 @@ class studyplanpage {
public function export_periods() {
$model = period::page_model($this);
$json = json_encode([
"type"=>"periods",
"version"=>2.0,
"perioddesc"=>$model,
"type" => "periods",
"version" => 2.0,
"perioddesc" => $model,
], \JSON_PRETTY_PRINT);
return [ "format" => "application/json", "content" => $json];
}
public function export_model() {
$model = [
'fullname' => $this->r->fullname,
@ -434,9 +431,10 @@ class studyplanpage {
return $lines;
}
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);
if ($content["type"] == "periods" && $content["version"] >= 2.0) {
return $this->import_periods_model($content["perioddesc"]);
@ -448,7 +446,9 @@ class studyplanpage {
}
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);
if ($content["type"] == "studylines" && $content["version"] >= 2.0) {
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');
class studyplanservice extends \external_api
{
class studyplanservice extends \external_api {
const CAP_EDIT = "local/treestudyplan:editstudyplan";
const CAP_VIEW = "local/treestudyplan:viewuserreports";
/************************
* *
* list_studyplans *
@ -128,9 +125,9 @@ class studyplanservice extends \external_api
public static function add_studyplan_parameters() {
return new \external_function_parameters( [
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"idnumber"=> new \external_value(PARAM_TEXT, 'idnumber of studyplan'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan'),
"shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"idnumber" => new \external_value(PARAM_TEXT, 'idnumber of studyplan'),
"description" => new \external_value(PARAM_TEXT, 'description of studyplan'),
"periods" => new \external_value(PARAM_INT, 'number of periods in studyplan'),
"startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'),
@ -156,7 +153,7 @@ class studyplanservice extends \external_api
'description' => $description,
'periods' => $periods,
'startdate' => $startdate,
'enddate' => empty($enddate)?null:$enddate,
'enddate' => empty($enddate) ? null : $enddate,
'aggregation' => $aggregation,
'aggregation_config' => $aggregationconfig,
'context_id' => $contextid,
@ -174,9 +171,9 @@ class studyplanservice extends \external_api
return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of studyplan'),
"name" => new \external_value(PARAM_TEXT, 'name of studyplan'),
"shortname"=> new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"idnumber"=> new \external_value(PARAM_TEXT, 'idnumber of studyplan'),
"description"=> new \external_value(PARAM_TEXT, 'description of studyplan'),
"shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'),
"idnumber" => new \external_value(PARAM_TEXT, 'idnumber of studyplan'),
"description" => new \external_value(PARAM_TEXT, 'description of studyplan'),
"periods" => new \external_value(PARAM_INT, 'number of periods in studyplan'),
"startdate" => new \external_value(PARAM_TEXT, 'start 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) {
// Validate access in the intended context.
$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);
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
@ -247,8 +244,8 @@ class studyplanservice extends \external_api
return new \external_function_parameters( [
"page_id" => new \external_value(PARAM_INT, 'id of studyplan to add line to'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
"shortname"=> new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color"=> new \external_value(PARAM_TEXT, 'description of studyline'),
"shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color" => new \external_value(PARAM_TEXT, 'description 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( [
"id" => new \external_value(PARAM_INT, 'id of studyline'),
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
"shortname"=> new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color"=> new \external_value(PARAM_TEXT, 'description of studyline'),
"shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
"color" => new \external_value(PARAM_TEXT, 'description of studyline'),
] );
}
@ -305,7 +302,6 @@ class studyplanservice extends \external_api
}
/************************
* *
* delete_studyline *
@ -381,7 +377,6 @@ class studyplanservice extends \external_api
return studyitem::editor_structure();
}
public static function get_studyitem($id) {
$o = studyitem::findById($id);
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'),
"type" => new \external_value(PARAM_TEXT, 'type of study item'),
"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),
"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),
@ -424,10 +419,10 @@ class studyplanservice extends \external_api
//'conditions' => $conditions,.
'slot' => $slot,
'layer' => $layer,
'competency_id' => isset($details['competency_id'])?$details['competency_id']:null,
'course_id' => isset($details['course_id'])?$details['course_id']:null,
'badge_id' => isset($details['badge_id'])?$details['badge_id']:null,
'continuation_id' => isset($details['continuation_id'])?$details['continuation_id']:null,
'competency_id' => isset($details['competency_id']) ? $details['competency_id'] : null,
'course_id' => isset($details['course_id']) ? $details['course_id'] : null,
'badge_id' => isset($details['badge_id']) ? $details['badge_id'] : null,
'continuation_id' => isset($details['continuation_id']) ? $details['continuation_id'] : null,
]);
return $o->editor_model();
}
@ -441,7 +436,7 @@ class studyplanservice extends \external_api
public static function edit_studyitem_parameters() {
return new \external_function_parameters( [
"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),
]);
}
@ -499,7 +494,6 @@ class studyplanservice extends \external_api
return studyitem::reorder($resequence)->model();
}
/************************
* *
* delete_studyitem *
@ -632,7 +626,6 @@ class studyplanservice extends \external_api
// Do sanity checks.
\external_api::validate_context($coursecontext);
// Check correct capabilities.
if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($itemid)->context()) ||
is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) {
@ -699,8 +692,8 @@ class studyplanservice extends \external_api
$scale->load_items();
if ($scale) {
$gradecfg = $DB->get_record("local_treestudyplan_gradecfg", ["scale_id"=>$scale->id]);
$scalepass = ($gradecfg)?$gradecfg->min_completed:0;
$gradecfg = $DB->get_record("local_treestudyplan_gradecfg", ["scale_id" => $scale->id]);
$scalepass = ($gradecfg) ? $gradecfg->min_completed : 0;
$scalemax = count($scale->scale_items);
// Find studyline id's.
@ -731,10 +724,14 @@ class studyplanservice extends \external_api
$gi->gradepass = $scalepass;
// 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 = "";
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.
// 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));
try {
$DB->set_field($tablename, $fieldname, $gradevalue, ["id" => $gi->iteminstance]);
}
catch(\dml_exception $x) {
} catch (\dml_exception $x) {
$updated = "fail";
$debug = strval($x);
}
@ -903,11 +899,10 @@ class studyplanservice extends \external_api
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();
} else{
} else {
return $plan->export_plan();
}
}
catch(\webservice_access_exception $x) {
} catch (\webservice_access_exception $x) {
return [ "format" => "", "content" => ""];
}
}
@ -930,8 +925,7 @@ class studyplanservice extends \external_api
$plan = studyplan::findById($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) {
} catch (\webservice_access_exception $x) {
return [ "format" => "", "content" => ""];
}
}
@ -962,8 +956,7 @@ class studyplanservice extends \external_api
$result = studyplan::import_studyplan($content, $format, $contextid);
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();
}
}
@ -990,14 +983,12 @@ class studyplanservice extends \external_api
// FIXME: Make sure this gets called for the page instead of the studyplan.
// Once proper page management is implemented.
$result = $plan->pages()[0]->import_studylines($content, $format);
return ($result?success::success():success::fail())->model();
}
catch(\webservice_access_exception $x) {
return ($result ? success::success() : success::fail())->model();
} catch (\webservice_access_exception $x) {
return success::fail("Access denied")->model();
}
}
/********************************************************
* *
* Read and write course module title and desc *
@ -1030,7 +1021,7 @@ class studyplanservice extends \external_api
// Check the course exists.
$course = \get_course($cm->course);
// 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.
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) {
$p = explode("=", $pair, 2);
$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) {
// 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( [
"id" => new \external_value(PARAM_INT, 'id of study item'),
"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'),
"enddate" => new \external_value(PARAM_TEXT, 'end date of period'),
]);
@ -1101,7 +1092,6 @@ class studyplanservice extends \external_api
$p = period::findById($id);
webservicehelper::require_capabilities(self::CAP_EDIT, $p->page()->studyplan()->context());
$p->edit([
'fullname' => $fullname,
'shortname' => $shortname,
@ -1121,8 +1111,8 @@ class studyplanservice extends \external_api
public static function course_period_timing_parameters() {
return new \external_function_parameters( [
"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'),
"span"=> new \external_value(PARAM_INT, 'Period span (default 1)', VALUE_DEFAULT),
"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),
]);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -39,8 +39,7 @@ if ($categoryid > 0) {
} else if ($contextid > 0) {
$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;
}
else
@ -50,7 +49,7 @@ if ($categoryid > 0) {
} else {
// If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("edit");
$contextid=1; // fallback to system context.
$contextid=1; // Fallback to system context.
foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) {
$contextid = $ctx->ctxid;
@ -76,16 +75,13 @@ if ($studyplancontext->id > 1) {
$PAGE->navbar->add(get_string('cfg_plans', 'local_treestudyplan'));
}
// Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$studyplancontext->id, $categoryid]);
$catlist = courseservice::list_accessible_categories_with_usage("edit");
// Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param);
@ -94,7 +90,6 @@ function t($str, $param=null, $plugin='local_treestudyplan') {
print $OUTPUT->header();
?>
<div id='root'>
<div class='vue-loader' v-show='false'>
@ -106,7 +101,7 @@ print $OUTPUT->header();
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<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)'
: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>
</b-form-select>
</div>

View File

@ -77,8 +77,7 @@ print "</thead>";
print "<tbody>";
if (count($invites) > 0) {
foreach ($invites as $invite)
{
foreach ($invites as $invite) {
$testlink = $INVITEDURL."?key={$invite->invitekey}";
print "<tr data-id='{$invite->id}'>";
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();

View File

@ -32,7 +32,7 @@ $PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext);
// See if we can get a valid user for this invited.
$invitekey = optional_param('key', '', PARAM_ALPHANUM); // module name.
$invitekey = optional_param('key', '', PARAM_ALPHANUM); // Module name.
$PAGE->set_url("/local/treestudyplan/invited.php", array('key' => $invitekey));
$invite = $DB->get_record_select("local_treestudyplan_invit", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $invitekey]);
@ -41,10 +41,8 @@ if (empty($invite)) {
$PAGE->set_title(get_string('invalid_invitekey_title', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan'));
print $OUTPUT->header();
// Render page for skill level 0 (global).
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:selectowngradables'] = 'Teachers can select gradables in their own courses in study plan view mode (manual modes only)';
$string['report'] = 'Progress report';
$string['report_invited'] = 'Progress report for {$a}';
$string['report_index'] = 'View student progress reports';
@ -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_desc'] = 'Use Moodle core completion';
$string['setting_bistate_heading'] = 'Defaults for Completed + Required goalsn';
$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:selectowngradables'] = 'Docenten kunnen in hun eigen cursussen zelf activiteiten selecteren in een studieplan (docentenweergave, alleen handmatige modes)';
$string['report'] = 'Voortgangsrapport';
$string['report_invited'] = 'Voortgang van {$a}';
$string['report_index'] = 'Studieplannen van studenten inzien';

38
lib.php
View File

@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die();
function local_treestudyplan_unit_get_editor_options($context) {
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) {
@ -56,8 +56,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
{
$userstudyplans = studyplan::find_for_user($USER->id);
if (!empty($userstudyplans))
{
if (!empty($userstudyplans)) {
// Create studyplan node.
$node = navigation_node::create(
@ -83,15 +82,13 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$invitenode->showinflatnavigation = false;
$node->add_node($invitenode);
$navigation->add_node($node, 'mycourses');
}
else {
$hideprimary_hrefs[] = "/local/treestudyplan/myreport.php";
}
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(
get_string("link_viewplan", "local_treestudyplan"),
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())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan')
)
{
) {
$node = navigation_node::create(
get_string("cfg_plans", "local_treestudyplan"),
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;
$navigation->add_node($invitenode, 'mycourses');
// 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]);
}
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)) {
$node = $navigation->add(
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,
null,
"local_treestudyplan_editplan",
@ -169,7 +163,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
if (has_capability('local/treestudyplan:viewuserreports', $coursecategorycontext)) {
$node = $navigation->add(
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,
null,
"local_treestudyplan_viewplan",
@ -217,25 +211,21 @@ function local_treestudyplan_send_invite($inviteid) {
$invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}";
$data = [ 'permissions'=> '',
$data = [ 'permissions' => '',
'invitee' => $invite->name,
'sender' => "{$USER->firstname} {$USER->lastname}",
'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'] .= "<ul>\n";
if ($invite->allow_details )
{
if ($invite->allow_details ) {
$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";
}
if ($invite->allow_badges)
{
if ($invite->allow_badges) {
$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);},
$cohortcontext->get_parent_contexts(true)
);
array_pop($ctxpath); // pop system context off the list.
array_pop($ctxpath); // Pop system context off the list.
$ctxpath = array_reverse($ctxpath);
$ctxpath[] = $cohort->name;
@ -297,7 +287,6 @@ function local_treestudyplan_get_cohort_path($cohort) {
}
}
function local_treestudyplan_output_fragment_mod_edit_form($args) {
global $CFG;
global $DB;
@ -315,7 +304,7 @@ function local_treestudyplan_output_fragment_mod_edit_form($args) {
$course = \get_course($cm->course);
// 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);
@ -332,5 +321,4 @@ function local_treestudyplan_output_fragment_mod_edit_form($args) {
return $mform->render();
}

View File

@ -47,7 +47,7 @@ if ($teachermode) {
// Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$teachermode?'teaching':'myreport']);
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$teachermode ? 'teaching' : 'myreport']);
// Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') {
@ -55,23 +55,23 @@ function t($str, $param=null, $plugin='local_treestudyplan') {
}
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();

View File

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

View File

@ -39,8 +39,7 @@ if ($categoryid > 0) {
} else if ($contextid > 0) {
$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;
}
else
@ -50,7 +49,7 @@ if ($categoryid > 0) {
} else {
// If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("view");
$contextid=1; // fallback to system context.
$contextid=1; // Fallback to system context.
foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) {
$contextid = $ctx->ctxid;
@ -98,7 +97,7 @@ print $OUTPUT->header();
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<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)'
: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>
</b-form-select>
</div>