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

added custom field comparison

parent 38398d56
Branches
Tags
No related merge requests found
......@@ -19,6 +19,20 @@ class CRM_CivirulesConditions_FieldValueComparison extends CRM_CivirulesConditio
if (isset($data[$field])) {
return $this->normalizeValue($data[$field]);
}
if (strpos($field, 'custom_')===0) {
try {
$params['entityID'] = $data['id'];
$params[$field] = 1;
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
if (!empty($values[$field])) {
return $this->normalizeValue($values[$field]);
}
} catch (Exception $e) {
//do nothing
}
}
return null;
}
......
......@@ -36,11 +36,55 @@ class CRM_CivirulesConditions_Form_FieldValueComparison extends CRM_CivirulesCon
}
$return[$fieldKey] = $label;
}
$customFields = $this->getCustomfieldsForEntity($entityDef->entity);
foreach($customFields as $customFieldKey => $customFieldLabel) {
$return[$key.$customFieldKey] = $customFieldLabel;
}
}
}
return $return;
}
protected function getCustomfieldsForEntity($entity) {
$extends = array($entity);
if ($entity == 'Contact') {
$contact_types = civicrm_api3('ContactType', 'get', array());
foreach($contact_types['values'] as $type) {
$extends[] = $type['name'];
}
}
$return = array();
$processedGroups = array();
foreach($extends as $extend) {
$customGroups = civicrm_api3('CustomGroup', 'get', array('extends' => $extend));
foreach($customGroups['values'] as $customGroup) {
if (in_array($customGroup['id'], $processedGroups)) {
continue;
}
if ($customGroup['is_multiple']) {
//do not include multiple custom groups
continue;
}
$return = $return + $this->getCustomFieldPerGroup($customGroup['id'], $customGroup['title']);
$processedGroups[] = $customGroup['id'];
}
}
return $return;
}
protected function getCustomFieldPerGroup($group_id, $group_label) {
$fields = civicrm_api3('CustomField', 'get', array('custom_group_id' => $group_id));
$return = array();
foreach($fields['values'] as $field) {
$key = 'custom_'.$field['id'];
$return[$key] = $group_label.': '.$field['label'];
}
return $return;
}
/**
* Overridden parent method to build form
*
......@@ -87,7 +131,9 @@ class CRM_CivirulesConditions_Form_FieldValueComparison extends CRM_CivirulesCon
public function setDefaultValues() {
$data = array();
$defaultValues = parent::setDefaultValues();
$defaultValues['rule_condition_id'] = $this->ruleConditionId;
if ($this->ruleCondition->find(true)) {
$data = unserialize($this->ruleCondition->condition_params);
}
if (!empty($data['entity'])) {
$defaultValues['entity'] = $data['entity'];
}
......
......@@ -41,6 +41,7 @@
cj('#entity').change(function() {
var val = cj('#entity').val();
cj('#field').html(all_fields);
cj('#field option').each(function(index, el) {
if (cj(el).val().indexOf(val+'_') != 0) {
cj(el).remove();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment