This commit is contained in:
James Cole 2017-04-15 22:52:01 +02:00
parent 209a907c61
commit f0dab5bdb9
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php
/**
* HasAttachment.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\TransactionJournal;
class HasAttachment extends AbstractTrigger implements TriggerInterface
{
/**
* A trigger is said to "match anything", or match any given transaction,
* when the trigger value is very vague or has no restrictions. Easy examples
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
* has an amount of more than zero! Other examples are all the "Description"-triggers
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
*
* If the user tries to create such a trigger, this method MUST return true so Firefly III
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
* (even if it will still include 99.9% of the users transactions), this method MUST return
* false.
*
* @param null $value
*
* @return bool
*/
public static function willMatchEverything($value = null)
{
$value = intval($value);
if ($value < 0) {
return true;
}
return false;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function triggered(TransactionJournal $journal): bool
{
$minimum = intval($this->triggerValue);
$attachments = $journal->attachments()->count();
if ($attachments >= $minimum) {
return true;
}
return false;
}
}

View File

@ -176,6 +176,7 @@ return [
'category_is' => 'FireflyIII\Rules\Triggers\CategoryIs',
'budget_is' => 'FireflyIII\Rules\Triggers\BudgetIs',
'tag_is' => 'FireflyIII\Rules\Triggers\TagIs',
'has_attachments' => 'FireflyIII\Rules\Triggers\HasAttachment',
],
'rule-actions' => [
'set_category' => 'FireflyIII\Rules\Actions\SetCategory',

View File

@ -287,6 +287,8 @@ return [
'rule_trigger_category_is_choice' => 'Category is..',
'rule_trigger_budget_is_choice' => 'Budget is..',
'rule_trigger_tag_is_choice' => '(A) tag is..',
'rule_trigger_has_attachments_choice' => 'Has at least this many attachments',
'rule_trigger_has_attachments' => 'Has at least :trigger_value attachment(s)',
'rule_trigger_store_journal' => 'When a transaction is created',
'rule_trigger_update_journal' => 'When a transaction is updated',
'rule_action_set_category' => 'Set category to ":action_value"',