Moodle code style fixes part 4
This commit is contained in:
parent
a531ce80d7
commit
e694cefde3
|
@ -103,7 +103,7 @@ if ($_POST["action"] == "update") {
|
|||
}
|
||||
}
|
||||
$DB->update_record(GRADECFG_TABLE, $gradecfg);
|
||||
// reload to ensure proper rounding is done.
|
||||
// Reload to ensure proper rounding is done.
|
||||
$gradecfgs[$gradecfg->grade_points] = $DB->get_record(GRADECFG_TABLE, ['id' => $gradecfg->id]);
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ if ($_POST["action"] == "update") {
|
|||
if ($requireinsert) {
|
||||
// Insert into database and add to the list of grade configs.
|
||||
$id = $DB->insert_record(GRADECFG_TABLE, $gradecfg);
|
||||
// reload to ensure proper rounding is done.
|
||||
// Reload to ensure proper rounding is done.
|
||||
$gradecfg = $DB->get_record(GRADECFG_TABLE, ['id' => $id]);
|
||||
$gradecfgs[$id] = $gradecfg;
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ if ($_POST["action"] == "update") {
|
|||
|
||||
|
||||
|
||||
//process all available scales and load the current configuration for it.
|
||||
// Process all available scales and load the current configuration for it.
|
||||
$data = [];
|
||||
foreach ($scales as $scale) {
|
||||
$scale->load_items();
|
||||
|
@ -184,7 +184,7 @@ foreach ($scales as $scale) {
|
|||
|
||||
$row = [];
|
||||
$row[] = $scale->name;
|
||||
//$row[] = html_writer::tag("select", $optionsprogress, ['name' => "s_{$scale->id}_min_progress", 'autocomplete' => 'off']) ;.
|
||||
|
||||
$row[] = html_writer::tag("select", $optionscompleted, ['name' => "s_{$scale->id}_min_completed", 'autocomplete' => 'off']);
|
||||
$data[] = $row;
|
||||
}
|
||||
|
@ -197,11 +197,9 @@ $table = new html_table();
|
|||
$table->id = "";
|
||||
$table->attributes['class'] = 'generaltable m-roomtable';
|
||||
$table->tablealign = 'center';
|
||||
$table->summary = '';//get_string('uploadtimetable_preview', 'local_chronotable');.
|
||||
$table->head = [];
|
||||
$table->data = $data;
|
||||
$table->head[] = get_string('scale');
|
||||
//$table->head[] = get_string('min_progress', 'local_treestudyplan');.
|
||||
$table->head[] = get_string('min_completed', 'local_treestudyplan');
|
||||
|
||||
print $OUTPUT->heading(get_string('cfg_grades_desc_head', 'local_treestudyplan'));
|
||||
|
@ -213,7 +211,6 @@ $data = [];
|
|||
foreach ($gradecfgs as $g) {
|
||||
$row = [];
|
||||
$row[] = $g->grade_points;
|
||||
// $row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_min_progress", 'value' => "{$g->min_progress}", 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;.
|
||||
$row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_min_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;
|
||||
|
@ -221,7 +218,6 @@ foreach ($gradecfgs as $g) {
|
|||
|
||||
$row = [];
|
||||
$row[] = html_writer::tag("input", null, ['name' => "g_new_gradepoints", 'value' => '', 'type' => 'number', 'min' => '0', 'pattern' => '/d+', 'step' => '1', 'autocomplete' => 'off']);
|
||||
//$row[] = html_writer::tag("input", null, ['name' => "g_new_min_progress", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;.
|
||||
$row[] = html_writer::tag("input", null, ['name' => "g_new_min_completed", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']);
|
||||
|
||||
$data[] = $row;
|
||||
|
@ -231,11 +227,9 @@ $table = new html_table();
|
|||
$table->id = "";
|
||||
$table->attributes['class'] = 'generaltable m-roomtable';
|
||||
$table->tablealign = 'center';
|
||||
$table->summary = '';//get_string('uploadtimetable_preview', 'local_chronotable');.
|
||||
$table->head = [];
|
||||
$table->data = $data;
|
||||
$table->head[] = get_string('grade_points', 'local_treestudyplan');
|
||||
//$table->head[] = get_string('min_progress', 'local_treestudyplan');.
|
||||
$table->head[] = get_string('min_completed', 'local_treestudyplan');
|
||||
$table->head[] = get_string('delete', );
|
||||
|
||||
|
|
|
@ -40,8 +40,8 @@ abstract class aggregator {
|
|||
}
|
||||
|
||||
public static function list() {
|
||||
// static list, since we'd need to implement a lot of static data for new aggregation methods anyway.
|
||||
// and this is faster than any dynamic method.
|
||||
// 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
|
||||
"bistate",
|
||||
|
|
|
@ -131,7 +131,7 @@ class associationservice extends \external_api
|
|||
$params['exclude_id'] = $excludeid;
|
||||
}
|
||||
if ($contextid > 1) { // system context returns all cohorts, including system cohorts.
|
||||
// otherwise, .
|
||||
// Otherwise, .
|
||||
$sql .= " AND contextid = :context_id";
|
||||
$params['context_id'] = $contextid;
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ class associationservice extends \external_api
|
|||
|
||||
$users = [];
|
||||
// SQL JOIN script selecting all users that have a cohort linked to this studyplan .
|
||||
// or are directly linked.
|
||||
// Or are directly linked.
|
||||
$sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email
|
||||
FROM {user} u
|
||||
LEFT JOIN {cohort_members} cm ON u.id = cm.userid
|
||||
|
|
|
@ -87,7 +87,7 @@ class cascadecohortsync {
|
|||
foreach ($courseids as $courseid) {
|
||||
$course = \get_course($courseid);
|
||||
//\mtrace("Processing Course {$courseid} {$course->shortname}");.
|
||||
// first create any nonexistent links.
|
||||
// First create any nonexistent links.
|
||||
foreach ($cohortids as $cohortid) {
|
||||
$cohort = $DB->get_record('cohort', ['id'=>$cohortid]);
|
||||
//\mtrace("Processing cohort {$cohortid} {$cohort->shortname}");.
|
||||
|
@ -111,8 +111,8 @@ class cascadecohortsync {
|
|||
// If not, make it (maybe use some of the custom text to list the studyplans involved).
|
||||
if ($instance = $DB->get_record('enrol', $instanceparams)) {
|
||||
//\mtrace("Instance exists");.
|
||||
// it already exists.
|
||||
// check if this studyplan is already referenced in customtext4 in json format.
|
||||
// It already exists.
|
||||
// Check if this studyplan is already referenced in customtext4 in json format.
|
||||
|
||||
//TODO: Check this code - Maybe add option to not remember manually added stuff .
|
||||
$plans = json_decode($instance->customtext4);
|
||||
|
@ -126,7 +126,7 @@ class cascadecohortsync {
|
|||
}
|
||||
}
|
||||
if (!in_array($this->studyplanid , $plans)) {
|
||||
// if not, add it to the reference.
|
||||
// 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)]);
|
||||
|
@ -140,13 +140,13 @@ class cascadecohortsync {
|
|||
// Make or get new new cohort group - but only on creating of instances.
|
||||
$groupname = $cohort->name." ".strtolower(\get_string('defaultgroupname', 'core_group'));
|
||||
//\mtrace("Adding group {$groupname} for this method");.
|
||||
// and make sure the .
|
||||
// And make sure the .
|
||||
$instancenewparams['customint2'] = self::uploadenrolmentmethods_get_group($courseid, $groupname);
|
||||
}
|
||||
|
||||
if ($instanceid = $enrol->add_instance($course, $instancenewparams)) {
|
||||
// also record the (as of yet only) studyplans id requiring this association.
|
||||
// in the customtext4 field in json format.
|
||||
// Also record the (as of yet only) studyplans id requiring this association.
|
||||
// In the customtext4 field in json format.
|
||||
//\mtrace("Instance ({$instanceid} created. Updateing instance with studyplan id");.
|
||||
$instance = $DB->get_record('enrol', array('id' => $instanceid));
|
||||
$enrol->update_instance($instance, (object)["customtext4"=>json_encode([(int)($this->studyplanid)])]);
|
||||
|
@ -180,7 +180,7 @@ class cascadecohortsync {
|
|||
if (get_config("local_treestudyplan", "csync_autoremove")) {
|
||||
// Only try the autoremove if the option is enabled.
|
||||
//\mtrace("Autoremove scan for course {$courseid} {$course->shortname}");.
|
||||
// find all cohort syncs for this course.
|
||||
// Find all cohort syncs for this course.
|
||||
$searchparams = [
|
||||
'courseid' => $courseid,
|
||||
'enrol' => self::METHOD,
|
||||
|
@ -190,25 +190,25 @@ class cascadecohortsync {
|
|||
$records = $DB->get_records("enrol", $searchparams);
|
||||
foreach ($records as $instance) {
|
||||
if (!empty($instance->customtext4)) { // only check the records that have studyplan information in the customtext4 field.
|
||||
// first check if the cohort is not one of the cohort id's we have associated.
|
||||
// First check if the cohort is not one of the cohort id's we have associated.
|
||||
if (!in_array($instance->customint1, $cohortids)) {
|
||||
//\mtrace("Found cohort sync instance that is not currently liked to the studyplan: {$instance->id}");.
|
||||
// So it may or may not need to be removed.
|
||||
$plans = json_decode($instance->customtext4);
|
||||
if ($plans !== null && is_array($plans)) {
|
||||
//if a valid array is not returned, better leave it be, we don't want to mess with it.
|
||||
// otherwise, check if we should remove it.
|
||||
// Otherwise, check if we should remove it.
|
||||
if (in_array($this->studyplanid, $plans)) {
|
||||
//\mtrace("Found this studyplan in the id list - removing from list");.
|
||||
//if this plan was referenced before.
|
||||
// first remove the link.
|
||||
// First remove the link.
|
||||
$fplans = self::array_remove_value($plans, $this->studyplanid);
|
||||
if (count($fplans) == 0) {
|
||||
// delete the sync if there are no studyplan references left.
|
||||
// Delete the sync if there are no studyplan references left.
|
||||
//\mtrace("No references are left, removing instance");.
|
||||
$enrol->delete_instance($instance);
|
||||
} else {
|
||||
// otherwise just update the references so this studyplan is no longer linked.
|
||||
// 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)]);
|
||||
}
|
||||
|
|
|
@ -55,13 +55,13 @@ class completion {
|
|||
}
|
||||
|
||||
public static function count_states(array $states) {
|
||||
// initialize result array.
|
||||
// Initialize result array.
|
||||
$statecount = [];
|
||||
foreach (array_keys(self::LABELS) as $key) {
|
||||
$statecount[$key] = 0;
|
||||
}
|
||||
|
||||
// process all states in array and increment relevant counter for each one.
|
||||
// Process all states in array and increment relevant counter for each one.
|
||||
foreach ($states as $c) {
|
||||
if (array_key_exists($c, $statecount)) {
|
||||
$statecount[$c] += 1;
|
||||
|
|
|
@ -108,7 +108,7 @@ class completionscanner
|
|||
|
||||
public function model() {
|
||||
|
||||
// get completion info.
|
||||
// Get completion info.
|
||||
$students = self::get_course_students($this->courseid);
|
||||
$completed = 0;
|
||||
$ungraded = 0;
|
||||
|
|
|
@ -50,7 +50,7 @@ class corecompletioninfo {
|
|||
static public function completiontypes() {
|
||||
global $COMPLETIONCRITERIA_TYPES;
|
||||
// Just return the keys of the global array COMPLETION_CRITERIA_TYPES, so we don't have to manually.
|
||||
// add any completion types....
|
||||
// Add any completion types....
|
||||
return \array_keys($COMPLETIONCRITERIA_TYPES);
|
||||
}
|
||||
|
||||
|
@ -182,9 +182,9 @@ class corecompletioninfo {
|
|||
|
||||
foreach ($criterias as $criteria) {
|
||||
// Unfortunately, we cannot easily get the criteria details with get_details() without having a .
|
||||
// user completion object involved, so'we'll have to retrieve the details per completion type.
|
||||
// User completion object involved, so'we'll have to retrieve the details per completion type.
|
||||
// See moodle/completion/criteria/completion_criteria_*.php::get_details() for the code that is.
|
||||
// in the code below is based on.
|
||||
// In the code below is based on.
|
||||
|
||||
if ($type == COMPLETION_CRITERIA_TYPE_SELF) {
|
||||
$details = [
|
||||
|
@ -288,7 +288,7 @@ class corecompletioninfo {
|
|||
|
||||
$scanner = new completionscanner($criteria, $this->course);
|
||||
|
||||
// only add the items list if we actually have items...
|
||||
// Only add the items list if we actually have items...
|
||||
$cinfo["items"][] = [
|
||||
"id" => $criteria->id,
|
||||
"title" => $criteria->get_title_detailed(),
|
||||
|
@ -405,7 +405,7 @@ class corecompletioninfo {
|
|||
}
|
||||
}
|
||||
}
|
||||
// finally add the item to the items list.
|
||||
// Finally add the item to the items list.
|
||||
$cinfo["items"][] = $iinfo;
|
||||
}
|
||||
|
||||
|
@ -414,9 +414,9 @@ class corecompletioninfo {
|
|||
// Count and Progress amount to the sum of items.
|
||||
$cinfo["count"] = count($cinfo["items"]);
|
||||
$cinfo["progress"] = $progress;
|
||||
} else { //$typeaggregation == COMPLETION_AGGREGATION_ANY.
|
||||
} else { // Typeaggregation == COMPLETION_AGGREGATION_ANY.
|
||||
// Count and progress are either 1 or 0, since any of the items.
|
||||
// complete's the type.
|
||||
// Complete's the type.
|
||||
$cinfo["count"] = (count($cinfo["items"]) > 0)?1:0;
|
||||
$cinfo["progress"] = ($progress>0)?1:0;
|
||||
}
|
||||
|
@ -451,12 +451,12 @@ class corecompletioninfo {
|
|||
$result = new \stdClass;
|
||||
// Check if the final grade is available and numeric (safety check).
|
||||
if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) {
|
||||
// convert scale grades to corresponding scale name.
|
||||
// Convert scale grades to corresponding scale name.
|
||||
if (isset($scale)) {
|
||||
// get scale value.
|
||||
// Get scale value.
|
||||
$result->grade = $scale->get_nearest_item($grade->finalgrade);
|
||||
} else {
|
||||
// round final grade to 1 decimal point.
|
||||
// Round final grade to 1 decimal point.
|
||||
$result->grade = round($grade->finalgrade, 1);
|
||||
}
|
||||
|
||||
|
@ -491,12 +491,12 @@ class corecompletioninfo {
|
|||
$grade = $gi->get_final($userid); // Get the grade for the specified user.
|
||||
// Check if the final grade is available and numeric (safety check).
|
||||
if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) {
|
||||
// convert scale grades to corresponding scale name.
|
||||
// Convert scale grades to corresponding scale name.
|
||||
if (isset($scale)) {
|
||||
// get scale value.
|
||||
// Get scale value.
|
||||
return $scale->get_nearest_item($grade->finalgrade);
|
||||
} else {
|
||||
// round final grade to 1 decimal point.
|
||||
// Round final grade to 1 decimal point.
|
||||
return round($grade->finalgrade, 1);
|
||||
}
|
||||
} else {
|
||||
|
@ -536,13 +536,13 @@ class corecompletioninfo {
|
|||
if ($this->completion->is_course_complete($userid)) {
|
||||
$completed = $count;
|
||||
} else {
|
||||
// count all completions, but treat .
|
||||
// Count all completions, but treat .
|
||||
foreach ($completions as $completion) {
|
||||
$crit = $completion->get_criteria();
|
||||
if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
|
||||
// get the cm data object.
|
||||
// Get the cm data object.
|
||||
$cm = $this->modinfo->get_cm($crit->moduleinstance);
|
||||
// retrieve data for this object.
|
||||
// Retrieve data for this object.
|
||||
$data = $this->completion->get_data($cm, false, $userid);
|
||||
// Count complete, but failed as incomplete too...
|
||||
if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) {
|
||||
|
@ -588,7 +588,7 @@ class corecompletioninfo {
|
|||
$critcount = [];
|
||||
|
||||
// Before we check how many modules have been completed see if the course has completed. .
|
||||
// count all completions, but treat .
|
||||
// Count all completions, but treat .
|
||||
foreach ($completions as $completion) {
|
||||
$crit = $completion->get_criteria();
|
||||
|
||||
|
@ -605,9 +605,9 @@ class corecompletioninfo {
|
|||
|
||||
$typecount->count += 1;
|
||||
if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
|
||||
// get the cm data object.
|
||||
// Get the cm data object.
|
||||
$cm = $this->modinfo->get_cm($crit->moduleinstance);
|
||||
// retrieve data for this object.
|
||||
// Retrieve data for this object.
|
||||
$data = $this->completion->get_data($cm, false, $userid);
|
||||
// Count complete, but failed as incomplete too...
|
||||
if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) {
|
||||
|
@ -638,7 +638,7 @@ class corecompletioninfo {
|
|||
$ct = 1;
|
||||
$cmpl = ($c->completed > 0)?1:0;
|
||||
}
|
||||
// if ANY completion for the types, count only the criteria type with the highest completion percentage -.
|
||||
// If ANY completion for the types, count only the criteria type with the highest completion percentage -.
|
||||
// Overwrite data if current type is more complete.
|
||||
if ($aggregation == COMPLETION_AGGREGATION_ANY) {
|
||||
$pct = $cmpl/$ct;
|
||||
|
@ -648,7 +648,7 @@ class corecompletioninfo {
|
|||
$completionpercentage = $pct;
|
||||
}
|
||||
}
|
||||
// if ALL completion for the types, add the count for this type to that of the others.
|
||||
// If ALL completion for the types, add the count for this type to that of the others.
|
||||
else {
|
||||
$count += $ct;
|
||||
$completed += $cmpl;
|
||||
|
|
|
@ -41,7 +41,6 @@ class coursemoduleinfo {
|
|||
$this->id = $id;
|
||||
$this->cm = $DB->get_record("course_modules", ["id" => $id]);
|
||||
$this->cm_info = \cm_info::create($this->cm);
|
||||
// $this->db_record = $DB->get_record($this->cm_info->modname, ["id" => $this->cm_info->instance]);.
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
|
|
|
@ -80,7 +80,7 @@ class courseservice extends \external_api
|
|||
// Determine top categories from provided context.
|
||||
|
||||
if ($root->id == 0) {
|
||||
// on the system level, determine the user's topmost allowed catecories.
|
||||
// On the system level, determine the user's topmost allowed catecories.
|
||||
$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.
|
||||
|
@ -160,7 +160,7 @@ class courseservice extends \external_api
|
|||
{
|
||||
if ($operation == "edit") {
|
||||
$capability = self::CAP_EDIT;
|
||||
} else { // $operation == "view" || default.
|
||||
} else { // Operation == "view" || default.
|
||||
$capability = self::CAP_VIEW;
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ class courseservice extends \external_api
|
|||
public static function categories_by_capability($capability, \core_course_category $parent=null) {
|
||||
// List the categories in which the user has a specific capability.
|
||||
$list = [];
|
||||
// initialize parent if needed.
|
||||
// Initialize parent if needed.
|
||||
if ($parent == null) {
|
||||
$parent = \core_course_category::user_top();
|
||||
if (has_capability($capability, $parent->get_context())) {
|
||||
|
@ -233,7 +233,7 @@ class courseservice extends \external_api
|
|||
global $DB;
|
||||
if ($operation == "edit") {
|
||||
$capability = self::CAP_EDIT;
|
||||
} else { // $operation == "view" || default.
|
||||
} else { // Operation == "view" || default.
|
||||
$capability = self::CAP_VIEW;
|
||||
}
|
||||
$contextids = [];
|
||||
|
@ -268,10 +268,10 @@ class courseservice extends \external_api
|
|||
global $DB;
|
||||
if ($operation == "edit") {
|
||||
$capability = self::CAP_EDIT;
|
||||
} else { // $operation == "view" || default.
|
||||
} else { // Operation == "view" || default.
|
||||
$capability = self::CAP_VIEW;
|
||||
}
|
||||
// retrieve context ids used.
|
||||
// Retrieve context ids used.
|
||||
$contextids = [];
|
||||
$rs = $DB->get_recordset_sql("SELECT DISTINCT context_id, COUNT(*) as num FROM {local_treestudyplan}
|
||||
GROUP BY context_id");
|
||||
|
@ -400,7 +400,7 @@ class courseservice extends \external_api
|
|||
$badge = new \core_badges\badge($badgeid);
|
||||
$badgeinfo = new badgeinfo($badge);
|
||||
|
||||
// get the connected users.
|
||||
// Get the connected users.
|
||||
$students = associationservice::all_associated($studyplanid);
|
||||
// Just get the user ids.
|
||||
$studentids = array_map(function ($a) { return $a["id"];}, $students);
|
||||
|
|
|
@ -127,7 +127,7 @@ class gradeinfo {
|
|||
} else {
|
||||
list($c, $cminfo) = get_course_and_cm_from_instance($gi->iteminstance, $gi->itemmodule);
|
||||
$this->cmid = $cminfo->id;
|
||||
// sort by position in course.
|
||||
// Sort by position in course.
|
||||
// .
|
||||
$this->section = $cminfo->sectionnum;
|
||||
$ssequence = self::getSectionSequence($cminfo->section);
|
||||
|
@ -239,7 +239,7 @@ class gradeinfo {
|
|||
public function user_model($userid) {
|
||||
global $DB;
|
||||
$grade = $this->gradeitem->get_final($userid);
|
||||
// convert scale grades to corresponding scale name.
|
||||
// Convert scale grades to corresponding scale name.
|
||||
if (!empty($grade)) {
|
||||
if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) {
|
||||
$finalgrade = "-";
|
||||
|
@ -252,7 +252,7 @@ class gradeinfo {
|
|||
$finalgrade = "-";
|
||||
}
|
||||
|
||||
// retrieve the aggregator and determine completion.
|
||||
// Retrieve the aggregator and determine completion.
|
||||
if (!isset($this->studyitem)) {
|
||||
throw new \UnexpectedValueException("Study item not set (null) for gradeinfo in report mode");
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ class gradeinfo {
|
|||
$gitype = $gi->itemmodule;
|
||||
|
||||
if ($giname == $model["name"] && $gitype == $model["type"]) {
|
||||
// we have a match.
|
||||
// We have a match.
|
||||
if (!isset($model["selected"])) { $model["selected"] = true;}
|
||||
if (!isset($model["required"])) { $model["required"] = false;}
|
||||
if ($model["selected"] || $model["required"]) {
|
||||
|
@ -352,7 +352,7 @@ class gradeinfo {
|
|||
}
|
||||
}
|
||||
catch(\InvalidArgumentException $x) {
|
||||
// on InvalidArgumentException, the grade_item id can no longer be found.
|
||||
// On InvalidArgumentException, the grade_item id can no longer be found.
|
||||
// Remove the link to avoid database record hogging.
|
||||
$DB->delete_records($table, ['id' => $r->id]);
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ class gradeinfo {
|
|||
global $DB;
|
||||
$table = 'local_treestudyplan_gradeinc';
|
||||
if ($include) {
|
||||
// make sure a record exits.
|
||||
// Make sure a record exits.
|
||||
$r = $DB->get_record($table, ['studyitem_id' => $itemid, 'grade_item_id' => $gradeid]);
|
||||
if ($r) {
|
||||
$r->include = 1;
|
||||
|
@ -385,7 +385,7 @@ class gradeinfo {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
// remove if it should not be included.
|
||||
// Remove if it should not be included.
|
||||
$r = $DB->get_record($table, ['studyitem_id' => $itemid, 'grade_item_id' => $gradeid]);
|
||||
if ($r) {
|
||||
$DB->delete_records($table, ['id' => $r->id]);
|
||||
|
|
|
@ -25,9 +25,6 @@ require_once($CFG->libdir.'/externallib.php');
|
|||
|
||||
use \grade_item;
|
||||
|
||||
// $gi->courseid, .
|
||||
// $gi->itemmodule, .
|
||||
// $gi->iteminstance.
|
||||
class gradingscanner
|
||||
{
|
||||
private static $modsupported = [];
|
||||
|
@ -131,7 +128,7 @@ class gradingscanner
|
|||
private function grade_passed($grade) {
|
||||
global $DB;
|
||||
$table = "local_treestudyplan_gradecfg";
|
||||
// first determine if we have a grade_config for this scale or this maximum grade.
|
||||
// First determine if we have a grade_config for this scale or this maximum grade.
|
||||
$finalgrade = $grade->finalgrade;
|
||||
$scale = $this->gi->load_scale();
|
||||
if ( isset($scale)) {
|
||||
|
@ -142,11 +139,11 @@ class gradingscanner
|
|||
$gradecfg = null;
|
||||
}
|
||||
|
||||
// for point grades, a provided grade pass overrides the defaults in the gradeconfig.
|
||||
// for scales, the configuration in the gradeconfig is leading.
|
||||
// For point grades, a provided grade pass overrides the defaults in the gradeconfig.
|
||||
// For scales, the configuration in the gradeconfig is leading.
|
||||
|
||||
if ($gradecfg && (isset($scale) || $this->gi->gradepass == 0)) {
|
||||
// if so, we need to know if the grade is .
|
||||
// If so, we need to know if the grade is .
|
||||
if ($finalgrade >= $gradecfg->min_completed) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -154,7 +151,7 @@ class gradingscanner
|
|||
}
|
||||
} else if ($this->gi->gradepass > 0) {
|
||||
$range = floatval($this->gi->grademax - $this->gi->grademin);
|
||||
// if no gradeconfig and gradepass is set, use that one to determine config.
|
||||
// If no gradeconfig and gradepass is set, use that one to determine config.
|
||||
if ($finalgrade >= $this->gi->gradepass) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -162,8 +159,8 @@ class gradingscanner
|
|||
}
|
||||
} else {
|
||||
// Blind assumptions if nothing is provided.
|
||||
// over 55% of range is completed.
|
||||
// if range >= 3 and failed is enabled, assume that this means failed.
|
||||
// Over 55% of range is completed.
|
||||
// If range >= 3 and failed is enabled, assume that this means failed.
|
||||
$g = floatval($finalgrade - $this->gi->grademin);
|
||||
$range = floatval($this->gi->grademax - $this->gi->grademin);
|
||||
$score = $g / $range;
|
||||
|
|
|
@ -41,7 +41,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
private $acceptpending_as_submitted = False; // Also count ungraded but submitted .
|
||||
|
||||
public function __construct($configstr) {
|
||||
// allow public constructor for testing purposes.
|
||||
// Allow public constructor for testing purposes.
|
||||
$this->initialize($configstr);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
$config = \json_decode($configstr, true);
|
||||
|
||||
if (is_array($config)) {
|
||||
// copy all valid config settings to this item.
|
||||
// Copy all valid config settings to this item.
|
||||
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress", ] as $key) {
|
||||
if (array_key_exists($key, $config)) {
|
||||
$val = $config[$key];
|
||||
|
@ -100,9 +100,9 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
|
||||
|
||||
public function aggregate_binary_goals(array $completions, array $required = []) {
|
||||
// function is public to allow access for the testing code.
|
||||
// Function is public to allow access for the testing code.
|
||||
|
||||
// return te following conditions.
|
||||
// Return te following conditions.
|
||||
// Possible states:.
|
||||
// - completion::EXCELLENT - At least $threshexcellent fraction of goals are complete and all required goals are met.
|
||||
// - completion::GOOD - At least $threshgood fraction of goals are complete and all required goals are met.
|
||||
|
@ -157,14 +157,14 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
$course = $courseinfo->course();
|
||||
$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..
|
||||
// Loop through all associated gradables and count the totals, completed, etc..
|
||||
$completions = [];
|
||||
$required = [];
|
||||
foreach (gradeinfo::list_studyitem_gradables($studyitem) as $gi) {
|
||||
$completions[] = $this->grade_completion($gi, $userid);
|
||||
if ($gi->is_required()) {
|
||||
// if it's a required grade .
|
||||
// also add it's index in the completion list to the list of required grades .
|
||||
// If it's a required grade .
|
||||
// Also add it's index in the completion list to the list of required grades .
|
||||
$required[] = count($completions) - 1;
|
||||
}
|
||||
}
|
||||
|
@ -219,8 +219,8 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
if (empty($grade)) {
|
||||
return completion::INCOMPLETE;
|
||||
} else if ($grade->finalgrade === NULL) {
|
||||
// on assignments, grade NULL means a submission has not yet been graded,.
|
||||
// but on quizes this can also mean a quiz might have been started.
|
||||
// On assignments, grade NULL means a submission has not yet been graded,.
|
||||
// But on quizes this can also mean a quiz might have been started.
|
||||
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
|
||||
|
||||
// Since we want old results to be visible until a pending item was graded, we only use this state here.
|
||||
|
@ -232,7 +232,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
}
|
||||
} else {
|
||||
$grade = $gradeitem->get_final($userid);
|
||||
// first determine if we have a grade_config for this scale or this maximum grade.
|
||||
// First determine if we have a grade_config for this scale or this maximum grade.
|
||||
$finalgrade = $grade->finalgrade;
|
||||
$scale = $gradeinfo->getScale();
|
||||
if ( isset($scale)) {
|
||||
|
@ -243,35 +243,35 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
$gradecfg = null;
|
||||
}
|
||||
|
||||
// for point grades, a provided grade pass overrides the defaults in the gradeconfig.
|
||||
// for scales, the configuration in the gradeconfig is leading.
|
||||
// For point grades, a provided grade pass overrides the defaults in the gradeconfig.
|
||||
// For scales, the configuration in the gradeconfig is leading.
|
||||
|
||||
if ($gradecfg && (isset($scale) || $gradeitem->gradepass == 0)) {
|
||||
// if so, we need to know if the grade is .
|
||||
// If so, we need to know if the grade is .
|
||||
if ($finalgrade >= $gradecfg->min_completed) {
|
||||
// return completed if completed.
|
||||
// Return completed if completed.
|
||||
return completion::COMPLETED;
|
||||
} else if ($this->use_failed && $coursefinished) {
|
||||
// return failed if failed is enabled and the grade is less than the minimum grade for progress.
|
||||
// Return failed if failed is enabled and the grade is less than the minimum grade for progress.
|
||||
return completion::FAILED;
|
||||
} else {
|
||||
return completion::PROGRESS;
|
||||
}
|
||||
} else if ($gradeitem->gradepass > 0) {
|
||||
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
|
||||
// if no gradeconfig and gradepass is set, use that one to determine config.
|
||||
// If no gradeconfig and gradepass is set, use that one to determine config.
|
||||
if ($finalgrade >= $gradeitem->gradepass) {
|
||||
return completion::COMPLETED;
|
||||
} else if ($this->use_failed && $coursefinished) {
|
||||
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
|
||||
// Return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
|
||||
return completion::FAILED;
|
||||
} else {
|
||||
return completion::PROGRESS;
|
||||
}
|
||||
} else {
|
||||
// Blind assumptions if nothing is provided.
|
||||
// over 55% of range is completed.
|
||||
// if range >= 3 and failed is enabled, assume that this means failed.
|
||||
// Over 55% of range is completed.
|
||||
// If range >= 3 and failed is enabled, assume that this means failed.
|
||||
$g = floatval($finalgrade - $gradeitem->grademin);
|
||||
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
|
||||
$score = $g / $range;
|
||||
|
@ -279,7 +279,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
if ($score > 0.55) {
|
||||
return completion::COMPLETED;
|
||||
} else if ($this->use_failed && $coursefinished) {
|
||||
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
|
||||
// Return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
|
||||
return completion::FAILED;
|
||||
} else {
|
||||
return completion::PROGRESS;
|
||||
|
|
|
@ -35,7 +35,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
private $acceptpending_as_submitted = False; // Also count ungraded but submitted .
|
||||
|
||||
public function __construct($configstr) {
|
||||
// allow public constructor for testing purposes.
|
||||
// Allow public constructor for testing purposes.
|
||||
$this->initialize($configstr);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
$config = \json_decode($configstr, true);
|
||||
|
||||
if (is_array($config)) {
|
||||
// copy all valid config settings to this item.
|
||||
// Copy all valid config settings to this item.
|
||||
foreach (["accept_pending_as_submitted"] as $key) {
|
||||
if (array_key_exists($key, $config)) {
|
||||
$this->$key = boolval($config[$key]);
|
||||
|
@ -172,8 +172,8 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
if (empty($grade)) {
|
||||
return completion::INCOMPLETE;
|
||||
} else if ($grade->finalgrade === NULL) {
|
||||
// on assignments, grade NULL means a submission has not yet been graded,.
|
||||
// but on quizes this can also mean a quiz might have been started.
|
||||
// On assignments, grade NULL means a submission has not yet been graded,.
|
||||
// But on quizes this can also mean a quiz might have been started.
|
||||
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
|
||||
|
||||
// Since we want old results to be visible until a pending item was graded, we only use this state here.
|
||||
|
@ -185,7 +185,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
}
|
||||
} else {
|
||||
$grade = $gradeitem->get_final($userid);
|
||||
// first determine if we have a grade_config for this scale or this maximum grade.
|
||||
// First determine if we have a grade_config for this scale or this maximum grade.
|
||||
$finalgrade = $grade->finalgrade;
|
||||
$scale = $gradeinfo->getScale();
|
||||
if ( isset($scale)) {
|
||||
|
@ -196,35 +196,35 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
$gradecfg = null;
|
||||
}
|
||||
|
||||
// for point grades, a provided grade pass overrides the defaults in the gradeconfig.
|
||||
// for scales, the configuration in the gradeconfig is leading.
|
||||
// For point grades, a provided grade pass overrides the defaults in the gradeconfig.
|
||||
// For scales, the configuration in the gradeconfig is leading.
|
||||
|
||||
if ($gradecfg && (isset($scale) || $gradeitem->gradepass == 0)) {
|
||||
// if so, we need to know if the grade is .
|
||||
// If so, we need to know if the grade is .
|
||||
if ($finalgrade >= $gradecfg->min_completed) {
|
||||
// return completed if completed.
|
||||
// Return completed if completed.
|
||||
return completion::COMPLETED;
|
||||
} else if ($this->use_failed && $finalgrade < $gradecfg->min_progress) {
|
||||
// return failed if failed is enabled and the grade is less than the minimum grade for progress.
|
||||
// Return failed if failed is enabled and the grade is less than the minimum grade for progress.
|
||||
return completion::FAILED;
|
||||
} else {
|
||||
return completion::PROGRESS;
|
||||
}
|
||||
} else if ($gradeitem->gradepass > 0) {
|
||||
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
|
||||
// if no gradeconfig and gradepass is set, use that one to determine config.
|
||||
// If no gradeconfig and gradepass is set, use that one to determine config.
|
||||
if ($finalgrade >= $gradeitem->gradepass) {
|
||||
return completion::COMPLETED;
|
||||
} else if ($this->use_failed && $gradeitem->gradepass >= 3 && $range >= 3 && $finalgrade == 1) {
|
||||
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
|
||||
// Return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
|
||||
return completion::FAILED;
|
||||
} else {
|
||||
return completion::PROGRESS;
|
||||
}
|
||||
} else {
|
||||
// Blind assumptions if nothing is provided.
|
||||
// over 55% of range is completed.
|
||||
// if range >= 3 and failed is enabled, assume that this means failed.
|
||||
// Over 55% of range is completed.
|
||||
// If range >= 3 and failed is enabled, assume that this means failed.
|
||||
$g = floatval($finalgrade - $gradeitem->grademin);
|
||||
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
|
||||
$score = $g / $range;
|
||||
|
@ -232,7 +232,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
if ($score > 0.55) {
|
||||
return completion::COMPLETED;
|
||||
} else if ($this->use_failed && $range >= 3 && $finalgrade == 1) {
|
||||
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
|
||||
// Return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
|
||||
return completion::FAILED;
|
||||
} else {
|
||||
return completion::PROGRESS;
|
||||
|
|
|
@ -39,7 +39,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
|
||||
protected function aggregate_completion(array $a, $condition = "50") {
|
||||
if (in_array($condition, ['ALL', '67', '50', 'ANY'])) {
|
||||
// condition is one of the valid conditions.
|
||||
// Condition is one of the valid conditions.
|
||||
$ccompleted = 0;
|
||||
$cexcellent = 0;
|
||||
$cprogress = 0;
|
||||
|
@ -68,7 +68,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
return completion::COMPLETED;
|
||||
} else {
|
||||
// Return PROGRESS if one or more completions are COMPLETED or EXCELLENT, but the aggregation margin is not met.
|
||||
// state PROGRESS will not carry on if aggregations are chained.
|
||||
// State PROGRESS will not carry on if aggregations are chained.
|
||||
if ($cprogress > 0) {
|
||||
return completion::PROGRESS;
|
||||
} else if ($cpending > 0) {
|
||||
|
@ -81,7 +81,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
return completion::INCOMPLETE;
|
||||
}
|
||||
} else {
|
||||
// indeterminable, return null.
|
||||
// Indeterminable, return null.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -101,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.
|
||||
// If null result (conditions are unknown/null) - default to ALL.
|
||||
return isset($completed)?$completed:(self::aggregate_completion($completion, 'ALL'));
|
||||
}
|
||||
|
||||
|
@ -113,8 +113,8 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
if (empty($grade)) {
|
||||
return completion::INCOMPLETE;
|
||||
} else if ($grade->finalgrade === NULL) {
|
||||
// on assignments, grade NULL means a submission has not yet been graded,.
|
||||
// but on quizes this can also mean a quiz might have been started.
|
||||
// On assignments, grade NULL means a submission has not yet been graded,.
|
||||
// But on quizes this can also mean a quiz might have been started.
|
||||
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
|
||||
|
||||
// Since we want old results to be visible until a pending item was graded, we only use this state here.
|
||||
|
@ -141,8 +141,8 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
}
|
||||
} else {
|
||||
// Blind assumptions:.
|
||||
// over 55% of range is completed.
|
||||
// over 85% of range is excellent.
|
||||
// Over 55% of range is completed.
|
||||
// Over 85% of range is excellent.
|
||||
$g = floatval($finalgrade - $gradeitem->grademin);
|
||||
$range = floatval($gradeitem->grademax - $gradeitem->grademin);
|
||||
$score = $g / $range;
|
||||
|
|
|
@ -88,10 +88,10 @@ class gradegenerator {
|
|||
|
||||
private function generatedfeedback() {
|
||||
if (file_exists("/usr/games/fortune")) {
|
||||
// get a fortune if it is available.
|
||||
// Get a fortune if it is available.
|
||||
return shell_exec("/usr/games/fortune -n 160 -e disclaimer literature science pratchett wisdom education");
|
||||
} else {
|
||||
// get a random loremipsum string.
|
||||
// Get a random loremipsum string.
|
||||
return self::$loremipsum[rand(0, count(self::$loremipsum)-1)];
|
||||
}
|
||||
}
|
||||
|
@ -188,12 +188,12 @@ class gradegenerator {
|
|||
$gradecfg = null;
|
||||
}
|
||||
|
||||
// next generate the grade.
|
||||
// Next generate the grade.
|
||||
if ($gradecfg) {
|
||||
if (!$gr->done) {
|
||||
// INCOMPLETE.
|
||||
// fair chance of teacher forgetting to set incomplete to "no evidence".
|
||||
$grade = 0;// $grade = (rand(0, 100) > 15)?max(1, $gradecfg->min_progress-1):"0";.
|
||||
// Fair chance of teacher forgetting to set incomplete to "no evidence".
|
||||
$grade = 0;
|
||||
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>"" ];
|
||||
} else if (!$gr->result) {
|
||||
$grade = rand($gradecfg->min_progress, $gradecfg->min_completed -1 );
|
||||
|
@ -229,8 +229,8 @@ class gradegenerator {
|
|||
$r->gradetext = $r->grade;
|
||||
} else {
|
||||
// Blind assumptions if nothing is provided.
|
||||
// over 55% of range is completed.
|
||||
// under 35% is not done.
|
||||
// Over 55% of range is completed.
|
||||
// Under 35% is not done.
|
||||
$range = floatval($gi->grademax - $gi->grademin);
|
||||
|
||||
if (!$gr->done) {
|
||||
|
|
|
@ -37,7 +37,7 @@ class debugger {
|
|||
$this->fname = $filename;
|
||||
$this->tag = $tag;
|
||||
|
||||
// assume debug environment if cachejs is false.
|
||||
// Assume debug environment if cachejs is false.
|
||||
$this->enabled = (isset($CFG->cachejs) && $CFG->cachejs == false);
|
||||
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ class webservicehelper {
|
|||
|
||||
// List the categories in which the user has a specific capability.
|
||||
$list = [];
|
||||
// initialize parent if needed.
|
||||
// Initialize parent if needed.
|
||||
if ($parent == null) {
|
||||
$parent = \core_course_category::user_top();
|
||||
if (has_capability($capability, $parent->get_context())) {
|
||||
|
@ -76,7 +76,7 @@ class webservicehelper {
|
|||
|
||||
$children = $parent->get_children();
|
||||
// Since the change for a category permission is greatest at the lower levels,.
|
||||
// we scan in two stages, to focus the search more on the lower levels instead of diving deep into the first category.
|
||||
// We scan in two stages, to focus the search more on the lower levels instead of diving deep into the first category.
|
||||
// Stage one (surface check): check all children for the capability.
|
||||
foreach ($children as $child) {
|
||||
// Check if we should add this category.
|
||||
|
|
|
@ -72,9 +72,9 @@ class assign_scanner extends scanner_base {
|
|||
$graded = array_intersect($graded, $courseuserids);
|
||||
}
|
||||
|
||||
// determine how many id's have a grade, but also an ungraded submission.
|
||||
// Determine how many id's have a grade, but also an ungraded submission.
|
||||
$dual = array_intersect($ungraded, $graded);
|
||||
// subtract those from the graded count.
|
||||
// Subtract those from the graded count.
|
||||
return count($graded) - count($dual);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ require_once($CFG->dirroot.'/question/engine/states.php'); // for reading questi
|
|||
class quiz_scanner extends scanner_base {
|
||||
|
||||
protected function get_ungraded_submissions() {
|
||||
// count all users who have one or more questions that still need grading.
|
||||
// Count all users who have one or more questions that still need grading.
|
||||
global $DB;
|
||||
|
||||
// First find all question attempts that need grading.
|
||||
|
@ -62,7 +62,7 @@ class quiz_scanner extends scanner_base {
|
|||
}
|
||||
|
||||
public function count_graded($courseuserids=[]) {
|
||||
// count all users who submitted one or more finished tests.
|
||||
// Count all users who submitted one or more finished tests.
|
||||
global $DB;
|
||||
$sql = "SELECT DISTINCT g.userid
|
||||
FROM {grade_grades} g
|
||||
|
|
|
@ -61,7 +61,7 @@ class period {
|
|||
} 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 .
|
||||
// Or specified duration of the page and the sequence of the periods .
|
||||
$pcount = $page->periods();
|
||||
$ystart = $page->startdate()->getTimestamp();
|
||||
$yend = $page->enddate()->getTimestamp();
|
||||
|
@ -104,7 +104,7 @@ class period {
|
|||
public static function findForPage(studyplanpage $page): array {
|
||||
if (!array_key_exists($page->id(), self::$PAGECACHE)) {
|
||||
$periods = [];
|
||||
// find and add the periods to an array with the period sequence as a key.
|
||||
// Find and add the periods to an array with the period sequence as a key.
|
||||
for($i=1; $i <= $page->periods(); $i++) {
|
||||
$period = self::find($page, $i);
|
||||
$periods[$i] = $period;
|
||||
|
@ -153,7 +153,7 @@ class period {
|
|||
if ($this->r->enddate && strlen($this->r->enddate) > 0) {
|
||||
return new \DateTime($this->r->enddate);
|
||||
} else{
|
||||
// return a date 100 years into the future.
|
||||
// Return a date 100 years into the future.
|
||||
return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
$contextlist = new \core_privacy\local\request\contextlist();
|
||||
$contextlist->add_system_context(); // For invitations.
|
||||
|
||||
// add contexts for linked studyplans.
|
||||
// Add contexts for linked studyplans.
|
||||
$sql = "SELECT s.context_id FROM {local_treestudyplan} s
|
||||
INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id
|
||||
WHERE ( a.user_id = :userid )
|
||||
|
@ -172,7 +172,7 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
*/
|
||||
public static function delete_data_for_all_users_in_context(\context $context) {
|
||||
global $DB;
|
||||
// find studyplans in context.
|
||||
// Find studyplans in context.
|
||||
if ($context->contextlevel == CONTEXT_COURSECAT) {
|
||||
$sql = "SELECT s.id FROM {local_treestudyplan} WHERE ( a.user_id = :userid AND s.context_id = :contextid)";
|
||||
$planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id]);
|
||||
|
@ -233,7 +233,7 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
FROM {local_treestudyplan_invit} i;";
|
||||
$userlist->add_from_sql('userid', $sql, []);
|
||||
|
||||
// also add "contextless studyplans, they are considered in system context".
|
||||
// Also add "contextless studyplans, they are considered in system context".
|
||||
$sql = "SELECT a.user_id as userid FROM {local_treestudyplan_user} a
|
||||
INNER JOIN {local_treestudyplan} s ON a.studyplan_id = s.id
|
||||
WHERE ( a.context_id is NULL or a.context_id = 0)
|
||||
|
@ -242,7 +242,7 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
|
||||
}
|
||||
|
||||
// add the links to all study plans in this context.
|
||||
// Add the links to all study plans in this context.
|
||||
$sql = "SELECT a.user_id as userid FROM {local_treestudyplan_user} a
|
||||
INNER JOIN {local_treestudyplan} s ON a.studyplan_id = s.id
|
||||
WHERE ( a.context_id = :contextid )
|
||||
|
|
|
@ -39,8 +39,6 @@ class reportinvite_form extends moodleform {
|
|||
$mform->addElement('hidden', 'update', 0);
|
||||
$mform->setType('update', PARAM_INT);
|
||||
|
||||
// $mform->addElement('static', 'desc_new', get_string('invite_desc_new', 'local_treestudyplan')); // Add elements to your form.
|
||||
// $mform->addElement('static', 'desc_edit', get_string('invite_desc_edit', 'local_treestudyplan')); // Add elements to your form.
|
||||
|
||||
$mform->addElement('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.
|
||||
|
|
|
@ -56,7 +56,7 @@ class studentstudyplanservice extends \external_api
|
|||
$list = [];
|
||||
$studyplans = studyplan::find_for_user($userid);
|
||||
foreach ($studyplans as $studyplan) {
|
||||
// only include studyplans in the context the user has permissions for.
|
||||
// Only include studyplans in the context the user has permissions for.
|
||||
if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) {
|
||||
$list[] =$studyplan->simple_model();
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ class studentstudyplanservice extends \external_api
|
|||
|
||||
$map = [];
|
||||
foreach ($studyplans as $studyplan) {
|
||||
// only include studyplans in the context the user has permissions for.
|
||||
// Only include studyplans in the context the user has permissions for.
|
||||
if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) {
|
||||
$map[] = $studyplan->user_model($userid);
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ class studyitem {
|
|||
]
|
||||
];
|
||||
if ($mode == "export") {
|
||||
// remove slot and layer.
|
||||
// Remove slot and layer.
|
||||
unset($model["slot"]);
|
||||
unset($model["layer"]);
|
||||
unset($model["continuation_id"]);
|
||||
|
@ -168,7 +168,7 @@ class studyitem {
|
|||
$model['badge'] = $badgeinfo->name();
|
||||
} else {
|
||||
// Also supply a list of linked users, so the badgeinfo can give stats on .
|
||||
// the amount issued, related to this studyplan.
|
||||
// The amount issued, related to this studyplan.
|
||||
$studentids = $this->studyline()->studyplan()->find_linked_userids();
|
||||
$model['badge'] = $badgeinfo->editor_model($studentids);
|
||||
}
|
||||
|
@ -256,9 +256,9 @@ class studyitem {
|
|||
public function delete($force=false) {
|
||||
global $DB;
|
||||
|
||||
// check if this item is referenced in a START item.
|
||||
// Check if this item is referenced in a START item.
|
||||
if ($force) {
|
||||
// clear continuation id from any references to this item.
|
||||
// Clear continuation id from any references to this item.
|
||||
$records = $DB->get_records(self::TABLE, ['continuation_id' => $this->id]);
|
||||
foreach ($records as $r) {
|
||||
$r->continuation_id = 0;
|
||||
|
@ -269,11 +269,11 @@ class studyitem {
|
|||
if ($DB->count_records(self::TABLE, ['continuation_id' => $this->id]) > 0) {
|
||||
return success::fail('Cannot remove: item is referenced by another item');
|
||||
} else {
|
||||
// delete al related connections to this item.
|
||||
// Delete al related connections to this item.
|
||||
studyitemconnection::clear($this->id);
|
||||
// delete all grade inclusion references to this item.
|
||||
// Delete all grade inclusion references to this item.
|
||||
$DB->delete_records("local_treestudyplan_gradeinc", ['studyitem_id' => $this->id]);
|
||||
// delete the item itself.
|
||||
// Delete the item itself.
|
||||
$DB->delete_records(self::TABLE, ['id' => $this->id]);
|
||||
|
||||
return success::success();
|
||||
|
@ -416,7 +416,7 @@ class studyitem {
|
|||
|
||||
if ($this->isValid()) {
|
||||
if (strtolower($this->r->type) == 'course') {
|
||||
// determine competency by competency completion.
|
||||
// Determine competency by competency completion.
|
||||
$courseinfo = $this->getcourseinfo();
|
||||
return $this->aggregator->aggregate_course($courseinfo, $this, $userid);
|
||||
} else if (strtolower($this->r->type) =='start') {
|
||||
|
@ -429,7 +429,7 @@ class studyitem {
|
|||
return completion::COMPLETED;
|
||||
}
|
||||
} else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) {
|
||||
// completion of the linked items, according to the rule.
|
||||
// Completion of the linked items, according to the rule.
|
||||
$incompleted = [];
|
||||
// Retrieve incoming connections.
|
||||
$incoming = $DB->get_records(studyitemconnection::TABLE, ['to_id' => $this->r->id]);
|
||||
|
@ -440,12 +440,12 @@ class studyitem {
|
|||
return $this->aggregator->aggregate_junction($incompleted, $this, $userid);
|
||||
} else if (strtolower($this->r->type) =='badge') {
|
||||
global $DB;
|
||||
// badge awarded.
|
||||
// Badge awarded.
|
||||
if (badgeinfo::exists($this->r->badge_id)) {
|
||||
$badge = new \core_badges\badge($this->r->badge_id);
|
||||
if ($badge->is_issued($userid)) {
|
||||
if ($badge->can_expire()) {
|
||||
// get the issued badges and check if any of them have not expired yet.
|
||||
// Get the issued badges and check if any of them have not expired yet.
|
||||
$badgesissued = $DB->get_records("badge_issued", ["badge_id" => $this->r->badge_id, "user_id" => $userid]);
|
||||
$notexpired = false;
|
||||
$now = time();
|
||||
|
@ -466,27 +466,27 @@ class studyitem {
|
|||
return completion::INCOMPLETE;
|
||||
}
|
||||
} else {
|
||||
// return incomplete for other types.
|
||||
// Return incomplete for other types.
|
||||
return completion::INCOMPLETE;
|
||||
}
|
||||
} else {
|
||||
// return incomplete for other types.
|
||||
// Return incomplete for other types.
|
||||
return completion::INCOMPLETE;
|
||||
}
|
||||
}
|
||||
|
||||
public function duplicate($newline) {
|
||||
global $DB;
|
||||
// clone the database fields.
|
||||
// Clone the database fields.
|
||||
$fields = clone $this->r;
|
||||
// set new line id.
|
||||
// Set new line id.
|
||||
unset($fields->id);
|
||||
$fields->line_id = $newline->id();
|
||||
//create new record with the new data.
|
||||
$id = $DB->insert_record(self::TABLE, (array)$fields);
|
||||
$new = self::findById($id, $newline);
|
||||
|
||||
// copy the grading info if relevant.
|
||||
// Copy the grading info if relevant.
|
||||
$gradables = gradeinfo::list_studyitem_gradables($this);
|
||||
foreach ($gradables as $g) {
|
||||
gradeinfo::include_grade($g->getGradeitem()->id, $new->id(), true);
|
||||
|
@ -513,7 +513,7 @@ class studyitem {
|
|||
$item = self::add($model, true);
|
||||
|
||||
if (isset($model["course_id"])) {
|
||||
// attempt to import the gradables.
|
||||
// Attempt to import the gradables.
|
||||
foreach ($model["gradables"] as $gradable) {
|
||||
gradeinfo::import($item, $gradable);
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ class studyline {
|
|||
// TODO: Make this a little nicer.
|
||||
// Get the number of slots.
|
||||
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed, .
|
||||
// make sure there are enought slots to account for them.
|
||||
// Make sure there are enought slots to account for them.
|
||||
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
|
||||
$maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
|
||||
$numslots = max($this->page->periods(), $maxslot +1);
|
||||
|
@ -217,7 +217,7 @@ class studyline {
|
|||
$c->delete($force);
|
||||
}
|
||||
}
|
||||
// check if this item has study items in it.
|
||||
// Check if this item has study items in it.
|
||||
if ($DB->count_records(studyitem::TABLE, ['line_id' => $this->id]) > 0) {
|
||||
return success::fail('cannot delete studyline with items');
|
||||
} else {
|
||||
|
@ -282,7 +282,7 @@ class studyline {
|
|||
|
||||
// Get the number of slots.
|
||||
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed, .
|
||||
// make sure there are enought slots to account for them.
|
||||
// Make sure there are enought slots to account for them.
|
||||
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
|
||||
$maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
|
||||
$numslots = max($this->page->periods(), $maxslot +1);
|
||||
|
@ -324,18 +324,18 @@ class studyline {
|
|||
public function duplicate($newstudyplan, &$translation) {
|
||||
global $DB;
|
||||
|
||||
// clone the database fields.
|
||||
// Clone the database fields.
|
||||
$fields = clone $this->r;
|
||||
// set new studyplan id.
|
||||
// Set new studyplan id.
|
||||
unset($fields->id);
|
||||
$fields->studyplan_id = $newstudyplan->id();
|
||||
// create new record with the new data.
|
||||
// Create new record with the new data.
|
||||
$id = $DB->insert_record(self::TABLE, (array)$fields);
|
||||
$new = self::findById($id);
|
||||
|
||||
// Next copy all the study items for this studyline.
|
||||
// and record the original and copy id's in the $translation array.
|
||||
// so the calling function can connect the new studyitems as required.
|
||||
// And record the original and copy id's in the $translation array.
|
||||
// So the calling function can connect the new studyitems as required.
|
||||
$children = studyitem::find_studyline_children($this);
|
||||
$translation = [];
|
||||
foreach ($children as $c) {
|
||||
|
|
|
@ -71,9 +71,9 @@ class studyplan {
|
|||
}
|
||||
|
||||
public function pages() {
|
||||
// cached version of find_studyplan_children.
|
||||
// Cached version of find_studyplan_children.
|
||||
// (may be premature optimization, since .
|
||||
// find_studyplan_children also does some caching).
|
||||
// Find_studyplan_children also does some caching).
|
||||
if (empty($this->page_cache)) {
|
||||
$this->page_cache = studyplanpage::find_studyplan_children($this);
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ class studyplan {
|
|||
$model['advanced'] = [];
|
||||
}
|
||||
|
||||
// get a list of available scales.
|
||||
// Get a list of available scales.
|
||||
$scales = array_map( function($scale) {
|
||||
return [ "id" => $scale->id, "name" => $scale->name, ];
|
||||
}, \grade_scale::fetch_all(array('courseid'=>0)) );
|
||||
|
@ -210,7 +210,7 @@ class studyplan {
|
|||
|
||||
// Start temporary skräpp code.
|
||||
// Add a single page and copy the names.This keeps the data sane until the upgrade to .
|
||||
// real page management is done.
|
||||
// Real page management is done.
|
||||
// On import, adding an empty page messes things up for now, so we have an option to skip this....
|
||||
// TODO: Remove this when proper page management is implemented.
|
||||
if (!$bare) {
|
||||
|
@ -251,14 +251,14 @@ class studyplan {
|
|||
//reload the context...
|
||||
$this->context = null;
|
||||
$this->context();
|
||||
// reload aggregator.
|
||||
// Reload aggregator.
|
||||
$this->aggregator = aggregator::createOrDefault($this->r->aggregation, $this->r->aggregation_config);
|
||||
|
||||
// Start temporary skräpp code.
|
||||
// TODO: Until proper page editing is implemented, copy data from studyplan to it's first page.
|
||||
// This keeps the data sane until the upgrade is done.
|
||||
if (count($this->pages()) == 1) {
|
||||
// update the info to the page as well.
|
||||
// Update the info to the page as well.
|
||||
$page = $this->pages()[0];
|
||||
$pageeditable = ['name', 'shortname', 'description', 'periods', 'startdate', 'enddate'];
|
||||
$pageinfo = [];
|
||||
|
@ -490,7 +490,7 @@ class studyplan {
|
|||
'description' => $this->r->description,
|
||||
]);
|
||||
|
||||
// next, copy the studylines.
|
||||
// Next, copy the studylines.
|
||||
|
||||
foreach ($this->pages() as $p) {
|
||||
$newchild = $p->duplicate($newplan);
|
||||
|
@ -565,7 +565,7 @@ class studyplan {
|
|||
$content = json_decode($content, true);
|
||||
if ($content["version"] >= 2.0) {
|
||||
if ($content["type"] == "studyplanpage") {
|
||||
// import single page from a studyplanpage (wrapped in array of one page).
|
||||
// Import single page from a studyplanpage (wrapped in array of one page).
|
||||
return $this->import_pages_model([$content["page"]]);
|
||||
} else if ($content["type"] == "studyplan") {
|
||||
// Import all pages from the studyplan.
|
||||
|
|
|
@ -82,7 +82,7 @@ class studyplanpage {
|
|||
if ($this->r->enddate && strlen($this->r->enddate) > 0) {
|
||||
return new \DateTime($this->r->enddate);
|
||||
} else{
|
||||
// return a date 100 years into the future.
|
||||
// Return a date 100 years into the future.
|
||||
return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ class studyplanpage {
|
|||
'enddate' => empty($this->r->enddate)?null:$this->r->enddate,
|
||||
]);
|
||||
|
||||
// next, copy the studylines.
|
||||
// Next, copy the studylines.
|
||||
|
||||
$children = studyline::find_page_children($this);
|
||||
$itemtranslation = [];
|
||||
|
@ -286,11 +286,11 @@ class studyplanpage {
|
|||
$linetranslation[$c->id()] = $newchild->id();
|
||||
}
|
||||
|
||||
// now the itemtranslation array contains all of the old child id's as keys and all of the related new ids as values.
|
||||
// Now the itemtranslation array contains all of the old child id's as keys and all of the related new ids as values.
|
||||
// (feature of the studyline::duplicate function).
|
||||
// use this to recreate the lines in the new plan.
|
||||
// Use this to recreate the lines in the new plan.
|
||||
foreach (array_keys($itemtranslation) as $itemid) {
|
||||
// copy based on the outgoing connections of each item, to avoid duplicates.
|
||||
// Copy based on the outgoing connections of each item, to avoid duplicates.
|
||||
$connections = studyitemconnection::find_outgoing($itemid);
|
||||
foreach ($connections as $conn) {
|
||||
studyitemconnection::connect($itemtranslation[$conn->from_id], $itemtranslation[$conn->to_id]);
|
||||
|
@ -329,9 +329,9 @@ class studyplanpage {
|
|||
$csv .= ", \"{$name}\"";
|
||||
}
|
||||
$csv .= "\r\n";
|
||||
// next, make one line per studyline.
|
||||
// Next, make one line per studyline.
|
||||
foreach ($model["studylines"] as $line) {
|
||||
// determine how many fields are simultaneous in the line at maximum.
|
||||
// Determine how many fields are simultaneous in the line at maximum.
|
||||
$maxlines = 1;
|
||||
for($i = 1; $i <= $periods; $i++) {
|
||||
if (count($line["slots"]) > $i) {
|
||||
|
@ -489,13 +489,11 @@ class studyplanpage {
|
|||
if (empty($line)) {
|
||||
$linemodel["page_id"] = $this->id;
|
||||
$line = studyline::add($linemodel);
|
||||
} else {
|
||||
//$line->edit($linemodel); // Update the line with the settings from the imported file.
|
||||
}
|
||||
$linemap[$ix] = $line;
|
||||
}
|
||||
|
||||
// next, let each study line import the study items.
|
||||
// Next, let each study line import the study items.
|
||||
$itemtranslation = [];
|
||||
$connections = [];
|
||||
foreach ($model as $ix => $linemodel) {
|
||||
|
|
|
@ -232,7 +232,7 @@ class studyplanservice extends \external_api
|
|||
|
||||
public static function delete_studyplan($id, $force=false) {
|
||||
$o = studyplan::findById($id);
|
||||
// validate if the requesting user has the right to edit the plan in it's current context.
|
||||
// Validate if the requesting user has the right to edit the plan in it's current context.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
return $o->delete(!!$force)->model();
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ class studyplanservice extends \external_api
|
|||
}
|
||||
|
||||
public static function add_studyline($pageid, $name, $shortname, $color, $sequence) {
|
||||
// validate if the requesting user has the right to edit the plan in it's current context.
|
||||
// Validate if the requesting user has the right to edit the plan in it's current context.
|
||||
$page = studyplanpage::findById($pageid);
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $page->studyplan()->context());
|
||||
|
||||
|
@ -293,7 +293,7 @@ class studyplanservice extends \external_api
|
|||
|
||||
public static function edit_studyline($id, $name, $shortname, $color) {
|
||||
$o = studyline::findById($id);
|
||||
// validate if the requesting user has the right to edit the plan in it's current context.
|
||||
// Validate if the requesting user has the right to edit the plan in it's current context.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
|
||||
$o->edit([
|
||||
|
@ -324,7 +324,7 @@ class studyplanservice extends \external_api
|
|||
|
||||
public static function delete_studyline($id) {
|
||||
$o = studyline::findById($id);
|
||||
// validate if the requesting user has the right to edit the plan in it's current context.
|
||||
// Validate if the requesting user has the right to edit the plan in it's current context.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
return $o->delete()->model();
|
||||
|
||||
|
@ -352,7 +352,7 @@ class studyplanservice extends \external_api
|
|||
}
|
||||
|
||||
public static function reorder_studylines($resequence) {
|
||||
// validate if the requesting user has the right to edit the lines in it's current context.
|
||||
// Validate if the requesting user has the right to edit the lines in it's current context.
|
||||
foreach ($resequence as $sq) {
|
||||
$o = studyline::findById(($sq['id']));
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
|
||||
|
@ -627,13 +627,13 @@ class studyplanservice extends \external_api
|
|||
public static function include_grade($gradeid, $itemid, $include, $required=false) {
|
||||
global $USER;
|
||||
|
||||
// find related course and course context.
|
||||
// Find related course and course context.
|
||||
$coursecontext = gradeinfo::getCourseContextById($gradeid);
|
||||
// do sanity checks.
|
||||
// Do sanity checks.
|
||||
\external_api::validate_context($coursecontext);
|
||||
|
||||
|
||||
// check correct capabilities.
|
||||
// Check correct capabilities.
|
||||
if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($itemid)->context()) ||
|
||||
is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) {
|
||||
return gradeinfo::include_grade($gradeid, $itemid, $include, $required)->model();
|
||||
|
@ -694,7 +694,7 @@ class studyplanservice extends \external_api
|
|||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
|
||||
|
||||
$list = [];
|
||||
// check if scaleid is valid.
|
||||
// Check if scaleid is valid.
|
||||
$scale = \grade_scale::fetch(['id' => $scaleid]);
|
||||
$scale->load_items();
|
||||
|
||||
|
@ -703,10 +703,10 @@ class studyplanservice extends \external_api
|
|||
$scalepass = ($gradecfg)?$gradecfg->min_completed:0;
|
||||
$scalemax = count($scale->scale_items);
|
||||
|
||||
// find studyline id's.
|
||||
// Find studyline id's.
|
||||
$studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]);
|
||||
foreach ($studylineids as $studylineid) {
|
||||
// find id's of studyitems of type course.
|
||||
// Find id's of studyitems of type course.
|
||||
$records = $DB->get_records(studyitem::TABLE, ['line_id' => $studylineid]);
|
||||
|
||||
foreach ($records as $itemr) {
|
||||
|
@ -719,9 +719,9 @@ class studyplanservice extends \external_api
|
|||
foreach ($gradables as $g) {
|
||||
$gi = $g->getGradeItem();
|
||||
|
||||
// only change items that do not yet have grades.
|
||||
// otherwise we will need to implement grade recalculations and it is not worth the trouble. .
|
||||
// if grades are given, you likely don't want to change it like this anyway.
|
||||
// Only change items that do not yet have grades.
|
||||
// Otherwise we will need to implement grade recalculations and it is not worth the trouble. .
|
||||
// If grades are given, you likely don't want to change it like this anyway.
|
||||
|
||||
if (!$gi->has_grades()) {
|
||||
$gi->gradetype = GRADE_TYPE_SCALE;
|
||||
|
@ -736,8 +736,8 @@ class studyplanservice extends \external_api
|
|||
$debug = "";
|
||||
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.
|
||||
// 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.
|
||||
$tablename = $gi->itemmodule;
|
||||
$fieldname = "grade";
|
||||
if ($result && $gi->itemtype == "mod" && $dbman->table_exists($tablename)) {
|
||||
|
@ -832,10 +832,10 @@ class studyplanservice extends \external_api
|
|||
// Validate permissions.
|
||||
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
|
||||
|
||||
// find studyline id's.
|
||||
// Find studyline id's.
|
||||
$studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]);
|
||||
foreach ($studylineids as $studylineid) {
|
||||
// find id's of studyitems of type course.
|
||||
// Find id's of studyitems of type course.
|
||||
$records = $DB->get_records(studyitem::TABLE, ['line_id' => $studylineid]);
|
||||
|
||||
foreach ($records as $itemr) {
|
||||
|
@ -1029,10 +1029,10 @@ class studyplanservice extends \external_api
|
|||
|
||||
// Check the course exists.
|
||||
$course = \get_course($cm->course);
|
||||
// require_login.
|
||||
// Require_login.
|
||||
require_login($course, false, $cm); // needed to setup proper $COURSE.
|
||||
|
||||
// get needed info to create the correct form.
|
||||
// Get needed info to create the correct form.
|
||||
list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course);
|
||||
$modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php";
|
||||
if (file_exists($modmoodleform)) {
|
||||
|
@ -1042,14 +1042,14 @@ class studyplanservice extends \external_api
|
|||
}
|
||||
$mformclassname = 'mod_'.$module->name.'_mod_form';
|
||||
|
||||
// now hack the received data into $_POST, so the mform thinks it has been submitted "normally".
|
||||
// Now hack the received data into $_POST, so the mform thinks it has been submitted "normally".
|
||||
foreach (explode("&", $formdata) as $pair) {
|
||||
$p = explode("=", $pair, 2);
|
||||
$k = urldecode($p[0]);
|
||||
$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.
|
||||
// Its a bracketet field, like filename[text] which should be separated and put into a named array.
|
||||
list($k, $h) = explode("[", $k, 2);
|
||||
if (strlen($k) > 0 && strlen($h) > 1) {
|
||||
$h = rtrim($h, "]");
|
||||
|
@ -1064,7 +1064,7 @@ class studyplanservice extends \external_api
|
|||
}
|
||||
|
||||
// Now create the mform and update the module...
|
||||
// update_moduleinfo() actually needs the mform somehow. Hence the ugly hacks.
|
||||
// Update_moduleinfo() actually needs the mform somehow. Hence the ugly hacks.
|
||||
$mform = new $mformclassname($data, $cw->section, $cm, $course);
|
||||
$mform->set_data($data);
|
||||
|
||||
|
@ -1173,12 +1173,12 @@ class studyplanservice extends \external_api
|
|||
'reset_start_date_old' => $course->startdate,
|
||||
'reset_end_date_old' => $course->enddate,
|
||||
]);
|
||||
// purge course cache so the dates are properly reflected.
|
||||
// Purge course cache so the dates are properly reflected.
|
||||
\course_modinfo::purge_course_cache($course->id);
|
||||
|
||||
return (new courseinfo($course->id))->editor_model();
|
||||
} else {
|
||||
// probably should return a nice message.
|
||||
// Probably should return a nice message.
|
||||
throw new \webservice_access_exception("You do not have date change permissions on this course");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class autocohortsync extends \core\task\scheduled_task {
|
|||
|
||||
foreach ($studyplans as $studyplan) {
|
||||
// Only process studyplans that have been marked for change because .
|
||||
// a cohort change has occurred or a course has been added....
|
||||
// A cohort change has occurred or a course has been added....
|
||||
if ($studyplan->has_csync_changed()) {
|
||||
\mtrace("Studyplan {$studyplan->shortname()} needs processing");
|
||||
$enroller = new cascadecohortsync($studyplan);
|
||||
|
|
|
@ -32,7 +32,7 @@ class teachingfinder {
|
|||
|
||||
$records = $DB->get_records(self::TABLE, ['teacher_id' => $userid]);
|
||||
if (count($records) == 0) {
|
||||
// initiate a search if the cache is empty.
|
||||
// Initiate a search if the cache is empty.
|
||||
self::update_teaching_cache($userid);
|
||||
$DB->get_records(self::TABLE, ['teacher_id' => $userid]);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class teachingfinder {
|
|||
WHERE startdate <= NOW() and enddate >= NOW()";
|
||||
$pageids = $DB->get_fieldset_sql($sql, []);
|
||||
|
||||
// then parse them to see if the user has the grading permission in any of them .
|
||||
// Then parse them to see if the user has the grading permission in any of them .
|
||||
// (Which would make them a teacher for all intents and purposes).
|
||||
|
||||
foreach ($pageids as $pageid) {
|
||||
|
|
|
@ -57,7 +57,7 @@ if ($categoryid > 0) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// reload page with selected category.
|
||||
// Reload page with selected category.
|
||||
$url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]);
|
||||
header('Location: '.$url->out(false), true, 302);
|
||||
exit;
|
||||
|
|
|
@ -37,7 +37,7 @@ use local_treestudyplan;
|
|||
|
||||
$INVITEDURL = "/local/treestudyplan/invited.php";
|
||||
|
||||
//admin_externalpage_setup('major');.
|
||||
// Admin_externalpage_setup('major');.
|
||||
$systemcontext = context_system::instance();
|
||||
|
||||
$PAGE->set_url("/local/treestudyplan/invitations.php", array());
|
||||
|
|
|
@ -45,7 +45,7 @@ if (empty($invite)) {
|
|||
print $OUTPUT->header();
|
||||
|
||||
|
||||
// render page for skill level 0 (global).
|
||||
// Render page for skill level 0 (global).
|
||||
|
||||
print "<div class='box errorbox alert alert-danger'>";
|
||||
print get_string('invalid_invitekey_error', 'local_treestudyplan');
|
||||
|
|
14
lib.php
14
lib.php
|
@ -49,7 +49,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
|
|||
// Using some javascript magic we'll hide the links that are not accessible.
|
||||
// (Since the Output API does not easily support inline style tags, adding one through Javascript is easier,.
|
||||
// and not much more complex than loading a separate stylesheet for each link we want to hide).
|
||||
// we will add all the hrefs that should be hidden to this variable below.
|
||||
// We will add all the hrefs that should be hidden to this variable below.
|
||||
$hideprimary_hrefs = [];
|
||||
|
||||
if ($USER->id > 1) // Don't show if user is not logged in (id == 0) or is guest user (id == 1).
|
||||
|
@ -59,7 +59,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
|
|||
if (!empty($userstudyplans))
|
||||
{
|
||||
|
||||
// create studyplan node.
|
||||
// Create studyplan node.
|
||||
$node = navigation_node::create(
|
||||
get_string("link_myreport", "local_treestudyplan"),
|
||||
new moodle_url($CFG->wwwroot . "/local/treestudyplan/myreport.php", array()),
|
||||
|
@ -71,7 +71,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
|
|||
$node->showinflatnavigation = true;
|
||||
$node->showinsecondarynavigation=true;
|
||||
|
||||
// create invitenode node.
|
||||
// Create invitenode node.
|
||||
$invitenode = navigation_node::create(
|
||||
get_string("manage_invites", "local_treestudyplan"),
|
||||
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invitations.php", array()),
|
||||
|
@ -132,7 +132,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
|
|||
$hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php";
|
||||
$hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php";
|
||||
}
|
||||
// create invitenode node.
|
||||
// Create invitenode node.
|
||||
$invitenode = navigation_node::create(
|
||||
get_string("nav_invited", "local_treestudyplan"),
|
||||
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invited.php", array()),
|
||||
|
@ -164,7 +164,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
|
|||
"local_treestudyplan_editplan",
|
||||
new pix_icon("editplans", '', 'local_treestudyplan')
|
||||
);
|
||||
//$node->make_active();.
|
||||
|
||||
}
|
||||
if (has_capability('local/treestudyplan:viewuserreports', $coursecategorycontext)) {
|
||||
$node = $navigation->add(
|
||||
|
@ -175,7 +175,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
|
|||
"local_treestudyplan_viewplan",
|
||||
new pix_icon("viewplans", '', 'local_treestudyplan')
|
||||
);
|
||||
//$node->make_active();.
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ function local_treestudyplan_output_fragment_mod_edit_form($args) {
|
|||
// Check the course exists.
|
||||
$course = \get_course($cm->course);
|
||||
|
||||
// require_login.
|
||||
// Require_login.
|
||||
require_login($course, false, $cm); // needed to setup proper $COURSE.
|
||||
|
||||
list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course);
|
||||
|
|
|
@ -57,7 +57,7 @@ if ($categoryid > 0) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// reload page with selected category.
|
||||
// Reload page with selected category.
|
||||
$url = new \moodle_url('/local/treestudyplan/view-plan.php', ["contextid" => $contextid]);
|
||||
header('Location: '.$url->out(false), true, 302);
|
||||
exit;
|
||||
|
|
Loading…
Reference in New Issue
Block a user