Config: Removed nightshifts query

main
Igor Scheller 6 years ago committed by msquare
parent 0734807eef
commit 2a134e6c0b

@ -79,23 +79,13 @@ return [
// local timezone // local timezone
'timezone' => env('TIMEZONE', 'Europe/Berlin'), 'timezone' => env('TIMEZONE', 'Europe/Berlin'),
// weigh every shift the same
//'shift_sum_formula' => 'SUM(`end` - `start`)',
// Multiply 'night shifts' and freeloaded shifts (start or end between 2 and 6 exclusive) by 2 // Multiply 'night shifts' and freeloaded shifts (start or end between 2 and 6 exclusive) by 2
'shift_sum_formula' => ' 'night_shifts' => [
SUM( 'enabled' => true, // Disable to weigh every shift the same
(1 + 'start' => 2,
( 'end' => 6,
(HOUR(FROM_UNIXTIME(`Shifts`.`end`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) < 6) 'multiplier' => 2,
OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`start`)) < 6) ],
OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) <= 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) >= 6)
)
)
* (`Shifts`.`end` - `Shifts`.`start`)
* (1 - 3 * `ShiftEntry`.`freeloaded`)
)
',
// Voucher calculation // Voucher calculation
'voucher_settings' => [ 'voucher_settings' => [

@ -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 * @return int|string
*/ */
function stats_angels_needed_for_nightshifts() function stats_angels_needed_for_nightshifts()
{ {
$nightShiftsConfig = config('night_shifts');
$nightStartTime = $nightShiftsConfig['start'];
$nightEndTime = $nightShiftsConfig['end'];
$night_start = parse_date( $night_start = parse_date(
'Y-m-d H:i', '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(" $result = Db::selectOne("
SELECT SUM(`count`) AS `count` FROM ( SELECT SUM(`count`) AS `count` FROM (
SELECT SELECT

@ -26,8 +26,7 @@ function User_delete($user_id)
*/ */
function User_tshirt_score($user) function User_tshirt_score($user)
{ {
$shift_sum_formula = config('shift_sum_formula'); $shift_sum_formula = User_get_shifts_sum_query();
$result_shifts = DB::selectOne(' $result_shifts = DB::selectOne('
SELECT ROUND((' . $shift_sum_formula . ') / 3600, 2) AS `tshirt_score` SELECT ROUND((' . $shift_sum_formula . ') / 3600, 2) AS `tshirt_score`
FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
@ -530,3 +529,34 @@ function User_get_eligable_voucher_count(&$user)
return $eligable_vouchers; 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']
);
}

@ -16,7 +16,7 @@ function admin_active_title()
function admin_active() function admin_active()
{ {
$tshirt_sizes = config('tshirt_sizes'); $tshirt_sizes = config('tshirt_sizes');
$shift_sum_formula = config('shift_sum_formula'); $shift_sum_formula = User_get_shifts_sum_query();
$request = request(); $request = request();
$msg = ''; $msg = '';

@ -532,6 +532,7 @@ function User_view(
$admin_user_worklog_privilege, $admin_user_worklog_privilege,
$user_worklogs $user_worklogs
) { ) {
$nightShiftsConfig = config('night_shifts');
$user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']); $user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']);
$myshifts_table = ''; $myshifts_table = '';
if ($its_me || $admin_user_privilege) { if ($its_me || $admin_user_privilege) {
@ -619,8 +620,12 @@ function User_view(
]), ]),
($its_me || $admin_user_privilege) ? '<h2>' . __('Shifts') . '</h2>' : '', ($its_me || $admin_user_privilege) ? '<h2>' . __('Shifts') . '</h2>' : '',
$myshifts_table, $myshifts_table,
$its_me ? info( ($its_me && $nightShiftsConfig['enabled']) ? info(
glyph('info-sign') . __('Your night shifts between 2 and 8 am count twice.'), glyph('info-sign') . sprintf(
__('Your night shifts between %d and %d am count twice.'),
$nightShiftsConfig['start'],
$nightShiftsConfig['end']
),
true true
) : '', ) : '',
$its_me && count($shifts) == 0 $its_me && count($shifts) == 0

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Engelsystem 2.0\n" "Project-Id-Version: Engelsystem 2.0\n"
"POT-Creation-Date: 2017-12-29 19:01+0100\n" "POT-Creation-Date: 2017-12-29 19:01+0100\n"
"PO-Revision-Date: 2018-08-27 22:26+0200\n" "PO-Revision-Date: 2018-09-17 12:10+0200\n"
"Last-Translator: msquare <msquare@notrademark.de>\n" "Last-Translator: msquare <msquare@notrademark.de>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: de_DE\n" "Language: de_DE\n"
@ -2768,8 +2768,9 @@ msgid "JSON Export"
msgstr "JSON Export" msgstr "JSON Export"
#: /Users/msquare/workspace/projects/engelsystem/includes/view/User_view.php:598 #: /Users/msquare/workspace/projects/engelsystem/includes/view/User_view.php:598
msgid "Your night shifts between 2 and 8 am count twice." #, php-format
msgstr "Deine Nachtschichten zwischen 2 und 8 Uhr zählen doppelt." msgid "Your night shifts between %d and %d am count twice."
msgstr "Deine Nachtschichten zwischen %d und %d Uhr zählen doppelt."
#: /Users/msquare/workspace/projects/engelsystem/includes/view/User_view.php:603 #: /Users/msquare/workspace/projects/engelsystem/includes/view/User_view.php:603
#, php-format #, php-format

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Engelsystem 2.0\n" "Project-Id-Version: Engelsystem 2.0\n"
"POT-Creation-Date: 2017-04-25 05:23+0200\n" "POT-Creation-Date: 2017-04-25 05:23+0200\n"
"PO-Revision-Date: 2017-04-25 05:23+0200\n" "PO-Revision-Date: 2018-09-17 12:11+0200\n"
"Last-Translator: samba <samba@autistici.org>\n" "Last-Translator: samba <samba@autistici.org>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: pt_BR\n" "Language: pt_BR\n"
@ -2385,8 +2385,9 @@ msgid "Action"
msgstr "Ação" msgstr "Ação"
#: includes/view/User_view.php:373 #: includes/view/User_view.php:373
msgid "Your night shifts between 2 and 8 am count twice." #, php-format
msgstr "Os seus turnos noturnos entre 2h e 8h contam como dois." msgid "Your night shifts between %d and %d am count twice."
msgstr "Os seus turnos noturnos entre %dh e %dh contam como dois."
#: includes/view/User_view.php:374 #: includes/view/User_view.php:374
#, php-format #, php-format

Loading…
Cancel
Save