Ejemplo n.º 1
0
 /**
  * @returns String the task for this transition or NULL if no task is defined
  * @param mixed $endNode SWNode instance or string that will be converted to SWNode instance (e.g 'workflowId/nodeId')
  * @throws SWException
  */
 public function getTransitionTask($endNode)
 {
     if (!$endNode instanceof SWNode) {
         $endNode = new SWNode($endNode, $this->getWorkflowId());
     }
     $endNodeId = $endNode->toString();
     return isset($this->_tr[$endNodeId]) ? $this->_tr[$endNodeId] : null;
 }
Ejemplo n.º 2
0
 /**
  *
  */
 private function _loadTransition($tr, $defWfId)
 {
     if (is_string($tr)) {
         $trAr = explode(',', $tr);
         foreach ($trAr as $aTr) {
             $objNode = new SWNode(trim($aTr), $defWfId);
             $this->_tr[$objNode->toString()] = null;
         }
     } elseif (is_array($tr)) {
         foreach ($tr as $key => $value) {
             if (is_string($key)) {
                 $objNode = new SWNode(trim($key), $defWfId);
                 if ($value != null) {
                     $this->_tr[$objNode->toString()] = $value;
                 } else {
                     $this->_tr[$objNode->toString()] = null;
                 }
             } else {
                 $objNode = new SWNode(trim($value), $defWfId);
                 $this->_tr[$objNode->toString()] = null;
             }
         }
     }
 }
 /**
  * Log event fired
  * 
  * @param string $ev event name
  * @param SWNode $source
  * @param SWNode $dest
  */
 private function _logEventFire($ev, $source, $dest)
 {
     Yii::log(Yii::t('simpleWorkflow', 'event fired : \'{event}\' status [{source}] -> [{destination}]', array('{event}' => $ev, '{source}' => is_null($source) ? 'null' : $source->toString(), '{destination}' => $dest->toString())), CLogger::LEVEL_INFO, self::SW_LOG_CATEGORY);
 }
 /**
  * @param array $wf workflow definition
  * @param string $wfId workflow Id
  */
 private function _createWorkflow($wf, $wfId)
 {
     if (!is_array($wf) || empty($wfId)) {
         throw new SWException(Yii::t('simpleWorkflow', 'invalid argument'));
     }
     $wfDefinition = array();
     if (!isset($wf['initial'])) {
         throw new SWException(Yii::t('simpleWorkflow', 'missing initial status for workflow {workflow}', array('{workflow}' => $wfId)), SWException::SW_ERR_IN_WORKFLOW);
     }
     // load node list
     $nodeIds = array();
     foreach ($wf['node'] as $rnode) {
         $node = new SWNode($rnode, $wfId);
         if (in_array($node->getId(), $nodeIds)) {
             throw new SWException(Yii::t('simpleWorkflow', 'duplicate node id {nodeId}', array('{nodeId}' => $node->getId())), SWException::SW_ERR_IN_WORKFLOW);
         } else {
             $nodeIds[] = $node->getId();
         }
         $wfDefinition[$node->getId()] = $node;
         if ($node->getId() == $wf['initial'] || $node->toString() == $wf['initial']) {
             $wfDefinition['swInitialNode'] = $node;
         }
     }
     // checks that initialnode is set
     if (!isset($wfDefinition['swInitialNode'])) {
         throw new SWException(Yii::t('simpleWorkflow', 'missing initial status for workflow {workflow}', array('{workflow}' => $wfId)), SWException::SW_ERR_IN_WORKFLOW);
     }
     return $wfDefinition;
 }
Ejemplo n.º 5
0
 public static function SW_NODE($status)
 {
     $node = new SWNode($status, WaterRequests::WORKFLOW);
     if ($node) {
         return $node->toString();
     }
     return '';
 }
Ejemplo n.º 6
0
 /**
  * Returns an array where keys are status id and values are status labels.
  *
  * @param array $statusList SWNode list
  * @param array $options (optional)
  * @throws CException
  */
 private static function _createListData($model, $statusList, $options = array())
 {
     $result = array();
     $exclude = null;
     $includeCurrent = true;
     $currentStatus = $model->swHasStatus() ? $model->swGetStatus() : null;
     if ($currentStatus != null) {
         $result[$currentStatus->toString()] = $currentStatus->getLabel();
     }
     $encodeLabel = isset($options['encode']) ? (bool) $options['encode'] : true;
     // process options
     if (count($options) != 0) {
         if (isset($options['prompt'])) {
             $result[''] = $options['prompt'];
         }
         if (isset($options['exclude'])) {
             if (is_string($options['exclude'])) {
                 $exclude = array_map('trim', explode(",", $options['exclude']));
             } elseif (is_array($options['exclude'])) {
                 $exclude = $options['exclude'];
             } else {
                 throw new CException('incorrect type for option "exclude" : array or string expected');
             }
             foreach ($exclude as $key => $value) {
                 $node = new SWNode($value, $model->swGetWorkflowId());
                 $exclude[$key] = $node->toString();
             }
         }
         if (isset($options['includeCurrent'])) {
             $includeCurrent = (bool) $options['includeCurrent'];
         }
         if ($exclude != null && $currentStatus != null && in_array($currentStatus->toString(), $exclude)) {
             $includeCurrent = false;
         }
     }
     if (count($statusList) != 0) {
         foreach ($statusList as $nodeObj) {
             if ($exclude == null || $exclude != null && !in_array($nodeObj->toString(), $exclude)) {
                 $result[$nodeObj->toString()] = $encodeLabel ? CHtml::encode($nodeObj->getLabel()) : $nodeObj->getLabel();
             }
         }
     }
     if ($includeCurrent == false && $currentStatus != null) {
         unset($result[$currentStatus->toString()]);
     }
     return $result;
 }