summaryrefslogtreecommitdiffstats
path: root/modules-available/exams
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/exams')
-rw-r--r--modules-available/exams/baseconfig/getconfig.inc.php17
-rw-r--r--modules-available/exams/inc/exams.inc.php9
-rw-r--r--modules-available/exams/page.inc.php32
3 files changed, 31 insertions, 27 deletions
diff --git a/modules-available/exams/baseconfig/getconfig.inc.php b/modules-available/exams/baseconfig/getconfig.inc.php
index 120bdbff..7e4a70df 100644
--- a/modules-available/exams/baseconfig/getconfig.inc.php
+++ b/modules-available/exams/baseconfig/getconfig.inc.php
@@ -1,24 +1,27 @@
<?php
-$foofoo = function($machineUuid) {
+/** @var ?string $uuid */
+/** @var ?string $ip */
+
+if ($uuid !== null) {
// Leave clients in any runmode alone
$res = Database::queryFirst('SELECT machineuuid FROM runmode WHERE machineuuid = :uuid',
- array('uuid' => $machineUuid), true);
+ array('uuid' => $uuid), true);
if (is_array($res))
return;
// Check if exam mode should apply
$locations = ConfigHolder::get('SLX_LOCATIONS');
- if ($locations === false) {
+ if ($locations === null) {
$locationIds = [];
} else {
$locationIds = explode(' ', $locations);
}
if (Exams::isInExamMode($locationIds, $lectureId, $autoLogin)) {
ConfigHolder::add('SLX_EXAM', 'yes', 10000);
- if (strlen($lectureId) > 0) {
+ if (!empty($lectureId)) {
ConfigHolder::add('SLX_EXAM_START', $lectureId, 10000);
}
- if (strlen($autoLogin) > 0) {
+ if (!empty($autoLogin)) {
ConfigHolder::add('SLX_AUTOLOGIN', $autoLogin, 10000);
}
ConfigHolder::add('SLX_SYSTEMD_TARGET', 'exam-mode', 10000);
@@ -26,6 +29,4 @@ $foofoo = function($machineUuid) {
// No saver
ConfigHolder::add('SLX_SCREEN_SAVER_TIMEOUT', '0', 1000);
}
-};
-
-$foofoo($uuid); \ No newline at end of file
+} \ No newline at end of file
diff --git a/modules-available/exams/inc/exams.inc.php b/modules-available/exams/inc/exams.inc.php
index da4dec85..2a54c262 100644
--- a/modules-available/exams/inc/exams.inc.php
+++ b/modules-available/exams/inc/exams.inc.php
@@ -4,14 +4,11 @@ class Exams
{
/**
- * @param int[] of location ids. must bot be an associative array.
- * @return: bool true iff for any of the given location ids an exam is scheduled.
+ * @param int[] $locationIds of location ids. must be an associative array.
+ * @return bool true iff for any of the given location ids an exam is scheduled.
**/
- public static function isInExamMode($locationIds, &$lectureId = false, &$autoLogin = false)
+ public static function isInExamMode(array $locationIds, ?string &$lectureId = null, ?string &$autoLogin = null): bool
{
- if (!is_array($locationIds)) {
- $locationIds = array($locationIds);
- }
if (empty($locationIds)) {
$locationIds[] = 0;
}
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");
}
}