summaryrefslogtreecommitdiff
path: root/includes/controller/user_worklog_controller.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/controller/user_worklog_controller.php')
-rw-r--r--includes/controller/user_worklog_controller.php94
1 files changed, 54 insertions, 40 deletions
diff --git a/includes/controller/user_worklog_controller.php b/includes/controller/user_worklog_controller.php
index bd62c83c..a7218071 100644
--- a/includes/controller/user_worklog_controller.php
+++ b/includes/controller/user_worklog_controller.php
@@ -2,25 +2,27 @@
/**
* Delete a work log entry.
+ *
+ * @return array
*/
function user_worklog_delete_controller()
{
global $user;
-
+
$request = request();
$userWorkLog = UserWorkLog($request->input('user_worklog_id'));
if (empty($userWorkLog)) {
redirect(user_link($user));
}
$user_source = User($userWorkLog['user_id']);
-
+
if ($request->has('confirmed')) {
UserWorkLog_delete($userWorkLog);
-
+
success(_('Work log entry deleted.'));
redirect(user_link($user_source));
}
-
+
return [
UserWorkLog_delete_title(),
UserWorkLog_delete_view($user_source, $userWorkLog)
@@ -29,29 +31,31 @@ function user_worklog_delete_controller()
/**
* Edit work log for user.
+ *
+ * @return array
*/
function user_worklog_edit_controller()
{
global $user;
-
+
$request = request();
$userWorkLog = UserWorkLog($request->input('user_worklog_id'));
if (empty($userWorkLog)) {
redirect(user_link($user));
}
$user_source = User($userWorkLog['user_id']);
-
+
if ($request->has('submit')) {
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
-
+
if ($valid) {
UserWorkLog_update($userWorkLog);
-
+
success(_('Work log entry updated.'));
redirect(user_link($user_source));
}
}
-
+
return [
UserWorkLog_edit_title(),
UserWorkLog_edit_view($user_source, $userWorkLog)
@@ -59,34 +63,38 @@ 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)
{
$request = request();
-
+
$valid = true;
-
- $userWorkLog['work_timestamp'] = parse_date('Y-m-d H:i', $request->input('work_timestamp') . ' 00:00');
- if ($userWorkLog['work_timestamp'] == null) {
+
+ $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 ##[.##].'));
}
-
+
$userWorkLog['comment'] = $request->input('comment');
if (empty($userWorkLog['comment'])) {
$valid = false;
error(_('Please enter a comment.'));
}
-
+
return [
$valid,
$userWorkLog
@@ -95,30 +103,32 @@ function user_worklog_from_request($userWorkLog)
/**
* Add work log entry to user.
+ *
+ * @return array
*/
function user_worklog_add_controller()
{
global $user;
-
+
$request = request();
$user_source = User($request->input('user_id'));
if (empty($user_source)) {
redirect(user_link($user));
}
-
+
$userWorkLog = UserWorkLog_new($user_source);
-
+
if ($request->has('submit')) {
list ($valid, $userWorkLog) = user_worklog_from_request($userWorkLog);
-
+
if ($valid) {
UserWorkLog_create($userWorkLog);
-
+
success(_('Work log entry created.'));
redirect(user_link($user_source));
}
}
-
+
return [
UserWorkLog_add_title(),
UserWorkLog_add_view($user_source, $userWorkLog)
@@ -128,12 +138,14 @@ 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)
{
return page_link_to('user_worklog', [
- 'action' => 'add',
+ 'action' => 'add',
'user_id' => $user['UID']
]);
}
@@ -141,12 +153,13 @@ 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)
{
return page_link_to('user_worklog', [
- 'action' => 'edit',
+ 'action' => 'edit',
'user_worklog_id' => $userWorkLog['id']
]);
}
@@ -154,34 +167,37 @@ function user_worklog_edit_link($userWorkLog)
/**
* Link to work log entry delete.
*
- * @param UserWorkLog $userWorkLog
- * @param array[] $parameters
+ * @param array $userWorkLog
+ * @param array[] $parameters
+ * @return string
*/
function user_worklog_delete_link($userWorkLog, $parameters = [])
{
return page_link_to('user_worklog', array_merge([
- 'action' => 'delete',
+ 'action' => 'delete',
'user_worklog_id' => $userWorkLog['id']
], $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));
}
-
+
switch ($action) {
case 'add':
return user_worklog_add_controller();
@@ -191,5 +207,3 @@ function user_worklogs_controller()
return user_worklog_delete_controller();
}
}
-
-?> \ No newline at end of file