reduce complexity of shifts controller

This commit is contained in:
msquare 2016-10-04 21:20:38 +02:00
parent a50b26490c
commit 27c9650dc4
7 changed files with 44 additions and 65 deletions

View File

@ -50,9 +50,6 @@ function angeltypes_about_controller() {
} else {
$angeltypes = AngelTypes();
}
if ($angeltypes === false) {
engelsystem_error("Unable to load angeltypes.");
}
return [
_("Teams/Job description"),
@ -223,9 +220,6 @@ function angeltypes_list_controller() {
}
$angeltypes = AngelTypes_with_user($user);
if ($angeltypes === false) {
engelsystem_error("Unable to load angeltypes.");
}
foreach ($angeltypes as &$angeltype) {
$actions = [

View File

@ -21,9 +21,6 @@ function shift_entry_add_controller() {
$shift = Shift($shift_id);
$shift['Name'] = $room_array[$shift['RID']];
if ($shift === false) {
engelsystem_error('Unable to load shift.');
}
if ($shift == null) {
redirect(page_link_to('user_shifts'));
}

View File

@ -159,19 +159,13 @@ function shift_delete_controller() {
$shift_id = $_REQUEST['delete_shift'];
$shift = Shift($shift_id);
if ($shift === false) {
engelsystem_error('Unable to load shift.');
}
if ($shift == null) {
redirect(page_link_to('user_shifts'));
}
// Schicht löschen bestätigt
if (isset($_REQUEST['delete'])) {
$result = Shift_delete($shift_id);
if ($result === false) {
engelsystem_error('Unable to delete shift.');
}
Shift_delete($shift_id);
engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
success(_("Shift deleted."));
@ -196,33 +190,15 @@ function shift_controller() {
}
$shift = Shift($_REQUEST['shift_id']);
if ($shift === false) {
engelsystem_error('Unable to load shift.');
}
if ($shift == null) {
error(_('Shift could not be found.'));
error(_("Shift could not be found."));
redirect(page_link_to('user_shifts'));
}
$shifttype = ShiftType($shift['shifttype_id']);
if ($shifttype === false || $shifttype == null) {
engelsystem_error('Unable to load shift type.');
}
$room = Room($shift['RID']);
if ($room === false || $room == null) {
engelsystem_error('Unable to load room.');
}
$angeltypes = AngelTypes();
if ($angeltypes === false) {
engelsystem_error('Unable to load angeltypes.');
}
$user_shifts = Shifts_by_user($user);
if ($user_shifts === false) {
engelsystem_error('Unable to load users shifts.');
}
$signed_up = false;
foreach ($user_shifts as $user_shift) {

View File

@ -48,9 +48,6 @@ function shifttype_edit_controller() {
$description = "";
$angeltypes = AngelTypes();
if ($angeltypes === false) {
engelsystem_error("Unable to load angel types.");
}
if (isset($_REQUEST['shifttype_id'])) {
$shifttype = ShiftType($_REQUEST['shifttype_id']);

View File

@ -91,7 +91,7 @@ function AngelType_validate_name($name, $angeltype) {
* @param User $user
*/
function AngelTypes_with_user($user) {
return sql_select("
$result = sql_select("
SELECT `AngelTypes`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`,
@ -100,16 +100,24 @@ function AngelTypes_with_user($user) {
LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id`
AND `UserAngelTypes`.`user_id`=" . $user['UID'] . "
ORDER BY `name`");
if ($result === false) {
engelsystem_error("Unable to load angeltypes.");
}
return $result;
}
/**
* Returns all angeltypes.
*/
function AngelTypes() {
return sql_select("
$result = sql_select("
SELECT *
FROM `AngelTypes`
ORDER BY `name`");
if ($result === false) {
engelsystem_error("Unable to load angeltypes.");
}
return $result;
}
/**

View File

@ -51,7 +51,7 @@ function ShiftType_create($name, $angeltype_id, $description) {
function ShiftType($shifttype_id) {
$shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
if ($shifttype === false) {
return false;
engelsystem_error('Unable to load shift type.');
}
if ($shifttype == null) {
return null;

View File

@ -93,9 +93,6 @@ function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_
if ($user_shifts == null) {
$user_shifts = Shifts_by_user($user);
if ($user_shifts === false) {
engelsystem_error('Unable to load users shifts.');
}
}
$collides = Shift_collides($shift, $user_shifts);
@ -166,7 +163,11 @@ function Shift_delete_by_psid($shift_psid) {
function Shift_delete($shift_id) {
mail_shift_delete(Shift($shift_id));
return sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
$result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
if ($result === false) {
engelsystem_error('Unable to delete shift.');
}
return $result;
}
/**
@ -232,7 +233,7 @@ function Shift_create($shift) {
* Return users shifts.
*/
function Shifts_by_user($user) {
return sql_select("
$result = sql_select("
SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.*, `Shifts`.*, `Room`.*
FROM `ShiftEntry`
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
@ -241,6 +242,10 @@ function Shifts_by_user($user) {
WHERE `UID`='" . sql_escape($user['UID']) . "'
ORDER BY `start`
");
if ($result === false) {
engelsystem_error('Unable to load users shifts.');
}
return $result;
}
/**
@ -304,9 +309,13 @@ function Shift($shift_id) {
$shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'");
if ($shifts_source === false) {
return false;
engelsystem_error('Unable to load shift.');
}
if (count($shifts_source) > 0) {
if (empty($shifts_source)) {
return null;
}
$result = $shifts_source[0];
$result['ShiftEntry'] = $shiftsEntry_source;
@ -323,8 +332,6 @@ function Shift($shift_id) {
}
return $result;
}
return null;
}
/**