diff options
Diffstat (limited to 'modules-available/exams/page.inc.php')
-rw-r--r-- | modules-available/exams/page.inc.php | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 868f5927..d229b883 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -23,7 +23,7 @@ class Page_Exams extends Page } else { $tmp = Database::simpleQuery("SELECT locationid FROM exams_x_location WHERE examid= :examid", array('examid' => $examidOrLocations)); $active = array(); - while ($row = $tmp->fetch(PDO::FETCH_ASSOC)) { + foreach ($tmp as $row) { $active[] = (int)$row['locationid']; } } @@ -40,7 +40,7 @@ class Page_Exams extends Page . "GROUP BY examid " . "ORDER BY examid ASC"); - while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) { + foreach ($tmp as $exam) { $view = $edit = false; // User has permission for all locations if (in_array(0, $this->userViewLocations)) { @@ -87,7 +87,7 @@ class Page_Exams extends Page "GROUP BY lectureid " . "ORDER BY starttime ASC, displayname ASC", ['rangeMax' => $this->rangeMax, 'rangeMin' => $this->rangeMin]); - while ($lecture = $tmp->fetch(PDO::FETCH_ASSOC)) { + foreach ($tmp as $lecture) { $this->lectures[] = $lecture; } } @@ -103,7 +103,7 @@ class Page_Exams extends Page } // returns true if user is allowed to edit the exam - protected function userCanEditExam($examid = NULL) + protected function userCanEditExam(string $examid = NULL): bool { if (in_array(0, $this->userEditLocations)) // Trivial case -- don't query if global perms return true; @@ -111,16 +111,19 @@ class Page_Exams extends Page return User::hasPermission('exams.edit'); // Check locations of existing exam $res = Database::simpleQuery("SELECT locationid FROM exams_x_location WHERE examid= :examid", array('examid' => $examid)); - while ($locId = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $locId) { if (!in_array($locId['locationid'], $this->userEditLocations)) return false; } return true; } - // checks if user is allowed to save an exam with all the locations - // needs information if it's add (second para = true) or edit (second para = false) - protected function userCanEditLocation($locationids) { + /** + * checks if user is allowed to save an exam with all the locations + * needs information if it's add (second para = true) or edit (second para = false) + */ + protected function userCanEditLocation(array $locationids): bool + { return empty(array_diff($locationids, $this->userEditLocations)); } @@ -213,7 +216,10 @@ class Page_Exams extends Page return json_encode($out); } - protected function makeExamsForTemplate() + /** + * @return array{exams: array, decollapse: bool} + */ + protected function makeExamsForTemplate(): array { $out = []; $now = time(); @@ -248,7 +254,7 @@ class Page_Exams extends Page return ['exams' => $out, 'decollapse' => $hasCollapsed]; } - protected function makeLectureExamList() + protected function makeLectureExamList(): array { $out = []; $now = time(); @@ -288,7 +294,7 @@ class Page_Exams extends Page ] + $source; } - private function isDateSane($time) + private function isDateSane(int $time): bool { return ($time >= strtotime('-10 years') && $time <= strtotime('+10 years')); } @@ -296,7 +302,7 @@ class Page_Exams extends Page private function saveExam() { if (!Request::isPost()) { - Util::traceError('Is not post'); + ErrorHandler::traceError('Is not post'); } /* process form-data */ $locationids = Request::post('locations', [], "ARRAY"); @@ -453,7 +459,7 @@ class Page_Exams extends Page } elseif ($this->action === false) { - Util::traceError("action not implemented"); + ErrorHandler::traceError("action not implemented"); } } |