diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 642d3d70..2dff7019 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -225,12 +225,14 @@ function AngelType_ids() * Returns angelType by id. * * @param int $angeltype_id angelType ID - * @return array + * @return array|null */ function AngelType($angeltype_id) { - return DB::selectOne( + $angelType = DB::selectOne( 'SELECT * FROM `AngelTypes` WHERE `id`=?', [$angeltype_id] ); + + return empty($angelType) ? null : $angelType; } diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php index 6d782ec4..766a5849 100644 --- a/includes/model/EventConfig_model.php +++ b/includes/model/EventConfig_model.php @@ -5,11 +5,13 @@ use Engelsystem\Database\DB; /** * Get event config. * - * @return array + * @return array|null */ function EventConfig() { - return DB::selectOne('SELECT * FROM `EventConfig` LIMIT 1'); + $config = DB::selectOne('SELECT * FROM `EventConfig` LIMIT 1'); + + return empty($config) ? null : $config; } /** diff --git a/includes/model/Message_model.php b/includes/model/Message_model.php index 9bd7d6ef..3f66f74a 100644 --- a/includes/model/Message_model.php +++ b/includes/model/Message_model.php @@ -16,11 +16,13 @@ function Message_ids() * Returns message by id. * * @param int $message_id message ID - * @return array + * @return array|null */ function Message($message_id) { - return DB::selectOne('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]); + $message = DB::selectOne('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]); + + return empty($message) ? null : $message; } /** diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php index 36a375aa..b29f68fe 100644 --- a/includes/model/Room_model.php +++ b/includes/model/Room_model.php @@ -148,14 +148,16 @@ function Room_update($room_id, $name, $from_frab, $map_url, $description) * Returns room by id. * * @param int $room_id RID - * @return array + * @return array|null */ function Room($room_id) { - return DB::selectOne(' + $room = DB::selectOne(' SELECT * FROM `Room` WHERE `RID` = ?', [ $room_id ]); + + return empty($room) ? null : $room; } diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 02eace1e..ebf600f3 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -134,11 +134,13 @@ function ShiftEntry_update($shift_entry) * Get a shift entry. * * @param int $shift_entry_id - * @return array + * @return array|null */ function ShiftEntry($shift_entry_id) { - return DB::selectOne('SELECT * FROM `ShiftEntry` WHERE `id` = ?', [$shift_entry_id]); + $shiftEntry = DB::selectOne('SELECT * FROM `ShiftEntry` WHERE `id` = ?', [$shift_entry_id]); + + return empty($shiftEntry) ? null : $shiftEntry; } /** diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php index 0e8ef3a4..599810be 100644 --- a/includes/model/ShiftTypes_model.php +++ b/includes/model/ShiftTypes_model.php @@ -66,11 +66,13 @@ function ShiftType_create($name, $angeltype_id, $description) * Get a shift type by id. * * @param int $shifttype_id - * @return array + * @return array|null */ function ShiftType($shifttype_id) { - return DB::selectOne('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]); + $shiftType = DB::selectOne('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]); + + return empty($shiftType) ? null : $shiftType; } /** diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 5719a8e1..94513ff3 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -552,7 +552,7 @@ function Shift_update($shift) * Update a shift by its external id. * * @param array $shift - * @return bool|null + * @return int * @throws Exception */ function Shift_update_by_psid($shift) diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index c744cdd7..b1005095 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -193,15 +193,17 @@ function UserAngelType_create($user, $angeltype) * Get an UserAngelType by its id. * * @param int $user_angeltype_id - * @return array + * @return array|null */ function UserAngelType($user_angeltype_id) { - return DB::selectOne(' + $angelType = DB::selectOne(' SELECT * FROM `UserAngelTypes` WHERE `id`=? LIMIT 1', [$user_angeltype_id]); + + return empty($angelType) ? null : $angelType; } /** @@ -209,11 +211,11 @@ function UserAngelType($user_angeltype_id) * * @param array $user * @param array $angeltype - * @return array + * @return array|null */ function UserAngelType_by_User_and_AngelType($user, $angeltype) { - return DB::selectOne(' + $angelType = DB::selectOne(' SELECT * FROM `UserAngelTypes` WHERE `user_id`=? @@ -225,6 +227,8 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) $angeltype['id'] ] ); + + return empty($angelType) ? null : $angelType; } /** diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php index a1476f95..2c251d66 100644 --- a/includes/model/UserDriverLicenses_model.php +++ b/includes/model/UserDriverLicenses_model.php @@ -41,14 +41,16 @@ function UserDriverLicense_valid($user_driver_license) * Get a users driver license information * * @param int $user_id The users id - * @return array + * @return array|null */ function UserDriverLicense($user_id) { - return DB::selectOne(' + $driverLicense = DB::selectOne(' SELECT * FROM `UserDriverLicenses` WHERE `user_id`=?', [$user_id]); + + return empty($driverLicense) ? null : $driverLicense; } /** diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index df0ec8f6..ff39ba8f 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -6,13 +6,15 @@ use Engelsystem\Database\Db; * Load a single work log entry. * * @param int $user_worklog_id - * @return array + * @return array|null */ function UserWorkLog($user_worklog_id) { - return Db::selectOne("SELECT * FROM `UserWorkLog` WHERE `id`=?", [ + $workLog = Db::selectOne("SELECT * FROM `UserWorkLog` WHERE `id`=?", [ $user_worklog_id ]); + + return empty($workLog) ? null : $workLog; } /** diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 70a03736..d2498462 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -406,44 +406,52 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de * Returns user by id. * * @param int $user_id UID - * @return array + * @return array|null */ function User($user_id) { - return DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]); + $user = DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]); + + return empty($user) ? null : $user; } /** * Returns User by api_key. * * @param string $api_key User api key - * @return array Matching user, empty if not found + * @return array|null Matching user, null if not found */ function User_by_api_key($api_key) { - return DB::selectOne('SELECT * FROM `User` WHERE `api_key`=? LIMIT 1', [$api_key]); + $user = DB::selectOne('SELECT * FROM `User` WHERE `api_key`=? LIMIT 1', [$api_key]); + + return empty($user) ? null : $user; } /** * Returns User by email. * * @param string $email - * @return array Matching user, empty on error + * @return array|null Matching user, null when not found */ function User_by_email($email) { - return DB::selectOne('SELECT * FROM `User` WHERE `email`=? LIMIT 1', [$email]); + $user = DB::selectOne('SELECT * FROM `User` WHERE `email`=? LIMIT 1', [$email]); + + return empty($user) ? null : $user; } /** * Returns User by password token. * * @param string $token - * @return array Matching user, empty when not found + * @return array|null Matching user, null when not found */ function User_by_password_recovery_token($token) { - return DB::selectOne('SELECT * FROM `User` WHERE `password_recovery_token`=? LIMIT 1', [$token]); + $user = DB::selectOne('SELECT * FROM `User` WHERE `password_recovery_token`=? LIMIT 1', [$token]); + + return empty($user) ? null : $user; } /**