Skip to content
Snippets Groups Projects
Commit f25af729 authored by jaapjansma's avatar jaapjansma
Browse files

add condition for group id

parent c4e7103e
Branches
Tags
No related merge requests found
......@@ -44,7 +44,6 @@ class CRM_CivirulesActions_Form_GroupContact extends CRM_Core_Form {
* @return array
* @access protected
*/
protected function getGroups() {
return array('' => ts('-- please select --')) + CRM_Contact_BAO_GroupContact::getGroupList();
}
......
<?php
return array (
0 =>
array (
'name' => 'Civirules:Condition.FieldValueComparison',
'entity' => 'CiviRuleCondition',
'params' =>
array (
'version' => 3,
'name' => 'field_value_comparison',
'label' => 'Field value comparison',
'class_name' => 'CRM_CivirulesConditions_FieldValueComparison',
'is_active' => 1
),
),
);
\ No newline at end of file
<?php
class CRM_CivirulesConditions_Form_Form extends CRM_Core_Form
{
protected $ruleConditionId = false;
protected $ruleCondition;
protected $condition;
protected $rule;
protected $event;
/**
* @var CRM_Civirules_Event
*/
protected $eventClass;
/**
* Overridden parent method to perform processing before form is build
*
* @access public
*/
public function preProcess()
{
$this->ruleConditionId = CRM_Utils_Request::retrieve('rule_condition_id', 'Integer');
$this->ruleCondition = new CRM_Civirules_BAO_RuleCondition();
$this->ruleCondition->id = $this->ruleConditionId;
$this->condition = new CRM_Civirules_BAO_Condition();
$this->rule = new CRM_Civirules_BAO_Rule();
$this->event = new CRM_Civirules_BAO_Event();
if (!$this->ruleCondition->find(true)) {
throw new Exception('Civirules could not find ruleCondition');
}
$this->condition->id = $this->ruleCondition->condition_id;
if (!$this->condition->find(true)) {
throw new Exception('Civirules could not find condition');
}
$this->rule->id = $this->ruleCondition->rule_id;
if (!$this->rule->find(true)) {
throw new Exception('Civirules could not find rule');
}
$this->event->id = $this->rule->event_id;
if (!$this->event->find(true)) {
throw new Exception('Civirules could not find event');
}
$this->eventClass = CRM_Civirules_BAO_Event::getPostEventObjectByClassName($this->event->class_name, true);
$this->eventClass->setEventId($this->event->id);
parent::preProcess();
$this->setFormTitle();
}
/**
* Overridden parent method to set default values
*
* @return array $defaultValues
* @access public
*/
public function setDefaultValues() {
$defaultValues = array();
$defaultValues['rule_condition_id'] = $this->ruleConditionId;
return $defaultValues;
}
public function postProcess() {
$session = CRM_Core_Session::singleton();
$session->setStatus('Condition '.$this->condition->label.' parameters updated to CiviRule '.$this->rule->label, 'Condition parameters updated', 'success');
$redirectUrl = CRM_Utils_System::url('civicrm/civirule/form/rule', 'action=update&id='.$this->ruleId, TRUE);
CRM_Utils_System::redirect($redirectUrl);
}
/**
* Method to set the form title
*
* @access protected
*/
protected function setFormTitle() {
$title = 'CiviRules Edit Condition parameters';
$this->assign('ruleConditionHeader', 'Edit Condition '.$this->condition->label.' of CiviRule '.$this->rule->label);
CRM_Utils_System::setTitle($title);
}
}
\ No newline at end of file
<?php
/**
* Class for CiviRules ValueComparison Form
*
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_CivirulesConditions_Form_GroupContact_GroupId extends CRM_CivirulesConditions_Form_Form {
/**
* Method to get groups
*
* @return array
* @access protected
*/
protected function getGroups() {
return array('' => ts('-- please select --')) + CRM_Contact_BAO_GroupContact::getGroupList();
}
/**
* Overridden parent method to build form
*
* @access public
*/
public function buildQuickForm() {
$this->add('hidden', 'rule_condition_id');
$this->add('select', 'group_id', ts('Group'), $this->getGroups(), true);
$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();
$data = unserialize($this->ruleCondition->condition_params);
if (!empty($data['group_id'])) {
$defaultValues['group_id'] = $data['group_id'];
}
return $defaultValues;
}
/**
* Overridden parent method to process form data after submission
*
* @throws Exception when rule condition not found
* @access public
*/
public function postProcess() {
$data['group_id'] = $this->_submitValues['group_id'];
$this->ruleCondition->condition_params = serialize($data);
$this->ruleCondition->save();
parent::postProcess();
}
}
\ No newline at end of file
<?php
return array (
0 =>
array (
'name' => 'Civirules:Condition.GroupContact.GroupId',
'entity' => 'CiviRuleCondition',
'params' =>
array (
'version' => 3,
'name' => 'groupcontact_group_id',
'label' => 'Group is',
'class_name' => 'CRM_CivirulesConditions_GroupContact_GroupId',
'is_active' => 1
),
),
);
\ No newline at end of file
<?php
class CRM_CivirulesConditions_GroupContact_GroupId extends CRM_Civirules_Condition {
private $conditionParams = array();
/**
* Method to set the Rule Condition data
*
* @param array $ruleCondition
* @access public
*/
public function setRuleConditionData($ruleCondition) {
parent::setRuleConditionData($ruleCondition);
$this->conditionParams = array();
if (!empty($this->ruleCondition['condition_params'])) {
$this->conditionParams = unserialize($this->ruleCondition['condition_params']);
}
}
public function isConditionValid(CRM_Civirules_EventData_EventData $eventData) {
$groupContact = $eventData->getEntityData('GroupContact');
if ($groupContact['group_id'] == $this->conditionParams['group_id']) {
return true;
}
return false;
}
/**
* Returns a redirect url to extra data input from the user after adding a condition
*
* Return false if you do not need extra data input
*
* @param int $ruleConditionId
* @return bool|string
* @access public
* @abstract
*/
public function getExtraDataInputUrl($ruleConditionId) {
return CRM_Utils_System::url('civicrm/civirule/form/condition/groupcontact/groupid/', 'rule_condition_id='.$ruleConditionId);
}
/**
* Returns a user friendly text explaining the condition params
* e.g. 'Older than 65'
*
* @return string
* @access public
*/
public function userFriendlyConditionParams() {
if (!empty($this->conditionParams['group_id'])) {
$group = civicrm_api3('Group', 'getvalue', array('return' => 'title', 'id' => $this->conditionParams['group_id']));
return ts('Group is %1', array(1 => $group));
}
return '';
}
/**
* Returns an array with required entity names
*
* @return array
* @access public
*/
public function requiredEntities() {
return array('GroupContact');
}
}
\ No newline at end of file
<h3>{$ruleConditionHeader}</h3>
<div class="crm-block crm-form-block crm-civirule-rule_condition-block-group_id">
<div class="crm-section">
<div class="label">{$form.group_id.label}</div>
<div class="content">{$form.group_id.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
......@@ -36,6 +36,12 @@
<title>Value comparison</title>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/civirule/form/condition/groupcontact/groupid</path>
<page_callback>CRM_CivirulesConditions_Form_GroupContact_GroupId</page_callback>
<title>Group Id</title>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/civirule/form/condition/contributionstatus</path>
<page_callback>CRM_CivirulesConditions_Form_ContributionStatus</page_callback>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment