Moodle code style fixes part 2
This commit is contained in:
		
							parent
							
								
									1a3df05195
								
							
						
					
					
						commit
						acf3409890
					
				
					 31 changed files with 177 additions and 342 deletions
				
			
		|  | @ -41,8 +41,7 @@ $grade_cfgs = []; | |||
| foreach ($mappings as $cfg) { | ||||
|     if (!empty($cfg->scale_id)) { | ||||
|         $scale_cfgs[$cfg->scale_id] = $cfg; | ||||
|     } | ||||
|     else if (!empty($cfg->grade_points)) { | ||||
|     } else if (!empty($cfg->grade_points)) { | ||||
|         $grade_cfgs[$cfg->grade_points] = $cfg; | ||||
|     } | ||||
| } | ||||
|  | @ -71,8 +70,7 @@ if ($_POST["action"] == "update") { | |||
|             } | ||||
| 
 | ||||
| 
 | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             $scalecfg = (object)[ "scale_id" => $scale->id, ]; | ||||
|             $requireinsert = false; | ||||
|             foreach (["min_progress", "min_completed"] as $handle) { | ||||
|  | @ -97,8 +95,7 @@ if ($_POST["action"] == "update") { | |||
|         if (array_key_exists($deletekey, $_POST) && boolval($_POST[$deletekey]) === true) { | ||||
|             $DB->delete_records(GRADECFG_TABLE, ["id" => $gradecfg->id]); | ||||
|             $deletelist[] = $gradecfg; | ||||
|         } | ||||
|         else | ||||
|         } else | ||||
|         { | ||||
|             foreach (["min_progress", "min_completed"] as $handle) { | ||||
|                 $key = "g_{$gradecfg->grade_points}_{$handle}"; | ||||
|  |  | |||
|  | @ -62,8 +62,7 @@ class cascadeusersync { | |||
|                 if (!($instance = $DB->get_record('enrol', $instanceparams))) { | ||||
|                     if ($instanceid = $enrol->add_default_instance($course)) { | ||||
|                         $instance = $DB->get_record('enrol', array('id' => $instanceid)); | ||||
|                     } | ||||
|                     else { | ||||
|                     } else { | ||||
|                         // Instance not added for some reason, so report an error somewhere.
 | ||||
|                         // (or not).
 | ||||
|                         $instance = null; | ||||
|  |  | |||
|  | @ -45,8 +45,7 @@ class completion { | |||
|     public static function label($completion) { | ||||
|         if (array_key_exists($completion, self::LABELS)) { | ||||
|             return self::LABELS[$completion]; | ||||
|         } | ||||
|         else | ||||
|         } else | ||||
|         { | ||||
|             return self::LABELS[self::INCOMPLETE]; | ||||
|         } | ||||
|  |  | |||
|  | @ -89,8 +89,7 @@ class completionscanner | |||
|         if (!array_key_exists($userid, $this->pending_cache)) { | ||||
|             if ($this->scanner === null) { | ||||
|                 $this->pending_cache[$userid] = false; | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 $this->pending_cache[$userid] = $this->scanner->has_ungraded_submission($userid);; | ||||
|             } | ||||
|         } | ||||
|  | @ -133,8 +132,7 @@ class completionscanner | |||
|                     } else if ($completion_status == COMPLETION_COMPLETE) { | ||||
|                         $completed++; | ||||
|                     } | ||||
|                 } | ||||
|                 else{ | ||||
|                 } else{ | ||||
|                     if ($completion->is_complete()) { | ||||
|                         $completed++; | ||||
|                     } | ||||
|  |  | |||
|  | @ -193,24 +193,21 @@ class corecompletioninfo { | |||
|                                 "requirement" => get_string('markingyourselfcomplete', 'completion'), | ||||
|                                 "status" => "", | ||||
|                             ]; | ||||
|                         } | ||||
|                         else if ($type == COMPLETION_CRITERIA_TYPE_DATE) { | ||||
|                         } else if ($type == COMPLETION_CRITERIA_TYPE_DATE) { | ||||
|                             $details = [ | ||||
|                                 "type" => get_string('datepassed', 'completion'), | ||||
|                                 "criteria" => get_string('remainingenroleduntildate', 'completion'), | ||||
|                                 "requirement" => date("Y-m-d", $criteria->timeend), | ||||
|                                 "status" => "", | ||||
|                             ]; | ||||
|                         } | ||||
|                         else if ($type == COMPLETION_CRITERIA_TYPE_UNENROL) { | ||||
|                         } else if ($type == COMPLETION_CRITERIA_TYPE_UNENROL) { | ||||
|                             $details = [ | ||||
|                                 "type" => get_string('unenrolment', 'completion'), | ||||
|                                 "criteria" => get_string('unenrolment', 'completion'), | ||||
|                                 "requirement" => get_string('unenrolingfromcourse', 'completion'), | ||||
|                                 "status" => "", | ||||
|                             ]; | ||||
|                         } | ||||
|                         else if ($type == COMPLETION_CRITERIA_TYPE_ACTIVITY) { | ||||
|                         } else if ($type == COMPLETION_CRITERIA_TYPE_ACTIVITY) { | ||||
|                             $cm = $this->modinfo->get_cm($criteria->moduleinstance); | ||||
|                             $details = [ | ||||
|                                 "type" => $criteria->get_title(), | ||||
|  | @ -245,16 +242,14 @@ class corecompletioninfo { | |||
| 
 | ||||
|                             $details['requirement'] = implode(', ', $details['requirement']); | ||||
| 
 | ||||
|                         } | ||||
|                         else if ($type == COMPLETION_CRITERIA_TYPE_DURATION) { | ||||
|                         } else if ($type == COMPLETION_CRITERIA_TYPE_DURATION) { | ||||
|                             $details = [ | ||||
|                                 "type" => get_string('periodpostenrolment', 'completion'), | ||||
|                                 "criteria" => get_string('remainingenroledfortime', 'completion'), | ||||
|                                 "requirement" => get_string('xdays', 'completion', ceil($criteria->enrolperiod / (60*60*24))), | ||||
|                                 "status" => "", | ||||
|                             ]; | ||||
|                         } | ||||
|                         else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) { | ||||
|                         } else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) { | ||||
|                             $details = [ | ||||
|                                 "type" => get_string('coursegrade', 'completion'), | ||||
|                                 "criteria" => get_string('graderequired', 'completion'), | ||||
|  | @ -262,8 +257,7 @@ class corecompletioninfo { | |||
|                                 "requirement" => get_string('graderequired', 'completion').": ".format_float($criteria->gradepass, 1), | ||||
|                                 "status" => "", | ||||
|                             ]; | ||||
|                         } | ||||
|                         else if ($type == COMPLETION_CRITERIA_TYPE_ROLE) { | ||||
|                         } else if ($type == COMPLETION_CRITERIA_TYPE_ROLE) { | ||||
|                             $criteria = $criteria->get_title(); | ||||
| 
 | ||||
|                             $details = [ | ||||
|  | @ -272,8 +266,7 @@ class corecompletioninfo { | |||
|                                 "requirement" => get_string('markedcompleteby', 'completion', $criteria), | ||||
|                                 "status" => "", | ||||
|                             ]; | ||||
|                         } | ||||
|                         else if ($type == COMPLETION_CRITERIA_TYPE_COURSE) { | ||||
|                         } else if ($type == COMPLETION_CRITERIA_TYPE_COURSE) { | ||||
|                             $prereq = get_course($criteria->courseinstance); | ||||
|                             $coursecontext = \context_course::instance($prereq->id, MUST_EXIST); | ||||
|                             $fullname = format_string($prereq->fullname, true, array('context' => $coursecontext)); | ||||
|  | @ -325,8 +318,7 @@ class corecompletioninfo { | |||
|         } | ||||
|         if ($typeaggregation == COMPLETION_AGGREGATION_ALL) { | ||||
|             return $completed >= $count; | ||||
|         } | ||||
|         else { // COMPLETION_AGGREGATION_ANY.
 | ||||
|         } else { // COMPLETION_AGGREGATION_ANY.
 | ||||
|             return $completed > 1; | ||||
|         } | ||||
| 
 | ||||
|  | @ -402,8 +394,7 @@ class corecompletioninfo { | |||
|                                 } | ||||
|                             } | ||||
| 
 | ||||
|                         } | ||||
|                         else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) { | ||||
|                         } else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) { | ||||
|                             // Make sure we provide the current course grade.
 | ||||
|                             $iinfo['grade'] = floatval($iinfo['details']['status']); | ||||
|                             if ($iinfo["grade"] > 0) { | ||||
|  | @ -423,8 +414,7 @@ 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.
 | ||||
|                         $cinfo["count"] = (count($cinfo["items"]) > 0)?1:0; | ||||
|  | @ -465,8 +455,7 @@ class corecompletioninfo { | |||
|                     if (isset($scale)) { | ||||
|                         // get scale value.
 | ||||
|                         $result->grade = $scale->get_nearest_item($grade->finalgrade); | ||||
|                     } | ||||
|                     else | ||||
|                     } else | ||||
|                     { | ||||
|                         // round final grade to 1 decimal point.
 | ||||
|                         $result->grade =  round($grade->finalgrade, 1); | ||||
|  | @ -474,8 +463,7 @@ class corecompletioninfo { | |||
| 
 | ||||
|                     $result->feedback = trim($grade->feedback); | ||||
|                     $result->pending = (new gradingscanner($gi))->pending($userid); | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     $result->grade = "-"; // Activity is gradable, but user did not receive a grade yet.
 | ||||
|                     $result->feedback = null; | ||||
|                     $result->pending = false; | ||||
|  | @ -508,14 +496,12 @@ class corecompletioninfo { | |||
|                     if (isset($scale)) { | ||||
|                         // get scale value.
 | ||||
|                         return $scale->get_nearest_item($grade->finalgrade); | ||||
|                     } | ||||
|                     else | ||||
|                     } else | ||||
|                     { | ||||
|                         // round final grade to 1 decimal point.
 | ||||
|                         return round($grade->finalgrade, 1); | ||||
|                     } | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return "-"; // User did not receive a grade yet for this course.
 | ||||
|                 } | ||||
|             } | ||||
|  | @ -551,8 +537,7 @@ class corecompletioninfo { | |||
|         // Before we check how many modules have been completed see if the course has completed. .
 | ||||
|         if ($this->completion->is_course_complete($userid)) { | ||||
|             $completed = $count; | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             // count all completions, but treat .
 | ||||
|             foreach ($completions as $completion) { | ||||
|                 $crit = $completion->get_criteria(); | ||||
|  | @ -567,8 +552,7 @@ class corecompletioninfo { | |||
|                     } else { | ||||
|                         $completed += 1; | ||||
|                     } | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     if ($completion->is_complete()) { | ||||
|                         $completed += 1; | ||||
|                     } | ||||
|  | @ -633,8 +617,7 @@ class corecompletioninfo { | |||
|                 } else { | ||||
|                     $typecount->completed += 1; | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 if ($completion->is_complete()) { | ||||
|                     $typecount->completed += 1; | ||||
|                 } | ||||
|  | @ -653,8 +636,7 @@ class corecompletioninfo { | |||
|                 if ($c->aggregation == COMPLETION_AGGREGATION_ALL) { | ||||
|                     $ct = $c->count; | ||||
|                     $cmpl = $c->completed; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     $ct = 1; | ||||
|                     $cmpl = ($c->completed > 0)?1:0; | ||||
|                 } | ||||
|  |  | |||
|  | @ -78,8 +78,7 @@ class courseinfo { | |||
|         global $USER, $DB; | ||||
|         if ($userid <= 0) { | ||||
|             $usr = $USER; | ||||
|         } | ||||
|         else | ||||
|         } else | ||||
|         { | ||||
|             $usr = $DB->get_record('user', ['id' => $userid, 'deleted' => 0]); | ||||
|         } | ||||
|  | @ -124,8 +123,7 @@ class courseinfo { | |||
|             else { | ||||
|                 return "present"; | ||||
|             } | ||||
|         } | ||||
|         else{ | ||||
|         } else{ | ||||
|             return "future"; | ||||
|         } | ||||
|     } | ||||
|  | @ -231,8 +229,7 @@ class courseinfo { | |||
|             foreach ($gradables as $gradable) { | ||||
|                 $info['grades'][] = $gradable->editor_model($studyitem); | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             $cc = new corecompletioninfo($this->course); | ||||
|             $info['completion'] = $cc->editor_model(); | ||||
|         } | ||||
|  | @ -280,8 +277,7 @@ class courseinfo { | |||
|             foreach ($gradables as $gi) { | ||||
|                 $info['grades'][] = $gi->user_model($userid); | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             $cc = new corecompletioninfo($this->course); | ||||
|             $info['completion'] = $cc->user_model($userid); | ||||
|         } | ||||
|  |  | |||
|  | @ -98,7 +98,7 @@ class gradeinfo { | |||
|     public static function getCourseContextById($id) { | ||||
|         $gi = grade_item::fetch(["id" => $id]); | ||||
|         if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) { | ||||
|             throw new \InvalidArgumentException ("Grade {$id} not found in database". print_r($gi, true)); | ||||
|             throw new \InvalidArgumentException ("Grade {$id} not found in database"); | ||||
|         } | ||||
|         return \context_course::instance($gi->courseid);; | ||||
|     } | ||||
|  | @ -109,7 +109,7 @@ class gradeinfo { | |||
| 
 | ||||
|         $gi = grade_item::fetch(["id" => $id]); | ||||
|         if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) { | ||||
|             throw new \InvalidArgumentException ("Grade {$id} not found in database". print_r($gi, true)); | ||||
|             throw new \InvalidArgumentException ("Grade {$id} not found in database"); | ||||
|         } | ||||
|         $this->id = $id; | ||||
|         $this->gradeitem = $gi; | ||||
|  | @ -124,8 +124,7 @@ class gradeinfo { | |||
|             $this->cmid = 0; | ||||
|             $this->section = 0; | ||||
|             $this->sectionorder = 0; | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             list($c, $cminfo) = get_course_and_cm_from_instance($gi->iteminstance, $gi->itemmodule); | ||||
|             $this->cmid = $cminfo->id; | ||||
|             // sort by position in course.
 | ||||
|  | @ -137,11 +136,9 @@ class gradeinfo { | |||
|             $this->link = "/mod/{$gi->itemmodule}/view.php?id={$cminfo->id}"; | ||||
|             if ($gi->itemmodule == 'quiz') { | ||||
|                 $this->gradinglink = "/mod/{$gi->itemmodule}/report.php?id={$cminfo->id}&mode=grading"; | ||||
|             } | ||||
|             else if ($gi->itemmodule == "assign") { | ||||
|             } else if ($gi->itemmodule == "assign") { | ||||
|                 $this->gradinglink = $this->link ."&action=grading"; | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 $this->gradinglink = $this->link; | ||||
|             } | ||||
|         } | ||||
|  | @ -246,16 +243,13 @@ class gradeinfo { | |||
|         if (!empty($grade)) { | ||||
|             if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) { | ||||
|                 $finalgrade = "-"; | ||||
|             } | ||||
|             else if (isset($this->scale)) { | ||||
|             } else if (isset($this->scale)) { | ||||
|                 $finalgrade = $this->scale->get_nearest_item($grade->finalgrade); | ||||
|             } | ||||
|             else | ||||
|             } else | ||||
|             { | ||||
|                 $finalgrade = round($grade->finalgrade, 1); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         } else | ||||
|         { | ||||
|             $finalgrade = "-"; | ||||
|         } | ||||
|  |  | |||
|  | @ -74,8 +74,7 @@ class gradingscanner | |||
|         if (!array_key_exists($userid, $this->pending_cache)) { | ||||
|             if ($this->scanner === null) { | ||||
|                 $this->pending_cache[$userid] = false; | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 $this->pending_cache[$userid] = $this->scanner->has_ungraded_submission($userid);; | ||||
|             } | ||||
|         } | ||||
|  | @ -107,8 +106,7 @@ class gradingscanner | |||
|                 $grade = $this->gi->get_final($userid); | ||||
|                 if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) { | ||||
|                     //skip.
 | ||||
|                 } | ||||
|                 else | ||||
|                 } else | ||||
|                 { | ||||
|                     //compare grade to minimum grade.
 | ||||
|                     if ($this->grade_passed($grade)) { | ||||
|  | @ -139,11 +137,9 @@ class gradingscanner | |||
|         $scale = $this->gi->load_scale(); | ||||
|         if ( isset($scale)) { | ||||
|             $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); | ||||
|         } | ||||
|         else if ($this->gi->grademin == 0) { | ||||
|         } else if ($this->gi->grademin == 0) { | ||||
|             $gradecfg = $DB->get_record($table, ["grade_points"=>$this->gi->grademax]); | ||||
|         } | ||||
|         else | ||||
|         } else | ||||
|         { | ||||
|             $gradecfg = null; | ||||
|         } | ||||
|  | @ -155,22 +151,18 @@ class gradingscanner | |||
|             // if so, we need to know if the grade is .
 | ||||
|             if ($finalgrade >= $gradecfg->min_completed) { | ||||
|                 return true; | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         else if ($this->gi->gradepass > 0) { | ||||
|         } 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 ($finalgrade >= $this->gi->gradepass) { | ||||
|                 return true; | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } 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.
 | ||||
|  | @ -180,8 +172,7 @@ class gradingscanner | |||
| 
 | ||||
|             if ($score > 0.55) { | ||||
|                 return true; | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|  |  | |||
|  | @ -142,17 +142,13 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { | |||
|         } | ||||
|         if ($fraction_completed >= $this->thresh_excellent && $allrequiredmet) { | ||||
|             return completion::EXCELLENT; | ||||
|         } | ||||
|         else if ($fraction_completed >= $this->thresh_good && $allrequiredmet) { | ||||
|         } else if ($fraction_completed >= $this->thresh_good && $allrequiredmet) { | ||||
|             return completion::GOOD; | ||||
|         } | ||||
|         else if ($fraction_completed >= $this->thresh_completed && $allrequiredmet) { | ||||
|         } else if ($fraction_completed >= $this->thresh_completed && $allrequiredmet) { | ||||
|             return completion::COMPLETED; | ||||
|         } | ||||
|         else if ($started == 0) { | ||||
|         } else if ($started == 0) { | ||||
|             return completion::INCOMPLETE; | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return completion::PROGRESS; | ||||
|         } | ||||
|     } | ||||
|  | @ -199,20 +195,15 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { | |||
| 
 | ||||
|         if ( $total == $statecount[completion::EXCELLENT]) { | ||||
|             return completion::EXCELLENT; | ||||
|         } | ||||
|         else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD]) { | ||||
|         } else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD]) { | ||||
|             return completion::GOOD; | ||||
|         } | ||||
|         else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD] + $statecount[completion::COMPLETED]) { | ||||
|         } else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD] + $statecount[completion::COMPLETED]) { | ||||
|             return completion::COMPLETED; | ||||
|         } | ||||
|         else if (    $statecount[completion::FAILED]) { | ||||
|         } else if (    $statecount[completion::FAILED]) { | ||||
|             return completion::FAILED; | ||||
|         } | ||||
|         else if ( $total == $statecount[completion::INCOMPLETE]) { | ||||
|         } else if ( $total == $statecount[completion::INCOMPLETE]) { | ||||
|             return completion::INCOMPLETE; | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return completion::PROGRESS; | ||||
|         } | ||||
|     } | ||||
|  | @ -227,8 +218,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { | |||
| 
 | ||||
|         if (empty($grade)) { | ||||
|             return completion::INCOMPLETE; | ||||
|         } | ||||
|         else if ($grade->finalgrade === NULL) { | ||||
|         } 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.
 | ||||
|             // Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
 | ||||
|  | @ -240,19 +230,16 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { | |||
|             } else { | ||||
|                 return completion::INCOMPLETE; | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             $grade = $gradeitem->get_final($userid); | ||||
|             // first determine if we have a grade_config for this scale or this maximum grade.
 | ||||
|             $finalgrade = $grade->finalgrade; | ||||
|             $scale = $gradeinfo->getScale(); | ||||
|             if ( isset($scale)) { | ||||
|                 $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); | ||||
|             } | ||||
|             else if ($gradeitem->grademin == 0) { | ||||
|             } else if ($gradeitem->grademin == 0) { | ||||
|                 $gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]); | ||||
|             } | ||||
|             else | ||||
|             } else | ||||
|             { | ||||
|                 $gradecfg = null; | ||||
|             } | ||||
|  | @ -265,30 +252,24 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { | |||
|                 if ($finalgrade >= $gradecfg->min_completed) { | ||||
|                     // return completed if completed.
 | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|                 else if ($this->use_failed && $coursefinished) { | ||||
|                 } else if ($this->use_failed && $coursefinished) { | ||||
|                     // return failed if failed is enabled and the grade is less than the minimum grade for progress.
 | ||||
|                     return completion::FAILED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return completion::PROGRESS; | ||||
|                 } | ||||
|             } | ||||
|             else if ($gradeitem->gradepass > 0) { | ||||
|             } 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 ($finalgrade >= $gradeitem->gradepass) { | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|                 else if ($this->use_failed && $coursefinished) { | ||||
|                 } 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 completion::FAILED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return completion::PROGRESS; | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|             } 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.
 | ||||
|  | @ -298,12 +279,10 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { | |||
| 
 | ||||
|                 if ($score > 0.55) { | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|                 else if ($this->use_failed && $coursefinished) { | ||||
|                 } 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 completion::FAILED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return completion::PROGRESS; | ||||
|                 } | ||||
|             } | ||||
|  |  | |||
|  | @ -113,8 +113,7 @@ class core_aggregator extends \local_treestudyplan\aggregator { | |||
|                 // Not met and time is passed, means FAILED.
 | ||||
|                 if ($timing == "past") { | ||||
|                     return completion::FAILED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     // Check if any of the requirements are being met?.
 | ||||
|                     $completions = $completion->get_completions($userid); | ||||
|                     foreach ($completions as $c) { | ||||
|  | @ -126,8 +125,7 @@ class core_aggregator extends \local_treestudyplan\aggregator { | |||
|                     return completion::INCOMPLETE; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         else{ | ||||
|         } else{ | ||||
|             return completion::INCOMPLETE; | ||||
|         } | ||||
|     } | ||||
|  | @ -148,20 +146,15 @@ class core_aggregator extends \local_treestudyplan\aggregator { | |||
| 
 | ||||
|         if ( $total == $statecount[completion::EXCELLENT]) { | ||||
|             return completion::EXCELLENT; | ||||
|         } | ||||
|         else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD]) { | ||||
|         } else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD]) { | ||||
|             return completion::GOOD; | ||||
|         } | ||||
|         else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD] + $statecount[completion::COMPLETED]) { | ||||
|         } else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD] + $statecount[completion::COMPLETED]) { | ||||
|             return completion::COMPLETED; | ||||
|         } | ||||
|         else if (    $statecount[completion::FAILED]) { | ||||
|         } else if (    $statecount[completion::FAILED]) { | ||||
|             return completion::FAILED; | ||||
|         } | ||||
|         else if ( $total == $statecount[completion::INCOMPLETE]) { | ||||
|         } else if ( $total == $statecount[completion::INCOMPLETE]) { | ||||
|             return completion::INCOMPLETE; | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return completion::PROGRESS; | ||||
|         } | ||||
|     } | ||||
|  | @ -178,8 +171,7 @@ class core_aggregator extends \local_treestudyplan\aggregator { | |||
| 
 | ||||
|         if (empty($grade)) { | ||||
|             return completion::INCOMPLETE; | ||||
|         } | ||||
|         else if ($grade->finalgrade === NULL) { | ||||
|         } 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.
 | ||||
|             // Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
 | ||||
|  | @ -191,19 +183,16 @@ class core_aggregator extends \local_treestudyplan\aggregator { | |||
|             } else { | ||||
|                 return completion::INCOMPLETE; | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             $grade = $gradeitem->get_final($userid); | ||||
|             // first determine if we have a grade_config for this scale or this maximum grade.
 | ||||
|             $finalgrade = $grade->finalgrade; | ||||
|             $scale = $gradeinfo->getScale(); | ||||
|             if ( isset($scale)) { | ||||
|                 $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); | ||||
|             } | ||||
|             else if ($gradeitem->grademin == 0) { | ||||
|             } else if ($gradeitem->grademin == 0) { | ||||
|                 $gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]); | ||||
|             } | ||||
|             else | ||||
|             } else | ||||
|             { | ||||
|                 $gradecfg = null; | ||||
|             } | ||||
|  | @ -216,30 +205,24 @@ class core_aggregator extends \local_treestudyplan\aggregator { | |||
|                 if ($finalgrade >= $gradecfg->min_completed) { | ||||
|                     // return completed if completed.
 | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|                 else if ($this->use_failed && $finalgrade < $gradecfg->min_progress) { | ||||
|                 } 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 completion::FAILED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return completion::PROGRESS; | ||||
|                 } | ||||
|             } | ||||
|             else if ($gradeitem->gradepass > 0) { | ||||
|             } 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 ($finalgrade >= $gradeitem->gradepass) { | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|                 else if ($this->use_failed && $gradeitem->gradepass >= 3  && $range >= 3 && $finalgrade == 1) { | ||||
|                 } 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 completion::FAILED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return completion::PROGRESS; | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|             } 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.
 | ||||
