2 Commits

3 changed files with 59 additions and 0 deletions

28
Helper/FinanceHelper.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace Kanboard\Plugin\FinanceBuddy\Helper;
use Kanboard\Core\Base;
/**
* Template/controller helper for FinanceBuddy.
*
* FinanceBuddy is opt-in per board: every render and save point is gated on isEnabled(), so an
* un-enabled board is untouched. The flag lives in project metadata (key financebuddy_enabled),
* written by the checkbox on the project's Integrations page.
*/
class FinanceHelper extends Base
{
const ENABLED_KEY = 'financebuddy_enabled';
/**
* Is FinanceBuddy enabled for this board?
*
* @param integer $project_id
* @return bool
*/
public function isEnabled($project_id)
{
return (int) $this->projectMetadataModel->get($project_id, self::ENABLED_KEY, 0) === 1;
}
}

View File

@@ -13,6 +13,17 @@ class Plugin extends Base
$this->hook->on('template:layout:css', array( $this->hook->on('template:layout:css', array(
'template' => 'plugins/FinanceBuddy/Asset/css/finance.css', 'template' => 'plugins/FinanceBuddy/Asset/css/finance.css',
)); ));
// Per-board opt-in: a checkbox on the project's Settings -> Integrations page. Nothing
// else in the plugin renders or saves until a project manager enables it for that board.
$this->template->hook->attach('template:project:integrations', 'financeBuddy:project/integration');
}
public function getHelpers()
{
return array(
'Plugin\FinanceBuddy\Helper' => array('FinanceHelper'),
);
} }
public function getPluginName() public function getPluginName()

View File

@@ -0,0 +1,20 @@
<h3><i class="fa fa-money fa-fw" aria-hidden="true"></i> <?= t('FinanceBuddy') ?></h3>
<div class="listing">
<?php /* Hidden 0 before the checkbox so unchecking posts a value (a bare unchecked box posts
nothing, which would leave a stale 1). The checkbox's 1 wins when checked. The shared
Integrations form saves this straight into project metadata. */ ?>
<input type="hidden" name="<?= \Kanboard\Plugin\FinanceBuddy\Helper\FinanceHelper::ENABLED_KEY ?>" value="0">
<?= $this->form->checkbox(
\Kanboard\Plugin\FinanceBuddy\Helper\FinanceHelper::ENABLED_KEY,
t('Enable FinanceBuddy on this board'),
1,
isset($values['financebuddy_enabled']) && $values['financebuddy_enabled'] == 1
) ?>
<p class="form-help">
<?= t('When enabled, cards on this board can carry a money value (debit or credit, with optional installments), shown on the card and totalled per column. Boards left disabled are unaffected.') ?>
</p>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
</div>