Formatting

This commit is contained in:
Bot 2018-01-14 18:09:34 +01:00 committed by Igor Scheller
parent fe58e4f422
commit 5227fe6a94
6 changed files with 143 additions and 79 deletions

View File

@ -2,6 +2,8 @@
/** /**
* Delete a work log entry. * Delete a work log entry.
*
* @return array
*/ */
function user_worklog_delete_controller() function user_worklog_delete_controller()
{ {
@ -29,6 +31,8 @@ function user_worklog_delete_controller()
/** /**
* Edit work log for user. * Edit work log for user.
*
* @return array
*/ */
function user_worklog_edit_controller() function user_worklog_edit_controller()
{ {
@ -59,9 +63,10 @@ function user_worklog_edit_controller()
} }
/** /**
* Handle form
* *
* @param UserWorkLog $userWorkLog * @param array $userWorkLog
* @return [bool $valid, UserWorkLog $userWorkLog] * @return array [bool $valid, UserWorkLog $userWorkLog]
*/ */
function user_worklog_from_request($userWorkLog) function user_worklog_from_request($userWorkLog)
{ {
@ -69,14 +74,17 @@ function user_worklog_from_request($userWorkLog)
$valid = true; $valid = true;
$userWorkLog['work_timestamp'] = parse_date('Y-m-d H:i', $request->input('work_timestamp') . ' 00:00'); $userWorkLog['work_timestamp'] = parse_date(
'Y-m-d H:i',
$request->input('work_timestamp') . ' 00:00'
);
if (is_null($userWorkLog['work_timestamp'])) { if (is_null($userWorkLog['work_timestamp'])) {
$valid = false; $valid = false;
error(_('Please enter work date.')); error(_('Please enter work date.'));
} }
$userWorkLog['work_hours'] = $request->input('work_hours'); $userWorkLog['work_hours'] = $request->input('work_hours');
if (! preg_match("/[0-9]+(\.[0-9]+)?/", $userWorkLog['work_hours'])) { if (!preg_match("/[0-9]+(\.[0-9]+)?/", $userWorkLog['work_hours'])) {
$valid = false; $valid = false;
error(_('Please enter work hours in format ##[.##].')); error(_('Please enter work hours in format ##[.##].'));
} }
@ -95,6 +103,8 @@ function user_worklog_from_request($userWorkLog)
/** /**
* Add work log entry to user. * Add work log entry to user.
*
* @return array
*/ */
function user_worklog_add_controller() function user_worklog_add_controller()
{ {
@ -128,7 +138,9 @@ function user_worklog_add_controller()
/** /**
* Link to work log entry add for given user. * Link to work log entry add for given user.
* *
* @param User $user * @param array $user
*
* @return string
*/ */
function user_worklog_add_link($user) function user_worklog_add_link($user)
{ {
@ -141,7 +153,8 @@ function user_worklog_add_link($user)
/** /**
* Link to work log entry edit. * Link to work log entry edit.
* *
* @param UserWorkLog $userWorkLog * @param array $userWorkLog
* @return string
*/ */
function user_worklog_edit_link($userWorkLog) function user_worklog_edit_link($userWorkLog)
{ {
@ -154,8 +167,9 @@ function user_worklog_edit_link($userWorkLog)
/** /**
* Link to work log entry delete. * Link to work log entry delete.
* *
* @param UserWorkLog $userWorkLog * @param array $userWorkLog
* @param array[] $parameters * @param array[] $parameters
* @return string
*/ */
function user_worklog_delete_link($userWorkLog, $parameters = []) function user_worklog_delete_link($userWorkLog, $parameters = [])
{ {
@ -167,18 +181,20 @@ function user_worklog_delete_link($userWorkLog, $parameters = [])
/** /**
* Work log entry actions * Work log entry actions
*
* @return array
*/ */
function user_worklogs_controller() function user_worklog_controller()
{ {
global $user, $privileges; global $user, $privileges;
if (! in_array('admin_user_worklog', $privileges)) { if (!in_array('admin_user_worklog', $privileges)) {
redirect(user_link($user)); redirect(user_link($user));
} }
$request = request(); $request = request();
$action = $request->input('action'); $action = $request->input('action');
if (! $request->has('action')) { if (!$request->has('action')) {
redirect(user_link($user)); redirect(user_link($user));
} }

View File

@ -1,10 +1,12 @@
<?php <?php
use Engelsystem\Database\Db; use Engelsystem\Database\Db;
/** /**
* Load a single work log entry. * Load a single work log entry.
* *
* @param int $user_worklog_id * @param int $user_worklog_id
* @return array
*/ */
function UserWorkLog($user_worklog_id) function UserWorkLog($user_worklog_id)
{ {
@ -16,7 +18,8 @@ function UserWorkLog($user_worklog_id)
/** /**
* Returns all work log entries for a user. * Returns all work log entries for a user.
* *
* @param User $user * @param array $user
* @return array[]
*/ */
function UserWorkLogsForUser($user) function UserWorkLogsForUser($user)
{ {
@ -28,7 +31,8 @@ function UserWorkLogsForUser($user)
/** /**
* Delete a work log entry. * Delete a work log entry.
* *
* @param UserWorkLog $userWorkLog * @param $userWorkLog
* @return int
*/ */
function UserWorkLog_delete($userWorkLog) function UserWorkLog_delete($userWorkLog)
{ {
@ -37,7 +41,12 @@ function UserWorkLog_delete($userWorkLog)
$userWorkLog['id'] $userWorkLog['id']
]); ]);
engelsystem_log(sprintf('Delete work log for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment'])); engelsystem_log(sprintf(
'Delete work log for %s, %s hours, %s',
User_Nick_render($user_source),
$userWorkLog['work_hours'],
$userWorkLog['comment']
));
return $result; return $result;
} }
@ -45,7 +54,8 @@ function UserWorkLog_delete($userWorkLog)
/** /**
* Update work log entry (only work hours and comment) * Update work log entry (only work hours and comment)
* *
* @param UserWorkLog $userWorkLog * @param $userWorkLog
* @return int
*/ */
function UserWorkLog_update($userWorkLog) function UserWorkLog_update($userWorkLog)
{ {
@ -62,7 +72,12 @@ function UserWorkLog_update($userWorkLog)
$userWorkLog['id'] $userWorkLog['id']
]); ]);
engelsystem_log(sprintf('Updated work log for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment'])); engelsystem_log(sprintf(
'Updated work log for %s, %s hours, %s',
User_Nick_render($user_source),
$userWorkLog['work_hours'],
$userWorkLog['comment'])
);
return $result; return $result;
} }
@ -70,7 +85,8 @@ function UserWorkLog_update($userWorkLog)
/** /**
* Create a new work log entry * Create a new work log entry
* *
* @param UserWorkLog $userWorkLog * @param $userWorkLog
* @return bool
*/ */
function UserWorkLog_create($userWorkLog) function UserWorkLog_create($userWorkLog)
{ {
@ -95,7 +111,8 @@ function UserWorkLog_create($userWorkLog)
time() time()
]); ]);
engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment'])); engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', User_Nick_render($user_source),
$userWorkLog['work_hours'], $userWorkLog['comment']));
return $result; return $result;
} }
@ -104,12 +121,13 @@ function UserWorkLog_create($userWorkLog)
* New user work log entry * New user work log entry
* *
* @param array[] $user * @param array[] $user
* @return array
*/ */
function UserWorkLog_new($user) function UserWorkLog_new($user)
{ {
$work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', time())); $work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', time()));
$event_config = EventConfig(); $event_config = EventConfig();
if (! empty($event_config['buildup_start_date'])) { if (!empty($event_config['buildup_start_date'])) {
$work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', $event_config['buildup_start_date'])); $work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', $event_config['buildup_start_date']));
} }
return [ return [
@ -119,5 +137,3 @@ function UserWorkLog_new($user)
'comment' => '' 'comment' => ''
]; ];
} }
?>

