From 661e5595c4f5844cec94f4fb304c16650fa3b211 Mon Sep 17 00:00:00 2001 From: tike Date: Fri, 5 Feb 2016 22:57:57 +0100 Subject: [PATCH] issue #242 - make app caluclate number of vouchers for angels --- config/config.default.php | 6 ++++++ includes/model/ShiftEntry_model.php | 17 +++++++++++++++++ includes/model/User_model.php | 15 +++++++++++++++ includes/view/User_view.php | 4 +++- locale/de_DE.UTF-8/LC_MESSAGES/default.mo | Bin 37135 -> 37514 bytes locale/de_DE.UTF-8/LC_MESSAGES/default.po | 18 ++++++++++++++++++ 6 files changed, 59 insertions(+), 1 deletion(-) diff --git a/config/config.default.php b/config/config.default.php index e9ec0427..a8f4f454 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -47,6 +47,12 @@ $shift_sum_formula = "SUM( ))*(`Shifts`.`end` - `Shifts`.`start`)*(1 - 3 * `ShiftEntry`.`freeloaded`) )"; +// voucher calculation +$voucher_settings = array( + "initial_vouchers" => 2, + "shifts_per_voucher" => 1 +); + // weigh every shift the same // $shift_sum_formula = "SUM(`end` - `start`)"; diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 008531ff..6324c3bf 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -84,6 +84,23 @@ function ShiftEntries_upcoming_for_user($user) { "); } +/** + * Returns shifts completed by the given user. + * + * @param User $user + */ +function ShiftEntries_finished_by_user($user){ + return sql_select(" + SELECT * + FROM `ShiftEntry` + JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`) + JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id` + WHERE `ShiftEntry`.`UID`=" . sql_escape($user['UID']) . " + AND `Shifts`.`end` < " . sql_escape(time()) . " + ORDER BY `Shifts`.`end` + "); +} + /** * Returns all shift entries in given shift for given angeltype. * diff --git a/includes/model/User_model.php b/includes/model/User_model.php index e1bb2733..00c3bfdd 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -260,4 +260,19 @@ function User_generate_password_recovery_token(&$user) { return $user['password_recovery_token']; } + +function User_get_eligable_voucher_count(&$user) { + global $voucher_settings; + + $shifts_done = count(ShiftEntries_finished_by_user($user)); + + $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers']; + $elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers; + if ( $elegible_vouchers < 0) { + return 0; + } + + return $elegible_vouchers; +} + ?> diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 09668d6f..dbdc617b 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -45,8 +45,10 @@ function User_edit_vouchers_view($user) { buttons([ button(user_link($user), glyph('chevron-left') . _("back")) ]), + heading(sprintf(_("angel should receive at least %d vouchers."), User_get_eligable_voucher_count($user)), 3), + heading(_("This is a automatically calculated MINIMUM value, you can of course give out more if appropriate!"), 4), form([ - form_spinner('vouchers', _("Number of vouchers"), $user['got_voucher']), + form_spinner('vouchers', _("Number of vouchers given out"), $user['got_voucher']), form_submit('submit', _("Save")) ], page_link_to('users') . '&action=edit_vouchers&user_id=' . $user['UID']) ]); diff --git a/locale/de_DE.UTF-8/LC_MESSAGES/default.mo b/locale/de_DE.UTF-8/LC_MESSAGES/default.mo index c44c9a58be58cf03d42333077837064bbb147483..c9139c28f15e461f4e1165d95c15b0740724192d 100644 GIT binary patch delta 10708 zcmY+}3w+OI|Htv~Hq16VU}Fxm-^McA7(>jACFD5gV@|XE*x30%a`-uvNSKhCM55LS zS?NF$sZdEsq66JUbfCKX%U|91>%HsR{iyGw&z{$HeXsBLI)AtOwtB1ggWJ75UpA<< z-r@Sn%W;}xXt3if@^+khEmZ0_A+e6*kM%Jco1<>^#6X;cQJ9Oj;VNv2uUOBbp8FH^ zepegE3BXhgaU74+pM)A1k8$X>mSY|Ad#wji4IV*XJcB;?6*j_eumRr0Pz>Z{jKzt@ zFib*qupidO0`#GMr>r{RICIdS8}rc*m!S(EMvbrv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