From 8dc2b92d667f1401ab9f1315a36add61658f899c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 6 May 2021 10:26:09 +0200 Subject: Moderize Database handling * Auto-convert to utf8mb4_unicode_520_ci * Use foreach instead of while to loop over results * Drop useless statement caching * Keep emulated prepares, as we sometimes loop over nested queries --- modules-available/exams/page.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules-available/exams/page.inc.php') diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 868f5927..317e56c0 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; } } @@ -111,7 +111,7 @@ 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; } -- cgit v1.2.3-55-g7522