forked from Kajakaran/org.civicoop.civirules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldValueComparison.php
72 lines (63 loc) · 1.96 KB
/
FieldValueComparison.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class CRM_CivirulesConditions_FieldValueComparison extends CRM_CivirulesConditions_Generic_ValueComparison {
/**
* Returns the value of the field for the condition
* For example: I want to check if age > 50, this function would return the 50
*
* @param object CRM_Civirules_EventData_EventData $eventData
* @return
* @access protected
* @abstract
*/
protected function getFieldValue(CRM_Civirules_EventData_EventData $eventData) {
$entity = $this->conditionParams['entity'];
$field = $this->conditionParams['field'];
$data = $eventData->getEntityData($entity);
if (isset($data[$field])) {
return $this->normalizeValue($data[$field]);
}
return null;
}
/**
* Returns the value for the data comparison
*
* @return mixed
* @access protected
*/
protected function getComparisonValue() {
if (!empty($this->conditionParams['value'])) {
return $this->normalizeValue($this->conditionParams['value']);
} else {
return null;
}
}
protected function normalizeValue($value) {
if ($value === null) {
return null;
}
//@todo normalize value based on the field
return $value;
}
/**
* 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
*/
public function getExtraDataInputUrl($ruleConditionId) {
return CRM_Utils_System::url('civicrm/civirule/form/condition/fieldvaluecomparison/', '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() {
return htmlentities($this->conditionParams['entity'].'.'.$this->conditionParams['field'].' '.($this->getOperator())).' '.htmlentities($this->getComparisonValue());
}
}