|  | @ -249,12 +232,10 @@ class core_aggregator extends \local_treestudyplan\aggregator { | |||
| 
 | ||||
|                 if ($score > 0.55) { | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|                 else if ($this->use_failed && $range >= 3 && $finalgrade == 1) { | ||||
|                 } 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 completion::FAILED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return completion::PROGRESS; | ||||
|                 } | ||||
|             } | ||||
|  |  | |||
|  | @ -71,20 +71,16 @@ class tristate_aggregator extends \local_treestudyplan\aggregator { | |||
|                     // state PROGRESS will not carry on if aggregations are chained.
 | ||||
|                     if ($c_progress > 0) { | ||||
|                         return completion::PROGRESS; | ||||
|                     } | ||||
|                     else if ($c_pending > 0) { | ||||
|                     } else if ($c_pending > 0) { | ||||
|                         return completion::PENDING; | ||||
|                     } | ||||
|                     else { | ||||
|                     } else { | ||||
|                         return completion::INCOMPLETE; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 return completion::INCOMPLETE; | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         } else | ||||
|         { | ||||
|             // indeterminable, return null.
 | ||||
|             return null; | ||||
|  | @ -117,8 +113,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator { | |||
| 
 | ||||
|         if (empty($grade)) { | ||||
|             return completion::INCOMPLETE; | ||||
|         } | ||||
|         else if ($grade->finalgrade === NULL) { | ||||
|         } 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.
 | ||||
|             // Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
 | ||||
|  | @ -131,8 +126,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator { | |||
|                 return completion::INCOMPLETE; | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             $finalgrade = $grade->finalgrade; | ||||
|             $scale = $gradeinfo->getScale(); | ||||
| 
 | ||||
|  | @ -141,15 +135,12 @@ class tristate_aggregator extends \local_treestudyplan\aggregator { | |||
|                 if ($gradeitem->grademax > $gradeitem->gradepass && $finalgrade >= $gradeitem->grademax) { | ||||
|                     // If gradepass is configured .
 | ||||
|                     return completion::EXCELLENT; | ||||
|                 } | ||||
|                 else if ($finalgrade >= $gradeitem->gradepass) { | ||||
|                 } else if ($finalgrade >= $gradeitem->gradepass) { | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return completion::PROGRESS; | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 // Blind assumptions:.
 | ||||
|                 // over 55% of range is completed.
 | ||||
|                 // over 85% of range is excellent.
 | ||||
|  | @ -159,11 +150,9 @@ class tristate_aggregator extends \local_treestudyplan\aggregator { | |||
| 
 | ||||
|                 if ($score > 0.85) { | ||||
|                     return completion::EXCELLENT; | ||||
|                 } | ||||
|                 else if ($score > 0.55) { | ||||
|                 } else if ($score > 0.55) { | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|                 else { | ||||
|                 } else { | ||||
|                     return completion::PROGRESS; | ||||
|                 } | ||||
|             } | ||||
|  |  | |||
|  | @ -182,11 +182,9 @@ class gradegenerator { | |||
|             $scale = $gi->load_scale(); | ||||
|             if ( isset($scale)) { | ||||
|                 $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); | ||||
|             } | ||||
|             else if ($gi->grademin == 0) { | ||||
|             } else if ($gi->grademin == 0) { | ||||
|                 $gradecfg = $DB->get_record($table, ["grade_points"=>$gi->grademax]); | ||||
|             } | ||||
|             else | ||||
|             } else | ||||
|             { | ||||
|                 $gradecfg = null; | ||||
|             } | ||||
|  | @ -198,12 +196,10 @@ class gradegenerator { | |||
|                     // 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";.
 | ||||
|                     $r = (object)["gi" => $g, "grade" => $grade, "fb" =>"" ]; | ||||
|                 } | ||||
|                 else if (!$gr->result) { | ||||
|                 } else if (!$gr->result) { | ||||
|                     $grade =  rand($gradecfg->min_progress, $gradecfg->min_completed -1 ); | ||||
|                     $r = (object)["gi" => $g, "grade" => $grade, "fb" =>$gr->fb ]; | ||||
|                 } | ||||
|                 else{ | ||||
|                 } else{ | ||||
|                     // COMPLETED.
 | ||||
|                     $r = (object)["gi" => $g, "grade" => rand( $gradecfg->min_completed, $gi->grademax ), "fb" =>$gr->fb ]; | ||||
|                 } | ||||
|  | @ -218,25 +214,21 @@ class gradegenerator { | |||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|             } | ||||
|             else if ($gi->gradepass > 0) { | ||||
|             } else if ($gi->gradepass > 0) { | ||||
|                 if (!$gr->done) { | ||||
|                     // INCOMPLETe or FAILED.
 | ||||
|                     $grade =  rand(0, $gi->gradepass/2); | ||||
|                     $r = (object)["gi" => $g, "grade" => $grade, "fb" =>($grade > 0)?$gr->fb:"" ]; | ||||
|                 } | ||||
|                 else if (!$gr->result) { | ||||
|                 } else if (!$gr->result) { | ||||
|                     //PROGRESS.
 | ||||
|                     $r = (object)["gi" => $g, "grade" => rand( round($gi->gradepass/2), $gi->gradepass -1 ), "fb" =>$gr->fb ]; | ||||
|                 } | ||||
|                 else{ | ||||
|                 } else{ | ||||
|                     // COMPLETED.
 | ||||
|                     $r = (object)["gi" => $g, "grade" => rand(  $gi->gradepass, $gi->grademax ), "fb" =>$gr->fb ]; | ||||
|                 } | ||||
| 
 | ||||
|                 $r->gradetext = $r->grade; | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 // Blind assumptions if nothing is provided.
 | ||||
|                 // over 55% of range is completed.
 | ||||
|                 // under 35% is not done.
 | ||||
|  | @ -246,12 +238,10 @@ class gradegenerator { | |||
|                     // INCOMPLETe or FAILED.
 | ||||
|                     $grade =  rand(0, round($range * 0.35) - 1); | ||||
|                     $r = (object)["gi" => $g, "grade" =>  $gi->grademin+$grade, "fb" =>($grade > 0)?$gr->fb:"" ]; | ||||
|                 } | ||||
|                 else if (!$gr->result) { | ||||
|                 } 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{ | ||||
|                 } else{ | ||||
|                     // COMPLETED.
 | ||||
|                     $r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.55) , $range  ), "fb" =>$gr->fb ]; | ||||
|                 } | ||||
|  | @ -287,7 +277,7 @@ class gradegenerator { | |||
|     public function fromFile(string $filename) { | ||||
|         $filename = self::expand_tilde($filename); | ||||
|         if (file_exists($filename)) { | ||||
|             try{ | ||||
|             try { | ||||
|                 $json = file_get_contents($filename); | ||||
|                 $this->unserialize($json); | ||||
|             } catch(Exception $x) { | ||||
|  |  | |||
|  | @ -46,7 +46,8 @@ class debugger { | |||
|         if (strlen($tag) > 0) { | ||||
|             $tag .= ":\n"; | ||||
|         } | ||||
|         $this->writeblock($tag.print_r($object, true)); | ||||
|         $o = json_encode($object); | ||||
|         $this->writeblock($tag.": ".$o); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|  | @ -65,6 +66,4 @@ class debugger { | |||
|             fclose($fp); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -51,8 +51,7 @@ class webservicehelper { | |||
|                     return true; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         else if (has_capability($capability, $context)) { | ||||
|         } else if (has_capability($capability, $context)) { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
|  | @ -122,7 +121,7 @@ class webservicehelper { | |||
|         if (isset($contextid) && is_int($contextid) && $contextid > 0) { | ||||
| 
 | ||||
|             if (!in_array($contextid, self::$validated_contexts)) { // Cache the context and make sure it is only validated once...
 | ||||
|                 try{ | ||||
|                 try { | ||||
|                     $context = \context::instance_by_id($contextid); | ||||
|                 } | ||||
|                 catch(\dml_missing_record_exception $x) { | ||||
|  | @ -133,8 +132,7 @@ class webservicehelper { | |||
|                 self::$validated_contexts[$contextid] = $context; | ||||
|             } | ||||
|             return self::$validated_contexts[$contextid]; | ||||
|         } | ||||
|         else{ | ||||
|         } else{ | ||||
|             return static::system_context(); // This function ensures the system context is validated just once this call.
 | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -55,7 +55,7 @@ class period { | |||
|             // Clamp period index .
 | ||||
|             $periodnr = 1; | ||||
|         } | ||||
|         try{ | ||||
|         try { | ||||
|             $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) { | ||||
|  | @ -70,7 +70,7 @@ class period { | |||
|             $ydelta = $yend - $ystart; | ||||
|             $ptime = $ydelta / $pcount; | ||||
| 
 | ||||
|             try{ | ||||
|             try { | ||||
|                  // Check if we have a previous period to glance the end date of as a reference.
 | ||||
|                 $startdate = $DB->get_field(self::TABLE, "enddate", ["page_id"=>$page->id(), "period" => $periodnr-1], MUST_EXIST); | ||||
|                 $pstart = strtotime($startdate)+(24*60*60); // Add one day.
 | ||||
|  | @ -78,7 +78,7 @@ class period { | |||
|                 // If not, do a fair guess.
 | ||||
|                 $pstart = $ystart + (($periodnr-1)*$ptime); | ||||
|             } | ||||
|             try{ | ||||
|             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.
 | ||||
|  | @ -152,8 +152,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")); | ||||
|         } | ||||
|  |  | |||
|  | @ -125,8 +125,7 @@ class studentstudyplanservice extends \external_api | |||
| 
 | ||||
|         if ($studyplan->has_linked_user($userid)) { | ||||
|             return $studyplan->user_model($userid); | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return null; | ||||
|         } | ||||
|     } | ||||
|  | @ -239,8 +238,7 @@ class studentstudyplanservice extends \external_api | |||
|             } else { | ||||
|                 return []; | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             $map = []; | ||||
|             foreach ($studyplans as $studyplan) { | ||||
|                 $map[] = $studyplan->user_model($userid); | ||||
|  | @ -283,8 +281,7 @@ class studentstudyplanservice extends \external_api | |||
|             } else { | ||||
|                 return []; | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             $map = []; | ||||
|             foreach ($studyplans as $studyplan) { | ||||
|                 $map[] = $studyplan->editor_model($userid); | ||||
|  |  | |||
|  | @ -193,8 +193,7 @@ class studyitem { | |||
|             foreach ($conn_out as $c) { | ||||
|                 $model["connections"][] = $c->to_id(); | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             foreach ($conn_out as $c) { | ||||
|                 $model['connections']['out'][$c->to_id()] = $c->model(); | ||||
|             } | ||||
|  | @ -247,11 +246,9 @@ class studyitem { | |||
|         // Check if referenced courses, badges and/or competencies still exist.
 | ||||
|         if ($this->r->type == static::COURSE) { | ||||
|             return courseinfo::exists($this->r->course_id); | ||||
|         } | ||||
|         else if ($this->r->type == static::BADGE) { | ||||
|         } else if ($this->r->type == static::BADGE) { | ||||
|             return badgeinfo::exists($this->r->badge_id); | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
|  | @ -271,8 +268,7 @@ 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 | ||||
|         } else | ||||
|         { | ||||
|             // delete al related connections to this item.
 | ||||
|             studyitemconnection::clear($this->id); | ||||
|  | @ -424,8 +420,7 @@ class studyitem { | |||
|                 // determine competency by competency completion.
 | ||||
|                 $courseinfo = $this->getcourseinfo(); | ||||
|                 return $this->aggregator->aggregate_course($courseinfo, $this, $userid); | ||||
|             } | ||||
|             else if (strtolower($this->r->type) =='start') { | ||||
|             } else if (strtolower($this->r->type) =='start') { | ||||
|                 // Does not need to use aggregator.
 | ||||
|                 // Either true, or the completion of the reference.
 | ||||
|                 if (self::exists($this->r->continuation_id)) { | ||||
|  | @ -434,8 +429,7 @@ class studyitem { | |||
|                 } else { | ||||
|                     return completion::COMPLETED; | ||||
|                 } | ||||
|             } | ||||
|             else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) { | ||||
|             } else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) { | ||||
|                 // completion of the linked items, according to the rule.
 | ||||
|                 $in_completed = []; | ||||
|                 // Retrieve incoming connections.
 | ||||
|  | @ -445,8 +439,7 @@ class studyitem { | |||
|                     $in_completed[] = $item->completion($userid); | ||||
|                 } | ||||
|                 return $this->aggregator->aggregate_junction($in_completed, $this, $userid); | ||||
|             } | ||||
|             else if (strtolower($this->r->type) =='badge') { | ||||
|             } else if (strtolower($this->r->type) =='badge') { | ||||
|                 global $DB; | ||||
|                 // badge awarded.
 | ||||
|                 if (badgeinfo::exists($this->r->badge_id)) { | ||||
|  | @ -464,8 +457,7 @@ class studyitem { | |||
|                                 } | ||||
|                             } | ||||
|                             return ($notexpired)?completion::COMPLETED:completion::INCOMPLETE; | ||||
|                         } | ||||
|                         else{ | ||||
|                         } else{ | ||||
|                             return completion::COMPLETED; | ||||
|                         } | ||||
|                     } else { | ||||
|  | @ -474,13 +466,11 @@ class studyitem { | |||
|                 } else { | ||||
|                     return completion::INCOMPLETE; | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 // return incomplete for other types.
 | ||||
|                 return completion::INCOMPLETE; | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             // return incomplete for other types.
 | ||||
|             return completion::INCOMPLETE; | ||||
|         } | ||||
|  |  | |||
|  | @ -162,8 +162,7 @@ class studyline { | |||
|                     } else if (in_array($c->type(), self::FILTER_TYPES)) { | ||||
|                         $slotset = self::SLOTSET_FILTER; | ||||
|                     } | ||||
|                 } | ||||
|                 else if (in_array($c->type(), self::FILTER0_TYPES)) { | ||||
|                 } else if (in_array($c->type(), self::FILTER0_TYPES)) { | ||||
|                     $slotset = self::SLOTSET_FILTER; | ||||
|                 } | ||||
|                 if (isset($slotset)) { | ||||
|  | @ -221,8 +220,7 @@ class studyline { | |||
|         // 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 | ||||
|         } else | ||||
|         { | ||||
|             $DB->delete_records(self::TABLE, ['id' => $this->id]); | ||||
|             return success::success(); | ||||
|  | @ -310,8 +308,7 @@ class studyline { | |||
|                     } else if (in_array($c->type(), self::FILTER_TYPES)) { | ||||
|                         $slotset = self::SLOTSET_FILTER; | ||||
|                     } | ||||
|                 } | ||||
|                 else if (in_array($c->type(), self::FILTER0_TYPES)) { | ||||
|                 } else if (in_array($c->type(), self::FILTER0_TYPES)) { | ||||
|                     $slotset = self::SLOTSET_FILTER; | ||||
|                 } | ||||
|                 if (isset($slotset)) { | ||||
|  |  | |||
|  | @ -85,7 +85,7 @@ class studyplan { | |||
|      */ | ||||
|     public function context(): \context{ | ||||
|         if (!isset($this->context)) { | ||||
|             try{ | ||||
|             try { | ||||
|                 $this->context = contextinfo::by_id($this->r->context_id)->context; | ||||
|             } | ||||
|             catch(\dml_missing_record_exception $x) { | ||||
|  | @ -290,8 +290,7 @@ class studyplan { | |||
| 
 | ||||
|         if ($DB->count_records('local_treestudyplan_page', ['studyplan_id' => $this->id]) > 0) { | ||||
|             return success::fail('cannot delete studyplan that still has pages'); | ||||
|         } | ||||
|         else | ||||
|         } else | ||||
|         { | ||||
|             $DB->delete_records('local_treestudyplan', ['id' => $this->id]); | ||||
|             return success::success(); | ||||
|  | @ -304,8 +303,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"; | ||||
|  | @ -557,8 +555,7 @@ class studyplan { | |||
|             // Now import each page.
 | ||||
|             return $plan->import_pages_model($content["studyplan"]["pages"]); | ||||
| 
 | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             error_log("Invalid format and type: {$content['type']} version {$content['version']}"); | ||||
|             return false; | ||||
|         } | ||||
|  | @ -571,13 +568,11 @@ class studyplan { | |||
|             if ($content["type"] == "studyplanpage") { | ||||
|                 // import single page from a studyplanpage (wrapped in array of one page).
 | ||||
|                 return $this->import_pages_model([$content["page"]]); | ||||
|             } | ||||
|             else if ($content["type"] == "studyplan") { | ||||
|             } else if ($content["type"] == "studyplan") { | ||||
|                 // Import all pages from the studyplan.
 | ||||
|                 return $this->import_pages_model($content["studyplan"]["pages"]); | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -81,8 +81,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")); | ||||
|         } | ||||
|  | @ -207,8 +206,7 @@ class studyplanpage { | |||
| 
 | ||||
|         if ($DB->count_records('local_treestudyplan_line', ['page_id' => $this->id]) > 0) { | ||||
|             return success::fail('cannot delete studyplan page that still has studylines'); | ||||
|         } | ||||
|         else | ||||
|         } else | ||||
|         { | ||||
|             $DB->delete_records(self::TABLE, ['id' => $this->id]); | ||||
|             return success::success(); | ||||
|  | @ -368,8 +366,7 @@ class studyplanpage { | |||
|                                         if ($g["selected"]) { | ||||
|                                             if ($first) { | ||||
|                                                 $first = false; | ||||
|                                             } | ||||
|                                             else{ | ||||
|                                             } else{ | ||||
|                                                 $csv .= "\r\n"; | ||||
|                                             } | ||||
|                                             $csv .= "- ".str_replace('"', '\'', $g["name"]); | ||||
|  | @ -444,11 +441,9 @@ class studyplanpage { | |||
|         $content = json_decode($content, true); | ||||
|         if ($content["type"] == "periods" && $content["version"] >= 2.0) { | ||||
|             return $this->import_periods_model($content["perioddesc"]); | ||||
|         } | ||||
|         else if ($content["type"] == "studyplanpage" && $content["version"] >= 2.0) { | ||||
|         } else if ($content["type"] == "studyplanpage" && $content["version"] >= 2.0) { | ||||
|             return $this->import_periods_model($content["page"]["perioddesc"]); | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
|  | @ -458,14 +453,11 @@ class studyplanpage { | |||
|         $content = json_decode($content, true); | ||||
|         if ($content["type"] == "studylines" && $content["version"] >= 2.0) { | ||||
|             return $this->import_studylines_model($content["studylines"]); | ||||
|         } | ||||
|         else if ($content["type"] == "studyplanpage" && $content["version"] >= 2.0) { | ||||
|         } else if ($content["type"] == "studyplanpage" && $content["version"] >= 2.0) { | ||||
|             return $this->import_studylines_model($content["page"]["studylines"]); | ||||
|         } | ||||
|         else if ($content["type"] == "studyplan" && $content["version"] >= 2.0) { | ||||
|         } else if ($content["type"] == "studyplan" && $content["version"] >= 2.0) { | ||||
|             return $this->import_studylines_model($content["studyplan"]["pages"][0]["studylines"]); | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -91,8 +91,7 @@ class studyplanservice extends \external_api | |||
|             $studyplan = studyplan::findById($id); | ||||
|             webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $studyplan->context()); | ||||
|             return $studyplan->editor_model(); | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return null; | ||||
|         } | ||||
|     } | ||||
|  | @ -638,8 +637,7 @@ class studyplanservice extends \external_api | |||
|         if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($item_id)->context()) || | ||||
|            is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) { | ||||
|             return gradeinfo::include_grade($grade_id, $item_id, $include, $required)->model(); | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             return success::fail("Access denied")->model(); | ||||
|         } | ||||
| 
 | ||||
|  | @ -736,8 +734,7 @@ class studyplanservice extends \external_api | |||
|                                 $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.
 | ||||
|  | @ -756,8 +753,7 @@ class studyplanservice extends \external_api | |||
|                                     } | ||||
|                                 } | ||||
| 
 | ||||
|                             } | ||||
|                             else { | ||||
|                             } else { | ||||
|                                 $updated = "skipped"; | ||||
|                             } | ||||
| 
 | ||||
|  | @ -899,7 +895,7 @@ class studyplanservice extends \external_api | |||
|     } | ||||
| 
 | ||||
|     public static function export_plan($studyplan_id, $format="json") { | ||||
|         try{ | ||||
|         try { | ||||
|             // Validate permissions.
 | ||||
|             webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); | ||||
| 
 | ||||
|  | @ -907,8 +903,7 @@ 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(); | ||||
|             } | ||||
|         } | ||||
|  | @ -930,7 +925,7 @@ class studyplanservice extends \external_api | |||
|     public static function export_studylines($studyplan_id) { | ||||
|         $systemcontext = webservicehelper::system_context(); | ||||
| 
 | ||||
|         try{ | ||||
|         try { | ||||
|             webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); | ||||
|             $plan = studyplan::findById($studyplan_id); | ||||
|             // FIXME: Make sure this gets called for the page instead of the studyplan.
 | ||||
|  | @ -960,7 +955,7 @@ class studyplanservice extends \external_api | |||
| 
 | ||||
|     public static function import_plan($content, $format="application/json", $context_id=1) { | ||||
| 
 | ||||
|         try{ | ||||
|         try { | ||||
|             // Validate import context.
 | ||||
|             $context = webservicehelper::find_context($context_id); | ||||
|             webservicehelper::require_capabilities(self::CAP_EDIT, $context); | ||||
|  | @ -987,7 +982,7 @@ class studyplanservice extends \external_api | |||
| 
 | ||||
|     public static function import_studylines($studyplan_id, $content, $format="application/json") { | ||||
| 
 | ||||
|         try{ | ||||
|         try { | ||||
|             $plan = studyplan::findById($studyplan_id); | ||||
|             // Validate import context.
 | ||||
|             webservicehelper::require_capabilities(self::CAP_EDIT, $plan->context()); | ||||
|  | @ -1155,11 +1150,9 @@ class studyplanservice extends \external_api | |||
|             // Determine end period number - Clip span between 1 and last period.
 | ||||
|             if ($span <= 1) { | ||||
|                 $pend = $pstart; | ||||
|             } | ||||
|             else if ($periodnr + ($span - 1) > $page->periods()) { | ||||
|             } else if ($periodnr + ($span - 1) > $page->periods()) { | ||||
|                 $pend = $periods[$page->periods()]; | ||||
|             } | ||||
|             else { | ||||
|             } else { | ||||
|                 $pend = $periods[$periodnr + ($span - 1)]; | ||||
|             } | ||||
| 
 | ||||
|  |  | |||
|  | @ -60,7 +60,6 @@ if ($options['help']) { | |||
|     cli_writeln($usage); | ||||
|     exit(2); | ||||
| } | ||||
| //cli_writeln(print_r($options, true));.
 | ||||
| 
 | ||||
| if (empty($options['studyplan']) && empty($options["all"])) { | ||||
|     cli_error('Missing mandatory argument studyplan.', 2); | ||||
|  |  | |||
|  | @ -152,7 +152,6 @@ foreach ($plans as $plan) { | |||
|                                             $ug->feedbacktext = nl2br( htmlspecialchars($gg->fb)); | ||||
|                                             $ug->feedbackformat = FORMAT_HTML; | ||||
| 
 | ||||
|                                             //print_r($ug);.
 | ||||
|                                             if (!$options["dryrun"]) { | ||||
|                                                 $a->update_grade($ug); | ||||
| 
 | ||||
|  | @ -175,8 +174,7 @@ foreach ($plans as $plan) { | |||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     } else | ||||
|                     { | ||||
|                         cli_writeln("      Skipping since it has not started yet"); | ||||
|                     } | ||||
|  |  | |||
|  | @ -379,8 +379,7 @@ 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; | ||||
|  |  | |||
							
								
								
									
										3
									
								
								doc.php
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								doc.php
									
									
									
									
									
								
							|  | @ -47,8 +47,7 @@ if ( in_array($mime, $text_types)) { | |||
| 	print $OUTPUT->header(); | ||||
| 	print file_get_contents($file); | ||||
| 	print $OUTPUT->footer(); | ||||
| } | ||||
| else { | ||||
| } else { | ||||
| 	header("Content-type: {$mime}"); | ||||
| 	print file_get_contents($file); | ||||
| } | ||||
|  | @ -40,8 +40,7 @@ $PAGE->set_context($systemcontext); | |||
| if ($update > 0) { | ||||
| 	$PAGE->set_title(get_string('invite_desc_edit', 'local_treestudyplan')); | ||||
| 	$PAGE->set_heading(get_string('invite_desc_edit', 'local_treestudyplan')); | ||||
| } | ||||
| else | ||||
| } else | ||||
| { | ||||
| 	$PAGE->set_title(get_string('invite_desc_new', 'local_treestudyplan')); | ||||
| 	$PAGE->set_heading(get_string('invite_desc_new', 'local_treestudyplan')); | ||||
|  | @ -58,8 +57,7 @@ if (!empty($add)) { | |||
| 	 'add' => 1, | ||||
| 	); | ||||
| 
 | ||||
| } | ||||
| else if (!empty($update)) { | ||||
| } 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) | ||||
|  | @ -68,8 +66,7 @@ else if (!empty($update)) { | |||
| 		exit; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| else if (!empty($resend)) { | ||||
| } 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) | ||||
|  | @ -86,8 +83,7 @@ else if (!empty($resend)) { | |||
| 	redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$resend}"); | ||||
| 	print $OUTPUT->footer(); | ||||
| 	exit; | ||||
| } | ||||
| else if (!empty($delete)) { | ||||
| } 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) | ||||
|  | @ -101,8 +97,7 @@ else if (!empty($delete)) { | |||
| 	redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); | ||||
| 	print $OUTPUT->footer(); | ||||
| 	exit; | ||||
| } | ||||
| else { | ||||
| } else { | ||||
| 	print_error('invalidaction'); | ||||
| } | ||||
| 
 | ||||
|  | @ -111,8 +106,7 @@ $mform->set_data($data); | |||
| 
 | ||||
| if ($mform->is_cancelled()) { | ||||
| 	redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); | ||||
| } | ||||
| else if ($data = $mform->get_data()) { | ||||
| } else if ($data = $mform->get_data()) { | ||||
| 	if (!empty($data->update)) | ||||
| 	{ | ||||
| 		 | ||||
|  | @ -150,8 +144,7 @@ else if ($data = $mform->get_data()) { | |||
| 
 | ||||
| 	exit; | ||||
| 	 | ||||
| } | ||||
| else | ||||
| } else | ||||
| { | ||||
| 	$data = null; | ||||
| 	if ($unitid > 0) | ||||
|  |  | |||
|  | @ -37,8 +37,7 @@ $contextid = optional_param('contextid', 0, PARAM_INT); // Context id. | |||
| if ($categoryid > 0) { | ||||
| 	$studyplancontext = context_coursecat::instance($categoryid); | ||||
| 	 | ||||
| } | ||||
| else if ($contextid > 0) { | ||||
| } else if ($contextid > 0) { | ||||
| 	$studyplancontext = context::instance_by_id($contextid); | ||||
| 	if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) | ||||
| 	{ | ||||
|  | @ -48,8 +47,7 @@ else if ($contextid > 0) { | |||
| 	{ | ||||
| 		$studyplancontext = $systemcontext; | ||||
| 	} | ||||
| } | ||||
| else | ||||
| } else | ||||
| { | ||||
| 	// If no context is selected, find the first available one.
 | ||||
| 	$available_contexts = courseservice::list_accessible_categories_with_usage("edit"); | ||||
|  |  | |||
|  | @ -25,8 +25,7 @@ if (isset($_SERVER['SCRIPT_FILENAME'])) { | |||
| 	$root = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))); | ||||
| 	error_log("Using {$root}/config.php"); | ||||
| 	require_once($root."/config.php"); | ||||
| } | ||||
| else | ||||
| } else | ||||
| { | ||||
| 	// If not, assume the cwd is not symlinked and proceed as we are used to.
 | ||||
| 	require_once("../../config.php"); | ||||
|  | @ -105,8 +104,7 @@ if (count($invites) > 0) { | |||
| 
 | ||||
| 		print "</td>"; | ||||
| 	} | ||||
| } | ||||
| else | ||||
| } else | ||||
| { | ||||
| 	print "<tr><td colspan='6'>".get_string('invite_table_empty', 'local_treestudyplan')."</td></tr>"; | ||||
| } | ||||
|  |  | |||
|  | @ -54,8 +54,7 @@ if (empty($invite)) { | |||
| 	print $OUTPUT->footer(); | ||||
| 
 | ||||
| 	exit; | ||||
| } | ||||
| else | ||||
| } else | ||||
| { | ||||
| 	// Load javascripts and specific css.
 | ||||
| 	$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css')); | ||||
|  |  | |||
							
								
								
									
										3
									
								
								lib.php
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								lib.php
									
									
									
									
									
								
							|  | @ -292,8 +292,7 @@ function local_treestudyplan_get_cohort_path($cohort) { | |||
|         $ctxpath[] = $cohort->name; | ||||
| 
 | ||||
|         return implode(" / ", $ctxpath); | ||||
|     } | ||||
|     else | ||||
|     } else | ||||
|     { | ||||
|         return $cohort->name; | ||||
|     } | ||||
|  |  | |||
|  | @ -37,8 +37,7 @@ $contextid = optional_param('contextid', 0, PARAM_INT); // Context id. | |||
| if ($categoryid > 0) { | ||||
| 	$studyplancontext = context_coursecat::instance($categoryid); | ||||
| 	 | ||||
| } | ||||
| else if ($contextid > 0) { | ||||
| } else if ($contextid > 0) { | ||||
| 	$studyplancontext = context::instance_by_id($contextid); | ||||
| 	if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) | ||||
| 	{ | ||||
|  | @ -48,8 +47,7 @@ else if ($contextid > 0) { | |||
| 	{ | ||||
| 		$studyplancontext = $systemcontext; | ||||
| 	} | ||||
| } | ||||
| else | ||||
| } else | ||||
| { | ||||
| 	// If no context is selected, find the first available one.
 | ||||
| 	$available_contexts = courseservice::list_accessible_categories_with_usage("view"); | ||||
|  |  | |||
		Reference in a new issue
	
	 PMKuipers
						PMKuipers