All actions and triggers.

This commit is contained in:
James Cole 2016-01-13 15:10:49 +01:00
parent 3dbb1f034d
commit 668633e764
9 changed files with 421 additions and 10 deletions

View File

@ -0,0 +1,56 @@
<?php
/**
* AddTag.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Rules\Actions;
use Auth;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
/**
* Class AddTag
*
* @package FireflyIII\Rules\Actions
*/
class AddTag implements ActionInterface
{
private $action;
private $journal;
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
* @param TransactionJournal $journal
*/
public function __construct(RuleAction $action, TransactionJournal $journal)
{
$this->action = $action;
$this->journal = $journal;
}
/**
* @return bool
*/
public function act()
{
// journal has this tag maybe?
$tag = Tag::firstOrCreateEncrypted(['tag' => $this->action->action_value, 'user_id' => Auth::user()->id]);
$count = $this->journal->tags()->where('id', $tag->id)->count();
if ($count == 0) {
$this->journal->tags()->save($tag);
}
return true;
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* AppendDescription.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
/**
* Class AppendDescription
*
* @package FireflyIII\Rules\Actions
*/
class AppendDescription implements ActionInterface
{
private $action;
private $journal;
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
* @param TransactionJournal $journal
*/
public function __construct(RuleAction $action, TransactionJournal $journal)
{
$this->action = $action;
$this->journal = $journal;
}
/**
* @return bool
*/
public function act()
{
$this->journal->description = $this->journal->description . $this->action->action_value;
$this->journal->save();
return true;
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* ClearBudget.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Rules\Actions;
use Auth;
use FireflyIII\Models\Category;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ClearBudget
*
* @package FireflyIII\Rules\Action
*/
class ClearBudget implements ActionInterface
{
private $action;
private $journal;
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
* @param TransactionJournal $journal
*/
public function __construct(RuleAction $action, TransactionJournal $journal)
{
$this->action = $action;
$this->journal = $journal;
}
/**
* @return bool
*/
public function act()
{
$this->journal->budgets()->detach();
return true;
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* ClearCategory.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Rules\Actions;
use Auth;
use FireflyIII\Models\Category;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ClearCategory
*
* @package FireflyIII\Rules\Action
*/
class ClearCategory implements ActionInterface
{
private $action;
private $journal;
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
* @param TransactionJournal $journal
*/
public function __construct(RuleAction $action, TransactionJournal $journal)
{
$this->action = $action;
$this->journal = $journal;
}
/**
* @return bool
*/
public function act()
{
$this->journal->categories()->detach();
return true;
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* PrependDescription.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
/**
* Class AppendDescription
*
* @package FireflyIII\Rules\Actions
*/
class PrependDescription implements ActionInterface
{
private $action;
private $journal;
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
* @param TransactionJournal $journal
*/
public function __construct(RuleAction $action, TransactionJournal $journal)
{
$this->action = $action;
$this->journal = $journal;
}
/**
* @return bool
*/
public function act()
{
$this->journal->description = $this->action->action_value . $this->journal->description;
$this->journal->save();
return true;
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* RemoveAllTags.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
/**
* Class RemoveAllTags
*
* @package FireflyIII\Rules\Actions
*/
class RemoveAllTags implements ActionInterface
{
private $action;
private $journal;
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
* @param TransactionJournal $journal
*/
public function __construct(RuleAction $action, TransactionJournal $journal)
{
$this->action = $action;
$this->journal = $journal;
}
/**
* @return bool
*/
public function act()
{
$this->journal->tags()->detach();
return true;
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* RemoveTag.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Rules\Actions;
use Auth;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
/**
* Class RemoveTag
*
* @package FireflyIII\Rules\Actions
*/
class RemoveTag implements ActionInterface
{
private $action;
private $journal;
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
* @param TransactionJournal $journal
*/
public function __construct(RuleAction $action, TransactionJournal $journal)
{
$this->action = $action;
$this->journal = $journal;
}
/**
* @return bool
*/
public function act()
{
// if tag does not exist, no need to continue:
$name = $this->action->action_value;
/** @var Tag $tag */
$tag = Auth::user()->tags()->get()->filter(
function (Tag $tag) use ($name) {
return $tag->tag == $name;
}
)->first();
if (!is_null($tag)) {
$this->journal->tags()->detach([$tag->id]);
}
return true;
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* SetDescription.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
/**
* Class SetDescription
*
* @package FireflyIII\Rules\Actions
*/
class SetDescription implements ActionInterface
{
private $action;
private $journal;
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
* @param TransactionJournal $journal
*/
public function __construct(RuleAction $action, TransactionJournal $journal)
{
$this->action = $action;
$this->journal = $journal;
}
/**
* @return bool
*/
public function act()
{
$this->journal->description = $this->action->action_value;
$this->journal->save();
return true;
}
}

View File

@ -183,21 +183,21 @@ return [
'amount_exactly' => 'FireflyIII\Rules\Triggers\AmountExactly',
'amount_more' => 'FireflyIII\Rules\Triggers\AmountMore',
'description_starts' => 'FireflyIII\Rules\Triggers\DescriptionStarts',
'description_ends' => 'FireflyIII\Rules\Triggers',
'description_ends' => 'FireflyIII\Rules\Triggers\DescriptionEnds',
'description_contains' => 'FireflyIII\Rules\Triggers\DescriptionContains',
'description_is' => 'FireflyIII\Rules\Triggers',
'description_is' => 'FireflyIII\Rules\Triggers\DescriptionIs',
],
'rule-actions' => [
'set_category' => 'FireflyIII\Rules\Actions\SetCategory',
'clear_category' => 'FireflyIII\Rules\Actions',
'clear_category' => 'FireflyIII\Rules\Actions\ClearCategory',
'set_budget' => 'FireflyIII\Rules\Actions\SetBudget',
'clear_budget' => 'FireflyIII\Rules\Actions',
'add_tag' => 'FireflyIII\Rules\Actions',
'remove_tag' => 'FireflyIII\Rules\Actions',
'remove_all_tags' => 'FireflyIII\Rules\Actions',
'set_description' => 'FireflyIII\Rules\Actions',
'append_description' => 'FireflyIII\Rules\Actions',
'prepend_description' => 'FireflyIII\Rules\Actions',
'clear_budget' => 'FireflyIII\Rules\Actions\ClearBudget',
'add_tag' => 'FireflyIII\Rules\Actions\AddTag',
'remove_tag' => 'FireflyIII\Rules\Actions\RemoveTag',
'remove_all_tags' => 'FireflyIII\Rules\Actions\RemoveAllTags',
'set_description' => 'FireflyIII\Rules\Actions\SetDescription',
'append_description' => 'FireflyIII\Rules\Actions\AppendDescription',
'prepend_description' => 'FireflyIII\Rules\Actions\PrependDescription',
],
];