Formatting

main
Bot 7 years ago committed by Igor Scheller
parent fe58e4f422
commit 5227fe6a94

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

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

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

@ -2,13 +2,18 @@
/**
* 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)
{
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([
button(user_link($user_source), glyph('remove') . _('cancel')),
button(user_worklog_delete_link($userWorkLog, [
@ -29,8 +34,9 @@ function UserWorkLog_delete_title()
/**
* Render edit table.
*
* @param User $user_source
* @param UserWorkLog $userWorkLog
* @param array $user_source
* @param array $userWorkLog
* @return string
*/
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.
*
* @param User $user_source
* @param UserWorkLog $userWorkLog
* @param array $user_source
* @param array $userWorkLog
* @return string
*/
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.
*
* @param User $user_source
* @param UserWorkLog $userWorkLog
* @param array $user_source
* @param array $userWorkLog
* @return string
*/
function UserWorkLog_add_view($user_source, $userWorkLog)
{
@ -92,5 +100,3 @@ function UserWorkLog_add_title()
{
return _('Add work log entry');
}
?>

@ -406,10 +406,21 @@ function User_view_myshift($shift, $user_source, $its_me)
* @param array[] $shifts
* @param array $user_source
* @param bool $its_me
* @param int $tshirt_score
* @param bool $tshirt_admin
* @param array[] $user_worklogs
* @param $admin_user_worklog_privilege
* @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 = [];
$timesum = 0;
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) {
foreach($user_worklogs as $worklog) {
if ($its_me || $admin_user_worklog_privilege) {
foreach ($user_worklogs as $worklog) {
$myshifts_table[$worklog['work_timestamp']] = User_view_worklog($worklog, $admin_user_worklog_privilege);
$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
* @param UserWorkLog $worklog
*
* @param array $worklog
* @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 = '';
if($admin_user_worklog_privilege) {
if ($admin_user_worklog_privilege) {
$actions = table_buttons([
button(
user_worklog_edit_link($worklog),
@ -500,6 +514,8 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege) {
* @param bool $its_me
* @param int $tshirt_score
* @param bool $tshirt_admin
* @param bool $admin_user_worklog_privilege
* @param array[] $user_worklogs
* @return string
*/
function User_view(
@ -517,9 +533,17 @@ function User_view(
) {
$user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']);
$myshifts_table = '';
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);
if(count($my_shifts) > 0) {
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
);
if (count($my_shifts) > 0) {
$myshifts_table = table([
'date' => _('Day &amp; time'),
'duration' => _('Duration'),
@ -528,7 +552,7 @@ function User_view(
'comment' => _('Comment'),
'actions' => _('Action')
], $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);
}
}

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

Loading…
Cancel
Save