/**
  * Returns an associative array containing all statuses that belong to a workflow.
  * The array returned is suitable to be used as list data value in (for instance) a dropdown list control.
  *
  * Usage example : assuming model Post has a SimpleWorkflowBehavior the following code displays a dropdown list
  * containing all statuses defined in $post current the workflow :
  *
  * <pre>
  * echo Html::dropDownList(
  * 		'status',
  * 		null,
  * 		WorkflowHelper::getAllStatusListData(
  * 			$post->getWorkflow()->getId(),
  * 			$post->getWorkflowSource()
  * 		)
  * )
  * </pre>
  * @param string $workflowId
  * @param IWorkflowSource $workflowSource
  * @return array
  */
 public static function getAllStatusListData($workflowId, $workflowSource)
 {
     $listData = [];
     $statuses = $workflowSource->getAllStatuses($workflowId);
     foreach ($statuses as $statusId => $statusInstance) {
         $listData[$statusId] = $statusInstance->getLabel();
     }
     return $listData;
 }
 /**
  * Validates an array that contains a workflow definition.
  *
  * @param string $wId
  * @param IWorkflowSource $source
  * @param string $initialStatusId
  * @param array $startStatusIdIndex
  * @param array $endStatusIdIndex
  * @throws WorkflowValidationException
  */
 public function validate($wId, $source, $initialStatusId, $startStatusIdIndex, $endStatusIdIndex)
 {
     if ($this->validate === true) {
         if (!\in_array($initialStatusId, $startStatusIdIndex)) {
             throw new WorkflowValidationException("Initial status not defined : {$initialStatusId}");
         }
         // detect not defined statuses
         $missingStatusIdSuspects = \array_diff($endStatusIdIndex, $startStatusIdIndex);
         if (count($missingStatusIdSuspects) != 0) {
             $missingStatusId = [];
             foreach ($missingStatusIdSuspects as $id) {
                 list($thisWid, $thisSid) = $source->parseStatusId($id, $wId);
                 if ($thisWid == $wId) {
                     $missingStatusId[] = $id;
                     // refering to the same workflow, this Id is not defined
                 }
             }
             if (count($missingStatusId) != 0) {
                 throw new WorkflowValidationException("One or more end status are not defined : " . VarDumper::dumpAsString($missingStatusId));
             }
         }
     }
 }