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/model/Shifts_model.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'includes/model/Shifts_model.php') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 939a4f4e..88b28998 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -112,7 +112,7 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) */ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) { - $result = DB::select(' + return DB::selectOne(' SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, @@ -150,12 +150,6 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) $angeltype['id'] ] ); - - if (empty($result)) { - return null; - } - - return $result[0]; } /** @@ -453,13 +447,13 @@ function Shift_update($shift) */ function Shift_update_by_psid($shift) { - $shift_source = DB::select('SELECT `SID` FROM `Shifts` WHERE `PSID`=?', [$shift['PSID']]); + $shift_source = DB::selectOne('SELECT `SID` FROM `Shifts` WHERE `PSID`=?', [$shift['PSID']]); if (empty($shift_source)) { throw new Exception('Shift not found.'); } - $shift['SID'] = $shift_source[0]['SID']; + $shift['SID'] = $shift_source['SID']; return Shift_update($shift); } @@ -537,18 +531,16 @@ function Shifts_by_user($user, $include_freeload_comments = false) */ function Shift($shift_id) { - $shifts_source = DB::select(' + $result = DB::selectOne(' SELECT `Shifts`.*, `ShiftTypes`.`name` FROM `Shifts` JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) WHERE `SID`=?', [$shift_id]); - if (empty($shifts_source)) { + if (empty($result)) { return null; } - $result = $shifts_source[0]; - $shiftsEntry_source = DB::select(' SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` -- cgit v1.2.3-54-g00ecf