diff options
author | msquare <msquare@notrademark.de> | 2016-03-22 14:40:52 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2016-03-22 14:40:52 +0100 |
commit | c35cf85db5207133a53b316b2bde8ec46f53a274 (patch) | |
tree | a58f8ed4dc700d16d2165e474f51694d8bce4352 /includes | |
parent | 1da3cba5a70328780a362af0ec06e9f6a689562a (diff) | |
parent | 661e5595c4f5844cec94f4fb304c16650fa3b211 (diff) |
Merge pull request #243 from tike/calculate_vouchers
issue #242 - make app caluclate number of vouchers for angels
Diffstat (limited to 'includes')
-rw-r--r-- | includes/model/ShiftEntry_model.php | 17 | ||||
-rw-r--r-- | includes/model/User_model.php | 15 | ||||
-rw-r--r-- | includes/view/User_view.php | 4 |
3 files changed, 35 insertions, 1 deletions
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 @@ -85,6 +85,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. * * @param int $shift_id 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']) ]); |