models: return null on empty result
This commit is contained in:
parent
646ffc1910
commit
0d154365a2
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue