FinanceBuddy v1.3.0 — per-board currency shipped. All clean (php -l, ASCII, README + TODO synced)
This commit is contained in:
@@ -19,6 +19,12 @@ class FinanceHelper extends Base
|
||||
const INSTALLMENT_CURRENT_KEY = 'financebuddy_installment_current';
|
||||
const INSTALLMENT_TOTAL_KEY = 'financebuddy_installment_total';
|
||||
|
||||
// Per-board currency symbol shown before every amount (default "R$"). Up to 4 chars; the stored
|
||||
// value is trimmed, capped, and defaulted on read, so an empty or oversized value is harmless.
|
||||
const CURRENCY_KEY = 'financebuddy_currency';
|
||||
const CURRENCY_DEFAULT = 'R$';
|
||||
const CURRENCY_MAX_LENGTH = 4;
|
||||
|
||||
// Per-column opt-out of the header total. Stored per column in PROJECT metadata as
|
||||
// financebuddy_hide_total_<column_id> = 'on' (hidden) or 'off' (shown, the default). Literal
|
||||
// on/off, never 1/0, so the flag is never dropped by the metadata save (PHP empty("0") === true).
|
||||
@@ -33,6 +39,9 @@ class FinanceHelper extends Base
|
||||
// Memoized per project_id: the board hooks below call isEnabled() once per card.
|
||||
private static $enabledCache = array();
|
||||
|
||||
// Memoized per project_id: currency() is likewise resolved once per card/column render.
|
||||
private static $currencyCache = array();
|
||||
|
||||
/**
|
||||
* Is FinanceBuddy enabled for this board?
|
||||
*
|
||||
@@ -50,6 +59,26 @@ class FinanceHelper extends Base
|
||||
return self::$enabledCache[$project_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-board currency symbol shown before amounts: the stored value trimmed and capped to
|
||||
* CURRENCY_MAX_LENGTH, or CURRENCY_DEFAULT ("R$") when empty. Memoized per project.
|
||||
*
|
||||
* @param integer $project_id
|
||||
* @return string
|
||||
*/
|
||||
public function currency($project_id)
|
||||
{
|
||||
$project_id = (int) $project_id;
|
||||
|
||||
if (! isset(self::$currencyCache[$project_id])) {
|
||||
$symbol = trim((string) $this->projectMetadataModel->get($project_id, self::CURRENCY_KEY, ''));
|
||||
$symbol = mb_substr($symbol, 0, self::CURRENCY_MAX_LENGTH);
|
||||
self::$currencyCache[$project_id] = $symbol === '' ? self::CURRENCY_DEFAULT : $symbol;
|
||||
}
|
||||
|
||||
return self::$currencyCache[$project_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stored finance values for a task, with defaults. One query (getAll) since the board renders
|
||||
* this per card.
|
||||
|
||||
Reference in New Issue
Block a user