Esempio n. 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function createRules()
 {
     // three rule groups to get started.
     $ruleGroup = new RuleGroup();
     $ruleGroup->user()->associate($this->user);
     $ruleGroup->order = 1;
     $ruleGroup->active = 1;
     $ruleGroup->title = 'Default rules';
     $ruleGroup->description = 'All your rules not in a particular group.';
     $ruleGroup->save();
     unset($ruleGroup);
     $ruleGroup = new RuleGroup();
     $ruleGroup->user()->associate($this->user);
     $ruleGroup->order = 2;
     $ruleGroup->active = 1;
     $ruleGroup->title = 'Empty rule group';
     $ruleGroup->description = 'Intentionally has no rules.';
     $ruleGroup->save();
     unset($ruleGroup);
     $ruleGroup = new RuleGroup();
     $ruleGroup->user()->associate($this->user);
     $ruleGroup->order = 3;
     $ruleGroup->active = 1;
     $ruleGroup->title = 'Rules for bills';
     $ruleGroup->description = 'All rules for bills and recurring costs.';
     $ruleGroup->save();
     unset($ruleGroup);
     // move groceries to correct budget/category
     $rule = new Rule();
     $rule->user()->associate($this->user);
     $rule->ruleGroup()->associate(RuleGroup::find(1));
     $rule->order = 1;
     $rule->active = 1;
     $rule->stop_processing = 0;
     $rule->title = 'Move groceries';
     $rule->description = 'Move groceries to correct category and budget.';
     $rule->save();
     // initial trigger for this rule:
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 1;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'user_action';
     $ruleTrigger->trigger_value = 'store-journal';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // content trigger for this rule.
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 2;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'description_contains';
     $ruleTrigger->trigger_value = 'groceries';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // another
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 3;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'from_account_is';
     $ruleTrigger->trigger_value = 'TestData Checking Account';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // actions for this rule. one, set category
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 1;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 0;
     $ruleAction->action_type = 'set_category';
     $ruleAction->action_value = 'Groceries';
     $ruleAction->save();
     unset($ruleAction);
     // actions for this rule. one, set budget
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 2;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 0;
     $ruleAction->action_type = 'set_budget';
     $ruleAction->action_value = 'Groceries';
     $ruleAction->save();
     unset($ruleAction);
     // move "gas" to "Car" and "Car"
     $rule = new Rule();
     $rule->user()->associate($this->user);
     $rule->ruleGroup()->associate(RuleGroup::find(1));
     $rule->order = 2;
     $rule->active = 1;
     $rule->stop_processing = 0;
     $rule->title = 'Move gas';
     $rule->description = null;
     $rule->save();
     // initial trigger for this rule:
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 1;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'user_action';
     $ruleTrigger->trigger_value = 'store-journal';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // content trigger for this rule.
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 2;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'description_contains';
     $ruleTrigger->trigger_value = 'gas';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // another
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 3;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'from_account_is';
     $ruleTrigger->trigger_value = 'TestData Checking Account';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // actions for this rule. one, set category
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 1;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 0;
     $ruleAction->action_type = 'set_category';
     $ruleAction->action_value = 'Car';
     $ruleAction->save();
     unset($ruleAction);
     // actions for this rule. one, set budget
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 2;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 0;
     $ruleAction->action_type = 'set_budget';
     $ruleAction->action_value = 'Car';
     $ruleAction->save();
     unset($ruleAction);
     // move savings to money management
     $rule = new Rule();
     $rule->user()->associate($this->user);
     $rule->ruleGroup()->associate(RuleGroup::find(1));
     $rule->order = 3;
     $rule->active = 1;
     $rule->stop_processing = 0;
     $rule->title = 'Move savings';
     $rule->description = null;
     $rule->save();
     // initial trigger for this rule:
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 1;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'user_action';
     $ruleTrigger->trigger_value = 'store-journal';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // is transfer
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 2;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'transaction_type';
     $ruleTrigger->trigger_value = 'Transfer';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // content trigger for this rule.
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 3;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'description_is';
     $ruleTrigger->trigger_value = 'Save money';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // another
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 4;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'from_account_is';
     $ruleTrigger->trigger_value = 'TestData Checking Account';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // another
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 5;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'to_account_is';
     $ruleTrigger->trigger_value = 'TestData Savings';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // actions for this rule. one, set category
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 1;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 0;
     $ruleAction->action_type = 'set_category';
     $ruleAction->action_value = 'Money Management';
     $ruleAction->save();
     unset($ruleAction);
     // move TV bill to "Bills" and "House"
     $rule = new Rule();
     $rule->user()->associate($this->user);
     $rule->ruleGroup()->associate(RuleGroup::find(3));
     $rule->order = 1;
     $rule->active = 1;
     $rule->stop_processing = 0;
     $rule->title = 'TV Bill';
     $rule->description = null;
     $rule->save();
     // initial trigger for this rule:
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 1;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'user_action';
     $ruleTrigger->trigger_value = 'store-journal';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // content trigger for this rule.
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 2;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'description_contains';
     $ruleTrigger->trigger_value = 'tv bill';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // another
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 3;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'from_account_is';
     $ruleTrigger->trigger_value = 'TestData Checking Account';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // actions for this rule. one, set category
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 1;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 0;
     $ruleAction->action_type = 'set_category';
     $ruleAction->action_value = 'House';
     $ruleAction->save();
     unset($ruleAction);
     // actions for this rule. one, set budget
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 2;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 0;
     $ruleAction->action_type = 'set_budget';
     $ruleAction->action_value = 'Bills';
     $ruleAction->save();
     unset($ruleAction);
     // move rent to bills, rent.
     $rule = new Rule();
     $rule->user()->associate($this->user);
     $rule->ruleGroup()->associate(RuleGroup::find(3));
     $rule->order = 2;
     $rule->active = 1;
     $rule->stop_processing = 1;
     $rule->title = 'Rent';
     $rule->description = 'Do something with rent.';
     $rule->save();
     // initial trigger for this rule:
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 1;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'user_action';
     $ruleTrigger->trigger_value = 'update-journal';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // content trigger for this rule.
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 2;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 0;
     $ruleTrigger->trigger_type = 'description_contains';
     $ruleTrigger->trigger_value = 'rent';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // another
     $ruleTrigger = new RuleTrigger();
     $ruleTrigger->rule()->associate($rule);
     $ruleTrigger->order = 3;
     $ruleTrigger->active = 1;
     $ruleTrigger->stop_processing = 1;
     $ruleTrigger->trigger_type = 'from_account_is';
     $ruleTrigger->trigger_value = 'TestData Checking Account';
     $ruleTrigger->save();
     unset($ruleTrigger);
     // actions for this rule. one, set category
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 1;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 0;
     $ruleAction->action_type = 'set_category';
     $ruleAction->action_value = 'House';
     $ruleAction->save();
     unset($ruleAction);
     // actions for this rule. one, set budget
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = 2;
     $ruleAction->active = 1;
     $ruleAction->stop_processing = 1;
     $ruleAction->action_type = 'set_budget';
     $ruleAction->action_value = 'Bills';
     $ruleAction->save();
     unset($ruleAction);
 }
Esempio n. 2
0
 /**
  * @param Rule  $rule
  * @param array $values
  *
  * @return RuleAction
  */
 public function storeAction(Rule $rule, array $values)
 {
     $ruleAction = new RuleAction();
     $ruleAction->rule()->associate($rule);
     $ruleAction->order = $values['order'];
     $ruleAction->active = 1;
     $ruleAction->stop_processing = $values['stopProcessing'];
     $ruleAction->action_type = $values['action'];
     $ruleAction->action_value = $values['value'];
     $ruleAction->save();
     return $ruleAction;
 }