From d71e7bbfad2f07f82df0c515608996d250fd4182 Mon Sep 17 00:00:00 2001 From: Bot Date: Mon, 2 Jan 2017 15:43:36 +0100 Subject: Formatting --- includes/model/AngelType_model.php | 44 +++--- includes/model/EventConfig_model.php | 18 ++- includes/model/LogEntries_model.php | 4 +- includes/model/Message_model.php | 33 ++-- includes/model/NeededAngelTypes_model.php | 24 +-- includes/model/Room_model.php | 5 +- includes/model/ShiftEntry_model.php | 29 ++-- includes/model/ShiftSignupState.php | 182 +++++++++++----------- includes/model/ShiftTypes_model.php | 19 ++- includes/model/ShiftsFilter.php | 60 ++++---- includes/model/Shifts_model.php | 229 ++++++++++++++++++---------- includes/model/UserAngelTypes_model.php | 53 ++++--- includes/model/UserDriverLicenses_model.php | 23 +-- includes/model/UserGroups_model.php | 1 + includes/model/User_model.php | 65 ++++---- includes/model/ValidationResult.php | 54 +++---- 16 files changed, 481 insertions(+), 362 deletions(-) (limited to 'includes/model') diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 022462c0..d52b1357 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -8,17 +8,17 @@ use Engelsystem\ValidationResult; function AngelType_new() { return [ - 'id' => null, - 'name' => "", - 'restricted' => false, - 'no_self_signup' => false, - 'description' => '', - 'requires_driver_license' => false, - 'contact_user_id' => null, - 'contact_name' => null, - 'contact_dect' => null, - 'contact_email' => null - ]; + 'id' => null, + 'name' => "", + 'restricted' => false, + 'no_self_signup' => false, + 'description' => '', + 'requires_driver_license' => false, + 'contact_user_id' => null, + 'contact_name' => null, + 'contact_dect' => null, + 'contact_email' => null + ]; } /** @@ -30,7 +30,7 @@ function AngelType_new() */ function AngelType_validate_contact_user_id($angeltype) { - if (! isset($angeltype['contact_user_id'])) { + if (!isset($angeltype['contact_user_id'])) { return new ValidationResult(true, null); } if (isset($angeltype['contact_name']) || isset($angeltype['contact_dect']) || isset($angeltype['contact_email'])) { @@ -53,9 +53,9 @@ function AngelType_contact_info($angeltype) if (isset($angeltype['contact_user_id'])) { $contact_user = User($angeltype['contact_user_id']); $contact_data = [ - 'contact_name' => $contact_user['Nick'], - 'contact_dect' => $contact_user['DECT'] - ]; + 'contact_name' => $contact_user['Nick'], + 'contact_dect' => $contact_user['DECT'] + ]; if ($contact_user['email_by_human_allowed']) { $contact_data['contact_email'] = $contact_user['email']; } @@ -63,10 +63,10 @@ function AngelType_contact_info($angeltype) } if (isset($angeltype['contact_name'])) { return [ - 'contact_name' => $angeltype['contact_name'], - 'contact_dect' => $angeltype['contact_dect'], - 'contact_email' => $angeltype['contact_email'] - ]; + 'contact_name' => $angeltype['contact_name'], + 'contact_dect' => $angeltype['contact_dect'], + 'contact_email' => $angeltype['contact_email'] + ]; } return null; } @@ -148,7 +148,7 @@ function AngelType_create($angeltype) * Validates a name for angeltypes. * Returns ValidationResult containing validation success and validated name. * - * @param string $name + * @param string $name * Wanted name for the angeltype * @param AngelType $angeltype * The angeltype the name is for @@ -186,7 +186,7 @@ function AngelTypes_with_user($user) { $result = sql_select(" SELECT `AngelTypes`.*, - `UserAngelTypes`.`id` as `user_angeltype_id`, + `UserAngelTypes`.`id` AS `user_angeltype_id`, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter` FROM `AngelTypes` @@ -230,7 +230,7 @@ function AngelType_ids() * Returns angelType by id. * * @param $angeltype_id angelType - * ID + * ID */ function AngelType($angeltype_id) { diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php index b4fdb728..584c1515 100644 --- a/includes/model/EventConfig_model.php +++ b/includes/model/EventConfig_model.php @@ -20,14 +20,20 @@ function EventConfig() * Update event config. * * @param string $event_name - * @param int $buildup_start_date - * @param int $event_start_date - * @param int $event_end_date - * @param int $teardown_end_date + * @param int $buildup_start_date + * @param int $event_start_date + * @param int $event_end_date + * @param int $teardown_end_date * @param string $event_welcome_msg */ -function EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg) -{ +function EventConfig_update( + $event_name, + $buildup_start_date, + $event_start_date, + $event_end_date, + $teardown_end_date, + $event_welcome_msg +) { if (EventConfig() == null) { return sql_query("INSERT INTO `EventConfig` SET `event_name`=" . sql_null($event_name) . ", diff --git a/includes/model/LogEntries_model.php b/includes/model/LogEntries_model.php index 2a3a1d6e..47e48f6f 100644 --- a/includes/model/LogEntries_model.php +++ b/includes/model/LogEntries_model.php @@ -3,9 +3,9 @@ /** * Creates a log entry. * - * @param $nick Username + * @param $nick Username * @param $message Log - * Message + * Message */ function LogEntry_create($nick, $message) { diff --git a/includes/model/Message_model.php b/includes/model/Message_model.php index 6ee19792..39eada71 100644 --- a/includes/model/Message_model.php +++ b/includes/model/Message_model.php @@ -12,7 +12,7 @@ function Message_ids() * Returns message by id. * * @param $message_id message - * ID + * ID */ function Message($message_id) { @@ -32,21 +32,36 @@ function Message($message_id) * send message * * @param $receiver_user_id User - * ID of Reciever - * @param $text Text - * of Message + * ID of Reciever + * @param $text Text + * of Message */ function Message_send($receiver_user_id, $text) { global $user; - + $text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($text)); $receiver_user_id = preg_replace("/([^0-9]{1,})/ui", '', strip_tags($receiver_user_id)); - - if (($text != "" && is_numeric($receiver_user_id)) && (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($receiver_user_id) . "' AND NOT `UID`='" . sql_escape($user['UID']) . "' LIMIT 1") > 0)) { - sql_query("INSERT INTO `Messages` SET `Datum`='" . sql_escape(time()) . "', `SUID`='" . sql_escape($user['UID']) . "', `RUID`='" . sql_escape($receiver_user_id) . "', `Text`='" . sql_escape($text) . "'"); + + if ( + ($text != "" && is_numeric($receiver_user_id)) + && (sql_num_query(" + SELECT * + FROM `User` + WHERE `UID`='" . sql_escape($receiver_user_id) . "' + AND NOT `UID`='" . sql_escape($user['UID']) . "' + LIMIT 1 + ") > 0) + ) { + sql_query(" + INSERT INTO `Messages` + SET `Datum`='" . sql_escape(time()) . "', + `SUID`='" . sql_escape($user['UID']) . "', + `RUID`='" . sql_escape($receiver_user_id) . "', + `Text`='" . sql_escape($text) . "' + "); return true; } - + return false; } diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php index e2661b9a..6a929f2f 100644 --- a/includes/model/NeededAngelTypes_model.php +++ b/includes/model/NeededAngelTypes_model.php @@ -71,10 +71,10 @@ function NeededAngelTypes_by_shift($shiftId) if ($needed_angeltypes_source === false) { engelsystem_error("Unable to load needed angeltypes."); } - - // Use settings from room - if (count($needed_angeltypes_source) == 0) { - $needed_angeltypes_source = sql_select(" + + // Use settings from room + if (count($needed_angeltypes_source) == 0) { + $needed_angeltypes_source = sql_select(" SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted` FROM `NeededAngelTypes` JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` @@ -83,11 +83,11 @@ function NeededAngelTypes_by_shift($shiftId) AND `count` > 0 ORDER BY `room_id` DESC "); - if ($needed_angeltypes_source === false) { - engelsystem_error("Unable to load needed angeltypes."); - } - } - + if ($needed_angeltypes_source === false) { + engelsystem_error("Unable to load needed angeltypes."); + } + } + $shift_entries = ShiftEntries_by_shift($shiftId); $needed_angeltypes = []; foreach ($needed_angeltypes_source as $angeltype) { @@ -95,13 +95,13 @@ function NeededAngelTypes_by_shift($shiftId) $angeltype['taken'] = 0; foreach ($shift_entries as $shift_entry) { if ($shift_entry['TID'] == $angeltype['angel_type_id'] && $shift_entry['freeloaded'] == 0) { - $angeltype['taken'] ++; + $angeltype['taken']++; $angeltype['shift_entries'][] = $shift_entry; } } - + $needed_angeltypes[] = $angeltype; } - + return $needed_angeltypes; } diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php index d7031d84..4c097f23 100644 --- a/includes/model/Room_model.php +++ b/includes/model/Room_model.php @@ -2,6 +2,7 @@ /** * returns a list of rooms. + * * @param boolean $show_all returns also hidden rooms when true */ function Rooms($show_all = false) @@ -22,7 +23,7 @@ function Room_delete($room_id) /** * Create a new room * - * @param string $name + * @param string $name * Name of the room * @param boolean $from_frab * Is this a frab imported room? @@ -51,7 +52,7 @@ function Room_create($name, $from_frab, $public) function Room($room_id) { $room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($room_id) . "' AND `show` = 'Y'"); - + if ($room_source === false) { return false; } diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index c25938e3..a0755e3c 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -7,14 +7,14 @@ function ShiftEntry_new() { return [ - 'id' => null, - 'SID' => null, - 'TID' => null, - 'UID' => null, - 'Comment' => null, - 'freeloaded_comment' => null, - 'freeloaded' => false - ]; + 'id' => null, + 'SID' => null, + 'TID' => null, + 'UID' => null, + 'Comment' => null, + 'freeloaded_comment' => null, + 'freeloaded' => false + ]; } /** @@ -31,7 +31,18 @@ function ShiftEntries_freeleaded_count() function ShiftEntries_by_shift($shift_id) { return sql_select(" - SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded` + SELECT + `User`.`Nick`, + `User`.`email`, + `User`.`email_shiftinfo`, + `User`.`Sprache`, + `User`.`Gekommen`, + `ShiftEntry`.`UID`, + `ShiftEntry`.`TID`, + `ShiftEntry`.`SID`, + `AngelTypes`.`name` AS `angel_type_name`, + `ShiftEntry`.`Comment`, + `ShiftEntry`.`freeloaded` FROM `ShiftEntry` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` diff --git a/includes/model/ShiftSignupState.php b/includes/model/ShiftSignupState.php index 9c20a575..d5c7f457 100644 --- a/includes/model/ShiftSignupState.php +++ b/includes/model/ShiftSignupState.php @@ -9,40 +9,40 @@ namespace Engelsystem; class ShiftSignupState { - /** - * Shift has free places - */ - const FREE = 'FREE'; - - /** - * Shift collides with users shifts - */ - const COLLIDES = 'COLLIDES'; - - /** - * User cannot join because of a restricted angeltype or user is not in the angeltype - */ - const ANGELTYPE = 'ANGELTYPE'; - - /** - * Shift is full - */ - const OCCUPIED = 'OCCUPIED'; - - /** - * User is admin and can do what he wants. - */ - const ADMIN = 'ADMIN'; - - /** - * Shift has already ended, no signup - */ - const SHIFT_ENDED = 'SHIFT_ENDED'; - - /** - * User is already signed up - */ - const SIGNED_UP = 'SIGNED_UP'; + /** + * Shift has free places + */ + const FREE = 'FREE'; + + /** + * Shift collides with users shifts + */ + const COLLIDES = 'COLLIDES'; + + /** + * User cannot join because of a restricted angeltype or user is not in the angeltype + */ + const ANGELTYPE = 'ANGELTYPE'; + + /** + * Shift is full + */ + const OCCUPIED = 'OCCUPIED'; + + /** + * User is admin and can do what he wants. + */ + const ADMIN = 'ADMIN'; + + /** + * Shift has already ended, no signup + */ + const SHIFT_ENDED = 'SHIFT_ENDED'; + + /** + * User is already signed up + */ + const SIGNED_UP = 'SIGNED_UP'; private $state; @@ -54,69 +54,69 @@ class ShiftSignupState $this->freeEntries = $free_entries; } - /** - * Combine this state with another state from the same shift. - * - * @param ShiftSignupState $shiftSignupState - * The other state to combine - */ - public function combineWith(ShiftSignupState $shiftSignupState) - { - $this->freeEntries += $shiftSignupState->getFreeEntries(); - - if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) { - $this->state = $shiftSignupState->state; - } - } + /** + * Combine this state with another state from the same shift. + * + * @param ShiftSignupState $shiftSignupState + * The other state to combine + */ + public function combineWith(ShiftSignupState $shiftSignupState) + { + $this->freeEntries += $shiftSignupState->getFreeEntries(); + + if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) { + $this->state = $shiftSignupState->state; + } + } private function valueForState($state) { switch ($state) { - case ShiftSignupState::SHIFT_ENDED: - return 100; - - case ShiftSignupState::SIGNED_UP: - return 90; - - case ShiftSignupState::FREE: - return 80; - - case ShiftSignupState::ANGELTYPE: - case ShiftSignupState::COLLIDES: - return 70; - - case ShiftSignupState::OCCUPIED: - case ShiftSignupState::ADMIN: - return 60; + case ShiftSignupState::SHIFT_ENDED: + return 100; + + case ShiftSignupState::SIGNED_UP: + return 90; + + case ShiftSignupState::FREE: + return 80; + + case ShiftSignupState::ANGELTYPE: + case ShiftSignupState::COLLIDES: + return 70; + + case ShiftSignupState::OCCUPIED: + case ShiftSignupState::ADMIN: + return 60; + } } + + /** + * Returns true, if signup is allowed + */ + public function isSignupAllowed() + { + switch ($this->state) { + case ShiftSignupState::FREE: + case ShiftSignupState::ADMIN: + return true; + } + return false; + } + + /** + * Return the shift signup state + */ + public function getState() + { + return $this->state; } - /** - * Returns true, if signup is allowed - */ - public function isSignupAllowed() - { - switch ($this->state) { - case ShiftSignupState::FREE: - case ShiftSignupState::ADMIN: - return true; + /** + * How many places are free in this shift for the angeltype? + */ + public function getFreeEntries() + { + return $this->freeEntries; } - return false; - } - - /** - * Return the shift signup state - */ - public function getState() - { - return $this->state; - } - - /** - * How many places are free in this shift for the angeltype? - */ - public function getFreeEntries() - { - return $this->freeEntries; - } } diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php index fb361db9..8b1d56b8 100644 --- a/includes/model/ShiftTypes_model.php +++ b/includes/model/ShiftTypes_model.php @@ -2,6 +2,7 @@ /** * Delete a shift type. + * * @param int $shifttype_id */ function ShiftType_delete($shifttype_id) @@ -12,34 +13,38 @@ function ShiftType_delete($shifttype_id) /** * Update a shift type. * - * @param int $shifttype_id + * @param int $shifttype_id * @param string $name - * @param int $angeltype_id + * @param int $angeltype_id * @param string $description */ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) { - return sql_query("UPDATE `ShiftTypes` SET + return sql_query(" + UPDATE `ShiftTypes` SET `name`='" . sql_escape($name) . "', `angeltype_id`=" . sql_null($angeltype_id) . ", `description`='" . sql_escape($description) . "' - WHERE `id`='" . sql_escape($shifttype_id) . "'"); + WHERE `id`='" . sql_escape($shifttype_id) . "' + "); } /** * Create a shift type. * * @param string $name - * @param int $angeltype_id + * @param int $angeltype_id * @param string $description * @return new shifttype id */ function ShiftType_create($name, $angeltype_id, $description) { - $result = sql_query("INSERT INTO `ShiftTypes` SET + $result = sql_query(" + INSERT INTO `ShiftTypes` SET `name`='" . sql_escape($name) . "', `angeltype_id`=" . sql_null($angeltype_id) . ", - `description`='" . sql_escape($description) . "'"); + `description`='" . sql_escape($description) . "' + "); if ($result === false) { return false; } diff --git a/includes/model/ShiftsFilter.php b/includes/model/ShiftsFilter.php index cba6fee7..1e8d49cf 100644 --- a/includes/model/ShiftsFilter.php +++ b/includes/model/ShiftsFilter.php @@ -10,28 +10,28 @@ namespace Engelsystem; class ShiftsFilter { - /** - * How long can the time interval be? - */ - const MAX_DURATION = 86400; - // one day - - /** - * Shift is completely full. - */ - const FILLED_FILLED = 1; - - /** - * Shift has some free slots. - */ - const FILLED_FREE = 0; - - /** - * Has the user "user shifts admin" privilege? - * - * @var boolean - */ - private $userShiftsAdmin; + /** + * How long can the time interval be? + */ + const MAX_DURATION = 86400; + // one day + + /** + * Shift is completely full. + */ + const FILLED_FILLED = 1; + + /** + * Shift has some free slots. + */ + const FILLED_FREE = 0; + + /** + * Has the user "user shifts admin" privilege? + * + * @var boolean + */ + private $userShiftsAdmin; private $filled = []; @@ -48,11 +48,11 @@ class ShiftsFilter $this->user_shifts_admin = $user_shifts_admin; $this->rooms = $rooms; $this->types = $types; - + $this->filled = [ - ShiftsFilter::FILLED_FREE - ]; - + ShiftsFilter::FILLED_FREE + ]; + if ($user_shifts_admin) { $this->filled[] = ShiftsFilter::FILLED_FILLED; } @@ -84,9 +84,7 @@ class ShiftsFilter public function getTypes() { if (count($this->types) == 0) { - return [ - 0 - ]; + return [0]; } return $this->types; } @@ -99,9 +97,7 @@ class ShiftsFilter public function getRooms() { if (count($this->rooms) == 0) { - return [ - 0 - ]; + return [0]; } return $this->rooms; } diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 0d49f5da..c489c63e 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -14,7 +14,7 @@ function Shifts_by_room($room) function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) { $SQL = "SELECT * FROM ( - SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name` + SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` AS `room_name` FROM `Shifts` JOIN `Room` USING (`RID`) JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id` @@ -27,7 +27,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) UNION - SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name` + SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` AS `room_name` FROM `Shifts` JOIN `Room` USING (`RID`) JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id` @@ -36,7 +36,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . " AND `NeededAngelTypes`.`angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ") AND `NeededAngelTypes`.`count` > 0 - AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts + AND NOT `Shifts`.`PSID` IS NULL) AS tmp_shifts ORDER BY `start`"; $result = sql_select($SQL); @@ -48,7 +48,14 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) { - $SQL = "SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` + $SQL = " + SELECT + `NeededAngelTypes`.*, + `Shifts`.`SID`, + `AngelTypes`.`id`, + `AngelTypes`.`name`, + `AngelTypes`.`restricted`, + `AngelTypes`.`no_self_signup` FROM `Shifts` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID` JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id` @@ -58,7 +65,13 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) UNION - SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` + SELECT + `NeededAngelTypes`.*, + `Shifts`.`SID`, + `AngelTypes`.`id`, + `AngelTypes`.`name`, + `AngelTypes`.`restricted`, + `AngelTypes`.`no_self_signup` FROM `Shifts` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID` JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id` @@ -74,7 +87,14 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) { - $result = sql_select("SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` + $result = sql_select(" + SELECT + `NeededAngelTypes`.*, + `Shifts`.`SID`, + `AngelTypes`.`id`, + `AngelTypes`.`name`, + `AngelTypes`.`restricted`, + `AngelTypes`.`no_self_signup` FROM `Shifts` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID` JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id` @@ -84,7 +104,13 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) UNION - SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` + SELECT + `NeededAngelTypes`.*, + `Shifts`.`SID`, + `AngelTypes`.`id`, + `AngelTypes`.`name`, + `AngelTypes`.`restricted`, + `AngelTypes`.`no_self_signup` FROM `Shifts` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID` JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id` @@ -102,7 +128,18 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) { - $SQL = "SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded` + $SQL = " + SELECT + `User`.`Nick`, + `User`.`email`, + `User`.`email_shiftinfo`, + `User`.`Sprache`, + `User`.`Gekommen`, + `ShiftEntry`.`UID`, + `ShiftEntry`.`TID`, + `ShiftEntry`.`SID`, + `ShiftEntry`.`Comment`, + `ShiftEntry`.`freeloaded` FROM `Shifts` JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` @@ -120,13 +157,13 @@ function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) * Check if a shift collides with other shifts (in time). * * @param Shift $shift - * @param array $shifts + * @param array $shifts */ function Shift_collides($shift, $shifts) { foreach ($shifts as $other_shift) { if ($shift['SID'] != $other_shift['SID']) { - if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) { + if (!($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) { return true; } } @@ -142,7 +179,7 @@ function Shift_free_entries($needed_angeltype, $shift_entries) $taken = 0; foreach ($shift_entries as $shift_entry) { if ($shift_entry['freeloaded'] == 0) { - $taken ++; + $taken++; } } return max(0, $needed_angeltype['count'] - $taken); @@ -151,27 +188,35 @@ function Shift_free_entries($needed_angeltype, $shift_entries) /** * Check if shift signup is allowed from the end users point of view (no admin like privileges) * - * @param Shift $shift - * The shift + * @param Shift $shift + * The shift * @param AngelType $angeltype - * The angeltype to which the user wants to sign up - * @param array $user_shifts - * List of the users shifts - * @param boolean $angeltype_supporter - * True, if the user has angeltype supporter rights for the angeltype, which enables him to sign somebody up for the shift. + * The angeltype to which the user wants to sign up + * @param array $user_shifts + * List of the users shifts + * @param boolean $angeltype_supporter + * True, if the user has angeltype supporter rights for the angeltype, which enables him to sign + * somebody up for the shift. */ -function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries) -{ +function Shift_signup_allowed_angel( + $user, + $shift, + $angeltype, + $user_angeltype, + $user_shifts, + $needed_angeltype, + $shift_entries +) { $free_entries = Shift_free_entries($needed_angeltype, $shift_entries); - + if ($user['Gekommen'] == 0) { return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries); } - + if ($user_shifts == null) { $user_shifts = Shifts_by_user($user); } - + $signed_up = false; foreach ($user_shifts as $user_shift) { if ($user_shift['SID'] == $shift['SID']) { @@ -179,40 +224,44 @@ function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, break; } } - + if ($signed_up) { // you cannot join if you already singed up for this shift - return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries); + return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries); } - + if (time() > $shift['start']) { // you can only join if the shift is in future - return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries); + return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries); } if ($free_entries == 0) { // you cannot join if shift is full - return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries); + return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries); } - + if ($user_angeltype == null) { $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); } - - if ($user_angeltype == null || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) || ($angeltype['restricted'] == 1 && $user_angeltype != null && ! isset($user_angeltype['confirm_user_id']))) { + + if ( + $user_angeltype == null + || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) + || ($angeltype['restricted'] == 1 && $user_angeltype != null && !isset($user_angeltype['confirm_user_id'])) + ) { // you cannot join if user is not of this angel type - // you cannot join if you are not confirmed - // you cannot join if angeltype has no self signup - - return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries); + // you cannot join if you are not confirmed + // you cannot join if angeltype has no self signup + + return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries); } - + if (Shift_collides($shift, $user_shifts)) { // you cannot join if user alread joined a parallel or this shift - return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries); + return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries); } - - // Hooray, shift is free for you! - return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); + + // Hooray, shift is free for you! + return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); } /** @@ -224,14 +273,14 @@ function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, if ($free_entries == 0) { return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries); } - + return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); } /** * Check if an admin can sign up a user to a shift. * - * @param Shift $shift + * @param Shift $shift * The shift * @param AngelType $angeltype * The angeltype to which the user wants to sign up @@ -239,38 +288,56 @@ function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries) { $free_entries = Shift_free_entries($needed_angeltype, $shift_entries); - + if ($free_entries == 0) { // User shift admins may join anybody in every shift - return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries); + return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries); } - + return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); } /** * Check if an angel can sign up for given shift. * - * @param Shift $shift - * The shift + * @param Shift $shift + * The shift * @param AngelType $angeltype - * The angeltype to which the user wants to sign up - * @param array $user_shifts - * List of the users shifts + * The angeltype to which the user wants to sign up + * @param array $user_shifts + * List of the users shifts */ -function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries) -{ +function Shift_signup_allowed( + $signup_user, + $shift, + $angeltype, + $user_angeltype = null, + $user_shifts = null, + $needed_angeltype, + $shift_entries +) { global $user, $privileges; - + if (in_array('user_shifts_admin', $privileges)) { return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries); } - - if (in_array('shiftentry_edit_angeltype_supporter', $privileges) && User_is_AngelType_supporter($user, $angeltype)) { + + if ( + in_array('shiftentry_edit_angeltype_supporter', $privileges) + && User_is_AngelType_supporter($user, $angeltype) + ) { return Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries); } - - return Shift_signup_allowed_angel($signup_user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries); + + return Shift_signup_allowed_angel( + $signup_user, + $shift, + $angeltype, + $user_angeltype, + $user_shifts, + $needed_angeltype, + $shift_entries + ); } /** @@ -287,7 +354,7 @@ function Shift_delete_by_psid($shift_psid) function Shift_delete($shift_id) { mail_shift_delete(Shift($shift_id)); - + $result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'"); if ($result === false) { engelsystem_error('Unable to delete shift.'); @@ -303,8 +370,9 @@ function Shift_update($shift) global $user; $shift['name'] = ShiftType($shift['shifttype_id'])['name']; mail_shift_change(Shift($shift['SID']), $shift); - - return sql_query("UPDATE `Shifts` SET + + return sql_query(" + UPDATE `Shifts` SET `shifttype_id`='" . sql_escape($shift['shifttype_id']) . "', `start`='" . sql_escape($shift['start']) . "', `end`='" . sql_escape($shift['end']) . "', @@ -314,7 +382,8 @@ function Shift_update($shift) `PSID`=" . sql_null($shift['PSID']) . ", `edited_by_user_id`='" . sql_escape($user['UID']) . "', `edited_at_timestamp`=" . time() . " - WHERE `SID`='" . sql_escape($shift['SID']) . "'"); + WHERE `SID`='" . sql_escape($shift['SID']) . "' + "); } /** @@ -341,7 +410,8 @@ function Shift_update_by_psid($shift) function Shift_create($shift) { global $user; - $result = sql_query("INSERT INTO `Shifts` SET + $result = sql_query(" + INSERT INTO `Shifts` SET `shifttype_id`='" . sql_escape($shift['shifttype_id']) . "', `start`='" . sql_escape($shift['start']) . "', `end`='" . sql_escape($shift['end']) . "', @@ -350,7 +420,8 @@ function Shift_create($shift) `URL`=" . sql_null($shift['URL']) . ", `PSID`=" . sql_null($shift['PSID']) . ", `created_by_user_id`='" . sql_escape($user['UID']) . "', - `created_at_timestamp`=" . time()); + `created_at_timestamp`=" . time() + ); if ($result === false) { return false; } @@ -384,7 +455,7 @@ function Shifts_by_user($user, $include_freeload_comments = false) * Returns Shift by id. * * @param $shift_id Shift - * ID + * ID */ function Shift($shift_id) { @@ -394,30 +465,30 @@ function Shift($shift_id) JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) WHERE `SID`='" . sql_escape($shift_id) . "'"); $shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'"); - + if ($shifts_source === false) { engelsystem_error('Unable to load shift.'); } - + if (empty($shifts_source)) { return null; } - + $result = $shifts_source[0]; - + $result['ShiftEntry'] = $shiftsEntry_source; $result['NeedAngels'] = []; - + $temp = NeededAngelTypes_by_shift($shift_id); foreach ($temp as $e) { $result['NeedAngels'][] = [ - 'TID' => $e['angel_type_id'], - 'count' => $e['count'], - 'restricted' => $e['restricted'], - 'taken' => $e['taken'] - ]; + 'TID' => $e['angel_type_id'], + 'count' => $e['count'], + 'restricted' => $e['restricted'], + 'taken' => $e['taken'] + ]; } - + return $result; } @@ -427,7 +498,7 @@ function Shift($shift_id) function Shifts() { $shifts_source = sql_select(" - SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`RID`, `Room`.`Name` as `room_name` + SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`RID`, `Room`.`Name` AS `room_name` FROM `Shifts` JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID` @@ -435,15 +506,15 @@ function Shifts() if ($shifts_source === false) { return false; } - + foreach ($shifts_source as &$shift) { $needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']); if ($needed_angeltypes === false) { return false; } - + $shift['angeltypes'] = $needed_angeltypes; } - + return $shifts_source; } diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index ea7a454c..fae2b996 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -7,7 +7,7 @@ /** * Checks if a user joined an angeltype. * - * @param User $user + * @param User $user * The user to be checked * @param Angeltype $angeltype * The angeltype to be checked @@ -51,19 +51,20 @@ function User_angeltypes($user) function User_unconfirmed_AngelTypes($user) { $result = sql_select(" - SELECT - `UserAngelTypes`.*, - `AngelTypes`.`name`, - count(`UnconfirmedMembers`.`user_id`) as `count` - FROM `UserAngelTypes` - JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` - JOIN `UserAngelTypes` as `UnconfirmedMembers` ON `UserAngelTypes`.`angeltype_id`=`UnconfirmedMembers`.`angeltype_id` - WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "' - AND `UserAngelTypes`.`supporter`=TRUE - AND `AngelTypes`.`restricted`=TRUE - AND `UnconfirmedMembers`.`confirm_user_id` IS NULL - GROUP BY `UserAngelTypes`.`angeltype_id` - ORDER BY `AngelTypes`.`name`"); + SELECT + `UserAngelTypes`.*, + `AngelTypes`.`name`, + count(`UnconfirmedMembers`.`user_id`) AS `count` + FROM `UserAngelTypes` + JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` + JOIN `UserAngelTypes` AS `UnconfirmedMembers` ON `UserAngelTypes`.`angeltype_id`=`UnconfirmedMembers`.`angeltype_id` + WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "' + AND `UserAngelTypes`.`supporter`=TRUE + AND `AngelTypes`.`restricted`=TRUE + AND `UnconfirmedMembers`.`confirm_user_id` IS NULL + GROUP BY `UserAngelTypes`.`angeltype_id` + ORDER BY `AngelTypes`.`name` + "); if ($result === false) { engelsystem_error("Unable to load user angeltypes."); } @@ -73,7 +74,7 @@ function User_unconfirmed_AngelTypes($user) /** * Returns true if user is angeltype supporter or has privilege admin_user_angeltypes. * - * @param User $user + * @param User $user * @param AngelType $angeltype */ function User_is_AngelType_supporter(&$user, $angeltype) @@ -87,13 +88,14 @@ function User_is_AngelType_supporter(&$user, $angeltype) WHERE `user_id`='" . sql_escape($user['UID']) . "' AND `angeltype_id`='" . sql_escape($angeltype['id']) . "' AND `supporter`=TRUE - LIMIT 1") > 0) || in_array('admin_user_angeltypes', $user['privileges']); + LIMIT 1 + ") > 0) || in_array('admin_user_angeltypes', $user['privileges']); } /** * Add or remove supporter rights. * - * @param int $user_angeltype_id + * @param int $user_angeltype_id * @param bool $supporter */ function UserAngelType_update($user_angeltype_id, $supporter) @@ -102,7 +104,8 @@ function UserAngelType_update($user_angeltype_id, $supporter) UPDATE `UserAngelTypes` SET `supporter`=" . sql_bool($supporter) . " WHERE `id`='" . sql_escape($user_angeltype_id) . "' - LIMIT 1"); + LIMIT 1 + "); if ($result === false) { engelsystem_error("Unable to update supporter rights."); } @@ -119,7 +122,8 @@ function UserAngelTypes_delete_all($angeltype_id) $result = sql_query(" DELETE FROM `UserAngelTypes` WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "' - AND `confirm_user_id` IS NULL"); + AND `confirm_user_id` IS NULL + "); if ($result === false) { engelsystem_error("Unable to delete all unconfirmed users."); } @@ -129,7 +133,7 @@ function UserAngelTypes_delete_all($angeltype_id) /** * Confirm all unconfirmed UserAngelTypes for given Angeltype. * - * @param int $angeltype_id + * @param int $angeltype_id * @param User $confirm_user */ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) @@ -138,7 +142,8 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) UPDATE `UserAngelTypes` SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "' WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "' - AND `confirm_user_id` IS NULL"); + AND `confirm_user_id` IS NULL + "); if ($result === false) { engelsystem_error("Unable to confirm all users."); } @@ -148,7 +153,7 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) /** * Confirm an UserAngelType with confirming user. * - * @param int $user_angeltype_id + * @param int $user_angeltype_id * @param User $confirm_user */ function UserAngelType_confirm($user_angeltype_id, $confirm_user) @@ -180,7 +185,7 @@ function UserAngelType_delete($user_angeltype) /** * Create an UserAngelType. * - * @param User $user + * @param User $user * @param Angeltype $angeltype */ function UserAngelType_create($user, $angeltype) @@ -219,7 +224,7 @@ function UserAngelType($user_angeltype_id) /** * Get an UserAngelType by user and angeltype. * - * @param User $user + * @param User $user * @param Angeltype $angeltype */ function UserAngelType_by_User_and_AngelType($user, $angeltype) diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php index 7d1be528..a36b79c1 100644 --- a/includes/model/UserDriverLicenses_model.php +++ b/includes/model/UserDriverLicenses_model.php @@ -7,14 +7,14 @@ function UserDriverLicense_new() { return [ - 'user_id' => null, - 'has_car' => false, - 'has_license_car' => false, - 'has_license_3_5t_transporter' => false, - 'has_license_7_5t_truck' => false, - 'has_license_12_5t_truck' => false, - 'has_license_forklift' => false - ]; + 'user_id' => null, + 'has_car' => false, + 'has_license_car' => false, + 'has_license_3_5t_transporter' => false, + 'has_license_7_5t_truck' => false, + 'has_license_12_5t_truck' => false, + 'has_license_forklift' => false + ]; } /** @@ -26,7 +26,12 @@ function UserDriverLicense_new() */ function UserDriverLicense_valid($user_driver_license) { - return $user_driver_license['has_car'] || $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift']; + return $user_driver_license['has_car'] + || $user_driver_license['has_license_car'] + || $user_driver_license['has_license_3_5t_transporter'] + || $user_driver_license['has_license_7_5t_truck'] + || $user_driver_license['has_license_12_5t_truck'] + || $user_driver_license['has_license_forklift']; } /** diff --git a/includes/model/UserGroups_model.php b/includes/model/UserGroups_model.php index 61fd074a..bbef85b6 100644 --- a/includes/model/UserGroups_model.php +++ b/includes/model/UserGroups_model.php @@ -2,6 +2,7 @@ /** * Returns users groups + * * @param User $user */ function User_groups($user) diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 9324bf53..1a09c160 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -22,7 +22,8 @@ function User_delete($user_id) */ function User_update($user) { - return sql_query("UPDATE `User` SET + return sql_query(" + UPDATE `User` SET `Nick`='" . sql_escape($user['Nick']) . "', `Name`='" . sql_escape($user['Name']) . "', `Vorname`='" . sql_escape($user['Vorname']) . "', @@ -46,7 +47,8 @@ function User_update($user) `arrival_date`='" . sql_escape($user['arrival_date']) . "', `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "', `planned_departure_date`=" . sql_null($user['planned_departure_date']) . " - WHERE `UID`='" . sql_escape($user['UID']) . "'"); + WHERE `UID`='" . sql_escape($user['UID']) . "' + "); } /** @@ -83,19 +85,19 @@ function User_tshirts_count() function User_sortable_columns() { return [ - 'Nick', - 'Name', - 'Vorname', - 'Alter', - 'DECT', - 'email', - 'Size', - 'Gekommen', - 'Aktiv', - 'force_active', - 'Tshirt', - 'lastLogIn' - ]; + 'Nick', + 'Name', + 'Vorname', + 'Alter', + 'DECT', + 'email', + 'Size', + 'Gekommen', + 'Aktiv', + 'force_active', + 'Tshirt', + 'lastLogIn' + ]; } /** @@ -116,7 +118,7 @@ function Users($order_by = 'Nick') function User_is_freeloader($user) { global $max_freeloadable_shifts, $user; - + return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts; } @@ -130,7 +132,8 @@ function Users_by_angeltype_inverted($angeltype) $result = sql_select(" SELECT `User`.* FROM `User` - LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "') + LEFT JOIN `UserAngelTypes` + ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "') WHERE `UserAngelTypes`.`id` IS NULL ORDER BY `Nick`"); if ($result === false) { @@ -149,7 +152,7 @@ function Users_by_angeltype($angeltype) $result = sql_select(" SELECT `User`.*, - `UserAngelTypes`.`id` as `user_angeltype_id`, + `UserAngelTypes`.`id` AS `user_angeltype_id`, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter`, `UserDriverLicenses`.* @@ -207,7 +210,7 @@ function User_validate_jabber($jabber) $jabber = strip_item($jabber); if ($jabber == '') { // Empty is ok - return new ValidationResult(true, ''); + return new ValidationResult(true, ''); } return new ValidationResult(check_email($jabber), $jabber); } @@ -223,20 +226,20 @@ function User_validate_planned_arrival_date($planned_arrival_date) { if ($planned_arrival_date == null) { // null is not okay - return new ValidationResult(false, time()); + return new ValidationResult(false, time()); } $event_config = EventConfig(); if ($event_config == null) { // Nothing to validate against - return new ValidationResult(true, $planned_arrival_date); + return new ValidationResult(true, $planned_arrival_date); } if (isset($event_config['buildup_start_date']) && $planned_arrival_date < $event_config['buildup_start_date']) { // Planned arrival can not be before buildup start date - return new ValidationResult(false, $event_config['buildup_start_date']); + return new ValidationResult(false, $event_config['buildup_start_date']); } if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) { // Planned arrival can not be after teardown end date - return new ValidationResult(false, $event_config['teardown_end_date']); + return new ValidationResult(false, $event_config['teardown_end_date']); } return new ValidationResult(true, $planned_arrival_date); } @@ -254,24 +257,24 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de { if ($planned_departure_date == null) { // null is okay - return new ValidationResult(true, null); + return new ValidationResult(true, null); } if ($planned_arrival_date > $planned_departure_date) { // departure cannot be before arrival - return new ValidationResult(false, $planned_arrival_date); + return new ValidationResult(false, $planned_arrival_date); } $event_config = EventConfig(); if ($event_config == null) { // Nothing to validate against - return new ValidationResult(true, $planned_departure_date); + return new ValidationResult(true, $planned_departure_date); } if (isset($event_config['buildup_start_date']) && $planned_departure_date < $event_config['buildup_start_date']) { // Planned arrival can not be before buildup start date - return new ValidationResult(false, $event_config['buildup_start_date']); + return new ValidationResult(false, $event_config['buildup_start_date']); } if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) { // Planned arrival can not be after teardown end date - return new ValidationResult(false, $event_config['teardown_end_date']); + return new ValidationResult(false, $event_config['teardown_end_date']); } return new ValidationResult(true, $planned_departure_date); } @@ -384,14 +387,14 @@ function User_generate_password_recovery_token(&$user) function User_get_eligable_voucher_count(&$user) { global $voucher_settings; - + $shifts_done = count(ShiftEntries_finished_by_user($user)); - + $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers']; $elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers; if ($elegible_vouchers < 0) { return 0; } - + return $elegible_vouchers; } diff --git a/includes/model/ValidationResult.php b/includes/model/ValidationResult.php index 7dfcb5ba..b08e9d31 100644 --- a/includes/model/ValidationResult.php +++ b/includes/model/ValidationResult.php @@ -12,33 +12,33 @@ class ValidationResult private $value; - /** - * Constructor. - * - * @param boolean $valid - * Is the value valid? - * @param * $value - * The validated value - */ - public function __construct($valid, $value) - { - $this->valid = $valid; - $this->value = $value; - } + /** + * Constructor. + * + * @param boolean $valid + * Is the value valid? + * @param * $value + * The validated value + */ + public function __construct($valid, $value) + { + $this->valid = $valid; + $this->value = $value; + } - /** - * Is the value valid? - */ - public function isValid() - { - return $this->valid; - } + /** + * Is the value valid? + */ + public function isValid() + { + return $this->valid; + } - /** - * The parsed/validated value. - */ - public function getValue() - { - return $this->value; - } + /** + * The parsed/validated value. + */ + public function getValue() + { + return $this->value; + } } -- cgit v1.2.3-54-g00ecf