You are here

public static function WorkflowState::getStates in Workflow 7.2

Same name and namespace in other branches
  1. 7 includes/Entity/WorkflowState.php \WorkflowState::getStates()

Get all states in the system, with options to filter, only where a workflow exists.

Parameters

$wid: The requested Workflow ID.

bool $reset: An option to refresh all caches.

Return value

array $states An array of cached states.

D7.x-2.x: deprecated workflow_get_workflow_states --> workflow_state_load_multiple D7.x-2.x: deprecated workflow_get_workflow_states_all --> workflow_state_load_multiple D7.x-2.x: deprecated workflow_get_other_states_by_sid --> workflow_state_load_multiple

6 calls to WorkflowState::getStates()
Workflow::getStates in includes/Entity/Workflow.php
Gets all states for a given workflow.
Workflow::rebuildInternals in includes/Entity/Workflow.php
Rebuild internals that get saved separately.
WorkflowState::deactivate in includes/Entity/WorkflowState.php
Deactivate a Workflow State, moving existing nodes to a given State.
WorkflowState::load in includes/Entity/WorkflowState.php
Alternative constructor, loading objects from table {workflow_states}.
WorkflowState::loadByName in includes/Entity/WorkflowState.php
Get all states in the system, with options to filter, only where a workflow exists.

... See full list

File

includes/Entity/WorkflowState.php, line 102
Contains workflow\includes\Entity\WorkflowState. Contains workflow\includes\Entity\WorkflowStateController.

Class

WorkflowState
Class WorkflowState

Code

public static function getStates($wid = 0, $reset = FALSE) {
  if ($reset) {
    self::$states = array();
  }
  if (empty(self::$states)) {

    // Build the query, and get ALL states.
    // Note: self::states[] is populated in respective constructors.
    $query = db_select('workflow_states', 'ws');
    $query
      ->fields('ws');
    $query
      ->orderBy('ws.weight');
    $query
      ->orderBy('ws.wid');

    // Just for grins, add a tag that might result in modifications.
    $query
      ->addTag('workflow_states');

    // @see #2285983 for using SQLite.
    // $query->execute()->fetchAll(PDO::FETCH_CLASS, 'WorkflowState');

    /* @var $tmp DatabaseStatementBase */
    $statement = $query
      ->execute();
    $statement
      ->setFetchMode(PDO::FETCH_CLASS, 'WorkflowState');
    foreach ($statement
      ->fetchAll() as $state) {
      self::$states[$state->sid] = $state;
    }
  }
  if (!$wid) {

    // All states are requested and cached: return them.
    return self::$states;
  }
  else {

    // All states of only 1 Workflow is requested: return this one.
    $result = array();
    foreach (self::$states as $state) {
      if ($state->wid == $wid) {
        $result[$state->sid] = $state;
      }
    }
    return $result;
  }
}