Perforce Chronicle 2012.2/486814
API Documentation
|
A workflow condition to check if given input is contained in record field values. More...
Protected Member Functions | |
_evaluate (Workflow_Model_Transition $transition, P4Cms_Record $record, array $pending=null) | |
Looks for given string or regex pattern (passed via options) in record field values. |
A workflow condition to check if given input is contained in record field values.
Returns true if input is found in at least one record field, false otherwise.
Input is specified via condition options:
fields - list with record fields to include in search (all fields by default) string - for literal match (case in-sensitive) pattern - for regex comparison
Workflow_Workflow_Condition_Contains::_evaluate | ( | Workflow_Model_Transition $ | transition, |
P4Cms_Record $ | record, | ||
array $ | pending = null |
||
) | [protected] |
Looks for given string or regex pattern (passed via options) in record field values.
Returns true if input is found in at least one field, otherwise return false.
File content (if set) field and all non-textual fields are excluded.
If both string and patterns options are set, then condition is evaluated as true if either one comparison is successful.
Workflow_Model_Transition | $transition | transition to evaluate this condition for. |
P4Cms_Record | $record | record to evaluate this condition for in context. |
array | null | $pending | optional - updated values to consider. |
Reimplemented from Workflow_ConditionAbstract.
{ // get selected record fields (all fields if no option provided) if ($this->getOption('fields')) { // remove non-existant fields $fields = array_intersect((array) $this->getOption('fields'), $record->getFields()); } else { $fields = $record->getFields(); } // exclude all non-textual fields foreach ($fields as $key => $field) { $metadata = $record->getFieldMetadata($field); if (isset($metadata['mimeType']) && strpos($metadata['mimeType'], 'text/') !== 0) { unset($fields[$key]); } } // search for string/regex input in record fields $string = (string) $this->getOption('string'); $pattern = (string) $this->getOption('pattern'); foreach ($fields as $field) { // take value from pending values array if present, else from record. $value = isset($pending[$field]) ? $pending[$field] : $record->getValue($field); // compare against string (literal match) if ($string !== '' && stripos($value, $string) !== false) { return true; } // compare against regex pattern if ($pattern !== '' && preg_match($pattern, $value) > 0) { return true; } } // input not found return false; }