diff options
Diffstat (limited to 'includes/model')
-rw-r--r-- | includes/model/AngelType_model.php | 3 | ||||
-rw-r--r-- | includes/model/UserAngelTypes_model.php | 37 | ||||
-rw-r--r-- | includes/model/User_model.php | 26 |
3 files changed, 61 insertions, 5 deletions
diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 832a3236..df5e6ae1 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -92,7 +92,8 @@ function AngelTypes_with_user($user) { return sql_select(" SELECT `AngelTypes`.*, `UserAngelTypes`.`id` as `user_angeltype_id`, - `UserAngelTypes`.`confirm_user_id` + `UserAngelTypes`.`confirm_user_id`, + `UserAngelTypes`.`coordinator` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id` AND `UserAngelTypes`.`user_id`=" . $user['UID'] . " diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index 4987eddd..b9b44032 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -1,9 +1,42 @@ <?php +/** + * User angeltypes model + */ + +/** + * Returns true if user is angeltype coordinator or has privilege admin_user_angeltypes. + * + * @param User $user + * @param AngelType $angeltype + */ +function User_is_AngelType_coordinator($user, $angeltype) { + return (sql_num_query(" + SELECT `id` + FROM `UserAngelTypes` + WHERE `user_id`=" . sql_escape($user['UID']) . " + AND `angeltype_id`=" . sql_escape($angeltype['id']) . " + AND `coordinator`=TRUE + LIMIT 1") > 0) || in_array('admin_user_angeltypes', privileges_for_user($user['UID'])); +} + +/** + * Add or remove coordinator rights. + * + * @param int $user_angeltype_id + * @param bool $coordinator + */ +function UserAngelType_update($user_angeltype_id, $coordinator) { + return sql_query(" + UPDATE `UserAngelTypes` + SET `coordinator`=" . ($coordinator ? 'TRUE' : 'FALSE') . " + WHERE `id`=" . sql_escape($user_angeltype_id) . " + LIMIT 1"); +} /** * Delete all unconfirmed UserAngelTypes for given Angeltype. - * - * @param int $angeltype_id + * + * @param int $angeltype_id */ function UserAngelTypes_delete_all($angeltype_id) { return sql_query(" diff --git a/includes/model/User_model.php b/includes/model/User_model.php index d369ea3e..c8c48e6c 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -1,12 +1,34 @@ <?php +/** + * User model + */ + +/** + * Returns all users that are not member of given angeltype. + * + * @param Angeltype $angeltype + */ +function Users_by_angeltype_inverted($angeltype) { + return sql_select(" + SELECT `User`.* + FROM `User` + LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`=" . sql_escape($angeltype['id']) . ") + WHERE `UserAngelTypes`.`id` IS NULL + ORDER BY `Nick`"); +} /** * Returns all members of given angeltype. - * @param Angeltype $angeltype + * + * @param Angeltype $angeltype */ function Users_by_angeltype($angeltype) { return sql_select(" - SELECT `User`.*, `UserAngelTypes`.`id` as `user_angeltype_id`, `UserAngelTypes`.`confirm_user_id` + SELECT + `User`.*, + `UserAngelTypes`.`id` as `user_angeltype_id`, + `UserAngelTypes`.`confirm_user_id`, + `UserAngelTypes`.`coordinator` FROM `User` JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id` WHERE `UserAngelTypes`.`angeltype_id`=" . sql_escape($angeltype['id']) . " |