Skip to content
Snippets Groups Projects
Commit 7379a099 authored by Erik Hommel's avatar Erik Hommel
Browse files

added BAOs

parent 6ac3965a
No related branches found
No related tags found
No related merge requests found
<?php
/**
* BAO Rule for CiviRule Rule
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_Rule extends CRM_Civirules_DAO_Rule {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$rule = new CRM_Civirules_BAO_Rule();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$rule->$key = $value;
}
}
}
$rule->find();
while ($rule->fetch()) {
$row = array();
self::storeValues($rule, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update rule
*
* @param array $params
* @return array $result
* @access public
* @throws Exception when params is empty
* @static
*/
public static function add($params) {
$result = array();
if (empty($params)) {
throw new Exception('Params can not be empty when adding or updating a civirule rule');
}
$rule = new CRM_Civirules_BAO_Rule();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$rule->$key = $value;
}
}
$rule->save();
self::storeValues($rule, $result);
return $result;
}
/**
* Function to delete a rule with id
*
* @param int $rule_id
* @throws Exception when rule_id is empty
* @access public
* @static
*/
public static function delete_with_id($rule_id) {
if (empty($rule_id)) {
throw new Exception('rule_id can not be empty when attempting to delete a civirule rule');
}
$rule = new CRM_Civirules_BAO_Rule();
$rule->id = $rule_id;
$rule->delete();
return;
}
/**
* Function to disable a rule
*
* @param int $rule_id
* @throws Exception when rule_id is empty
* @access public
* @static
*/
public static function disable($rule_id) {
if (empty($rule_id)) {
throw new Exception('rule_id can not be empty when attempting to disable a civirule rule');
}
$rule = new CRM_Civirules_BAO_Rule();
$rule->id = $rule_id;
$rule->find(true);
self::add(array('id' => $rule->id, 'is_active' => 0));
}
/**
* Function to enable an rule
*
* @param int $rule_id
* @throws Exception when rule_id is empty
* @access public
* @static
*/
public static function enable($rule_id) {
if (empty($rule_id)) {
throw new Exception('rule_id can not be empty when attempting to enable a civirule rule');
}
$rule = new CRM_Civirules_BAO_Rule();
$rule->id = $rule_id;
$rule->find(true);
self::add(array('id' => $rule->id, 'is_active' => 1));
}
}
\ No newline at end of file
<?php
/**
* BAO RuleAction for CiviRule Rule Action
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_RuleAction extends CRM_Civirules_DAO_RuleAction {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$rule_action = new CRM_Civirules_BAO_RuleAction();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$rule_action->$key = $value;
}
}
}
$rule_action->find();
while ($rule_action->fetch()) {
$row = array();
self::storeValues($rule_action, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update rule action
*
* @param array $params
* @return array $result
* @access public
* @throws Exception when params is empty
* @static
*/
public static function add($params) {
$result = array();
if (empty($params)) {
throw new Exception('Params can not be empty when adding or updating a civirule rule action');
}
$rule_action = new CRM_Civirules_BAO_RuleAction();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$rule_action->$key = $value;
}
}
$rule_action->save();
self::storeValues($rule_action, $result);
return $result;
}
/**
* Function to delete a rule action with id
*
* @param int $rule_action_id
* @throws Exception when rule_action_id is empty
* @access public
* @static
*/
public static function delete_with_id($rule_action_id) {
if (empty($rule_action_id)) {
throw new Exception('rule_action_id can not be empty when attempting to delete a civirule rule action');
}
$rule_action = new CRM_Civirules_BAO_RuleAction();
$rule_action->id = $rule_action_id;
$rule_action->delete();
return;
}
/**
* Function to disable a rule action
*
* @param int $rule_action_id
* @throws Exception when rule_action_id is empty
* @access public
* @static
*/
public static function disable($rule_action_id) {
if (empty($rule_action_id)) {
throw new Exception('rule_action_id can not be empty when attempting to disable a civirule rule action');
}
$rule_action = new CRM_Civirules_BAO_RuleAction();
$rule_action->id = $rule_action_id;
$rule_action->find(true);
self::add(array('id' => $rule_action->id, 'is_active' => 0));
}
/**
* Function to enable a rule action
*
* @param int $rule_action_id
* @throws Exception when rule_action_id is empty
* @access public
* @static
*/
public static function enable($rule_action_id) {
if (empty($rule_action_id)) {
throw new Exception('rule_action_id can not be empty when attempting to enable a civirule rule action');
}
$rule_action = new CRM_Civirules_BAO_RuleAction();
$rule_action->id = $rule_action_id;
$rule_action->find(true);
self::add(array('id' => $rule_action->id, 'is_active' => 1));
}
}
\ No newline at end of file
<?php
/**
* BAO RuleCondition for CiviRule Rule Condition
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_RuleCondition extends CRM_Civirules_DAO_RuleCondition {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$rule_condition = new CRM_Civirules_BAO_RuleCondition();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$rule_condition->$key = $value;
}
}
}
$rule_condition->find();
while ($rule_condition->fetch()) {
$row = array();
self::storeValues($rule_condition, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update rule condition
*
* @param array $params
* @return array $result
* @access public
* @throws Exception when params is empty
* @static
*/
public static function add($params) {
$result = array();
if (empty($params)) {
throw new Exception('Params can not be empty when adding or updating a civirule rule condition');
}
$rule_condition = new CRM_Civirules_BAO_RuleCondition();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$rule_condition->$key = $value;
}
}
$rule_condition->save();
self::storeValues($rule_condition, $result);
return $result;
}
/**
* Function to delete a rule condition with id
*
* @param int $rule_condition_id
* @throws Exception when rule_condition_id is empty
* @access public
* @static
*/
public static function delete_with_id($rule_condition_id) {
if (empty($rule_condition_id)) {
throw new Exception('rule_condition_id can not be empty when attempting to delete a civirule rule condition');
}
$rule_condition = new CRM_Civirules_BAO_RuleCondition();
$rule_condition->id = $rule_condition_id;
$rule_condition->delete();
return;
}
/**
* Function to disable a rule condition
*
* @param int $rule_condition_id
* @throws Exception when rule_condition_id is empty
* @access public
* @static
*/
public static function disable($rule_condition_id) {
if (empty($rule_condition_id)) {
throw new Exception('rule_condition_id can not be empty when attempting to disable a civirule rule condition');
}
$rule_condition = new CRM_Civirules_BAO_RuleCondition();
$rule_condition->id = $rule_condition_id;
$rule_condition->find(true);
self::add(array('id' => $rule_condition->id, 'is_active' => 0));
}
/**
* Function to enable a rule condition
*
* @param int $rule_condition_id
* @throws Exception when rule_condition_id is empty
* @access public
* @static
*/
public static function enable($rule_condition_id) {
if (empty($rule_condition_id)) {
throw new Exception('rule_condition_id can not be empty when attempting to enable a civirule rule condition');
}
$rule_condition = new CRM_Civirules_BAO_RuleCondition();
$rule_condition->id = $rule_condition_id;
$rule_condition->find(true);
self::add(array('id' => $rule_condition->id, 'is_active' => 1));
}
}
\ No newline at end of file
<?php
/**
* BAO RuleEvent for CiviRule Rule Condition
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_RuleEvent extends CRM_Civirules_DAO_RuleEvent {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$rule_event = new CRM_Civirules_BAO_RuleEvent();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$rule_event->$key = $value;
}
}
}
$rule_event->find();
while ($rule_event->fetch()) {
$row = array();
self::storeValues($rule_event, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update rule event
*
* @param array $params
* @return array $result
* @access public
* @throws Exception when params is empty
* @static
*/
public static function add($params) {
$result = array();
if (empty($params)) {
throw new Exception('Params can not be empty when adding or updating a civirule rule event');
}
$rule_event = new CRM_Civirules_BAO_RuleEvent();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$rule_event->$key = $value;
}
}
$rule_event->save();
self::storeValues($rule_event, $result);
return $result;
}
/**
* Function to delete a rule event with id
*
* @param int $rule_event_id
* @throws Exception when rule_event_id is empty
* @access public
* @static
*/
public static function delete_with_id($rule_event_id) {
if (empty($rule_event_id)) {
throw new Exception('rule_event_id can not be empty when attempting to delete a civirule rule event');
}
$rule_event = new CRM_Civirules_BAO_RuleEvent();
$rule_event->id = $rule_event_id;
$rule_event->delete();
return;
}
/**
* Function to disable a rule event
*
* @param int $rule_event_id
* @throws Exception when rule_event_id is empty
* @access public
* @static
*/
public static function disable($rule_event_id) {
if (empty($rule_event_id)) {
throw new Exception('rule_event_id can not be empty when attempting to disable a civirule rule event');
}
$rule_event = new CRM_Civirules_BAO_RuleEvent();
$rule_event->id = $rule_event_id;
$rule_event->find(true);
self::add(array('id' => $rule_event->id, 'is_active' => 0));
}
/**
* Function to enable a rule event
*
* @param int $rule_event_id
* @throws Exception when rule_event_id is empty
* @access public
* @static
*/
public static function enable($rule_event_id) {
if (empty($rule_event_id)) {
throw new Exception('rule_event_id can not be empty when attempting to enable a civirule rule event');
}
$rule_event = new CRM_Civirules_BAO_RuleEvent();
$rule_event->id = $rule_event_id;
$rule_event->find(true);
self::add(array('id' => $rule_event->id, 'is_active' => 1));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment