コード例 #1
0
 /**
  * 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_TriggerData_TriggerData $triggerData
  * @return
  * @access protected
  * @abstract
  */
 protected function getFieldValue(CRM_Civirules_TriggerData_TriggerData $triggerData)
 {
     $entity = $this->conditionParams['entity'];
     $field = $this->conditionParams['field'];
     $data = $triggerData->getEntityData($entity);
     if (isset($data[$field])) {
         return $this->normalizeValue($data[$field]);
     }
     if ($this->isRelativeDate($field)) {
         $relativeDate = $this->parseRelativeDate($field);
         $field = $relativeDate['field'];
         $interval = $relativeDate['interval'];
         if (isset($data[$field])) {
             $date = new DateTime($data[$field]);
             $today = new DateTime("now");
             $diff = $date->diff($today);
             return $this->normalizeValue($diff->format('%' . $interval));
         }
     }
     if (strpos($field, 'custom_') === 0) {
         $custom_field_id = str_replace("custom_", "", $field);
         try {
             $params['entityID'] = $data['id'];
             $params[$field] = 1;
             $values = CRM_Core_BAO_CustomValueTable::getValues($params);
             $value = null;
             if (!empty($values[$field])) {
                 $value = $this->normalizeValue($values[$field]);
             } elseif (!empty($values['error_message'])) {
                 $value = $triggerData->getCustomFieldValue($custom_field_id);
             }
             if ($value !== null) {
                 $value = $this->convertMultiselectCustomfieldToArray($custom_field_id, $value);
                 return $this->normalizeValue($value);
             }
         } catch (Exception $e) {
             //do nothing
         }
     }
     return null;
 }