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

added custom field checking on activity

parent 2eaead8c
No related branches found
No related tags found
No related merge requests found
......@@ -13,10 +13,43 @@ class CRM_Civirules_Utils_CustomDataFromPre {
}
}
}
foreach($params as $key => $value) {
if (stripos($key, 'custom_')===0) {
list($custom_, $fid, $id) = explode("_", $key, 3);
self::setCustomData($objectName, $fid, $value, $id);
}
}
}
private static function setCustomData($objectName, $field_id, $value, $id) {
self::$customValues[$field_id][$id] = $value;
$v = $value;
$custom_field = civicrm_api3('CustomField', 'getsingle', array('id' => $field_id));
/**
* Convert value array from
* value_a => 1
* value_b => 1
*
* To
* [] => value_a
* [] => value_b
*
*/
if (!empty($custom_field['option_group_id']) && is_array($value)) {
$all_ones = true;
foreach($value as $i => $j) {
if ($j != 1) {
$all_ones = false;
}
}
if ($all_ones) {
$v = array();
foreach($value as $i => $j) {
$v[] = $i;
}
}
}
self::$customValues[$field_id][$id] = $v;
}
public static function addCustomDataToTriggerData(CRM_Civirules_TriggerData_TriggerData $triggerData) {
......
......@@ -41,12 +41,14 @@ class CRM_Civirules_Utils_HookInvoker {
private function invoke($fnSuffix, $numParams, &$arg1 = null, &$arg2 = null, &$arg3 = null, &$arg4 = null, &$arg5 = null) {
$hook = CRM_Utils_Hook::singleton();
$civiVersion = CRM_Core_BAO_Domain::version();
if (version_compare('4.4', $civiVersion, '<=')) {
if (version_compare('4.4', $civiVersion, '>=')) {
//in CiviCRM 4.4 the invoke function has 5 arguments maximum
return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $fnSuffix);
} else {
//in CiviCRM 4.5 and later the invoke function has 6 arguments
return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, CRM_Utils_Hook::$_nullObject, $fnSuffix);
}
//in CiviCRM 4.5 and later the invoke function has 6 arguments
return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, null, $fnSuffix);
}
}
\ No newline at end of file
......@@ -26,14 +26,21 @@ class CRM_CivirulesConditions_FieldValueComparison extends CRM_CivirulesConditio
$params['entityID'] = $data['id'];
$params[$field] = 1;
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$value = null;
if (!empty($values[$field])) {
return $this->normalizeValue($values[$field]);
$value = $this->normalizeValue($values[$field]);
} elseif (!empty($values['error_message'])) {
$custom_values = $triggerData->getCustomFieldValues($custom_field_id);
if (!empty($custom_values)) {
return $this->normalizeValue(reset($custom_values));
$value = $custom_values;
}
}
if ($value !== null) {
$value = $this->convertMultiselectCustomfieldToArray($custom_field_id, $value);
return $this->normalizeValue($value);
}
} catch (Exception $e) {
//do nothing
}
......@@ -42,6 +49,23 @@ class CRM_CivirulesConditions_FieldValueComparison extends CRM_CivirulesConditio
return null;
}
/**
* Returns an array of value when the custom field is a multi select
* otherwise just return the value
*
* @param $custom_field_id
* @param $value
* @return mixed
*/
protected function convertMultiselectCustomfieldToArray($custom_field_id, $value) {
$custom_field = civicrm_api3('CustomField', 'getsingle', array('id' => $custom_field_id));
if (CRM_Core_BAO_CustomField::isSerialized($custom_field)) {
$value = trim($value, CRM_Core_DAO::VALUE_SEPARATOR);
$value = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
}
return $value;
}
/**
* Returns the value for the data comparison
*
......
......@@ -84,6 +84,7 @@
CRM.api3('CustomField', 'getsingle', {'sequential': 1, 'id': custom_field_id}, true)
.done(function(data) {
switch(data.html_type) {
case 'CheckBox':
case 'Multi-Select':
case 'AdvMulti-Select':
multiple = true;
......
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