summaryrefslogtreecommitdiff
path: root/includes/model/User_model.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/model/User_model.php')
-rw-r--r--includes/model/User_model.php105
1 files changed, 17 insertions, 88 deletions
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'];
}