Renamed variables for more consistent worklog naming
This commit is contained in:
parent
f732a4af6f
commit
f4f3487c93
|
@ -11,22 +11,22 @@ use Engelsystem\Models\Worklog;
|
||||||
function user_worklog_delete_controller()
|
function user_worklog_delete_controller()
|
||||||
{
|
{
|
||||||
$request = request();
|
$request = request();
|
||||||
$userWorkLog = Worklog::find($request->input('user_worklog_id'));
|
$worklog = Worklog::find($request->input('user_worklog_id'));
|
||||||
if (empty($userWorkLog)) {
|
if (empty($worklog)) {
|
||||||
throw_redirect(user_link(auth()->user()->id));
|
throw_redirect(user_link(auth()->user()->id));
|
||||||
}
|
}
|
||||||
$user_source = $userWorkLog->user;
|
$user = $worklog->user;
|
||||||
|
|
||||||
if ($request->hasPostData('submit')) {
|
if ($request->hasPostData('submit')) {
|
||||||
UserWorkLog_delete($userWorkLog);
|
UserWorkLog_delete($worklog);
|
||||||
|
|
||||||
success(__('Work log entry deleted.'));
|
success(__('Work log entry deleted.'));
|
||||||
throw_redirect(user_link($user_source->id));
|
throw_redirect(user_link($user->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
UserWorkLog_delete_title(),
|
UserWorkLog_delete_title(),
|
||||||
UserWorkLog_delete_view($user_source)
|
UserWorkLog_delete_view($user)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,33 +38,33 @@ function user_worklog_delete_controller()
|
||||||
function user_worklog_edit_controller()
|
function user_worklog_edit_controller()
|
||||||
{
|
{
|
||||||
$request = request();
|
$request = request();
|
||||||
$userWorkLog = Worklog::find($request->input('user_worklog_id'));
|
$worklog = Worklog::find($request->input('user_worklog_id'));
|
||||||
if (empty($userWorkLog)) {
|
if (empty($worklog)) {
|
||||||
throw_redirect(user_link(auth()->user()->id));
|
throw_redirect(user_link(auth()->user()->id));
|
||||||
}
|
}
|
||||||
$user_source = $userWorkLog->user;
|
$user = $worklog->user;
|
||||||
|
|
||||||
if ($request->hasPostData('submit')) {
|
if ($request->hasPostData('submit')) {
|
||||||
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
|
list ($valid, $worklog) = user_worklog_from_request($worklog);
|
||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
$userWorkLog->save();
|
$worklog->save();
|
||||||
|
|
||||||
engelsystem_log(sprintf(
|
engelsystem_log(sprintf(
|
||||||
'Updated work log for %s, %s hours, %s',
|
'Updated work log for %s, %s hours, %s',
|
||||||
User_Nick_render($userWorkLog->user, true),
|
User_Nick_render($worklog->user, true),
|
||||||
$userWorkLog->hours,
|
$worklog->hours,
|
||||||
$userWorkLog->comment
|
$worklog->comment
|
||||||
));
|
));
|
||||||
|
|
||||||
success(__('Work log entry updated.'));
|
success(__('Work log entry updated.'));
|
||||||
throw_redirect(user_link($user_source->id));
|
throw_redirect(user_link($user->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
UserWorkLog_edit_title(),
|
UserWorkLog_edit_title(),
|
||||||
UserWorkLog_edit_view($user_source, $userWorkLog)
|
UserWorkLog_edit_view($user, $worklog)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ function user_worklog_edit_controller()
|
||||||
* Handle form
|
* Handle form
|
||||||
*
|
*
|
||||||
* @param Worklog $worklog
|
* @param Worklog $worklog
|
||||||
* @return bool[]|Worklog[] [bool $valid, Worklog $userWorkLog]
|
* @return bool[]|Worklog[] [bool $valid, Worklog $worklog]
|
||||||
*/
|
*/
|
||||||
function user_worklog_from_request(Worklog $worklog)
|
function user_worklog_from_request(Worklog $worklog)
|
||||||
{
|
{
|
||||||
|
@ -117,27 +117,27 @@ function user_worklog_from_request(Worklog $worklog)
|
||||||
function user_worklog_add_controller()
|
function user_worklog_add_controller()
|
||||||
{
|
{
|
||||||
$request = request();
|
$request = request();
|
||||||
$user_source = User::find($request->input('user_id'));
|
$user = User::find($request->input('user_id'));
|
||||||
if (!$user_source) {
|
if (!$user) {
|
||||||
throw_redirect(user_link(auth()->user()->id));
|
throw_redirect(user_link(auth()->user()->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
$userWorkLog = UserWorkLog_new($user_source->id);
|
$worklog = UserWorkLog_new($user->id);
|
||||||
|
|
||||||
if ($request->hasPostData('submit')) {
|
if ($request->hasPostData('submit')) {
|
||||||
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
|
list ($valid, $worklog) = user_worklog_from_request($worklog);
|
||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
UserWorkLog_create($userWorkLog);
|
UserWorkLog_create($worklog);
|
||||||
|
|
||||||
success(__('Work log entry created.'));
|
success(__('Work log entry created.'));
|
||||||
throw_redirect(user_link($user_source->id));
|
throw_redirect(user_link($user->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
UserWorkLog_add_title(),
|
UserWorkLog_add_title(),
|
||||||
UserWorkLog_add_view($user_source, $userWorkLog)
|
UserWorkLog_add_view($user, $worklog)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,29 +159,29 @@ function user_worklog_add_link(User $user)
|
||||||
/**
|
/**
|
||||||
* Link to work log entry edit.
|
* Link to work log entry edit.
|
||||||
*
|
*
|
||||||
* @param Worklog $userWorkLog
|
* @param Worklog $worklog
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function user_worklog_edit_link(Worklog $userWorkLog)
|
function user_worklog_edit_link(Worklog $worklog)
|
||||||
{
|
{
|
||||||
return page_link_to('user_worklog', [
|
return page_link_to('user_worklog', [
|
||||||
'action' => 'edit',
|
'action' => 'edit',
|
||||||
'user_worklog_id' => $userWorkLog->id
|
'user_worklog_id' => $worklog->id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link to work log entry delete.
|
* Link to work log entry delete.
|
||||||
*
|
*
|
||||||
* @param Worklog $userWorkLog
|
* @param Worklog $worklog
|
||||||
* @param array[] $parameters
|
* @param array[] $parameters
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function user_worklog_delete_link(Worklog $userWorkLog, $parameters = [])
|
function user_worklog_delete_link(Worklog $worklog, $parameters = [])
|
||||||
{
|
{
|
||||||
return page_link_to('user_worklog', array_merge([
|
return page_link_to('user_worklog', array_merge([
|
||||||
'action' => 'delete',
|
'action' => 'delete',
|
||||||
'user_worklog_id' => $userWorkLog->id
|
'user_worklog_id' => $worklog->id
|
||||||
], $parameters));
|
], $parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,18 +27,18 @@ function UserWorkLogsForUser($userId, Carbon $sinceTime = null)
|
||||||
/**
|
/**
|
||||||
* Delete a work log entry.
|
* Delete a work log entry.
|
||||||
*
|
*
|
||||||
* @param Worklog $userWorkLog
|
* @param Worklog $worklog
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function UserWorkLog_delete(Worklog $userWorkLog)
|
function UserWorkLog_delete(Worklog $worklog)
|
||||||
{
|
{
|
||||||
$result = $userWorkLog->delete();
|
$result = $worklog->delete();
|
||||||
|
|
||||||
engelsystem_log(sprintf(
|
engelsystem_log(sprintf(
|
||||||
'Delete work log for %s, %s hours, %s',
|
'Delete work log for %s, %s hours, %s',
|
||||||
User_Nick_render($userWorkLog->user, true),
|
User_Nick_render($worklog->user, true),
|
||||||
$userWorkLog->hours,
|
$worklog->hours,
|
||||||
$userWorkLog->comment
|
$worklog->comment
|
||||||
));
|
));
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -47,20 +47,20 @@ function UserWorkLog_delete(Worklog $userWorkLog)
|
||||||
/**
|
/**
|
||||||
* Create a new work log entry
|
* Create a new work log entry
|
||||||
*
|
*
|
||||||
* @param Worklog $userWorkLog
|
* @param Worklog $worklog
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function UserWorkLog_create(Worklog $userWorkLog)
|
function UserWorkLog_create(Worklog $worklog)
|
||||||
{
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$userWorkLog->creator()->associate($user);
|
$worklog->creator()->associate($user);
|
||||||
$result = $userWorkLog->save();
|
$result = $worklog->save();
|
||||||
|
|
||||||
engelsystem_log(sprintf(
|
engelsystem_log(sprintf(
|
||||||
'Added work log entry for %s, %s hours, %s',
|
'Added work log entry for %s, %s hours, %s',
|
||||||
User_Nick_render($userWorkLog->user, true),
|
User_Nick_render($worklog->user, true),
|
||||||
$userWorkLog->hours,
|
$worklog->hours,
|
||||||
$userWorkLog->comment
|
$worklog->comment
|
||||||
));
|
));
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -6,19 +6,19 @@ use Engelsystem\Models\Worklog;
|
||||||
/**
|
/**
|
||||||
* Delete work log entry.
|
* Delete work log entry.
|
||||||
*
|
*
|
||||||
* @param User $user_source
|
* @param User $user
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function UserWorkLog_delete_view($user_source)
|
function UserWorkLog_delete_view(User $user)
|
||||||
{
|
{
|
||||||
return page_with_title(UserWorkLog_delete_title(), [
|
return page_with_title(UserWorkLog_delete_title(), [
|
||||||
info(sprintf(
|
info(sprintf(
|
||||||
__('Do you want to delete the worklog entry for %s?'),
|
__('Do you want to delete the worklog entry for %s?'),
|
||||||
User_Nick_render($user_source)
|
User_Nick_render($user)
|
||||||
), true),
|
), true),
|
||||||
form([
|
form([
|
||||||
buttons([
|
buttons([
|
||||||
button(user_link($user_source->id), glyph('remove') . __('cancel')),
|
button(user_link($user->id), glyph('remove') . __('cancel')),
|
||||||
form_submit('submit', glyph('ok') . __('delete'), 'btn-danger', false),
|
form_submit('submit', glyph('ok') . __('delete'), 'btn-danger', false),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
|
@ -36,17 +36,17 @@ function UserWorkLog_delete_title()
|
||||||
/**
|
/**
|
||||||
* Render edit table.
|
* Render edit table.
|
||||||
*
|
*
|
||||||
* @param User $user_source
|
* @param User $user
|
||||||
* @param Worklog $userWorkLog
|
* @param Worklog $worklog
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function UserWorkLog_edit_form($user_source, Worklog $userWorkLog)
|
function UserWorkLog_edit_form(User $user, Worklog $worklog)
|
||||||
{
|
{
|
||||||
return form([
|
return form([
|
||||||
form_info(__('User'), User_Nick_render($user_source)),
|
form_info(__('User'), User_Nick_render($user)),
|
||||||
form_date('work_timestamp', __('Work date'), $userWorkLog->worked_at->timestamp, null, time()),
|
form_date('work_timestamp', __('Work date'), $worklog->worked_at->timestamp, null, time()),
|
||||||
form_text('work_hours', __('Work hours'), $userWorkLog->hours),
|
form_text('work_hours', __('Work hours'), $worklog->hours),
|
||||||
form_text('comment', __('Comment'), $userWorkLog->comment, false, 200),
|
form_text('comment', __('Comment'), $worklog->comment, false, 200),
|
||||||
form_submit('submit', __('Save'))
|
form_submit('submit', __('Save'))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -54,36 +54,36 @@ function UserWorkLog_edit_form($user_source, Worklog $userWorkLog)
|
||||||
/**
|
/**
|
||||||
* Form for edit a user work log entry.
|
* Form for edit a user work log entry.
|
||||||
*
|
*
|
||||||
* @param User $user_source
|
* @param User $user
|
||||||
* @param Worklog $userWorkLog
|
* @param Worklog $worklog
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function UserWorkLog_edit_view($user_source, Worklog $userWorkLog)
|
function UserWorkLog_edit_view(User $user, Worklog $worklog)
|
||||||
{
|
{
|
||||||
return page_with_title(UserWorkLog_edit_title(), [
|
return page_with_title(UserWorkLog_edit_title(), [
|
||||||
buttons([
|
buttons([
|
||||||
button(user_link($user_source->id), __('back'))
|
button(user_link($user->id), __('back'))
|
||||||
]),
|
]),
|
||||||
msg(),
|
msg(),
|
||||||
UserWorkLog_edit_form($user_source, $userWorkLog)
|
UserWorkLog_edit_form($user, $worklog)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form for adding a user work log entry.
|
* Form for adding a user work log entry.
|
||||||
*
|
*
|
||||||
* @param User $user_source
|
* @param User $user
|
||||||
* @param Worklog $userWorkLog
|
* @param Worklog $worklog
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function UserWorkLog_add_view($user_source, Worklog $userWorkLog)
|
function UserWorkLog_add_view(User $user, Worklog $worklog)
|
||||||
{
|
{
|
||||||
return page_with_title(UserWorkLog_add_title(), [
|
return page_with_title(UserWorkLog_add_title(), [
|
||||||
buttons([
|
buttons([
|
||||||
button(user_link($user_source->id), __('back'))
|
button(user_link($user->id), __('back'))
|
||||||
]),
|
]),
|
||||||
msg(),
|
msg(),
|
||||||
UserWorkLog_edit_form($user_source, $userWorkLog)
|
UserWorkLog_edit_form($user, $worklog)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue