1 <?php
2 /**
3 * This is the base class for all workflow source implementations. It provides
4 * basic initialization features and a set of methods that must be implemented
5 * by workflow source classes.<br/>
6 */
7 abstract class SWWorkflowSource extends CApplicationComponent
8 {
9 /**
10 * @var array list of workflow names that shoumd ne loaded when the component is initialized
11 */
12 public $preload=array();
13 /**
14 * @var string when a workflow name is automatically built from the model name, this prefix is added to the
15 * model name so to avoid clashes (e.g. model 'MyModel' is by default inserted into workflow 'swMyModel')
16 */
17 public $workflowNamePrefix='sw';
18 /**
19 * Create and returns a SWNode object. The SWNode returned doesn't have to be defined
20 * in a workflow currently loaded.<br/>
21 * If $node is a string, it can be a fully qualified node id (e.g workflowId/NodeId)
22 * or only a nodeId, but in this case, argument $workflowId must contain the id of the
23 * workflow to use.<br/>
24 * If $node is a SWNode object, then it is returned with no modification.
25 *
26 * @return SWNode the node object
27 */
28 public function createSWNode($node,$workflowId)
29 {
30 return new SWNode($node,$workflowId);
31 }
32 /**
33 * Add a workflow to the internal workflow collection. The definition
34 * of the workflow to add is provided in the $definition argument as an associative array.
35 * This method is used for instance when a workflow definition is provided by a
36 * model and not by a php file or another source. If a workflow with the same id is already
37 * loaded, it is not over written.
38 *
39 * @param array $definition workflow definition
40 * @param string $id unique id for the workflow to add
41 */
42 abstract public function addWorkflow($definition, $id);
43 /**
44 * Loads the workflow whose id is passed as argument from the source.
45 * If it was already loaded, then it is not reloaded unles $forceReload is set to TRUE.
46 * If the workflow could not be found, an exception is thrown.
47 *
48 * @param string $workflowId the id of the workflow to load
49 * @param boolean $forceReload force workflow reload
50 */
51 abstract public function loadWorkflow($workflowId,$forceReload=false);
52 /**
53 * Search for the node passed as argument in the workflow definition. Note that if
54 * this node is not found among the currently loaded workflows, this method will try
55 * to load the workflow it belongs to.
56 *
57 * @param mixed node String or SWNode object to look for
58 * @return SWNode the node as it is defined in a workflow, or NULL if not found
59 */
60 abstract public function getNodeDefinition($node, $defaultWorkflowId=null);
61 /**
62 * Returns an array containing all SWNode object for each status that can be reached
63 * from $startStatus. It does not evaluate node constraint but only the fact that a transition
64 * exist beteween $startStatus and nodes returned. If no nodes are found, an empty array is returned.
65 * An exception is thrown if $startStatus is not found among all worklows available.
66 *
67 *@return array SWNode array
68 */
69 abstract public function getNextNodes($sourceNode,$workflowId=null);
70 /**
71 * Checks if there is a transition between the two nodes passed as argument.
72 *
73 * @param mixed $sourceNode can be provided as a SWNode object, or as a string that
74 * can contain a workflowId or not.
75 * @param mixed $targetNode target node to test
76 * @return boolean true if $nextStatus can be reached from $startStatus
77 */
78 abstract public function isNextNode($sourceNode,$targetNode,$workflowId=null);
79 /**
80 * Returns the initial node defined for the workflow whose id is passed as
81 * argument. A valid workflow must have one and only one initial status. If it's
82 * note the case, workflow can't be loaded.<br/>
83 *
84 * @return SWnode initial node for $workflowId
85 */
86 abstract public function getInitialNode($workflowId);
87 /**
88 * Fetch all nodes belonging to the workflow whose Id is passed as argument.
89 *
90 * @param string $workflowId id of the workflow that owns all nodes returned
91 * @return array all nodes belonging to workflow $workflowId
92 */
93 abstract public function getAllNodes($workflowId);
94
95 }
96
97 ?>
98