diff options
Diffstat (limited to 'includes/model/Shifts_model.php')
-rw-r--r-- | includes/model/Shifts_model.php | 90 |
1 files changed, 19 insertions, 71 deletions
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 21abc888..88b28998 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -10,11 +10,7 @@ use Engelsystem\ShiftSignupState; */ function Shifts_by_room($room) { - $result = DB::select('SELECT * FROM `Shifts` WHERE `RID`=? ORDER BY `start`', [$room['RID']]); - if (DB::getStm()->errorCode() != '00000') { - engelsystem_error('Unable to load shifts.'); - } - return $result; + return DB::select('SELECT * FROM `Shifts` WHERE `RID`=? ORDER BY `start`', [$room['RID']]); } /** @@ -49,7 +45,8 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) AND NOT `Shifts`.`PSID` IS NULL) AS tmp_shifts ORDER BY `start`'; - $result = DB::select( + + return DB::select( $sql, [ $shiftsFilter->getStartTime(), @@ -58,10 +55,6 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) $shiftsFilter->getEndTime(), ] ); - if (DB::getStm()->errorCode() != '00000') { - engelsystem_error('Unable to load shifts by filter.'); - } - return $result; } /** @@ -100,7 +93,8 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ') AND `start` BETWEEN ? AND ? AND NOT `Shifts`.`PSID` IS NULL'; - $result = DB::select( + + return DB::select( $sql, [ $shiftsFilter->getStartTime(), @@ -109,10 +103,6 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) $shiftsFilter->getEndTime(), ] ); - if (DB::getStm()->errorCode() != '00000') { - engelsystem_error('Unable to load needed angeltypes by filter.'); - } - return $result; } /** @@ -122,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`, @@ -160,13 +150,6 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) $angeltype['id'] ] ); - if (DB::getStm()->errorCode() != '00000') { - engelsystem_error('Unable to load needed angeltypes by filter.'); - } - if (empty($result)) { - return null; - } - return $result[0]; } /** @@ -193,17 +176,13 @@ function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ') AND `start` BETWEEN ? AND ? ORDER BY `Shifts`.`start`'; - $result = DB::select( + return DB::select( $sql, [ $shiftsFilter->getStartTime(), $shiftsFilter->getEndTime(), ] ); - if (DB::getStm()->errorCode() != '00000') { - engelsystem_error('Unable to load shift entries by filter.'); - } - return $result; } /** @@ -402,41 +381,29 @@ function Shift_signup_allowed( * Delete a shift by its external id. * * @param int $shift_psid - * @return bool */ function Shift_delete_by_psid($shift_psid) { DB::delete('DELETE FROM `Shifts` WHERE `PSID`=?', [$shift_psid]); - - if (DB::getStm()->errorCode() != '00000') { - return false; - } - - return true; } /** * Delete a shift. * * @param int $shift_id - * @return bool */ function Shift_delete($shift_id) { mail_shift_delete(Shift($shift_id)); - $result = DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]); - if (DB::getStm()->errorCode() != '00000') { - engelsystem_error('Unable to delete shift.'); - } - return $result; + DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]); } /** * Update a shift. * * @param array $shift - * @return bool + * @return int Updated row count */ function Shift_update($shift) { @@ -444,7 +411,7 @@ function Shift_update($shift) $shift['name'] = ShiftType($shift['shifttype_id'])['name']; mail_shift_change(Shift($shift['SID']), $shift); - return (bool)DB::update(' + return DB::update(' UPDATE `Shifts` SET `shifttype_id` = ?, `start` = ?, @@ -480,16 +447,13 @@ function Shift_update($shift) */ function Shift_update_by_psid($shift) { - $shift_source = DB::select('SELECT `SID` FROM `Shifts` WHERE `PSID`=?', [$shift['PSID']]); - if (DB::getStm()->errorCode() != '00000') { - return false; - } + $shift_source = DB::selectOne('SELECT `SID` FROM `Shifts` WHERE `PSID`=?', [$shift['PSID']]); if (empty($shift_source)) { - return null; + throw new Exception('Shift not found.'); } - $shift['SID'] = $shift_source[0]['SID']; + $shift['SID'] = $shift_source['SID']; return Shift_update($shift); } @@ -497,7 +461,7 @@ function Shift_update_by_psid($shift) * Create a new shift. * * @param array $shift - * @return int|false shift id or false + * @return int ID of the new created shift */ function Shift_create($shift) { @@ -528,9 +492,7 @@ function Shift_create($shift) time(), ] ); - if (DB::getStm()->errorCode() != '00000') { - return false; - } + return DB::getPdo()->lastInsertId(); } @@ -543,7 +505,7 @@ function Shift_create($shift) */ function Shifts_by_user($user, $include_freeload_comments = false) { - $result = DB::select(' + return DB::select(' SELECT `ShiftTypes`.`id` AS `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`, ' . ($include_freeload_comments ? '`ShiftEntry`.`freeload_comment`, ' : '') . ' @@ -559,10 +521,6 @@ function Shifts_by_user($user, $include_freeload_comments = false) $user['UID'] ] ); - if (DB::getStm()->errorCode() != '00000') { - engelsystem_error('Unable to load users shifts.'); - } - return $result; } /** @@ -573,22 +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 (DB::getStm()->errorCode() != '00000') { - engelsystem_error('Unable to load shift.'); - } - - if (empty($shifts_source)) { + if (empty($result)) { return null; } - $result = $shifts_source[0]; - $shiftsEntry_source = DB::select(' SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` @@ -613,7 +565,7 @@ function Shift($shift_id) /** * Returns all shifts with needed angeltypes and count of subscribed jobs. * - * @return array|false + * @return array */ function Shifts() { @@ -624,10 +576,6 @@ function Shifts() JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID` '); - if (DB::getStm()->errorCode() != '00000') { - return false; - } - foreach ($shifts_source as &$shift) { $needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']); $shift['angeltypes'] = $needed_angeltypes; |