Perforce Chronicle 2012.2/486814
API Documentation

Workflow_Model_State Class Reference

Workflow state model. More...

Inheritance diagram for Workflow_Model_State:
P4Cms_Model P4Cms_ModelInterface

List of all members.

Public Member Functions

 getLabel ()
 Get the current label.
 getTransition ($name)
 Get specified transition.
 getTransitionModel ($name)
 Get specified transition from this state as model.
 getTransitionModels ()
 Get the transitions attached to this state as models.
 getTransitions ()
 Get list of transitions attached to this state.
 getValidTransitionsFor (P4Cms_Record $record, array $pending=null)
 Get the transitions that are valid for the given record (as determined by transition conditions).
 getWorkflow ()
 Get the workflow that this state belongs to.
 hasTransition ($name)
 Check if state has the specified transition.
 setWorkflow (Workflow_Model_Workflow $workflow)
 Set a workflow that is partially made up by this state.

Public Attributes

const PUBLISHED = 'published'
const RECORD_FIELD = 'workflowState'
const RECORD_SCHEDULED_FIELD = 'workflowScheduledState'
const RECORD_TIME_FIELD = 'workflowScheduledTime'

Static Protected Attributes

static $_fields

Detailed Description

Workflow state model.

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_Model_State::getLabel ( )

Get the current label.

Returns:
string the current label or id if label is empty or not a string.
    {
        $label = $this->_getValue('label');
        return is_string($label) && strlen($label) ? $label : (string) $this->getId();
    }
Workflow_Model_State::getTransition ( name)

Get specified transition.

Parameters:
string$nametransition name.
Returns:
array field details for the named transition.
Exceptions:
Workflow_Exceptionif transition is not found between transitions defined for this state.
    {
        $transitions = $this->getTransitions();

        if (!array_key_exists($name, $transitions)) {
            throw new Workflow_Exception(
                "Transition '$name' not found among the transitions for this state."
            );
        }

        return is_array($transitions[$name]) ? $transitions[$name] : array();
    }
Workflow_Model_State::getTransitionModel ( name)

Get specified transition from this state as model.

Parameters:
string$nametransition name.
Returns:
Workflow_Model_Transition state transition model.
    {
        // create transition model
        $transition = new Workflow_Model_Transition($this->getTransition($name));
        $transition->setId($name)
                   ->setFromState($this)
                   ->setToState($this->getWorkflow()->getStateModel($name));

        return $transition;
    }
Workflow_Model_State::getTransitionModels ( )

Get the transitions attached to this state as models.

Returns:
P4Cms_Model_Iterator transitions of this state.
    {
        $transitions = new P4Cms_Model_Iterator();
        foreach ($this->getTransitions() as $name => $values) {
            $transitions[] = $this->getTransitionModel($name);
        }

        return $transitions;
    }
Workflow_Model_State::getTransitions ( )

Get list of transitions attached to this state.

Returns:
array the list of transitions (transitions definitions).
    {
        $transitions = $this->_getValue('transitions');
        $transitions = is_array($transitions) ? $transitions : array();
        
        // return only the transitions that have valid target states.
        return array_intersect_key(
            $transitions, 
            $this->getWorkflow()->getStates()
        );
    }
Workflow_Model_State::getValidTransitionsFor ( P4Cms_Record record,
array $  pending = null 
)

Get the transitions that are valid for the given record (as determined by transition conditions).

There is the option of passing an array of pending values to consider when evaluating conditions. These would typically come from a request as the user makes changes to the record.

Parameters:
P4Cms_Record$recordthe record to evaulate for context.
array | null$pendingoptional - updated values to consider.
Returns:
P4Cms_Model_Iterator a list of allowed transitions for this record.
    {
        $transitions = new P4Cms_Model_Iterator;
        foreach ($this->getTransitionModels() as $transition) {
            if ($transition->areConditionsMetFor($record, $pending)) {
                $transitions[] = $transition;
            }
        }

        return $transitions;
    }
Workflow_Model_State::getWorkflow ( )

Get the workflow that this state belongs to.

Returns:
Workflow_Model_Workflow workflow that this state belongs to
Exceptions:
Workflow_Exceptionif no valid workflow has been set
    {
        if (!$this->_getValue('workflow') instanceof Workflow_Model_Workflow) {
            throw new Workflow_Exception(
                "Cannot get workflow for state. No workflow has been set."
            );
        }

        return $this->_getValue('workflow');
    }
Workflow_Model_State::hasTransition ( name)

Check if state has the specified transition.

Parameters:
string$nametransition name.
Returns:
bool true if state defines given transition, false otherwise.
    {
        try {
            $this->getTransition($name);
            return true;
        } catch (Workflow_Exception $e) {
            return false;
        }
    }
Workflow_Model_State::setWorkflow ( Workflow_Model_Workflow workflow)

Set a workflow that is partially made up by this state.

Parameters:
Workflow_Model_Workflow$workflowworkflow that is made up (partially) by this state.
    {
        $this->_setValue('workflow', $workflow);
    }

Member Data Documentation

Workflow_Model_State::$_fields [static, protected]
Initial value:
 array(
        'label'         => array(
            'accessor'  => 'getLabel'
        ),
        'transitions'   => array(
            'accessor'  => 'getTransitions'
        ),
        'workflow'      => array(
            'accessor'  => 'getWorkflow',
            'mutator'   => 'setWorkflow'
        )
    )

Reimplemented from P4Cms_Model.

const Workflow_Model_State::PUBLISHED = 'published'
const Workflow_Model_State::RECORD_FIELD = 'workflowState'
const Workflow_Model_State::RECORD_SCHEDULED_FIELD = 'workflowScheduledState'
const Workflow_Model_State::RECORD_TIME_FIELD = 'workflowScheduledTime'

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