You are here

function casetracker_case_state_load in Case Tracker 5

Same name and namespace in other branches
  1. 6 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

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

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

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'.

19 calls to casetracker_case_state_load()
casetracker_cases_overview in ./casetracker.module
Menu callback; displays a list of all cases in a table. See the README.txt for the various URLs we support.
casetracker_case_form_common in ./casetracker.module
Common form elements for cases, generic enough for use either in a full node display, or in comment displays and updating. Default values are calculated based on an existing $form['nid']['#value'].
casetracker_case_state_confirm_delete in ./casetracker.module
If the user has asked to delete a case state, we'll double-check.
casetracker_case_state_edit in ./casetracker.module
Displays a form for adding or editing a case state.
casetracker_case_state_overview in ./casetracker.module
Displays an administrative overview of all case states available.

... See full list

File

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

Code

function casetracker_case_state_load($realm = NULL, $csid = NULL) {
  static $states_lookup = array();
  if (!$states_lookup) {
    $results = db_query("SELECT csid, case_state_name, case_state_realm, weight FROM {casetracker_case_states} ORDER BY weight");
    while ($result = db_fetch_object($results)) {

      // offer cached csid and realm lookups from a one-time query.
      $states_lookup[$result->case_state_realm][$result->csid] = array(
        'name' => $result->case_state_name,
        'realm' => $result->case_state_realm,
        'weight' => (int) $result->weight,
        'csid' => (int) $result->csid,
      );
      $states_lookup[$result->csid] = $states_lookup[$result->case_state_realm][$result->csid];
    }
  }
  if ($csid && $realm) {
    return $states_lookup[$csid]['name'];
  }
  elseif ($csid && !$realm) {
    return $states_lookup[$csid];
  }
  elseif (!$csid && $realm) {
    $options = array();

    // suitable for form api.
    foreach ($states_lookup[$realm] as $state) {
      $options[$state['csid']] = $state['name'];
    }
    return $options;
  }
}