コード例 #1
0
 public function testNextNodeIds_06()
 {
     $n = new SWNode(array('id' => 'w1/node1', 'transition' => array('node1' => 'task1', 'w2/node2' => 'task2', 'node3')));
     $this->assertTrue($n->equals('w1/node1'));
     $next = $n->getNextNodeIds();
     $this->assertEquals(count($next), 3);
     $this->assertTrue(in_array('w1/node1', $next));
     $this->assertTrue(in_array('w2/node2', $next));
     $this->assertTrue(in_array('w1/node3', $next));
 }
コード例 #2
0
 /**
  *
  */
 public function testMetadata_01()
 {
     $n = new SWNode(array('id' => 'w1/node1', 'metadata' => array('attr1' => 'value1', 'attr2' => 'value2', 'attr3' => array(1, 2, 3))));
     $this->assertEquals($n->attr1, 'value1');
     $this->assertEquals($n->attr2, 'value2');
     $this->assertTrue(is_array($n->attr3) and isset($n->attr3[1]));
     $this->assertEquals(count(array_diff($n->attr3, array(1, 2, 3))), 0);
     $this->assertTrue(count($n->getMetadata()) == 3);
     $md = $n->getMetadata();
     $this->assertEquals($md['attr1'], 'value1');
     $this->assertEquals($md['attr2'], 'value2');
     $this->assertTrue(is_array($md['attr3']));
 }
コード例 #3
0
 public function testEquals_03()
 {
     $n = new SWNode('node1', 'w1');
     try {
         $n->equals('');
         $this->fail();
     } catch (SWException $e) {
         $this->assertEquals($e->getCode(), SWException::SW_ERR_CREATE_NODE);
     }
     try {
         $n->equals(null);
         $this->fail();
     } catch (SWException $e) {
         $this->assertEquals($e->getCode(), SWException::SW_ERR_CREATE_NODE);
     }
 }
コード例 #4
0
 public function testCreateFromString_03()
 {
     $n = new SWNode('a/node_1');
     $this->assertEquals($n->getLabel(), 'node_1');
     try {
         $n = new SWNode('a/node-1');
         // character '-' is not allowed
         $this->fail();
     } catch (SWException $e) {
         $this->assertEquals($e->getCode(), SWException::SW_ERR_CREATE_NODE);
     }
     try {
         $n = new SWNode('a/1node');
         // character '1' is not allowed
         $this->fail();
     } catch (SWException $e) {
         $this->assertEquals($e->getCode(), SWException::SW_ERR_CREATE_NODE);
     }
 }
コード例 #5
0
 public function testTransitionTask_02()
 {
     $n = new SWNode(array('id' => 'w1/node1', 'transition' => array('node1' => 'task1', 'w2/node2' => 'task2', 'node3')));
     $this->assertTrue($n->getTransitionTask('w1/node1') == 'task1');
     $this->assertTrue($n->getTransitionTask('node1') == 'task1');
     $this->assertTrue($n->getTransitionTask('w2/node2') == 'task2');
     $this->assertTrue($n->getTransitionTask('node2') == null);
     // will be converted to w1/node2 : no transition then
     $this->assertTrue($n->getTransitionTask('w1/node3') == null);
     $this->assertTrue($n->getTransitionTask('node3') == null);
 }
コード例 #6
0
 /**
  * @param array $wf workflow definition
  * @param string $wfId workflow Id
  */
 private function _createWorkflow($wf, $wfId)
 {
     if (!is_array($wf) or 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
     foreach ($wf['node'] as $rnode) {
         $node = new SWNode($rnode, $wfId);
         $wfDefinition[$node->getId()] = $node;
         if ($node->getId() == $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;
 }
コード例 #7
0
ファイル: SWNode.php プロジェクト: honglei619/simpleWorkflow
 /**
  * SWnode comparator method. Note that only the node and the workflow id
  * members are compared.
  *
  * @param mixed SWNode object or string. If a string is provided it is used to create
  * a new SWNode object.
  */
 public function equals($status)
 {
     if ($status instanceof SWNode) {
         return $status->toString() == $this->toString();
     } else {
         try {
             $other = new SWNode($status, $this->getWorkflowId());
             return $other->equals($this);
         } catch (Exception $e) {
             throw new SWException('comparaison error - the value passed as argument (value=' . $status . ') cannot be converted into a SWNode', $e->getCode());
         }
     }
 }
コード例 #8
0
ファイル: SWNode.php プロジェクト: niranjan2m/Voyanga
 /**
  *
  */
 public function equals($status)
 {
     if (is_a($status, 'SWnode') and $status->getWorkflowId() == $this->getWorkflowId() and $status->getId() == $this->getId()) {
         return true;
     } elseif (is_string($status) and !empty($status)) {
         $other = new SWNode($status, $this->getWorkflowId());
         return $other->equals($this);
     } else {
         return false;
     }
 }
コード例 #9
0
 public function testCreateFromString_06()
 {
     $n = new SWNode('node1_aaa', 'w1');
     $this->assertEquals($n->getId(), 'node1_aaa');
     $this->assertEquals($n->getWorkflowId(), 'w1');
     $n = new SWNode('workflow_test/node1_aaa');
     $this->assertEquals($n->getId(), 'node1_aaa');
     $this->assertEquals($n->getWorkflowId(), 'workflow_test');
 }
コード例 #10
0
 /**
  * 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);
 }
コード例 #11
0
ファイル: WaterRequests.php プロジェクト: Gnafu/wiz
 public static function SW_NODE($status)
 {
     $node = new SWNode($status, WaterRequests::WORKFLOW);
     if ($node) {
         return $node->toString();
     }
     return '';
 }
コード例 #12
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;
 }
コード例 #13
0
 /**
  * @param array $wf workflow definition
  * @param string $wfId workflow Id
  */
 private function _createWorkflow($wf, $wfId)
 {
     if (!is_array($wf) || empty($wfId)) {
         throw new SWException('invalid argument');
     }
     $wfDefinition = array();
     if (!isset($wf['initial'])) {
         throw new SWException('missing initial status for 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('duplicate node id : ' . $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('missing initial status for workflow : ' . $wfId, SWException::SW_ERR_IN_WORKFLOW);
     }
     return $wfDefinition;
 }