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

first batch of BAOs

parent b54d78e3
No related branches found
No related tags found
No related merge requests found
<?php
/**
* BAO Action for CiviRule Action
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_Action extends CRM_Civirules_DAO_Action {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$action = new CRM_Civirules_BAO_Action();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$action->$key = $value;
}
}
}
$action->find();
while ($action->fetch()) {
$row = array();
self::storeValues($action, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update 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 action');
}
$action = new CRM_Civirules_BAO_Action();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$action->$key = $value;
}
}
$action->save();
self::storeValues($action, $result);
return $result;
}
/**
* Function to delete an action with id
*
* @param int $action_id
* @throws Exception when action_id is empty
* @access public
* @static
*/
public static function delete_with_id($action_id) {
if (empty($action_id)) {
throw new Exception('action_id can not be empty when attempting to delete a civirule action');
}
$action = new CRM_Civirules_BAO_Action();
$action->id = $action_id;
$action->delete();
return;
}
/**
* Function to disable an action
*
* @param int $action_id
* @throws Exception when action_id is empty
* @access public
* @static
*/
public static function disable($action_id) {
if (empty($action_id)) {
throw new Exception('action_id can not be empty when attempting to disable a civirule action');
}
$action = new CRM_Civirules_BAO_Action();
$action->id = $action_id;
$action->find(true);
self::add(array('id' => $action->id, 'is_active' => 0));
}
/**
* Function to enable an action
*
* @param int $action_id
* @throws Exception when action_id is empty
* @access public
* @static
*/
public static function enable($action_id) {
if (empty($action_id)) {
throw new Exception('action_id can not be empty when attempting to enable a civirule action');
}
$action = new CRM_Civirules_BAO_Action();
$action->id = $action_id;
$action->find(true);
self::add(array('id' => $action->id, 'is_active' => 1));
}
}
<?php
/**
* BAO Comparison for CiviRule Comparison
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_Comparison extends CRM_Civirules_DAO_Comparison {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$comparison = new CRM_Civirules_BAO_Comparison();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$comparison->$key = $value;
}
}
}
$comparison->find();
while ($comparison->fetch()) {
$row = array();
self::storeValues($comparison, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update comparison
*
* @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 comparison');
}
$comparison = new CRM_Civirules_BAO_Comparison();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$comparison->$key = $value;
}
}
$comparison->save();
self::storeValues($comparison, $result);
return $result;
}
/**
* Function to delete a comparison with id
*
* @param int $comparison_id
* @throws Exception when comparison_id is empty
* @access public
* @static
*/
public static function delete_with_id($comparison_id) {
if (empty($comparison_id)) {
throw new Exception('comparison_id can not be empty when attempting to delete a civirule comparison');
}
$comparison = new CRM_Civirules_BAO_Comparison();
$comparison->id = $comparison_id;
$comparison->delete();
return;
}
/**
* Function to disable a comparison
*
* @param int $comparison_id
* @throws Exception when comparison_id is empty
* @access public
* @static
*/
public static function disable($comparison_id) {
if (empty($comparison_id)) {
throw new Exception('comparison_id can not be empty when attempting to disable a civirule comparison');
}
$comparison = new CRM_Civirules_BAO_Comparison();
$comparison->id = $comparison_id;
$comparison->find(true);
self::add(array('id' => $comparison->id, 'is_active' => 0));
}
/**
* Function to enable a comparison
*
* @param int $comparison_id
* @throws Exception when comparison_id is empty
* @access public
* @static
*/
public static function enable($comparison_id) {
if (empty($comparison_id)) {
throw new Exception('comparison_id can not be empty when attempting to enable a civirule comparison');
}
$comparison = new CRM_Civirules_BAO_Comparison();
$comparison->id = $comparison_id;
$comparison->find(true);
self::add(array('id' => $comparison->id, 'is_active' => 1));
}
}
\ No newline at end of file
<?php
/**
* BAO Condition for CiviRule Condition
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_Condition extends CRM_Civirules_DAO_Condition {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$condition = new CRM_Civirules_BAO_Condition();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$condition->$key = $value;
}
}
}
$condition->find();
while ($condition->fetch()) {
$row = array();
self::storeValues($condition, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update 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 condition');
}
$condition = new CRM_Civirules_BAO_Condition();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$condition->$key = $value;
}
}
$condition->save();
self::storeValues($condition, $result);
return $result;
}
/**
* Function to delete a condition with id
*
* @param int $condition_id
* @throws Exception when condition_id is empty
* @access public
* @static
*/
public static function delete_with_id($condition_id) {
if (empty($condition_id)) {
throw new Exception('condition_id can not be empty when attempting to delete a civirule condition');
}
$condition = new CRM_Civirules_BAO_Condition();
$condition->id = $condition_id;
$condition->delete();
return;
}
/**
* Function to disable a condition
*
* @param int $condition_id
* @throws Exception when condition_id is empty
* @access public
* @static
*/
public static function disable($condition_id) {
if (empty($condition_id)) {
throw new Exception('condition_id can not be empty when attempting to disable a civirule condition');
}
$condition = new CRM_Civirules_BAO_Condition();
$condition->id = $condition_id;
$condition->find(true);
self::add(array('id' => $condition->id, 'is_active' => 0));
}
/**
* Function to enable a condition
*
* @param int $condition_id
* @throws Exception when condition_id is empty
* @access public
* @static
*/
public static function enable($condition_id) {
if (empty($condition_id)) {
throw new Exception('condition_id can not be empty when attempting to enable a civirule condition');
}
$condition = new CRM_Civirules_BAO_Condition();
$condition->id = $condition_id;
$condition->find(true);
self::add(array('id' => $condition->id, 'is_active' => 1));
}
}
\ No newline at end of file
<?php
/**
* BAO Condition for CiviRule Data Selector
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_DataSelector extends CRM_Civirules_DAO_DataSelector {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$data_selector = new CRM_Civirules_BAO_DataSelector();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$data_selector->$key = $value;
}
}
}
$data_selector->find();
while ($data_selector->fetch()) {
$row = array();
self::storeValues($data_selector, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update data selector
*
* @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 data selector');
}
$data_selector = new CRM_Civirules_BAO_DataSelector();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$data_selector->$key = $value;
}
}
$data_selector->save();
self::storeValues($data_selector, $result);
return $result;
}
/**
* Function to delete a data selector with id
*
* @param int $data_selector_id
* @throws Exception when data_selector_id is empty
* @access public
* @static
*/
public static function delete_with_id($data_selector_id) {
if (empty($data_selector_id)) {
throw new Exception('data_selector_id can not be empty when attempting to delete a civirule data selector');
}
$data_selector = new CRM_Civirules_BAO_DataSelector();
$data_selector->id = $data_selector_id;
$data_selector->delete();
return;
}
/**
* Function to disable a data selector
*
* @param int $data_selector_id
* @throws Exception when data_selector_id is empty
* @access public
* @static
*/
public static function disable($data_selector_id) {
if (empty($data_selector_id)) {
throw new Exception('data_selector_id can not be empty when attempting to disable a civirule data selector');
}
$data_selector = new CRM_Civirules_BAO_DataSelector();
$data_selector->id = $data_selector_id;
$data_selector->find(true);
self::add(array('id' => $data_selector->id, 'is_active' => 0));
}
/**
* Function to enable a data selector
*
* @param int $data_selector_id
* @throws Exception when data_selector_id is empty
* @access public
* @static
*/
public static function enable($data_selector_id) {
if (empty($data_selector_id)) {
throw new Exception('data_selector_id can not be empty when attempting to enable a civirule data selector');
}
$data_selector = new CRM_Civirules_BAO_DataSelector();
$data_selector->id = $data_selector_id;
$data_selector->find(true);
self::add(array('id' => $data_selector->id, 'is_active' => 1));
}
}
\ No newline at end of file
<?php
/**
* BAO Event for CiviRule Event
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Civirules_BAO_Event extends CRM_Civirules_DAO_Event {
/**
* Function to get values
*
* @return array $result found rows with data
* @access public
* @static
*/
public static function get_values($params) {
$result = array();
$event = new CRM_Civirules_BAO_Event();
if (!empty($params)) {
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$event->$key = $value;
}
}
}
$event->find();
while ($event->fetch()) {
$row = array();
self::storeValues($event, $row);
$result[$row['id']] = $row;
}
return $result;
}
/**
* Function to add or update 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 event');
}
$event = new CRM_Civirules_BAO_Event();
$fields = self::fields();
foreach ($params as $key => $value) {
if (isset($fields[$key])) {
$event->$key = $value;
}
}
$event->save();
self::storeValues($event, $result);
return $result;
}
/**
* Function to delete an event with id
*
* @param int $event_id
* @throws Exception when event_id is empty
* @access public
* @static
*/
public static function delete_with_id($event_id) {
if (empty($event_id)) {
throw new Exception('event_id can not be empty when attempting to delete a civirule event');
}
$event = new CRM_Civirules_BAO_Event();
$event->id = $event_id;
$event->delete();
return;
}
/**
* Function to disable an event
*
* @param int $event_id
* @throws Exception when event_id is empty
* @access public
* @static
*/
public static function disable($event_id) {
if (empty($event_id)) {
throw new Exception('event_id can not be empty when attempting to disable a civirule event');
}
$event = new CRM_Civirules_BAO_Event();
$event->id = $event_id;
$event->find(true);
self::add(array('id' => $event->id, 'is_active' => 0));
}
/**
* Function to enable an event
*
* @param int $event_id
* @throws Exception when event_id is empty
* @access public
* @static
*/
public static function enable($event_id) {
if (empty($event_id)) {
throw new Exception('event_id can not be empty when attempting to enable a civirule event');
}
$event = new CRM_Civirules_BAO_Event();
$event->id = $event_id;
$event->find(true);
self::add(array('id' => $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.
Finish editing this message first!
Please register or to comment