reduce complexity of angeltype controller

main
msquare 8 years ago
parent 1636688394
commit d64f96b6a1

@ -11,11 +11,9 @@ function angeltypes_title() {
* Route angeltype actions. * Route angeltype actions.
*/ */
function angeltypes_controller() { function angeltypes_controller() {
if (! isset($_REQUEST['action'])) { $action = strip_request_item('action', 'list');
$_REQUEST['action'] = 'list';
}
switch ($_REQUEST['action']) { switch ($action) {
default: default:
case 'list': case 'list':
return angeltypes_list_controller(); return angeltypes_list_controller();
@ -67,10 +65,7 @@ function angeltype_delete_controller() {
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = load_angeltype();
if ($angeltype == null) {
redirect(page_link_to('angeltypes'));
}
if (isset($_REQUEST['confirmed'])) { if (isset($_REQUEST['confirmed'])) {
AngelType_delete($angeltype); AngelType_delete($angeltype);
@ -90,20 +85,20 @@ function angeltype_delete_controller() {
function angeltype_edit_controller() { function angeltype_edit_controller() {
global $privileges, $user; global $privileges, $user;
if (! User_is_AngelType_supporter($user, $angeltype)) {
redirect(page_link_to('angeltypes'));
}
// In supporter mode only allow to modify description // In supporter mode only allow to modify description
$supporter_mode = ! in_array('admin_angel_types', $privileges); $supporter_mode = ! in_array('admin_angel_types', $privileges);
if (isset($_REQUEST['angeltype_id'])) { if (isset($_REQUEST['angeltype_id'])) {
$angeltype = AngelType($_REQUEST['angeltype_id']); // Edit existing angeltype
if ($angeltype == null) { $angeltype = load_angeltype();
redirect(page_link_to('angeltypes'));
}
if (! User_is_AngelType_supporter($user, $angeltype)) {
redirect(page_link_to('angeltypes'));
}
} else { } else {
// New angeltype
if ($supporter_mode) { if ($supporter_mode) {
// Supporters aren't allowed to create new angeltypes.
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$angeltype = AngelType_new(); $angeltype = AngelType_new();
@ -156,21 +151,10 @@ function angeltype_controller() {
redirect('?'); redirect('?');
} }
if (! isset($_REQUEST['angeltype_id'])) { $angeltype = load_angeltype();
redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype == null) {
redirect(page_link_to('angeltypes'));
}
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
$user_driver_license = UserDriverLicense($user['UID']); $user_driver_license = UserDriverLicense($user['UID']);
$members = Users_by_angeltype($angeltype); $members = Users_by_angeltype($angeltype);
if ($members === false) {
engelsystem_error("Unable to load members.");
}
return [ return [
sprintf(_("Team %s"), $angeltype['name']), sprintf(_("Team %s"), $angeltype['name']),

@ -133,7 +133,7 @@ function Users_by_angeltype_inverted($angeltype) {
* @param Angeltype $angeltype * @param Angeltype $angeltype
*/ */
function Users_by_angeltype($angeltype) { function Users_by_angeltype($angeltype) {
return sql_select(" $result = sql_select("
SELECT SELECT
`User`.*, `User`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`, `UserAngelTypes`.`id` as `user_angeltype_id`,
@ -145,6 +145,10 @@ function Users_by_angeltype($angeltype) {
LEFT JOIN `UserDriverLicenses` ON `User`.`UID`=`UserDriverLicenses`.`user_id` LEFT JOIN `UserDriverLicenses` ON `User`.`UID`=`UserDriverLicenses`.`user_id`
WHERE `UserAngelTypes`.`angeltype_id`='" . sql_escape($angeltype['id']) . "' WHERE `UserAngelTypes`.`angeltype_id`='" . sql_escape($angeltype['id']) . "'
ORDER BY `Nick`"); ORDER BY `Nick`");
if ($result === false) {
engelsystem_error("Unable to load members.");
}
return $result;
} }
/** /**

Loading…
Cancel
Save