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

completed building basic form Rule

parent 09a2b152
No related branches found
No related tags found
No related merge requests found
......@@ -113,4 +113,20 @@ class CRM_Civirules_BAO_Action extends CRM_Civirules_DAO_Action {
$action->find(true);
self::add(array('id' => $action->id, 'is_active' => 1));
}
}
/**
* Function to retrieve the label of an action with actionId
*
* @param int $actionId
* @return string $action->label
* @access public
* @static
*/
public static function getActionLabelWithId($actionId) {
if (empty($actionId)) {
return '';
}
$action = new CRM_Civirules_BAO_Action();
$action->id = $actionId;
$action->find(true);
return $action->label;
}}
......@@ -34,29 +34,29 @@ class CRM_Civirules_DAO_Action extends CRM_Core_DAO {
'type' => CRM_Utils_Type::T_INT,
'required' => true
) ,
'label' => array(
'name' => 'label',
'name' => array(
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 64,
),
'description' => array(
'name' => 'description',
'type' => CRM_Utils_Type::T_TEXT,
),
'entity' => array(
'name' => 'entity',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 64,
) ,
'column' => array(
'name' => 'column',
'label' => array(
'name' => 'label',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
),
'function_name' => array(
'name' => 'function_name',
'api_entity' => array(
'name' => 'api_entity',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 45,
),
'api_action' => array(
'name' => 'api_action',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 256,
'maxlength' => 45,
) ,
'data_selector_id' => array(
'name' => 'data_selector_id',
'type' => CRM_Utils_Type::T_INT,
),
'is_active' => array(
'name' => 'is_active',
......@@ -76,12 +76,12 @@ class CRM_Civirules_DAO_Action extends CRM_Core_DAO {
static function &fieldKeys() {
if (!(self::$_fieldKeys)) {
self::$_fieldKeys = array(
'id' => 'id',
'id' => 'id',
'name' => 'name',
'label' => 'label',
'description' => 'description',
'entity' => 'entity',
'column' => 'column',
'function_name' => 'function_name',
'api_entity' => 'api_entity',
'api_action' => 'api_action',
'data_selector_id' => 'data_selector_id',
'is_active' => 'is_active'
);
}
......
......@@ -48,8 +48,8 @@ class CRM_Civirules_DAO_DataSelector extends CRM_Core_DAO {
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 64,
),
'column' => array(
'name' => 'column',
'column_name' => array(
'name' => 'column_name',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
),
......@@ -80,7 +80,7 @@ class CRM_Civirules_DAO_DataSelector extends CRM_Core_DAO {
'label' => 'label',
'description' => 'description',
'entity' => 'entity',
'column' => 'column',
'column_name' => 'column_name',
'function_name' => 'function_name',
'is_active' => 'is_active'
);
......
......@@ -53,6 +53,10 @@ class CRM_Civirules_DAO_Event extends CRM_Core_DAO {
'name' => 'action',
'type' => CRM_Utils_Type::T_STRING
),
'method' => array(
'name' => 'method',
'type' => CRM_Utils_Type::T_STRING
),
'is_active' => array(
'name' => 'is_active',
'type' => CRM_Utils_Type::T_INT,
......@@ -76,6 +80,7 @@ class CRM_Civirules_DAO_Event extends CRM_Core_DAO {
'label' => 'label',
'entity' => 'entity',
'action' => 'action',
'method' => 'method',
'is_active' => 'is_active'
);
}
......
......@@ -47,12 +47,8 @@ class CRM_Civirules_DAO_RuleAction extends CRM_Core_DAO {
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
),
'comparison_id' => array(
'name' => 'comparison_id',
'type' => CRM_Utils_Type::T_INT
),
'params' => array(
'name' => 'params',
'extra_params' => array(
'name' => 'extra_params',
'type' => CRM_Utils_Type::T_BLOB
),
'civicrm_form_class' => array(
......@@ -82,8 +78,7 @@ class CRM_Civirules_DAO_RuleAction extends CRM_Core_DAO {
'rule_id' => 'rule_id',
'action_id' => 'action_id',
'action_value' => 'action_value',
'comparison_id' => 'comparison_id',
'params' => 'params',
'extra_params' => 'extra_params',
'civicrm_form_class' => 'civicrm_form_class',
'is_active' => 'is_active'
);
......
......@@ -43,12 +43,12 @@ class CRM_Civirules_DAO_RuleCondition extends CRM_Core_DAO {
'type' => CRM_Utils_Type::T_INT
),
'condition_operator' => array(
'name' => 'condtion_operator',
'name' => 'condition_operator',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 25,
),
'condition_value' => array(
'name' => 'condtion_value',
'name' => 'condition_value',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
),
......@@ -89,10 +89,11 @@ class CRM_Civirules_DAO_RuleCondition extends CRM_Core_DAO {
* returns the list of fields that can be exported
*
* @access public
* return array
* @param boolean $prefix
* @return array
* @static
*/
static function &export($prefix = false)
static function &export($prefix = FALSE)
{
if (!(self::$_export)) {
self::$_export = array();
......
......@@ -148,7 +148,7 @@ class CRM_Civirules_Form_Rule extends CRM_Core_Form {
protected function createUpdateFormElements() {
$this->add('text', 'rule_event_label', '', array('size' => CRM_Utils_Type::HUGE));
$this->assign('ruleConditions', $this->getRuleConditions());
//$this->assign('ruleActions', $this->getRuleActions());
$this->assign('ruleActions', $this->getRuleActions());
}
/**
......@@ -230,6 +230,25 @@ class CRM_Civirules_Form_Rule extends CRM_Core_Form {
return $ruleConditions;
}
/**
* Function to get the rule actions for the rule
*
* @return array $ruleActions
* @access protected
*/
protected function getRuleActions() {
$actionParams = array(
'is_active' => 1,
'rule_id' => $this->ruleId);
$ruleActions = CRM_Civirules_BAO_RuleAction::getValues($actionParams);
foreach ($ruleActions as $ruleActionId => $ruleAction) {
$ruleActions[$ruleActionId]['label'] =
CRM_Civirules_BAO_Action::getActionLabelWithId($ruleAction['action_id']);
$ruleActions[$ruleActionId]['actions'] = $this->setRuleActionActions($ruleActionId);
}
return $ruleActions;
}
/**
* Function to set the actions for each rule condition
*
......@@ -261,4 +280,22 @@ class CRM_Civirules_Form_Rule extends CRM_Core_Form {
$deleteHtml = '<a class="action-item" title="Delete" href="'.$deleteUrl.'">Delete</a>';
return $deleteHtml;
}
/**
* Function to set the actions for each rule action
*
* @param int $ruleActionId
* @return array
* @access protected
*/
protected function setRuleActionActions($ruleActionId) {
$actionActions = array();
$updateUrl = CRM_Utils_System::url('civicrm/civirule/form/ruleaction', 'action=update&id='.
$ruleActionId);
$deleteUrl = CRM_Utils_System::url('civicrm/civirule/form/ruleaction', 'action=delete&id='.
$ruleActionId);
$actionActions[] = '<a class="action-item" title="Update" href="'.$updateUrl.'">Edit</a>';
$actionActions[] = '<a class="action-item" title="Delete" href="'.$deleteUrl.'">Delete</a>';
return $actionActions;
}
}
......@@ -20,4 +20,35 @@ class CRM_Civirules_Upgrader extends CRM_Civirules_Upgrader_Base {
$this->executeSqlFile('sql/createCiviruleRuleAction.sql');
$this->executeSqlFile('sql/createCiviruleRuleCondition.sql');
}
/**
* Upgrade 1001 - add columns api_action and api_entity to civirule_action
*/
public function upgrade_1001() {
$this->ctx->log->info('Applying update 1001 (add columns api_action and api_entity to civirule_action)');
if (CRM_Core_DAO::checkTableExists('civirule_action')) {
if (!CRM_Core_DAO::checkFieldExists('civirule_action', 'api_entity')) {
CRM_Core_DAO::executeQuery('ALTER TABLE civirule_action ADD COLUMN api_entity VARCHAR(45) AFTER label');
}
if (!CRM_Core_DAO::checkFieldExists('civirule_action', 'api_action')) {
CRM_Core_DAO::executeQuery('ALTER TABLE civirule_action ADD COLUMN api_action VARCHAR(45) AFTER api_entity');
}
}
return TRUE;
}
/**
* Upgrade 1002 - drop column comparison_id from civirule_rule_action
*/
public function upgrade_1002() {
$this->ctx->log->info('Applying update 1002 (drop column comparison_id from civirule_rule_action)');
if (CRM_Core_DAO::checkTableExists('civirule_rule_action')) {
if (CRM_Core_DAO::checkFieldExists('civirule_rule_action', 'comparison_id')) {
CRM_Core_DAO::executeQuery('ALTER TABLE civirule_rule_action DROP FOREIGN KEY fk_ra_comparison');
CRM_Core_DAO::executeQuery('ALTER TABLE civirule_rule_action DROP INDEX fk_ra_comparison_idx');
CRM_Core_DAO::executeQuery('ALTER TABLE civirule_rule_action DROP COLUMN comparison_id');
}
}
return TRUE;
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ CREATE TABLE IF NOT EXISTS civirule_action (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(64) NULL,
label VARCHAR(128) NULL,
api_entity VARCHAR(45) NULL,
api_action VARCHAR(45) NULL,
data_selector_id INT UNSIGNED NULL,
is_active TINYINT NULL DEFAULT 1,
PRIMARY KEY (id),
......
CREATE TABLE IF NOT EXISTS civirule_data_selector (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
entity VARCHAR(64) NULL,
column VARCHAR(128) NULL,
column_name VARCHAR(128) NULL,
label VARCHAR(68) NULL,
description TEXT NULL,
is_active TINYINT NULL DEFAULT 1,
......
......@@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS civirule_event (
label VARCHAR(128) NULL,
entity VARCHAR(68) NULL,
action VARCHAR(45) NULL,
method VARCHAR(45) NULL,
is_active TINYINT NULL DEFAULT 1,
PRIMARY KEY (id),
UNIQUE INDEX id_UNIQUE (id ASC))
......
......@@ -5,30 +5,34 @@
<div class="crm-section">
<div id="civirule_wrapper" class="dataTables_wrapper">
<table id="civirule-table" class="display">
<tbody>
{assign var="row_class" value="odd-row"}
<tbody>
{assign var="row_class" value="odd-row"}
{foreach from=$ruleActions key=action_id item=ruleAction}
<tr id="row1" class={$row_class}>
<td>{$ruleAction.label}</td>
<td>{$ruleAction.comparison}</td>
<td>{$ruleAction.action_value}</td>
<td>
<span>
{foreach from=$ruleAction.actions item=action_link}
{$action_link}
{/foreach}
</span>
</td>
</tr>
{if $row_class eq "odd-row"}
{assign var="row_class" value="even-row"}
{else}
{assign var="row_class" value="odd-row"}
{/if}
{/foreach}
</tbody>
</table>
</div> </div>
<tr id="row1" class={$row_class}>
<td>{$ruleAction.label}&nbsp;{$ruleAction.action_value}</td>
{if !empty($ruleAction.extra_params)}
<td>{$ruleAction.extra_params}</td>
{else}
<td>&nbsp;</td>
{/if}
<td>
<span>
{foreach from=$ruleAction.actions item=action_link}
{$action_link}
{/foreach}
</span>
</td>
</tr>
{if $row_class eq "odd-row"}
{assign var="row_class" value="even-row"}
{else}
{assign var="row_class" value="odd-row"}
{/if}
{/foreach}
</tbody>
</table>
</div>
</div>
{if $action eq 1}
<div class="crm-submit-buttons">
<span class="crm-button crm-button-type-next crm-button_qf_Rule_next">
......
......@@ -9,8 +9,8 @@
{assign var="row_class" value="odd-row"}
{foreach from=$ruleConditions key=ruleConditionIid item=ruleCondition}
<tr class={$row_class}>
<td>{$ruleCondition['condition_operator']}</td>
<td>{literal}{{/literal}{$ruleCondition.name}&nbsp;{$ruleCondition.comparison}&nbsp;{$ruleCondition.condition_value}{literal}}{/literal}</td>
<td>{$ruleCondition.condition_operator}</td>
<td>{$ruleCondition.name}&nbsp;{$ruleCondition.comparison}&nbsp;{$ruleCondition.condition_value}</td>
<td>
<span>
{foreach from=$ruleCondition.actions item=action_link}
......@@ -29,7 +29,7 @@
</table>
</div>
</div>
{if $action eq 1}
{if $action eq 1 or empty($ruleConditions)}
<div class="crm-submit-buttons">
<span class="crm-button crm-button-type-next crm-button_qf_Rule_next">
<input id="_qf_Rule_next-bottom" class="validate form-submit" type="submit" value="Add Condition" name="_qf_Rule_next">
......
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