summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/AngelType_model.php51
-rw-r--r--includes/model/EventConfig_model.php14
-rw-r--r--includes/model/Message_model.php6
-rw-r--r--includes/model/NeededAngelTypes_model.php17
-rw-r--r--includes/model/Room_model.php20
-rw-r--r--includes/model/ShiftEntry_model.php28
-rw-r--r--includes/model/ShiftTypes_model.php31
-rw-r--r--includes/model/Shifts_model.php90
-rw-r--r--includes/model/UserAngelTypes_model.php81
-rw-r--r--includes/model/UserDriverLicenses_model.php32
-rw-r--r--includes/model/User_model.php105
11 files changed, 77 insertions, 398 deletions
diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php
index d437f526..bc535667 100644
--- a/includes/model/AngelType_model.php
+++ b/includes/model/AngelType_model.php
@@ -77,31 +77,25 @@ function AngelType_contact_info($angeltype)
* Delete an Angeltype.
*
* @param array $angeltype
- * @return bool
*/
function AngelType_delete($angeltype)
{
- $result = DB::delete('
+ DB::delete('
DELETE FROM `AngelTypes`
WHERE `id`=?
LIMIT 1
', [$angeltype['id']]);
- if (is_null($result)) {
- engelsystem_error('Unable to delete angeltype.');
- }
engelsystem_log('Deleted angeltype: ' . AngelType_name_render($angeltype));
- return true;
}
/**
* Update Angeltype.
*
* @param array $angeltype The angeltype
- * @return bool
*/
function AngelType_update($angeltype)
{
- $result = DB::update('
+ DB::update('
UPDATE `AngelTypes` SET
`name` = ?,
`restricted` = ?,
@@ -126,15 +120,12 @@ function AngelType_update($angeltype)
$angeltype['id'],
]
);
- if (is_null($result)) {
- engelsystem_error('Unable to update angeltype.');
- }
+
engelsystem_log(
'Updated angeltype: ' . $angeltype['name'] . ($angeltype['restricted'] ? ', restricted' : '')
. ($angeltype['no_self_signup'] ? ', no_self_signup' : '')
. ($angeltype['requires_driver_license'] ? ', requires driver license' : '')
);
- return true;
}
/**
@@ -145,7 +136,7 @@ function AngelType_update($angeltype)
*/
function AngelType_create($angeltype)
{
- $result = DB::insert('
+ DB::insert('
INSERT INTO `AngelTypes` (
`name`,
`restricted`,
@@ -171,9 +162,7 @@ function AngelType_create($angeltype)
$angeltype['contact_email'],
]
);
- if (is_null($result)) {
- engelsystem_error('Unable to create angeltype.');
- }
+
$angeltype['id'] = DB::getPdo()->lastInsertId();
engelsystem_log(
'Created angeltype: ' . $angeltype['name']
@@ -224,7 +213,7 @@ function AngelType_validate_name($name, $angeltype)
*/
function AngelTypes_with_user($user)
{
- $result = DB::select('
+ return DB::select('
SELECT `AngelTypes`.*,
`UserAngelTypes`.`id` AS `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`,
@@ -233,11 +222,6 @@ function AngelTypes_with_user($user)
LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id`
AND `UserAngelTypes`.`user_id` = ?
ORDER BY `name`', [$user['UID']]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load angeltypes.');
- }
- return $result;
}
/**
@@ -247,15 +231,10 @@ function AngelTypes_with_user($user)
*/
function AngelTypes()
{
- $result = DB::select('
+ return DB::select('
SELECT *
FROM `AngelTypes`
ORDER BY `name`');
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load angeltypes.');
- }
- return $result;
}
/**
@@ -266,10 +245,6 @@ function AngelTypes()
function AngelType_ids()
{
$result = DB::select('SELECT `id` FROM `AngelTypes`');
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load angeltypes.');
- }
return select_array($result, 'id', 'id');
}
@@ -281,18 +256,8 @@ function AngelType_ids()
*/
function AngelType($angeltype_id)
{
- $angelType_source = DB::select(
+ return DB::selectOne(
'SELECT * FROM `AngelTypes` WHERE `id`=?',
[$angeltype_id]
);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load angeltype.');
- }
-
- if (empty($angelType_source)) {
- return null;
- }
-
- return array_shift($angelType_source);
}
diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php
index 112ad457..646d19c5 100644
--- a/includes/model/EventConfig_model.php
+++ b/includes/model/EventConfig_model.php
@@ -9,17 +9,7 @@ use Engelsystem\Database\DB;
*/
function EventConfig()
{
- $event_config = DB::select('SELECT * FROM `EventConfig` LIMIT 1');
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load event config.');
- return null;
- }
-
- if (empty($event_config)) {
- return null;
- }
-
- return array_shift($event_config);
+ return DB::selectOne('SELECT * FROM `EventConfig` LIMIT 1');
}
/**
@@ -31,7 +21,7 @@ function EventConfig()
* @param int $event_end_date
* @param int $teardown_end_date
* @param string $event_welcome_msg
- * @return bool
+ * @return int Rows updated
*/
function EventConfig_update(
$event_name,
diff --git a/includes/model/Message_model.php b/includes/model/Message_model.php
index ebd4b37e..9bb037af 100644
--- a/includes/model/Message_model.php
+++ b/includes/model/Message_model.php
@@ -20,11 +20,7 @@ function Message_ids()
*/
function Message($message_id)
{
- $message_source = DB::select('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]);
- if (empty($message_source)) {
- return null;
- }
- return array_shift($message_source);
+ return DB::selectOne('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]);
}
/**
diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php
index 97b085f0..d8de5e69 100644
--- a/includes/model/NeededAngelTypes_model.php
+++ b/includes/model/NeededAngelTypes_model.php
@@ -17,7 +17,7 @@ use Engelsystem\Database\DB;
*/
function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count)
{
- $result = DB::insert('
+ DB::insert('
INSERT INTO `NeededAngelTypes` ( `shift_id`, `angel_type_id`, `room_id`, `count`)
VALUES (?, ?, ?, ?)
',
@@ -27,9 +27,6 @@ function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count)
$room_id,
$count,
]);
- if ($result === false) {
- return false;
- }
return DB::getPdo()->lastInsertId();
}
@@ -38,22 +35,20 @@ function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count)
* Deletes all needed angel types from given shift.
*
* @param int $shift_id id of the shift
- * @return int count of affected rows
*/
function NeededAngelTypes_delete_by_shift($shift_id)
{
- return (int)DB::delete('DELETE FROM `NeededAngelTypes` WHERE `shift_id` = ?', [$shift_id]);
+ DB::delete('DELETE FROM `NeededAngelTypes` WHERE `shift_id` = ?', [$shift_id]);
}
/**
* Deletes all needed angel types from given room.
*
* @param int $room_id id of the room
- * @return int count of affected rows
*/
function NeededAngelTypes_delete_by_room($room_id)
{
- return (int)DB::delete(
+ DB::delete(
'DELETE FROM `NeededAngelTypes` WHERE `room_id` = ?',
[$room_id]
);
@@ -76,9 +71,6 @@ function NeededAngelTypes_by_shift($shiftId)
ORDER BY `room_id` DESC',
[$shiftId]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load needed angeltypes.');
- }
// Use settings from room
if (count($needed_angeltypes_source) == 0) {
@@ -91,9 +83,6 @@ function NeededAngelTypes_by_shift($shiftId)
AND `count` > 0
ORDER BY `room_id` DESC
', [$shiftId]);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load needed angeltypes.');
- }
}
$shift_entries = ShiftEntries_by_shift($shiftId);
diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php
index 17617b39..8425e5ad 100644
--- a/includes/model/Room_model.php
+++ b/includes/model/Room_model.php
@@ -17,11 +17,10 @@ function Rooms($show_all = false)
* Delete a room
*
* @param int $room_id
- * @return bool
*/
function Room_delete($room_id)
{
- return DB::delete('DELETE FROM `Room` WHERE `RID` = ?', [$room_id]);
+ DB::delete('DELETE FROM `Room` WHERE `RID` = ?', [$room_id]);
}
/**
@@ -35,7 +34,7 @@ function Room_delete($room_id)
*/
function Room_create($name, $from_frab, $public, $number = null)
{
- $result = DB::insert('
+ DB::insert('
INSERT INTO `Room` (`Name`, `FromPentabarf`, `show`, `Number`)
VALUES (?, ?, ?, ?)
',
@@ -46,9 +45,6 @@ function Room_create($name, $from_frab, $public, $number = null)
(int)$number,
]
);
- if (!$result) {
- return false;
- }
return DB::getPdo()->lastInsertId();
}
@@ -62,21 +58,11 @@ function Room_create($name, $from_frab, $public, $number = null)
*/
function Room($room_id, $onlyVisible = true)
{
- $room_source = DB::select('
+ return DB::selectOne('
SELECT *
FROM `Room`
WHERE `RID` = ?
' . ($onlyVisible ? 'AND `show` = \'Y\'' : ''),
[$room_id]
);
-
- if (DB::getStm()->errorCode() != '00000') {
- return false;
- }
-
- if (empty($room_source)) {
- return null;
- }
-
- return array_shift($room_source);
}
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index d7810feb..3a7254ad 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -28,10 +28,9 @@ function ShiftEntry_new()
*/
function ShiftEntries_freeleaded_count()
{
- $result = DB::select('SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1');
- $result = array_shift($result);
+ $result = DB::selectOne('SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1');
- if (!is_array($result)) {
+ if (empty($result)) {
return 0;
}
@@ -102,7 +101,6 @@ function ShiftEntry_create($shift_entry)
* Update a shift entry.
*
* @param array $shift_entry
- * @return bool
*/
function ShiftEntry_update($shift_entry)
{
@@ -120,39 +118,29 @@ function ShiftEntry_update($shift_entry)
$shift_entry['id']
]
);
-
- return (DB::getStm()->errorCode() == '00000');
}
/**
* Get a shift entry.
*
* @param int $shift_entry_id
- * @return array|false|null
+ * @return array|null
*/
function ShiftEntry($shift_entry_id)
{
- $shift_entry = DB::select('SELECT * FROM `ShiftEntry` WHERE `id` = ?', [$shift_entry_id]);
- if (DB::getStm()->errorCode() != '00000') {
- return false;
- }
- if (empty($shift_entry)) {
- return null;
- }
- return $shift_entry[0];
+ return DB::selectOne('SELECT * FROM `ShiftEntry` WHERE `id` = ?', [$shift_entry_id]);
}
/**
* Delete a shift entry.
*
* @param int $shift_entry_id
- * @return bool
*/
function ShiftEntry_delete($shift_entry_id)
{
$shift_entry = ShiftEntry($shift_entry_id);
mail_shift_removed(User($shift_entry['UID']), Shift($shift_entry['SID']));
- return DB::delete('DELETE FROM `ShiftEntry` WHERE `id` = ?', [$shift_entry_id]);
+ DB::delete('DELETE FROM `ShiftEntry` WHERE `id` = ?', [$shift_entry_id]);
}
/**
@@ -213,7 +201,7 @@ function ShiftEntries_finished_by_user($user)
*/
function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id)
{
- $result = DB::select('
+ return DB::select('
SELECT *
FROM `ShiftEntry`
WHERE `SID` = ?
@@ -224,10 +212,6 @@ function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id)
$angeltype_id,
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load shift entries.');
- }
- return $result;
}
/**
diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php
index 96a823d4..227df367 100644
--- a/includes/model/ShiftTypes_model.php
+++ b/includes/model/ShiftTypes_model.php
@@ -6,11 +6,10 @@ use Engelsystem\Database\DB;
* Delete a shift type.
*
* @param int $shifttype_id
- * @return bool
*/
function ShiftType_delete($shifttype_id)
{
- return DB::delete('DELETE FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]);
+ DB::delete('DELETE FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]);
}
/**
@@ -20,7 +19,6 @@ function ShiftType_delete($shifttype_id)
* @param string $name
* @param int $angeltype_id
* @param string $description
- * @return bool
*/
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
{
@@ -38,8 +36,6 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
$shifttype_id,
]
);
-
- return DB::getStm()->errorCode() == '00000';
}
/**
@@ -52,7 +48,7 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
*/
function ShiftType_create($name, $angeltype_id, $description)
{
- $result = DB::insert('
+ DB::insert('
INSERT INTO `ShiftTypes` (`name`, `angeltype_id`, `description`)
VALUES(?, ?, ?)
',
@@ -63,10 +59,6 @@ function ShiftType_create($name, $angeltype_id, $description)
]
);
- if ($result === false) {
- return false;
- }
-
return DB::getPdo()->lastInsertId();
}
@@ -78,28 +70,15 @@ function ShiftType_create($name, $angeltype_id, $description)
*/
function ShiftType($shifttype_id)
{
- $shifttype = DB::select('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load shift type.');
- }
- if (empty($shifttype)) {
- return null;
- }
- return array_shift($shifttype);
+ return DB::selectOne('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]);
}
/**
* Get all shift types.
*
- * @return array|false
+ * @return array
*/
function ShiftTypes()
{
- $result = DB::select('SELECT * FROM `ShiftTypes` ORDER BY `name`');
-
- if (DB::getStm()->errorCode() != '00000') {
- return false;
- }
-
- return $result;
+ return DB::select('SELECT * FROM `ShiftTypes` ORDER BY `name`');
}
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;
diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php
index 82f390ee..5b0caf98 100644
--- a/includes/model/UserAngelTypes_model.php
+++ b/includes/model/UserAngelTypes_model.php
@@ -27,23 +27,16 @@ function UserAngelType_exists($user, $angeltype)
* List users angeltypes.
*
* @param array $user
- * @return array|false
+ * @return array
*/
function User_angeltypes($user)
{
- $result = DB::select('
+ return DB::select('
SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter`
FROM `UserAngelTypes`
JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`
WHERE `UserAngelTypes`.`user_id`=?
', [$user['UID']]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load user angeltypes.');
- return false;
- }
-
- return $result;
}
/**
@@ -54,7 +47,7 @@ function User_angeltypes($user)
*/
function User_unconfirmed_AngelTypes($user)
{
- $result = DB::select('
+ return DB::select('
SELECT
`UserAngelTypes`.*,
`AngelTypes`.`name`,
@@ -69,12 +62,6 @@ function User_unconfirmed_AngelTypes($user)
GROUP BY `UserAngelTypes`.`angeltype_id`
ORDER BY `AngelTypes`.`name`
', [$user['UID']]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load user angeltypes.');
- }
-
- return $result;
}
/**
@@ -110,29 +97,21 @@ function User_is_AngelType_supporter(&$user, $angeltype)
*
* @param int $user_angeltype_id
* @param bool $supporter
- * @return int
*/
function UserAngelType_update($user_angeltype_id, $supporter)
{
- $result = DB::update('
+ DB::update('
UPDATE `UserAngelTypes`
SET `supporter`=?
WHERE `id`=?
LIMIT 1
', [$supporter, $user_angeltype_id]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to update supporter rights.');
- }
-
- return $result;
}
/**
* Delete all unconfirmed UserAngelTypes for given Angeltype.
*
* @param int $angeltype_id
- * @return bool
*/
function UserAngelTypes_delete_all($angeltype_id)
{
@@ -141,12 +120,6 @@ function UserAngelTypes_delete_all($angeltype_id)
WHERE `angeltype_id`=?
AND `confirm_user_id` IS NULL
', [$angeltype_id]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to delete all unconfirmed users.');
- }
-
- return true;
}
/**
@@ -154,22 +127,15 @@ function UserAngelTypes_delete_all($angeltype_id)
*
* @param int $angeltype_id
* @param array $confirm_user
- * @return bool
*/
function UserAngelTypes_confirm_all($angeltype_id, $confirm_user)
{
- $result = DB::update('
+ DB::update('
UPDATE `UserAngelTypes`
SET `confirm_user_id`=?
WHERE `angeltype_id`=?
AND `confirm_user_id` IS NULL
', [$confirm_user['UID'], $angeltype_id]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to confirm all users.');
- }
-
- return (bool)$result;
}
/**
@@ -181,26 +147,21 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user)
*/
function UserAngelType_confirm($user_angeltype_id, $confirm_user)
{
- $result = DB::update('
+ DB::update('
UPDATE `UserAngelTypes`
SET `confirm_user_id`=?
WHERE `id`=?
LIMIT 1', [$confirm_user['UID'], $user_angeltype_id]);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to confirm user angeltype.');
- }
- return (bool)$result;
}
/**
* Delete an UserAngelType.
*
* @param array $user_angeltype
- * @return bool
*/
function UserAngelType_delete($user_angeltype)
{
- return (bool)DB::delete('
+ DB::delete('
DELETE FROM `UserAngelTypes`
WHERE `id`=?
LIMIT 1', [$user_angeltype['id']]);
@@ -225,10 +186,6 @@ function UserAngelType_create($user, $angeltype)
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to create user angeltype.');
- }
-
return DB::getPdo()->lastInsertId();
}
@@ -240,21 +197,11 @@ function UserAngelType_create($user, $angeltype)
*/
function UserAngelType($user_angeltype_id)
{
- $angeltype = DB::select('
+ return DB::selectOne('
SELECT *
FROM `UserAngelTypes`
WHERE `id`=?
LIMIT 1', [$user_angeltype_id]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load user angeltype.');
- }
-
- if (empty($angeltype)) {
- return null;
- }
-
- return $angeltype[0];
}
/**
@@ -266,7 +213,7 @@ function UserAngelType($user_angeltype_id)
*/
function UserAngelType_by_User_and_AngelType($user, $angeltype)
{
- $angeltype = DB::select('
+ return DB::selectOne('
SELECT *
FROM `UserAngelTypes`
WHERE `user_id`=?
@@ -278,14 +225,4 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype)
$angeltype['id']
]
);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load user angeltype.');
- }
-
- if (empty($angeltype)) {
- return null;
- }
-
- return array_shift($angeltype);
}
diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php
index 525d2016..798aa6ab 100644
--- a/includes/model/UserDriverLicenses_model.php
+++ b/includes/model/UserDriverLicenses_model.php
@@ -41,25 +41,14 @@ function UserDriverLicense_valid($user_driver_license)
* Get a users driver license information
*
* @param int $user_id The users id
- * @return array|false|null
+ * @return array|null
*/
function UserDriverLicense($user_id)
{
- $user_driver_license = DB::select('
+ return DB::selectOne('
SELECT *
FROM `UserDriverLicenses`
WHERE `user_id`=?', [$user_id]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load user driver license.');
- return false;
- }
-
- if (empty($user_driver_license)) {
- return null;
- }
-
- return array_shift($user_driver_license);
}
/**
@@ -94,9 +83,6 @@ function UserDriverLicenses_create($user_driver_license, $user)
(bool)$user_driver_license['has_license_forklift'],
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to create user driver license');
- }
return $user_driver_license;
}
@@ -105,11 +91,10 @@ function UserDriverLicenses_create($user_driver_license, $user)
* Update a user's driver license entry
*
* @param array $user_driver_license The UserDriverLicense to update
- * @return bool
*/
function UserDriverLicenses_update($user_driver_license)
{
- $result = DB::update('
+ DB::update('
UPDATE `UserDriverLicenses`
SET
`has_car`=?,
@@ -130,23 +115,14 @@ function UserDriverLicenses_update($user_driver_license)
$user_driver_license['user_id'],
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to update user driver license information');
- }
- return $result;
}
/**
* Delete a user's driver license entry
*
* @param int $user_id
- * @return bool
*/
function UserDriverLicenses_delete($user_id)
{
- $result = DB::delete('DELETE FROM `UserDriverLicenses` WHERE `user_id`=?', [$user_id]);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to remove user driver license information');
- }
- return $result;
+ DB::delete('DELETE FROM `UserDriverLicenses` WHERE `user_id`=?', [$user_id]);
}
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index 2913c1a1..4757ed3c 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -11,24 +11,20 @@ use Engelsystem\ValidationResult;
* Delete a user
*
* @param int $user_id
- * @return bool
*/
function User_delete($user_id)
{
DB::delete('DELETE FROM `User` WHERE `UID`=?', [$user_id]);
-
- return DB::getStm()->errorCode() == '00000';
}
/**
* Update user.
*
* @param array $user
- * @return bool
*/
function User_update($user)
{
- return (bool)DB::update('
+ DB::update('
UPDATE `User` SET
`Nick`=?,
`Name`=?,
@@ -91,8 +87,7 @@ function User_update($user)
*/
function User_force_active_count()
{
- $result = DB::select('SELECT COUNT(*) FROM `User` WHERE `force_active` = 1');
- $result = array_shift($result);
+ $result = DB::selectOne('SELECT COUNT(*) FROM `User` WHERE `force_active` = 1');
if (empty($result)) {
return 0;
@@ -106,8 +101,7 @@ function User_force_active_count()
*/
function User_active_count()
{
- $result = DB::select('SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1');
- $result = array_shift($result);
+ $result = DB::selectOne('SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1');
if (empty($result)) {
return 0;
@@ -121,8 +115,7 @@ function User_active_count()
*/
function User_got_voucher_count()
{
- $result = DB::select('SELECT SUM(`got_voucher`) FROM `User`');
- $result = array_shift($result);
+ $result = DB::selectOne('SELECT SUM(`got_voucher`) FROM `User`');
if (empty($result)) {
return 0;
@@ -136,8 +129,7 @@ function User_got_voucher_count()
*/
function User_arrived_count()
{
- $result = DB::select('SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1');
- $result = array_shift($result);
+ $result = DB::selectOne('SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1');
if (empty($result)) {
return 0;
@@ -151,8 +143,7 @@ function User_arrived_count()
*/
function User_tshirts_count()
{
- $result = DB::select('SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1');
- $result = array_shift($result);
+ $result = DB::selectOne('SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1');
if (empty($result)) {
return 0;
@@ -188,23 +179,17 @@ function User_sortable_columns()
* Get all users, ordered by Nick by default or by given param.
*
* @param string $order_by
- * @return array|false
+ * @return array
*/
function Users($order_by = 'Nick')
{
- $result = DB::select(sprintf('
+ return DB::select(sprintf('
SELECT *
FROM `User`
ORDER BY `%s` ASC
',
trim(DB::getPdo()->quote($order_by), '\'')
));
-
- if (DB::getStm()->errorCode() != '00000') {
- return false;
- }
-
- return $result;
}
/**
@@ -228,7 +213,7 @@ function User_is_freeloader($user)
*/
function Users_by_angeltype_inverted($angeltype)
{
- $result = DB::select('
+ return DB::select('
SELECT `User`.*
FROM `User`
LEFT JOIN `UserAngelTypes`
@@ -240,10 +225,6 @@ function Users_by_angeltype_inverted($angeltype)
$angeltype['id']
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load users.');
- }
- return $result;
}
/**
@@ -254,12 +235,13 @@ function Users_by_angeltype_inverted($angeltype)
*/
function Users_by_angeltype($angeltype)
{
- $result = DB::select('
+ return DB::select('
SELECT
`User`.*,
`UserAngelTypes`.`id` AS `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`,
`UserAngelTypes`.`supporter`,
+ (`UserDriverLicenses`.`user_id` IS NOT NULL) as `wants_to_drive`,
`UserDriverLicenses`.*
FROM `User`
JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id`
@@ -271,10 +253,6 @@ function Users_by_angeltype($angeltype)
$angeltype['id']
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load members.');
- }
- return $result;
}
/**
@@ -399,17 +377,7 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de
*/
function User($user_id)
{
- $user_source = DB::select('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load user.');
- }
-
- if (empty($user_source)) {
- return null;
- }
-
- return array_shift($user_source);
+ return DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]);
}
/**
@@ -417,21 +385,11 @@ function User($user_id)
*
* @param string $api_key
* User api key
- * @return array|null Matching user, null on error
+ * @return array|null Matching user, null if not found
*/
function User_by_api_key($api_key)
{
- $user = DB::select('SELECT * FROM `User` WHERE `api_key`=? LIMIT 1', [$api_key]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to find user by api key.');
- }
-
- if (empty($user)) {
- return null;
- }
-
- return $user[0];
+ return DB::selectOne('SELECT * FROM `User` WHERE `api_key`=? LIMIT 1', [$api_key]);
}
/**
@@ -442,38 +400,18 @@ function User_by_api_key($api_key)
*/
function User_by_email($email)
{
- $user = DB::select('SELECT * FROM `User` WHERE `email`=? LIMIT 1', [$email]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load user.');
- }
-
- if (empty($user)) {
- return null;
- }
-
- return array_shift($user);
+ return DB::selectOne('SELECT * FROM `User` WHERE `email`=? LIMIT 1', [$email]);
}
/**
* Returns User by password token.
*
* @param string $token
- * @return array|null Matching user, null or false on error
+ * @return array|null Matching user, null when not found
*/
function User_by_password_recovery_token($token)
{
- $user = DB::select('SELECT * FROM `User` WHERE `password_recovery_token`=? LIMIT 1', [$token]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to load user.');
- }
-
- if (empty($user)) {
- return null;
- }
-
- return array_shift($user);
+ return DB::selectOne('SELECT * FROM `User` WHERE `password_recovery_token`=? LIMIT 1', [$token]);
}
/**
@@ -481,7 +419,6 @@ function User_by_password_recovery_token($token)
*
* @param array $user
* @param bool $log
- * @return bool
*/
function User_reset_api_key(&$user, $log = true)
{
@@ -497,15 +434,10 @@ function User_reset_api_key(&$user, $log = true)
$user['UID']
]
);
- if (DB::getStm()->errorCode() != '00000') {
- return false;
- }
if ($log) {
engelsystem_log(sprintf('API key resetted (%s).', User_Nick_render($user)));
}
-
- return true;
}
/**
@@ -528,9 +460,6 @@ function User_generate_password_recovery_token(&$user)
$user['UID'],
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to generate password recovery token.');
- }
engelsystem_log('Password recovery for ' . User_Nick_render($user) . ' started.');
return $user['password_recovery_token'];
}