summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-09-07 00:41:48 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2019-09-18 04:27:56 +0200
commitd71b27b78b29a2ed725a6e631bf8085bde257f18 (patch)
treebfb480bfdaa7369e51973bda31f75b3adfe45b99 /includes
parent64c4743f57c2444a2e40ab4f115cbc6bdc9bcde1 (diff)
Shifts: Save time as worklog if past shift gets deleted
Diffstat (limited to 'includes')
-rw-r--r--includes/controller/shifts_controller.php1
-rw-r--r--includes/model/Shifts_model.php2
-rw-r--r--includes/model/UserWorkLog_model.php35
3 files changed, 37 insertions, 1 deletions
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index caf124ba..a4d44151 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -220,6 +220,7 @@ function shift_delete_controller()
// Schicht löschen bestätigt
if ($request->hasPostData('delete')) {
+ UserWorkLog_from_shift($shift_id);
Shift_delete($shift_id);
engelsystem_log(
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 6bb17cf2..2408eb49 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -508,8 +508,8 @@ function Shift_delete_by_psid($shift_psid)
*/
function Shift_delete($shift_id)
{
- DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]);
mail_shift_delete(Shift($shift_id));
+ DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]);
}
/**
diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php
index 7b766c5e..c450d901 100644
--- a/includes/model/UserWorkLog_model.php
+++ b/includes/model/UserWorkLog_model.php
@@ -122,6 +122,41 @@ function UserWorkLog_create($userWorkLog)
}
/**
+ * @param array|int $shift
+ */
+function UserWorkLog_from_shift($shift)
+{
+ $shift = is_array($shift) ? $shift : Shift($shift);
+
+ if ($shift['start'] > time()) {
+ return;
+ }
+
+ $room = Room($shift['RID']);
+ foreach ($shift['ShiftEntry'] as $entry) {
+ if ($entry['freeloaded']) {
+ continue;
+ }
+ $type = AngelType($entry['TID']);
+
+ UserWorkLog_create([
+ 'user_id' => $entry['UID'],
+ 'work_timestamp' => $shift['start'],
+ 'work_hours' => ($shift['end'] - $shift['start']) / 60 / 60,
+ 'comment' => sprintf(
+ '%s (%s as %s) in %s, %s-%s',
+ $shift['name'],
+ $shift['title'],
+ $type['name'],
+ $room['Name'],
+ Carbon::createFromTimestamp($shift['start'])->format(__('m/d/Y h:i a')),
+ Carbon::createFromTimestamp($shift['end'])->format(__('m/d/Y h:i a'))
+ ),
+ ]);
+ }
+}
+
+/**
* New user work log entry
*
* @param int $userId