Perforce Chronicle 2012.2/486814
API Documentation

Workflow_Workflow_Condition_Contains Class Reference

A workflow condition to check if given input is contained in record field values. More...

Inheritance diagram for Workflow_Workflow_Condition_Contains:
Workflow_ConditionAbstract Workflow_PluginAbstract Workflow_ConditionInterface

List of all members.

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.

Detailed Description

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

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

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.

Parameters:
Workflow_Model_Transition$transitiontransition to evaluate this condition for.
P4Cms_Record$recordrecord to evaluate this condition for in context.
array | null$pendingoptional - updated values to consider.
Returns:
bool true if input is found in at least one record field value, false otherwise.

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;
    }

The documentation for this class was generated from the following file: