summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-17 12:33:15 +0200
committermsquare <msquare@notrademark.de>2018-09-23 11:40:53 +0200
commit2a134e6c0b8e7c5bbeade38d29052194bd9dfa46 (patch)
treebfd99cb3793e3cfa2ef0e4da550fcae528ed9273 /includes/model
parent0734807eef5a6b638b06d57aef6ee59ac78a3456 (diff)
Config: Removed nightshifts query
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/Stats.php10
-rw-r--r--includes/model/User_model.php34
2 files changed, 39 insertions, 5 deletions
diff --git a/includes/model/Stats.php b/includes/model/Stats.php
index 20376ac6..c8342d82 100644
--- a/includes/model/Stats.php
+++ b/includes/model/Stats.php
@@ -128,17 +128,21 @@ function stats_angels_needed_three_hours()
}
/**
- * Returns the number of needed angels for nightshifts (between 2 and 8)
+ * Returns the number of needed angels for nightshifts (see config)
*
* @return int|string
*/
function stats_angels_needed_for_nightshifts()
{
+ $nightShiftsConfig = config('night_shifts');
+ $nightStartTime = $nightShiftsConfig['start'];
+ $nightEndTime = $nightShiftsConfig['end'];
+
$night_start = parse_date(
'Y-m-d H:i',
- date('Y-m-d', time() + 12 * 60 * 60) . ' 02:00'
+ date('Y-m-d', time() + 12 * 60 * 60) . ' ' . $nightStartTime . ':00'
);
- $night_end = $night_start + 6 * 60 * 60;
+ $night_end = $night_start + ($nightEndTime - $nightStartTime) * 60 * 60;
$result = Db::selectOne("
SELECT SUM(`count`) AS `count` FROM (
SELECT
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index cbdb5efe..092ddf27 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -26,8 +26,7 @@ function User_delete($user_id)
*/
function User_tshirt_score($user)
{
- $shift_sum_formula = config('shift_sum_formula');
-
+ $shift_sum_formula = User_get_shifts_sum_query();
$result_shifts = DB::selectOne('
SELECT ROUND((' . $shift_sum_formula . ') / 3600, 2) AS `tshirt_score`
FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
@@ -530,3 +529,34 @@ function User_get_eligable_voucher_count(&$user)
return $eligable_vouchers;
}
+
+/**
+ * Generates the query to sum night shifts
+ *
+ * @return string
+ */
+function User_get_shifts_sum_query()
+{
+ $nightShifts = config('night_shifts');
+ if (!$nightShifts['enabled']) {
+ return 'SUM(`end` - `start`)';
+ }
+
+ return sprintf('
+ SUM(
+ (1 +
+ (
+ (HOUR(FROM_UNIXTIME(`Shifts`.`end`)) > %1$d AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) < %2$d)
+ OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) > %1$d AND HOUR(FROM_UNIXTIME(`Shifts`.`start`)) < %2$d)
+ OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) <= %1$d AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) >= %2$d)
+ )
+ )
+ * (`Shifts`.`end` - `Shifts`.`start`)
+ * (1 - (%3$d + 1) * `ShiftEntry`.`freeloaded`)
+ )
+ ',
+ $nightShifts['start'],
+ $nightShifts['end'],
+ $nightShifts['multiplier']
+ );
+}