From f7d499b362f3fb5eeac041f65183d03237ed5a2e Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Tue, 18 Oct 2022 19:15:22 +0200 Subject: [PATCH] Include phpcs for /includes --- .phpcs.xml | 6 +++- includes/application.php | 1 + includes/controller/angeltypes_controller.php | 3 +- includes/controller/shifts_controller.php | 7 +++-- .../controller/user_angeltypes_controller.php | 10 +++---- .../user_driver_licenses_controller.php | 2 +- includes/controller/users_controller.php | 24 ++++++++++----- includes/includes.php | 1 + includes/mailer/shifts_mailer.php | 16 +++++----- includes/model/AngelType_model.php | 6 ++-- includes/model/NeededAngelTypes_model.php | 9 ++++-- includes/model/ShiftEntry_model.php | 21 ++++++++----- includes/model/ShiftTypes_model.php | 6 ++-- includes/model/Shifts_model.php | 15 ++++++---- includes/model/Stats.php | 14 ++++----- includes/model/UserAngelTypes_model.php | 15 ++++++---- includes/model/UserGroups_model.php | 3 +- includes/model/UserWorkLog_model.php | 2 -- includes/model/User_model.php | 22 +++++++------- includes/pages/admin_active.php | 16 +++++++--- includes/pages/admin_groups.php | 6 ++-- includes/pages/admin_shifts.php | 25 +++++++++------- includes/pages/admin_user.php | 9 ++++-- includes/pages/guest_login.php | 26 +++++++++++----- includes/pages/user_atom.php | 8 ++--- includes/pages/user_myshifts.php | 3 +- includes/pages/user_shifts.php | 5 ++-- includes/sys_page.php | 2 +- includes/sys_template.php | 4 +-- includes/view/AngelTypes_view.php | 30 +++++++++++-------- includes/view/ShiftCalendarRenderer.php | 12 ++++---- includes/view/ShiftCalendarShiftRenderer.php | 6 ++-- includes/view/ShiftEntry_view.php | 21 ++++++++----- includes/view/Shifts_view.php | 16 +++++----- includes/view/UserHintsRenderer.php | 5 +++- includes/view/User_view.php | 12 ++++---- 36 files changed, 239 insertions(+), 150 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index a7a5325d..707dbc41 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -4,6 +4,7 @@ config db + includes public/index.php src tests @@ -18,5 +19,8 @@ - + + + /includes + diff --git a/includes/application.php b/includes/application.php index 9be48860..17c5ece5 100644 --- a/includes/application.php +++ b/includes/application.php @@ -6,6 +6,7 @@ use Engelsystem\Config\Config; /** * Include the autoloader */ + require_once __DIR__ . '/autoload.php'; /** diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 6d2380b1..17631412 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -305,7 +305,8 @@ function angeltypes_list_controller() $angeltype['membership'] = AngelType_render_membership($angeltype); if (!empty($angeltype['user_angeltype_id'])) { $actions[] = button( - page_link_to('user_angeltypes', + page_link_to( + 'user_angeltypes', ['action' => 'delete', 'user_angeltype_id' => $angeltype['user_angeltype_id']] ), __('leave'), diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index aee03dca..50d9af97 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -186,8 +186,11 @@ function shift_edit_controller() $angel_types_spinner = ''; foreach ($angeltypes as $angeltype_id => $angeltype_name) { - $angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name, - $needed_angel_types[$angeltype_id]); + $angel_types_spinner .= form_spinner( + 'type_' . $angeltype_id, + $angeltype_name, + $needed_angel_types[$angeltype_id] + ); } return page_with_title( diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 0b6c29ad..a0d4500b 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -28,11 +28,11 @@ function user_angeltypes_unconfirmed_hint() $count = count($unconfirmed_user_angeltypes); return _e( - 'There is %d unconfirmed angeltype.', - 'There are %d unconfirmed angeltypes.', - $count, - [$count] - ) + 'There is %d unconfirmed angeltype.', + 'There are %d unconfirmed angeltypes.', + $count, + [$count] + ) . ' ' . __('Angel types which need approvals:') . ' ' . join(', ', $unconfirmed_links); } diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index 26a1aa3f..c04fb1f3 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -110,7 +110,7 @@ function user_driver_license_edit_controller() $driverLicense->drive_car = $request->has('has_license_car'); $driverLicense->drive_3_5t = $request->has('has_license_3_5t_transporter'); $driverLicense->drive_7_5t = $request->has('has_license_7_5t_truck'); - $driverLicense->drive_12t= $request->has('has_license_12t_truck'); + $driverLicense->drive_12t = $request->has('has_license_12t_truck'); $driverLicense->drive_forklift = $request->has('has_license_forklift'); if ($driverLicense->wantsToDrive()) { diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index fcdb3fcc..b9e9f2a8 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -70,10 +70,12 @@ function user_delete_controller() if ($request->hasPostData('submit')) { $valid = true; - if (!( + if ( + !( $request->has('password') && $auth->verifyPassword($user, $request->postData('password')) - )) { + ) + ) { $valid = false; error(__('auth.password.error')); } @@ -173,8 +175,10 @@ function user_edit_vouchers_controller() $user_source->state->save(); success(__('Saved the number of vouchers.')); - engelsystem_log(User_Nick_render($user_source, true) . ': ' . sprintf('Got %s vouchers', - $user_source->state->got_voucher)); + engelsystem_log(User_Nick_render($user_source, true) . ': ' . sprintf( + 'Got %s vouchers', + $user_source->state->got_voucher + )); throw_redirect(user_link($user_source->id)); } @@ -206,7 +210,8 @@ function user_controller() $shifts = Shifts_by_user($user_source->id, auth()->can('user_shifts_admin')); foreach ($shifts as &$shift) { // TODO: Move queries to model - $shift['needed_angeltypes'] = Db::select(' + $shift['needed_angeltypes'] = Db::select( + ' SELECT DISTINCT `AngelTypes`.* FROM `ShiftEntry` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` @@ -216,7 +221,8 @@ function user_controller() [$shift['SID']] ); foreach ($shift['needed_angeltypes'] as &$needed_angeltype) { - $needed_angeltype['users'] = Db::select(' + $needed_angeltype['users'] = Db::select( + ' SELECT `ShiftEntry`.`freeloaded`, `users`.* FROM `ShiftEntry` JOIN `users` ON `ShiftEntry`.`UID`=`users`.`id` @@ -270,7 +276,8 @@ function users_list_controller() } $order_by = 'name'; - if ($request->has('OrderBy') && in_array($request->input('OrderBy'), [ + if ( + $request->has('OrderBy') && in_array($request->input('OrderBy'), [ 'name', 'first_name', 'last_name', @@ -285,7 +292,8 @@ function users_list_controller() 'planned_arrival_date', 'planned_departure_date', 'last_login_at', - ])) { + ]) + ) { $order_by = $request->input('OrderBy'); } diff --git a/includes/includes.php b/includes/includes.php index 57604d49..34678103 100644 --- a/includes/includes.php +++ b/includes/includes.php @@ -3,6 +3,7 @@ /** * Include legacy code */ + $includeFiles = [ __DIR__ . '/../includes/sys_auth.php', __DIR__ . '/../includes/sys_form.php', diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php index a2384631..78625e49 100644 --- a/includes/mailer/shifts_mailer.php +++ b/includes/mailer/shifts_mailer.php @@ -30,19 +30,19 @@ function mail_shift_change($old_shift, $new_shift) if ($old_shift['start'] != $new_shift['start']) { $message .= sprintf( - __('* Shift Start changed from %s to %s'), - date('Y-m-d H:i', $old_shift['start']), - date('Y-m-d H:i', $new_shift['start']) - ) . "\n"; + __('* Shift Start changed from %s to %s'), + date('Y-m-d H:i', $old_shift['start']), + date('Y-m-d H:i', $new_shift['start']) + ) . "\n"; $noticeable_changes = true; } if ($old_shift['end'] != $new_shift['end']) { $message .= sprintf( - __('* Shift End changed from %s to %s'), - date('Y-m-d H:i', $old_shift['end']), - date('Y-m-d H:i', $new_shift['end']) - ) . "\n"; + __('* Shift End changed from %s to %s'), + date('Y-m-d H:i', $old_shift['end']), + date('Y-m-d H:i', $new_shift['end']) + ) . "\n"; $noticeable_changes = true; } diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 2b67a958..898d9f1d 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -58,7 +58,8 @@ function AngelType_delete($angeltype) */ function AngelType_update($angeltype) { - Db::update(' + Db::update( + ' UPDATE `AngelTypes` SET `name` = ?, `restricted` = ?, @@ -104,7 +105,8 @@ function AngelType_update($angeltype) */ function AngelType_create($angeltype) { - Db::insert(' + Db::insert( + ' INSERT INTO `AngelTypes` ( `name`, `restricted`, diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php index 53a50213..fc47821a 100644 --- a/includes/model/NeededAngelTypes_model.php +++ b/includes/model/NeededAngelTypes_model.php @@ -18,7 +18,8 @@ use Engelsystem\Database\Db; */ function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count) { - Db::insert(' + Db::insert( + ' INSERT INTO `NeededAngelTypes` ( `shift_id`, `angel_type_id`, `room_id`, `count`) VALUES (?, ?, ?, ?) ', @@ -27,7 +28,8 @@ function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count) $angeltype_id, $room_id, $count, - ]); + ] + ); return Db::getPdo()->lastInsertId(); } @@ -77,7 +79,8 @@ function NeededAngelTypes_by_room($room_id) */ function NeededAngelTypes_by_shift($shiftId) { - $needed_angeltypes_source = Db::select(' + $needed_angeltypes_source = Db::select( + ' SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index a8e158bb..136c6b17 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -29,7 +29,8 @@ function ShiftEntries_freeloaded_count() */ function ShiftEntries_by_shift($shift_id) { - return Db::select(' + return Db::select( + ' SELECT `users`.*, `ShiftEntry`.`UID`, @@ -60,7 +61,8 @@ function ShiftEntry_create($shift_entry) $shifttype = ShiftType($shift['shifttype_id']); $room = Room::find($shift['RID']); $angeltype = AngelType($shift_entry['TID']); - $result = Db::insert(' + $result = Db::insert( + ' INSERT INTO `ShiftEntry` ( `SID`, `TID`, @@ -101,7 +103,8 @@ function ShiftEntry_create($shift_entry) */ function ShiftEntry_update($shift_entry) { - Db::update(' + Db::update( + ' UPDATE `ShiftEntry` SET `Comment` = ?, @@ -167,7 +170,8 @@ function ShiftEntry_delete($shiftEntry) */ function ShiftEntries_upcoming_for_user($userId) { - return Db::select(' + return Db::select( + ' SELECT * FROM `ShiftEntry` JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`) @@ -192,7 +196,8 @@ function ShiftEntries_upcoming_for_user($userId) */ function ShiftEntries_finished_by_user($userId, Carbon $sinceTime = null) { - return Db::select(' + return Db::select( + ' SELECT * FROM `ShiftEntry` JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`) @@ -219,7 +224,8 @@ function ShiftEntries_finished_by_user($userId, Carbon $sinceTime = null) */ function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) { - return Db::select(' + return Db::select( + ' SELECT * FROM `ShiftEntry` WHERE `SID` = ? @@ -240,7 +246,8 @@ function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) */ function ShiftEntries_freeloaded_by_user($userId) { - return Db::select(' + return Db::select( + ' SELECT * FROM `ShiftEntry` WHERE `freeloaded` = 1 diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php index d92c44d1..4e8bf74f 100644 --- a/includes/model/ShiftTypes_model.php +++ b/includes/model/ShiftTypes_model.php @@ -22,7 +22,8 @@ function ShiftType_delete($shifttype_id) */ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) { - Db::update(' + Db::update( + ' UPDATE `ShiftTypes` SET `name`=?, `angeltype_id`=?, @@ -48,7 +49,8 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) */ function ShiftType_create($name, $angeltype_id, $description) { - Db::insert(' + Db::insert( + ' INSERT INTO `ShiftTypes` (`name`, `angeltype_id`, `description`) VALUES(?, ?, ?) ', diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 59acf65e..4b428a87 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -197,7 +197,8 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) */ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) { - return Db::selectOne(' + return Db::selectOne( + ' SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, @@ -245,7 +246,8 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) */ function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) { - $sql = sprintf(' + $sql = sprintf( + ' SELECT users.*, `ShiftEntry`.`UID`, @@ -527,7 +529,8 @@ function Shift_update($shift) $shift['name'] = ShiftType($shift['shifttype_id'])['name']; mail_shift_change(Shift($shift['SID']), $shift); - return Db::update(' + return Db::update( + ' UPDATE `Shifts` SET `shifttype_id` = ?, `start` = ?, @@ -564,7 +567,8 @@ function Shift_update($shift) */ function Shift_create($shift, $transactionId = null) { - Db::insert(' + Db::insert( + ' INSERT INTO `Shifts` ( `shifttype_id`, `start`, @@ -607,7 +611,8 @@ function Shift_create($shift, $transactionId = null) */ function Shifts_by_user($userId, $include_freeload_comments = false) { - return Db::select(' + return Db::select( + ' SELECT `rooms`.*, `rooms`.name AS Name, diff --git a/includes/model/Stats.php b/includes/model/Stats.php index f595e328..4968fe3d 100644 --- a/includes/model/Stats.php +++ b/includes/model/Stats.php @@ -23,7 +23,7 @@ function stats_currently_working(ShiftsFilter $filter = null) )) AS `count` FROM `Shifts` WHERE (`end` >= UNIX_TIMESTAMP() AND `start` <= UNIX_TIMESTAMP()) - '. ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') + ' . ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') ); return $result['count'] ?: '-'; @@ -48,7 +48,7 @@ function stats_hours_to_work(ShiftsFilter $filter = null) LEFT JOIN schedule_shift AS s on Shifts.SID = s.shift_id WHERE `end` >= UNIX_TIMESTAMP() AND s.shift_id IS NULL - '. ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' + ' . ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' UNION ALL @@ -59,7 +59,7 @@ function stats_hours_to_work(ShiftsFilter $filter = null) LEFT JOIN schedule_shift AS s on Shifts.SID = s.shift_id WHERE `end` >= UNIX_TIMESTAMP() AND NOT s.shift_id IS NULL - '. ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' + ' . ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' ) AS `tmp` ' ); @@ -102,7 +102,7 @@ function stats_angels_needed_three_hours(ShiftsFilter $filter = null) LEFT JOIN schedule_shift AS s on Shifts.SID = s.shift_id WHERE `end` > UNIX_TIMESTAMP() AND `start` < ? AND s.shift_id IS NULL - '. ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' + ' . ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' UNION ALL @@ -129,7 +129,7 @@ function stats_angels_needed_three_hours(ShiftsFilter $filter = null) LEFT JOIN schedule_shift AS s on Shifts.SID = s.shift_id WHERE `end` > UNIX_TIMESTAMP() AND `start` < ? AND NOT s.shift_id IS NULL - '. ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' + ' . ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' ) AS `tmp`', [ $in3hours, $in3hours @@ -181,7 +181,7 @@ function stats_angels_needed_for_nightshifts(ShiftsFilter $filter = null) LEFT JOIN schedule_shift AS s on Shifts.SID = s.shift_id WHERE `end` > ? AND `start` < ? AND s.shift_id IS NULL - '. ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' + ' . ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' UNION ALL @@ -208,7 +208,7 @@ function stats_angels_needed_for_nightshifts(ShiftsFilter $filter = null) LEFT JOIN schedule_shift AS s on Shifts.SID = s.shift_id WHERE `end` > ? AND `start` < ? AND NOT s.shift_id IS NULL - '. ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' + ' . ($filter ? 'AND Shifts.RID IN (' . implode(',', $filter->getRooms()) . ')' : '') . ' ) AS `tmp`', [ $night_start, $night_end, diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index 7b4a98e5..90871ff1 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -80,7 +80,8 @@ function User_is_AngelType_supporter($user, $angeltype) $privileges = privileges_for_user($user->id); - return (count(Db::select(' + return (count(Db::select( + ' SELECT `id` FROM `UserAngelTypes` WHERE `user_id`=? @@ -88,11 +89,11 @@ function User_is_AngelType_supporter($user, $angeltype) AND `supporter`=TRUE LIMIT 1 ', - [ + [ $user->id, $angeltype['id'] ] - )) > 0) + )) > 0) || in_array('admin_user_angeltypes', $privileges); } @@ -194,7 +195,8 @@ function UserAngelType_delete($user_angeltype) */ function UserAngelType_create($userId, $angeltype) { - Db::insert(' + Db::insert( + ' INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`, `supporter`) VALUES (?, ?, FALSE) ', @@ -233,7 +235,8 @@ function UserAngelType($user_angeltype_id) */ function UserAngelType_by_User_and_AngelType($userId, $angeltype) { - $angelType = Db::selectOne(' + $angelType = Db::selectOne( + ' SELECT * FROM `UserAngelTypes` WHERE `user_id`=? @@ -256,7 +259,7 @@ function UserAngelType_by_User_and_AngelType($userId, $angeltype) * @param bool $onlyConfirmed * @return array[]|null */ -function UserAngelTypes_by_User($userId, $onlyConfirmed=false) +function UserAngelTypes_by_User($userId, $onlyConfirmed = false) { return Db::select( ' diff --git a/includes/model/UserGroups_model.php b/includes/model/UserGroups_model.php index a6cfdfca..5169fc74 100644 --- a/includes/model/UserGroups_model.php +++ b/includes/model/UserGroups_model.php @@ -10,7 +10,8 @@ use Engelsystem\Database\Db; */ function User_groups($userId) { - return Db::select(' + return Db::select( + ' SELECT `Groups`.* FROM `UserGroups` JOIN `Groups` ON `Groups`.`UID`=`UserGroups`.`group_id` diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index e7fa1c62..d564e7b7 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -1,8 +1,6 @@ select('users.*', + ->select( + 'users.*', 'UserAngelTypes.id AS user_angeltype_id', 'UserAngelTypes.confirm_user_id', 'UserAngelTypes.supporter', @@ -151,13 +152,13 @@ function User_validate_planned_arrival_date($planned_arrival_date) $teardown = $config->get('teardown_end'); /** @var Carbon $buildup */ - if (!empty($buildup) && Carbon::createFromTimestamp($planned_arrival_date)->lessThan($buildup->setTime(0,0))) { + if (!empty($buildup) && Carbon::createFromTimestamp($planned_arrival_date)->lessThan($buildup->setTime(0, 0))) { // Planned arrival can not be before buildup start date return new ValidationResult(false, $buildup->getTimestamp()); } /** @var Carbon $teardown */ - if (!empty($teardown) && Carbon::createFromTimestamp($planned_arrival_date)->greaterThanOrEqualTo($teardown->addDay()->setTime(0,0))) { + if (!empty($teardown) && Carbon::createFromTimestamp($planned_arrival_date)->greaterThanOrEqualTo($teardown->addDay()->setTime(0, 0))) { // Planned arrival can not be after teardown end date return new ValidationResult(false, $teardown->getTimestamp()); } @@ -189,13 +190,13 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de $teardown = $config->get('teardown_end'); /** @var Carbon $buildup */ - if (!empty($buildup) && Carbon::createFromTimestamp($planned_departure_date)->lessThan($buildup->setTime(0,0))) { + if (!empty($buildup) && Carbon::createFromTimestamp($planned_departure_date)->lessThan($buildup->setTime(0, 0))) { // Planned departure can not be before buildup start date return new ValidationResult(false, $buildup->getTimestamp()); } /** @var Carbon $teardown */ - if (!empty($teardown) && Carbon::createFromTimestamp($planned_departure_date)->greaterThanOrEqualTo($teardown->addDay()->setTime(0,0))) { + if (!empty($teardown) && Carbon::createFromTimestamp($planned_departure_date)->greaterThanOrEqualTo($teardown->addDay()->setTime(0, 0))) { // Planned departure can not be after teardown end date return new ValidationResult(false, $teardown->getTimestamp()); } @@ -237,18 +238,18 @@ function User_get_eligable_voucher_count($user) + $worklog->count(); $shiftsTime = 0; - foreach ($shifts as $shift){ + foreach ($shifts as $shift) { $shiftsTime += ($shift['end'] - $shift['start']) / 60 / 60; } - foreach ($worklog as $entry){ + foreach ($worklog as $entry) { $shiftsTime += $entry->hours; } $vouchers = $voucher_settings['initial_vouchers']; - if($voucher_settings['shifts_per_voucher']){ + if ($voucher_settings['shifts_per_voucher']) { $vouchers += $shifts_done / $voucher_settings['shifts_per_voucher']; } - if($voucher_settings['hours_per_voucher']){ + if ($voucher_settings['hours_per_voucher']) { $vouchers += $shiftsTime / $voucher_settings['hours_per_voucher']; } @@ -273,7 +274,8 @@ function User_get_shifts_sum_query() return 'COALESCE(SUM(`end` - `start`), 0)'; } - return sprintf(' + return sprintf( + ' COALESCE(SUM( (1 + ( (HOUR(FROM_UNIXTIME(`Shifts`.`end`)) > %1$d AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) < %2$d) diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 14cf8d5f..9800be9b 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -230,7 +230,9 @@ function admin_active() } $actions[] = form( [form_submit('submit', __('set active'), 'btn-sm', false, 'secondary')], - page_link_to('admin_active', $parameters), false, true + page_link_to('admin_active', $parameters), + false, + true ); } if ($usr->state->active) { @@ -243,7 +245,9 @@ function admin_active() } $actions[] = form( [form_submit('submit', __('remove active'), 'btn-sm', false, 'secondary')], - page_link_to('admin_active', $parametersRemove), false, true + page_link_to('admin_active', $parametersRemove), + false, + true ); } if (!$usr->state->got_shirt) { @@ -256,7 +260,9 @@ function admin_active() } $actions[] = form( [form_submit('submit', __('got t-shirt'), 'btn-sm', false, 'secondary')], - page_link_to('admin_active', $parametersShirt), false, true + page_link_to('admin_active', $parametersShirt), + false, + true ); } if ($usr->state->got_shirt) { @@ -269,7 +275,9 @@ function admin_active() } $actions[] = form( [form_submit('submit', __('remove t-shirt'), 'btn-sm', false, 'secondary')], - page_link_to('admin_active', $parameters), false, true + page_link_to('admin_active', $parameters), + false, + true ); } diff --git a/includes/pages/admin_groups.php b/includes/pages/admin_groups.php index c43135e1..68254a2f 100644 --- a/includes/pages/admin_groups.php +++ b/includes/pages/admin_groups.php @@ -39,8 +39,10 @@ function admin_groups() 'name' => $group['Name'], 'privileges' => join(', ', $privileges_html), 'actions' => button( - page_link_to('admin_groups', - ['action' => 'edit', 'id' => $group['UID']]), + page_link_to( + 'admin_groups', + ['action' => 'edit', 'id' => $group['UID']] + ), __('edit'), 'btn-sm' ) diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 2112961a..e78bdd75 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -240,11 +240,11 @@ function admin_shifts() $day = Carbon::createTimestampFromDatetime(date('Y-m-d', $start) . ' 00:00'); do { // Alle Schichtwechselstunden durchgehen - for($i = 0; $i < count($change_hours); $i++) { + for ($i = 0; $i < count($change_hours); $i++) { $start_hour = $change_hours[$i]; if ($i < count($change_hours) - 1) { // Normales Intervall zwischen zwei Schichtwechselstunden - $end_hour = $change_hours[$i+1]; + $end_hour = $change_hours[$i + 1]; } elseif ($shift_over_midnight) { // Letzte Schichtwechselstunde: Wenn eine 24h Abdeckung gewünscht ist, hier die erste Schichtwechselstunde als Ende ensetzen $end_hour = $change_hours[0]; @@ -294,7 +294,7 @@ function admin_shifts() } $day = Carbon::createTimestampFromDatetime(date('Y-m-d', $day + 36 * 60 * 60) . ' 00:00'); - } while($day <= $end_day); + } while ($day <= $end_day); usort($shifts, function ($a, $b) { return $a['start'] < $b['start'] ? -1 : 1; @@ -388,7 +388,8 @@ function admin_shifts() LIMIT 1', [$type_id]); if (!empty($angel_type_source)) { - Db::insert(' + Db::insert( + ' INSERT INTO `NeededAngelTypes` (`shift_id`, `angel_type_id`, `count`) VALUES (?, ?, ?) ', @@ -421,10 +422,10 @@ function admin_shifts() $angel_types = ''; foreach ($types as $type) { $angel_types .= '
' . form_spinner( - 'type_' . $type['id'], - $type['name'], - $needed_angel_types[$type['id']] - ) + 'type_' . $type['id'], + $type['name'], + $needed_angel_types[$type['id']] + ) . '
'; } @@ -433,10 +434,11 @@ function admin_shifts() '%s', page_link_to('admin_shifts_history'), icon('clock-history') - ), [ + ), + [ msg(), form([ - div('row',[ + div('row', [ div('col-md-6', [ form_select('shifttype_id', __('Shifttype'), $shifttypes, $shifttype_id), form_text('title', __('Title'), $title), @@ -501,7 +503,8 @@ function admin_shifts() ]), form_submit('preview', icon('search') . __('Preview')) ]) - ]); + ] + ); } /** diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index df715b98..502afba7 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -67,7 +67,8 @@ function admin_user() . html_select_key( 'size', 'eSize', - $tshirt_sizes, $user_source->personalData->shirt_size, + $tshirt_sizes, + $user_source->personalData->shirt_size, __('Please select...') ) . '' . "\n"; @@ -151,7 +152,8 @@ function admin_user() $html .= form_csrf(); $html .= ''; - $groups = Db::select(' + $groups = Db::select( + ' SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON ( @@ -205,7 +207,8 @@ function admin_user() || ($my_highest_group['group_id'] <= $his_highest_group['group_id']) ) ) { - $groups_source = Db::select(' + $groups_source = Db::select( + ' SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON ( diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 05c4a83e..4757bead 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -107,8 +107,10 @@ function guest_register() if (!$nickValidation->isValid()) { $valid = false; - $msg .= error(sprintf(__('Please enter a valid nick.') . ' ' . __('Use up to 24 letters, numbers, connecting punctuations or spaces for your nickname.'), - $nick), true); + $msg .= error(sprintf( + __('Please enter a valid nick.') . ' ' . __('Use up to 24 letters, numbers, connecting punctuations or spaces for your nickname.'), + $nick + ), true); } if (User::whereName($nick)->count() > 0) { $valid = false; @@ -164,7 +166,7 @@ function guest_register() $valid = false; $msg .= error(__('Your passwords don\'t match.'), true); } - } else if ($enable_password) { + } elseif ($enable_password) { $valid = false; $msg .= error(sprintf( __('Your password is too short (please use at least %s characters).'), @@ -378,8 +380,10 @@ function guest_register() 24, 'nickname' ), - form_info('', - __('Use up to 24 letters, numbers, connecting punctuations or spaces for your nickname.')) + form_info( + '', + __('Use up to 24 letters, numbers, connecting punctuations or spaces for your nickname.') + ) ]), $enable_pronoun ? div('col', [ @@ -451,7 +455,9 @@ function guest_register() form_date( 'planned_arrival_date', __('Planned date of arrival') . ' ' . entry_required(), - $planned_arrival_date, $buildup_start_date, $teardown_end_date + $planned_arrival_date, + $buildup_start_date, + $teardown_end_date ) ]) : '', ]), @@ -462,9 +468,13 @@ function guest_register() ]) : '', div('col', [ - $enable_tshirt_size ? form_select('tshirt_size', + $enable_tshirt_size ? form_select( + 'tshirt_size', __('Shirt size') . ' ' . entry_required(), - $tshirt_sizes, $tshirt_size, __('Please select...')) : '' + $tshirt_sizes, + $tshirt_size, + __('Please select...') + ) : '' ]), ]), diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php index dcbbed16..e79b3d46 100644 --- a/includes/pages/user_atom.php +++ b/includes/pages/user_atom.php @@ -74,10 +74,10 @@ function make_atom_entry_from_news(News $news) ' . htmlspecialchars($news->title) . '' . preg_replace( - '#^https?://#', - '', - page_link_to('news/' . $news->id) - ) . ' + '#^https?://#', + '', + page_link_to('news/' . $news->id) + ) . '' . $news->updated_at->format('Y-m-d\TH:i:sP') . '' . htmlspecialchars($news->text) . '' . "\n"; diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index b25ba51d..1c1eda64 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -48,7 +48,8 @@ function user_myshifts() ]); } elseif ($request->has('edit') && preg_match('/^\d+$/', $request->input('edit'))) { $shift_entry_id = $request->input('edit'); - $shift = Db::selectOne(' + $shift = Db::selectOne( + ' SELECT `ShiftEntry`.`freeloaded`, `ShiftEntry`.`freeload_comment`, diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index e9ab85e6..c2922a76 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -156,7 +156,8 @@ function load_types() error(__('The administration has not configured any angeltypes yet - or you are not subscribed to any angeltype.')); throw_redirect(page_link_to('/')); } - $types = Db::select(' + $types = Db::select( + ' SELECT `AngelTypes`.`id`, `AngelTypes`.`name`, @@ -318,7 +319,7 @@ function view_user_shifts() function ical_hint() { $user = auth()->user(); - if(!auth()->can('ical')) { + if (!auth()->can('ical')) { return ''; } diff --git a/includes/sys_page.php b/includes/sys_page.php index 5b1295f4..6f6f3f36 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -261,7 +261,7 @@ function strip_item($item) function check_email($email) { // Convert the domain part from idn to ascii - if(substr_count($email, '@') == 1) { + if (substr_count($email, '@') == 1) { list($name, $domain) = explode('@', $email); $domain = idn_to_ascii($domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); $email = $name . '@' . $domain; diff --git a/includes/sys_template.php b/includes/sys_template.php index cf51b291..f2960d1b 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -52,7 +52,7 @@ function tabs($tabs, $selected = 0) $id = null; } $tab_header[] = '
  • ' . button( shift_entry_create_link($shift, $angeltype), - __('Sign up'), 'btn-sm btn-primary text-nowrap d-print-none' + __('Sign up'), + 'btn-sm btn-primary text-nowrap d-print-none' ); break; diff --git a/includes/view/ShiftEntry_view.php b/includes/view/ShiftEntry_view.php index e39da500..45238e9f 100644 --- a/includes/view/ShiftEntry_view.php +++ b/includes/view/ShiftEntry_view.php @@ -93,7 +93,8 @@ function ShiftEntry_create_view_admin($shift, Room $room, $angeltype, $angeltype form_select('user_id', __('User'), $users_select, $signup_user->id), form_submit('submit', icon('check-lg') . __('Save')) ]) - ]); + ] + ); } /** @@ -108,17 +109,21 @@ function ShiftEntry_create_view_admin($shift, Room $room, $angeltype, $angeltype */ function ShiftEntry_create_view_supporter($shift, Room $room, $angeltype, $signup_user, $users_select) { - return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name'] + return page_with_title( + ShiftEntry_create_title() . ': ' . $shift['name'] . ' %c', [ Shift_view_header($shift, $room), - info(sprintf(__('Do you want to sign up the following user for this shift as %s?'), - AngelType_name_render($angeltype)), true), + info(sprintf( + __('Do you want to sign up the following user for this shift as %s?'), + AngelType_name_render($angeltype) + ), true), form([ form_select('user_id', __('User'), $users_select, $signup_user->id), form_submit('submit', icon('check-lg') . __('Save')) ]) - ]); + ] + ); } /** @@ -132,7 +137,8 @@ function ShiftEntry_create_view_supporter($shift, Room $room, $angeltype, $signu */ function ShiftEntry_create_view_user($shift, Room $room, $angeltype, $comment) { - return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name'] + return page_with_title( + ShiftEntry_create_title() . ': ' . $shift['name'] . ' %c', [ Shift_view_header($shift, $room), @@ -141,7 +147,8 @@ function ShiftEntry_create_view_user($shift, Room $room, $angeltype, $comment) form_textarea('comment', __('Comment (for your eyes only):'), $comment), form_submit('submit', icon('check-lg') . __('Save')) ]) - ]); + ] + ); } /** diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index 171f6462..91e075ae 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -93,8 +93,10 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null) } elseif (empty($user_angeltype)) { return button( page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]), - sprintf(__('Become %s'), - $angeltype['name']) + sprintf( + __('Become %s'), + $angeltype['name'] + ) ); } return ''; @@ -284,10 +286,10 @@ function shift_length($shift) { $length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ':'; $length .= str_pad( - (($shift['end'] - $shift['start']) % (60 * 60)) / 60, - 2, - '0', - STR_PAD_LEFT - ) . 'h'; + (($shift['end'] - $shift['start']) % (60 * 60)) / 60, + 2, + '0', + STR_PAD_LEFT + ) . 'h'; return $length; } diff --git a/includes/view/UserHintsRenderer.php b/includes/view/UserHintsRenderer.php index c9496652..b409d14e 100644 --- a/includes/view/UserHintsRenderer.php +++ b/includes/view/UserHintsRenderer.php @@ -21,7 +21,10 @@ class UserHintsRenderer $icon = $this->important ? 'exclamation-triangle' : 'info-circle'; return toolbar_popover( - $icon . ' text-white', '', $this->hints, 'bg-' . $hint_class + $icon . ' text-white', + '', + $this->hints, + 'bg-' . $hint_class ); } diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 95786c39..918121ed 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -357,7 +357,7 @@ function User_view_shiftentries($needed_angel_type) { $shift_info = '
    ' . $needed_angel_type['name'] . ': '; + . '">' . $needed_angel_type['name'] . ': '; $shift_entries = []; foreach ($needed_angel_type['users'] as $user_shift) { @@ -579,8 +579,8 @@ function User_view( $auth = auth(); $nightShiftsConfig = config('night_shifts'); $user_name = htmlspecialchars( - $user_source->personalData->first_name) . ' ' . htmlspecialchars($user_source->personalData->last_name - ); + $user_source->personalData->first_name + ) . ' ' . htmlspecialchars($user_source->personalData->last_name); $myshifts_table = ''; if ($its_me || $admin_user_privilege) { $my_shifts = User_view_myshifts( @@ -709,9 +709,9 @@ function User_view( ) : '', $its_me && count($shifts) == 0 ? error(sprintf( - __('Go to the shifts table to sign yourself up for some shifts.'), - page_link_to('user_shifts') - ), true) + __('Go to the shifts table to sign yourself up for some shifts.'), + page_link_to('user_shifts') + ), true) : '', $its_me ? ical_hint() : '' ]