View File

@ -22,8 +22,10 @@ function User_delete($user_id)
* Accounts only ended shifts. * Accounts only ended shifts.
* *
* @param array[] $user * @param array[] $user
* @return int
*/ */
function User_tshirt_score($user) { function User_tshirt_score($user)
{
$shift_sum_formula = config('shift_sum_formula'); $shift_sum_formula = config('shift_sum_formula');
$result_shifts = DB::selectOne(' $result_shifts = DB::selectOne('
@ -33,7 +35,7 @@ function User_tshirt_score($user) {
WHERE `User`.`UID` = ? WHERE `User`.`UID` = ?
AND `Shifts`.`end` < ? AND `Shifts`.`end` < ?
GROUP BY `User`.`UID` GROUP BY `User`.`UID`
',[ ', [
$user['UID'], $user['UID'],
time() time()
]); ]);
@ -43,7 +45,7 @@ function User_tshirt_score($user) {
LEFT JOIN `UserWorkLog` ON `User`.`UID` = `UserWorkLog`.`user_id` LEFT JOIN `UserWorkLog` ON `User`.`UID` = `UserWorkLog`.`user_id`
WHERE `User`.`UID` = ? WHERE `User`.`UID` = ?
AND `UserWorkLog`.`work_timestamp` < ? AND `UserWorkLog`.`work_timestamp` < ?
',[ ', [
$user['UID'], $user['UID'],
time() time()
]); ]);
@ -385,7 +387,7 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de
return new ValidationResult(false, $planned_arrival_date); return new ValidationResult(false, $planned_arrival_date);
} }
$event_config = EventConfig(); $event_config = EventConfig();
if (empty($event_config )) { if (empty($event_config)) {
// Nothing to validate against // Nothing to validate against
return new ValidationResult(true, $planned_departure_date); return new ValidationResult(true, $planned_departure_date);
} }

