mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-25 16:31:15 -06:00
Fix factory and triggers.
This commit is contained in:
parent
694447e66c
commit
51acc34a80
@ -71,7 +71,7 @@ class AbstractTrigger
|
||||
*/
|
||||
public static function makeFromTriggerValue(string $triggerValue)
|
||||
{
|
||||
$self = new self;
|
||||
$self = new static;
|
||||
$self->triggerValue = $triggerValue;
|
||||
|
||||
return $self;
|
||||
|
@ -55,7 +55,7 @@ class AmountExactly extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$amount = $journal->amount_positive;
|
||||
$compare = $this->trigger->trigger_value;
|
||||
$compare = $this->triggerValue;
|
||||
$result = bccomp($amount, $compare, 4);
|
||||
if ($result === 0) {
|
||||
// found something
|
||||
|
@ -55,7 +55,7 @@ class AmountLess extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$amount = $journal->amount_positive;
|
||||
$compare = $this->trigger->trigger_value;
|
||||
$compare = $this->triggerValue;
|
||||
$result = bccomp($amount, $compare, 4);
|
||||
if ($result === -1) {
|
||||
// found something
|
||||
|
@ -55,7 +55,7 @@ class AmountMore extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$amount = $journal->amount_positive;
|
||||
$compare = $this->trigger->trigger_value;
|
||||
$compare = $this->triggerValue;
|
||||
$result = bccomp($amount, $compare, 4);
|
||||
if ($result === 1) {
|
||||
// found something
|
||||
|
@ -54,7 +54,7 @@ class DescriptionContains extends AbstractTrigger implements TriggerInterface
|
||||
*/
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$source = strtolower($journal->description);
|
||||
|
||||
$strpos = strpos($source, $search);
|
||||
|
@ -55,7 +55,7 @@ class DescriptionEnds extends AbstractTrigger implements TriggerInterface
|
||||
{
|
||||
$description = strtolower($journal->description);
|
||||
$descriptionLength = strlen($description);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$searchLength = strlen($search);
|
||||
|
||||
// if the string to search for is longer than the description,
|
||||
|
@ -54,7 +54,7 @@ class DescriptionIs extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$description = strtolower($journal->description);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
if ($description == $search) {
|
||||
Log::debug('"' . $description . '" equals "' . $search . '" exactly. Return true.');
|
||||
|
@ -54,7 +54,7 @@ class DescriptionStarts extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$description = strtolower($journal->description);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
$part = substr($description, 0, strlen($search));
|
||||
|
||||
|
@ -54,7 +54,7 @@ class FromAccountContains extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$fromAccountName = strtolower($journal->source_account->name);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$strpos = strpos($fromAccountName, $search);
|
||||
|
||||
if (!($strpos === false)) {
|
||||
|
@ -55,7 +55,7 @@ class FromAccountEnds extends AbstractTrigger implements TriggerInterface
|
||||
{
|
||||
$name = strtolower($journal->source_account->name);
|
||||
$nameLength = strlen($name);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$searchLength = strlen($search);
|
||||
|
||||
// if the string to search for is longer than the account name,
|
||||
|
@ -54,7 +54,7 @@ class FromAccountIs extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$fromAccountName = strtolower($journal->source_account->name);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
if ($fromAccountName == $search) {
|
||||
Log::debug('"' . $fromAccountName . '" equals "' . $search . '" exactly. Return true.');
|
||||
|
@ -54,7 +54,7 @@ class FromAccountStarts extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$fromAccountName = strtolower($journal->source_account->name);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
$part = substr($fromAccountName, 0, strlen($search));
|
||||
|
||||
|
@ -54,7 +54,7 @@ class ToAccountContains extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$toAccountName = strtolower($journal->destination_account->name);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$strpos = strpos($toAccountName, $search);
|
||||
|
||||
if (!($strpos === false)) {
|
||||
|
@ -55,7 +55,7 @@ class ToAccountEnds extends AbstractTrigger implements TriggerInterface
|
||||
{
|
||||
$toAccountName = strtolower($journal->destination_account->name);
|
||||
$toAccountNameLength = strlen($toAccountName);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$searchLength = strlen($search);
|
||||
|
||||
// if the string to search for is longer than the account name,
|
||||
|
@ -54,7 +54,7 @@ class ToAccountIs extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$toAccountName = strtolower($journal->destination_account->name);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
if ($toAccountName == $search) {
|
||||
Log::debug('"' . $toAccountName . '" equals "' . $search . '" exactly. Return true.');
|
||||
|
@ -54,7 +54,7 @@ class ToAccountStarts extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$toAccountName = strtolower($journal->destination_account->name);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
$part = substr($toAccountName, 0, strlen($search));
|
||||
|
||||
|
@ -54,7 +54,7 @@ class TransactionType extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal)
|
||||
{
|
||||
$type = strtolower($journal->transactionType->type);
|
||||
$search = strtolower($this->trigger->trigger_value);
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
if ($type == $search) {
|
||||
Log::debug('Journal is of type "' . $type . '" which matches with "' . $search . '". Return true');
|
||||
|
@ -28,14 +28,17 @@ class TriggerFactory
|
||||
*
|
||||
* @param RuleTrigger $trigger
|
||||
*
|
||||
* @return TriggerInterface
|
||||
* @return AbstractTrigger
|
||||
*/
|
||||
public static function getTrigger(RuleTrigger $trigger): TriggerInterface
|
||||
public static function getTrigger(RuleTrigger $trigger)
|
||||
{
|
||||
$triggerType = $trigger->trigger_type;
|
||||
$class = self::getTriggerClass($triggerType);
|
||||
|
||||
return new $class($trigger);
|
||||
/** @var AbstractTrigger $class */
|
||||
$class = self::getTriggerClass($triggerType);
|
||||
$obj = $class::makeFromTriggerValue($trigger->trigger_value);
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user