From 9093a946b4a319027efed7ea5e5af51db5a13655 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sat, 1 Nov 2014 19:19:00 +0000 Subject: [PATCH] functions.inc.php: - add functions db_quota_text() and db_quota_percent() to generate queries for used quota ("x/y" and percentage) git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1712 a1433add-5e2c-0410-b055-b7f2511e0802 --- functions.inc.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/functions.inc.php b/functions.inc.php index 881e99b5..e9219fe3 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1302,6 +1302,34 @@ function db_get_boolean($bool) { } } +/** + * Returns a query that reports the used quota ("x / y") + * @param string column containing used quota + * @param string column containing allowed quota + * @param string column that will contain "x / y" + * @return string + */ +function db_quota_text($count, $quota, $fieldname) { + return " CASE $quota + WHEN '-1' THEN coalesce($count,0) + ELSE CONCAT(coalesce($count,0), ' / ', $quota) + END AS $fieldname"; +} + +/** + * Returns a query that reports the used quota ("x / y") + * @param string column containing used quota + * @param string column containing allowed quota + * @param string column that will contain "x / y" + * @return string + */ +function db_quota_percent($count, $quota, $fieldname) { + return " CASE $quota + WHEN '-1' THEN -1 + ELSE round(100 * coalesce($count,0) / $quota) + END AS $fieldname"; +} + /** * returns true if PostgreSQL is used, false otherwise */