You are here

function casetracker_case_state_load in Case Tracker 6

Same name and namespace in other branches
  1. 5 casetracker.module \casetracker_case_state_load()
  2. 7 casetracker.module \casetracker_case_state_load()

Returns information about the various case states and their options. The number of parameters passed will determine the return value.

Parameters

$csid: Optional; the state ID to return from the passed $realm.

$realm: Optional; the name of the realm ('status', 'priority', or 'type').

$reset: Optional; set to TRUE to reset the static cache.

Return value

$values If only $realm is passed, you'll receive an array with the keys being the state ID and the values being their names. If a $csid is also passed, you'll receive just a string of the state name. If ONLY a $csid is passed, we'll return a list of 'name', 'realm'.

8 calls to casetracker_case_state_load()
CasetrackerAdminTest::testCasetrackerAdminCreation in tests/casetracker_admin.test
Main test routine.
casetracker_realm_load in ./casetracker.module
Load states for a particular realm. Wrapper around casetracker_case_state_load()
casetracker_views_handler_field_priority_name::render in includes/casetracker_views_handler_field_priority_name.inc
casetracker_views_handler_field_status_name::render in includes/casetracker_views_handler_field_status_name.inc
casetracker_views_handler_field_type_name::render in includes/casetracker_views_handler_field_type_name.inc

... See full list

File

./casetracker.module, line 544
Enables the handling of projects and their cases.

Code

function casetracker_case_state_load($csid = NULL, $realm = NULL, $reset = FALSE) {
  static $states_lookup;
  if (!$states_lookup || $reset) {
    $results = db_query("SELECT csid, case_state_name AS name, case_state_realm AS realm, weight \n                         FROM {casetracker_case_states} ORDER BY weight");
    $states_lookup = array();
    while ($row = db_fetch_object($results)) {
      $row->display = casetracker_tt("case_states:{$row->csid}:name", $row->name);
      $states_lookup[$row->realm][$row->csid] = $states_lookup['all'][$row->csid] = $row;
    }
  }
  if ($csid && $realm) {
    return $states_lookup['all'][$csid]->display;
  }
  elseif ($csid && !$realm) {
    return $states_lookup['all'][$csid];
  }
  elseif (!$csid && $realm) {
    $options = array();

    // suitable for form api.
    if (!empty($states_lookup[$realm])) {
      foreach ($states_lookup[$realm] as $state) {
        $options[$state->csid] = $state->display;
      }
    }
    return $options;
  }
}