Skip to content
Snippets Groups Projects
Commit b7f8f658 authored by Jaap Jansma's avatar Jaap Jansma
Browse files

Merge pull request #64 from JohnFF/feature/string_contains

Features: String Contains condition & Display Message action
parents 0ca3a1cb 0643c2d9
Branches
Tags
No related merge requests found
......@@ -43,7 +43,7 @@ class CRM_Civirules_Form_RuleAction extends CRM_Core_Form {
$this->ruleAction = new CRM_Civirules_BAO_RuleAction();
$this->ruleAction->id = $this->ruleActionId;
if (!$this->ruleAction->find(true)) {
throw new Exception('Civirules could not find ruleAction');
throw new Exception('Civirules could not find ruleAction (RuleAction)');
}
$this->action = new CRM_Civirules_BAO_Action();
......
......@@ -79,7 +79,7 @@ class CRM_CivirulesActions_Activity_Form_Activity extends CRM_CivirulesActions_F
$defaultValues['subject'] = $data['subject'];
}
if (!empty($data['assignee_contact_id'])) {
$defaults['assignee_contact_id'] = $data['assignee_contact_id'];
$defaultValues['assignee_contact_id'] = $data['assignee_contact_id'];
}
return $defaultValues;
}
......
......@@ -35,7 +35,7 @@ class CRM_CivirulesActions_Form_Form extends CRM_Core_Form
$this->trigger = new CRM_Civirules_BAO_Trigger();
if (!$this->ruleAction->find(true)) {
throw new Exception('Civirules could not find ruleAction');
throw new Exception('Civirules could not find ruleAction (Form)');
}
$this->action->id = $this->ruleAction->action_id;
......@@ -103,4 +103,4 @@ class CRM_CivirulesActions_Form_Form extends CRM_Core_Form
CRM_Utils_System::setTitle($title);
}
}
\ No newline at end of file
}
<?php
return array (
0 =>
array (
'name' => 'Civirules:Action.DisplayMessage',
'entity' => 'CiviRuleAction',
'params' =>
array (
'version' => 3,
'name' => 'DisplayMessage',
'label' => 'Shows a message to CiviCRM users.',
'class_name' => 'CRM_CivirulesActions_User_DisplayMessage',
'is_active' => 1
),
),
);
\ No newline at end of file
<?php
/**
* Class for CiviRules Display Message Action
*
* @author John Kirk (CiviFirst) <john@civifirst.com>
* @license AGPL-3.0
*/
class CRM_CivirulesActions_User_DisplayMessage extends CRM_Civirules_Action {
/**
* Method processAction to execute the action
*
* @param CRM_Civirules_TriggerData_TriggerData $triggerData
* @access public
*
*/
public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData) {
$action_params = $this->getActionParameters();
CRM_Core_Session::setStatus($action_params['message'], ts($action_params['title']), $action_params['type']);
}
/**
* Method to return the url for additional form processing for action
* and return false if none is needed
*
* @param int $ruleActionId
* @return bool
* @access public
*/
public function getExtraDataInputUrl($ruleActionId) {
return CRM_Utils_System::url('civicrm/civirule/form/action/display_message/', 'rule_action_id='.$ruleActionId);
}
}
\ No newline at end of file
<?php
/**
* Class for CiviRules Contribution Thank You Date Form
*
* @author John Kirk (CiviCooP) <john@civifirst.com>
* @license AGPL-3.0
*/
class CRM_CivirulesActions_User_Form_DisplayMessage extends CRM_CivirulesActions_Form_Form {
/**
* Overridden parent method to build the form
*
* @access public
*/
public function buildQuickForm() {
$this->add('hidden', 'rule_action_id');
$messageTypes = array('alert' => 'Alert', 'info' => 'Info', 'success' => 'Success', 'error' => 'Error',);
$this->add('text', 'title', ts('Message title: '));
$this->add('text', 'message', ts('Message: '));
$this->addRadio('type', ts('Type of message: '), $messageTypes);
$this->addButtons(array(
array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE,),
array('type' => 'cancel', 'name' => ts('Cancel'))));
}
/**
* Overridden parent method to set default values
*
* @return array $defaultValues
* @access public
*/
public function setDefaultValues() {
$defaultValues = parent::setDefaultValues();
$defaultValues['rule_action_id'] = $this->ruleActionId;
if (!empty($this->ruleAction->action_params)) {
$data = unserialize($this->ruleAction->action_params);
}
if (!empty($data['title'])) {
$defaultValues['title'] = $data['title'];
}
if (!empty($data['message'])) {
$defaultValues['message'] = $data['message'];
}
if (!empty($data['type'])) {
$defaultValues['type'] = $data['type'];
}
return $defaultValues;
}
/**
* Overridden parent method to process form data after submitting
*
* @access public
*/
public function postProcess() {
$data['title'] = $this->_submitValues['title'];
$data['message'] = $this->_submitValues['message'];
$data['type'] = $this->_submitValues['type'];
$this->ruleAction->action_params = serialize($data);
$this->ruleAction->save();
parent::postProcess();
}
}
\ No newline at end of file
......@@ -74,6 +74,7 @@ abstract class CRM_CivirulesConditions_Generic_ValueComparison extends CRM_Civir
case '>=':
case '<':
case '<=':
case 'contains string':
$key = 'value';
break;
case 'is one of':
......@@ -196,6 +197,9 @@ abstract class CRM_CivirulesConditions_Generic_ValueComparison extends CRM_Civir
}
return false;
break;
case 'contains string':
return stripos($leftValue, $rightValue) !== FALSE;
break;
case 'contains one of':
$leftArray = $this->convertValueToArray($leftValue);
$rightArray = $this->convertValueToArray($rightValue);
......@@ -320,6 +324,7 @@ abstract class CRM_CivirulesConditions_Generic_ValueComparison extends CRM_Civir
'<' => ts('Is less than'),
'>=' => ts('Is greater than or equal to'),
'<=' => ts('Is less than or equal to'),
'contains string' => ts('Contains string (case insensitive)'),
'is one of' => ts('Is one of'),
'is not one of' => ts('Is not one of'),
'contains one of' => ts('Does contain one of'),
......
<h3>{$ruleActionHeader}</h3>
<div class="crm-block crm-form-block crm-civirule-rule_action-block-message-display">
<div id="title-block" class="crm-section">
<div class="label">{$form.title.label}</div>
<div class="content">{$form.title.html}</div>
<div class="clear"></div>
</div>
<div id="message-block" class="crm-section">
<div class="label">{$form.message.label}</div>
<div class="content">{$form.message.html}</div>
<div class="clear"></div>
</div>
<div id="type-block" class="crm-section">
<div class="label">{$form.type.label}</div>
<div class="content">{$form.type.html}</div>
<div class="clear"></div>
</div>
</div>
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
\ No newline at end of file
......@@ -217,4 +217,11 @@
<access_arguments>access CiviCRM</access_arguments>
<access_arguments>administer CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/civirule/form/action/display_message</path>
<page_callback>CRM_CivirulesActions_User_Form_DisplayMessage</page_callback>
<title>Display Message</title>
<access_arguments>access CiviCRM</access_arguments>
<access_arguments>administer CiviCRM</access_arguments>
</item>
</menu>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment