You are here

public static function WorkflowState::getStates in Workflow 7

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

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

Parameters

$sid : the requested State ID:

$wid : the requested Workflow ID:

$reset : an option to refresh all caches.:

Return value

: an array of states.

6 calls to WorkflowState::getStates()
Workflow::getStates in includes/Entity/Workflow.php
WorkflowItem::_allowed_values_string in includes/Field/WorkflowItem.php
WorkflowState::getStatesByName in includes/Entity/WorkflowState.php
WorkflowState::load in includes/Entity/WorkflowState.php
Alternative constructor, via a static function, loading objects from table {workflow_states}.
workflow_cleanup_form in workflow_cleanup/workflow_cleanup.module
The main cleanup page.

... See full list

File

includes/Entity/WorkflowState.php, line 88
Contains workflow\includes\Entity\WorkflowState.

Class

WorkflowState
@file Contains workflow\includes\Entity\WorkflowState.

Code

public static function getStates($sid = 0, $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');
    $query
      ->execute()
      ->fetchAll(PDO::FETCH_CLASS, 'WorkflowState');
  }
  if (!$sid && !$wid) {

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

  // If only 1 State is requested and cached: return this one.
  if ($sid) {

    // The sid may be deactivated/non-existent.
    $state = isset(self::$states[$sid]) ? self::$states[$sid] : (self::$states[$sid] = NULL);
    return array(
      $sid => $state,
    );
  }
  if ($wid) {

    // 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;
  }
}