From f82e5456d22af7e39a22a9a64e74072cf01e0a31 Mon Sep 17 00:00:00 2001 From: msquare Date: Fri, 28 Jul 2017 20:11:09 +0200 Subject: dried code by introducing selectOne for select queries with only one result line expected --- includes/pages/user_myshifts.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'includes/pages/user_myshifts.php') diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index a10e6f82..81f8f505 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -31,8 +31,7 @@ function user_myshifts() $user_id = $user['UID']; } - $shifts_user = DB::select('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]); - $shifts_user = array_shift($shifts_user); + $shifts_user = DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]); if ($request->has('reset')) { if ($request->input('reset') == 'ack') { @@ -49,7 +48,7 @@ function user_myshifts() ]); } elseif ($request->has('edit') && preg_match('/^\d*$/', $request->input('edit'))) { $user_id = $request->input('edit'); - $shift = DB::select(' + $shift = DB::selectOne(' SELECT `ShiftEntry`.`freeloaded`, `ShiftEntry`.`freeload_comment`, @@ -74,7 +73,6 @@ function user_myshifts() ] ); if (count($shift) > 0) { - $shift = array_shift($shift); $freeloaded = $shift['freeloaded']; $freeload_comment = $shift['freeload_comment']; @@ -128,7 +126,7 @@ function user_myshifts() } } elseif ($request->has('cancel') && preg_match('/^\d*$/', $request->input('cancel'))) { $user_id = $request->input('cancel'); - $shift = DB::select(' + $shift = DB::selectOne(' SELECT * FROM `Shifts` INNER JOIN `ShiftEntry` USING (`SID`) @@ -140,7 +138,6 @@ function user_myshifts() ] ); if (count($shift) > 0) { - $shift = array_shift($shift); if ( ($shift['start'] > time() + config('last_unsubscribe') * 3600) || in_array('user_shifts_admin', $privileges) -- cgit v1.2.3-54-g00ecf