View File

@ -2,13 +2,18 @@
/** /**
* Delete work log entry. * Delete work log entry.
* @param User $user_source *
* @param UserWorkLog $userWorkLog * @param array $user_source
* @param array $userWorkLog
* @return string
*/ */
function UserWorkLog_delete_view($user_source, $userWorkLog) function UserWorkLog_delete_view($user_source, $userWorkLog)
{ {
return page_with_title(UserWorkLog_delete_title(), [ return page_with_title(UserWorkLog_delete_title(), [
info(sprintf(_('Do you want to delete the worklog entry for %s?'), User_Nick_render($user_source)), true), info(sprintf(
_('Do you want to delete the worklog entry for %s?'),
User_Nick_render($user_source)
), true),
buttons([ buttons([
button(user_link($user_source), glyph('remove') . _('cancel')), button(user_link($user_source), glyph('remove') . _('cancel')),
button(user_worklog_delete_link($userWorkLog, [ button(user_worklog_delete_link($userWorkLog, [
@ -29,8 +34,9 @@ function UserWorkLog_delete_title()
/** /**
* Render edit table. * Render edit table.
* *
* @param User $user_source * @param array $user_source
* @param UserWorkLog $userWorkLog * @param array $userWorkLog
* @return string
*/ */
function UserWorkLog_edit_form($user_source, $userWorkLog) function UserWorkLog_edit_form($user_source, $userWorkLog)
{ {
@ -46,8 +52,9 @@ function UserWorkLog_edit_form($user_source, $userWorkLog)
/** /**
* Form for edit a user work log entry. * Form for edit a user work log entry.
* *
* @param User $user_source * @param array $user_source
* @param UserWorkLog $userWorkLog * @param array $userWorkLog
* @return string
*/ */
function UserWorkLog_edit_view($user_source, $userWorkLog) function UserWorkLog_edit_view($user_source, $userWorkLog)
{ {
@ -63,8 +70,9 @@ function UserWorkLog_edit_view($user_source, $userWorkLog)
/** /**
* Form for adding a user work log entry. * Form for adding a user work log entry.
* *
* @param User $user_source * @param array $user_source
* @param UserWorkLog $userWorkLog * @param array $userWorkLog
* @return string
*/ */
function UserWorkLog_add_view($user_source, $userWorkLog) function UserWorkLog_add_view($user_source, $userWorkLog)
{ {
@ -92,5 +100,3 @@ function UserWorkLog_add_title()
{ {
return _('Add work log entry'); return _('Add work log entry');
} }
?>

View File

@ -406,10 +406,21 @@ function User_view_myshift($shift, $user_source, $its_me)
* @param array[] $shifts * @param array[] $shifts
* @param array $user_source * @param array $user_source
* @param bool $its_me * @param bool $its_me
* @param int $tshirt_score
* @param bool $tshirt_admin
* @param array[] $user_worklogs
* @param $admin_user_worklog_privilege
* @return array * @return array
*/ */
function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin, $user_worklogs, $admin_user_worklog_privilege) function User_view_myshifts(
{ $shifts,
$user_source,
$its_me,
$tshirt_score,
$tshirt_admin,
$user_worklogs,
$admin_user_worklog_privilege
) {
$myshifts_table = []; $myshifts_table = [];
$timesum = 0; $timesum = 0;
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
@ -420,8 +431,8 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi
} }
} }
if($its_me || $admin_user_worklog_privilege) { if ($its_me || $admin_user_worklog_privilege) {
foreach($user_worklogs as $worklog) { foreach ($user_worklogs as $worklog) {
$myshifts_table[$worklog['work_timestamp']] = User_view_worklog($worklog, $admin_user_worklog_privilege); $myshifts_table[$worklog['work_timestamp']] = User_view_worklog($worklog, $admin_user_worklog_privilege);
$timesum += $worklog['work_hours'] * 3600; $timesum += $worklog['work_hours'] * 3600;
} }
@ -453,12 +464,15 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi
/** /**
* Renders table entry for user work log * Renders table entry for user work log
* @param UserWorkLog $worklog *
* @param array $worklog
* @param bool $admin_user_worklog_privilege * @param bool $admin_user_worklog_privilege
* @return array
*/ */
function User_view_worklog($worklog, $admin_user_worklog_privilege) { function User_view_worklog($worklog, $admin_user_worklog_privilege)
{
$actions = ''; $actions = '';
if($admin_user_worklog_privilege) { if ($admin_user_worklog_privilege) {
$actions = table_buttons([ $actions = table_buttons([
button( button(
user_worklog_edit_link($worklog), user_worklog_edit_link($worklog),
@ -500,6 +514,8 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege) {
* @param bool $its_me * @param bool $its_me
* @param int $tshirt_score * @param int $tshirt_score
* @param bool $tshirt_admin * @param bool $tshirt_admin
* @param bool $admin_user_worklog_privilege
* @param array[] $user_worklogs
* @return string * @return string
*/ */
function User_view( function User_view(
@ -517,9 +533,17 @@ function User_view(
) { ) {
$user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']); $user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']);
$myshifts_table = ''; $myshifts_table = '';
if($its_me || $admin_user_privilege) { if ($its_me || $admin_user_privilege) {
$my_shifts = User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin, $user_worklogs, $admin_user_worklog_privilege); $my_shifts = User_view_myshifts(
if(count($my_shifts) > 0) { $shifts,
$user_source,
$its_me,
$tshirt_score,
$tshirt_admin,
$user_worklogs,
$admin_user_worklog_privilege
);
if (count($my_shifts) > 0) {
$myshifts_table = table([ $myshifts_table = table([
'date' => _('Day &amp; time'), 'date' => _('Day &amp; time'),
'duration' => _('Duration'), 'duration' => _('Duration'),
@ -528,7 +552,7 @@ function User_view(
'comment' => _('Comment'), 'comment' => _('Comment'),
'actions' => _('Action') 'actions' => _('Action')
], $my_shifts); ], $my_shifts);
} elseif($user_source['force_active']) { } elseif ($user_source['force_active']) {
$myshifts_table = success(_('You have done enough to get a t-shirt.'), true); $myshifts_table = success(_('You have done enough to get a t-shirt.'), true);
} }
} }

View File

@ -132,7 +132,7 @@ if (
$content = user_shifts(); $content = user_shifts();
break; break;
case 'user_worklog': case 'user_worklog':
list($title, $content) = user_worklogs_controller(); list($title, $content) = user_worklog_controller();
break; break;
case 'user_messages': case 'user_messages':
$title = messages_title(); $title = messages_title();