Include phpcs for /includes

This commit is contained in:
Michael Weimann 2022-10-18 19:15:22 +02:00
parent 1af185c7ac
commit f7d499b362
No known key found for this signature in database
GPG Key ID: 34F0524D4DA694A1
36 changed files with 239 additions and 150 deletions

View File

@ -4,6 +4,7 @@
<file>config</file>
<file>db</file>
<file>includes</file>
<file>public/index.php</file>
<file>src</file>
<file>tests</file>
@ -19,4 +20,7 @@
<property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true" />
</properties>
</rule>
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>/includes</exclude-pattern>
</rule>
</ruleset>

View File

@ -6,6 +6,7 @@ use Engelsystem\Config\Config;
/**
* Include the autoloader
*/
require_once __DIR__ . '/autoload.php';
/**

View File

@ -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'),

View File

@ -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(

View File

@ -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');
}

View File

@ -3,6 +3,7 @@
/**
* Include legacy code
*/
$includeFiles = [
__DIR__ . '/../includes/sys_auth.php',
__DIR__ . '/../includes/sys_form.php',

View File

@ -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`,

View File

@ -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`,

View File

@ -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

View File

@ -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(?, ?, ?)
',

View File

@ -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,

View File

@ -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`=?
@ -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`=?

View File

@ -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`

View File

@ -1,8 +1,6 @@
<?php
use Carbon\Carbon;
use Engelsystem\Helpers\Shifts;
use Engelsystem\Models\Room;
use Engelsystem\Models\Worklog;
use Illuminate\Support\Collection;

View File

@ -87,7 +87,8 @@ function Users_by_angeltype_inverted($angeltype)
function Users_by_angeltype($angeltype)
{
return User::query()
->select('users.*',
->select(
'users.*',
'UserAngelTypes.id AS user_angeltype_id',
'UserAngelTypes.confirm_user_id',
'UserAngelTypes.supporter',
@ -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)

View File

@ -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
);
}

View File

@ -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'
)

View File

@ -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 (?, ?, ?)
',
@ -433,7 +434,8 @@ function admin_shifts()
'<a href="%s">%s</a>',
page_link_to('admin_shifts_history'),
icon('clock-history')
), [
),
[
msg(),
form([
div('row', [
@ -501,7 +503,8 @@ function admin_shifts()
]),
form_submit('preview', icon('search') . __('Preview'))
])
]);
]
);
}
/**

View File

@ -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...')
)
. '</td></tr>' . "\n";
@ -151,7 +152,8 @@ function admin_user()
$html .= form_csrf();
$html .= '<table>';
$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 (

View File

@ -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;
@ -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...')
) : ''
]),
]),

View File

@ -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`,

View File

@ -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`,

View File

@ -97,14 +97,17 @@ function AngelType_edit_view($angeltype, $supporter_mode)
? form_info(__('No Self Sign Up allowed'), $angeltype['no_self_signup'] ? __('Yes') : __('No'))
: form_checkbox('no_self_signup', __('No Self Sign Up allowed'), $angeltype['no_self_signup']),
$supporter_mode
? form_info(__('Requires driver license'),
? form_info(
__('Requires driver license'),
$angeltype['requires_driver_license']
? __('Yes')
: __('No'))
: __('No')
)
: form_checkbox(
'requires_driver_license',
__('Requires driver license'),
$angeltype['requires_driver_license']),
$angeltype['requires_driver_license']
),
$supporter_mode
? form_info(__('Show on dashboard'), $angeltype['show_on_dashboard'] ? __('Yes') : __('No'))
: form_checkbox('show_on_dashboard', __('Show on dashboard'), $angeltype['show_on_dashboard']),
@ -256,12 +259,15 @@ function AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $a
if ($admin_user_angeltypes) {
$member['actions'] = table_buttons([
$admin_angeltypes
? button(page_link_to('user_angeltypes', [
? button(
page_link_to('user_angeltypes', [
'action' => 'update',
'user_angeltype_id' => $member['user_angeltype_id'],
'supporter' => 1
]),
__('Add supporter rights'), 'btn-sm')
__('Add supporter rights'),
'btn-sm'
)
: '',
button(
page_link_to('user_angeltypes', [

View File

@ -136,7 +136,8 @@ class ShiftCalendarShiftRenderer
if (auth()->can('user_shifts_admin')) {
$html .= '<li class="list-group-item d-flex align-items-center ' . $this->classBg() . '">';
$html .= button(shift_entry_create_link_admin($shift),
$html .= button(
shift_entry_create_link_admin($shift),
icon('plus-lg') . __('Add more angels'),
'btn-sm'
);
@ -195,7 +196,8 @@ class ShiftCalendarShiftRenderer
. '</a> '
. 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;

View File

@ -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']
. ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
[
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']
. ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
[
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'))
])
]);
]
);
}
/**

View File

@ -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 '';

View File

@ -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
);
}

View File

@ -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(