You are here

function context_load_context in Context 6.2

Same name and namespace in other branches
  1. 6 context.module \context_load_context()

Context loader.

Parameters

$context: The parameters to use for loading this context. Can be an integer cid or partial context object.

Return value

Returns a fully-loaded context definition.

5 calls to context_load_context()
context_delete_context in ./context.module
Deletes an existing context.
context_save_context in ./context.module
Inserts or updates a context object into the database. @TODO: should probably return the new cid on success -- make sure this doesn't break any checks elsewhere.
context_ui_form_validate in context_ui/context_ui.admin.inc
hook_validate()
context_ui_import_submit in context_ui/context_ui.admin.inc
Import form submit handler. Evaluates import code and transfers to context definition form.
context_ui_menu_load in context_ui/context_ui.module
Helper loader to parse menu arguments and load contexts accordingly.

File

./context.module, line 184

Code

function context_load_context($context, $reset = FALSE) {
  static $cache = array();

  // Argument is a cid
  if (is_numeric($context)) {
    $cid = $context;
    if (!isset($cache[$cid])) {
      $context = db_fetch_object(db_query("SELECT * FROM {context} WHERE cid = %d", $cid));
    }
    else {
      return $cache[$cid];
    }
  }
  else {
    if (is_object($context) && isset($context->cid)) {
      $context = db_fetch_object(db_query("SELECT * FROM {context} WHERE cid = %d", $context->cid));
    }
    else {
      if (is_object($context) && $context->namespace && $context->attribute && $context->value) {
        $args = array(
          $context->namespace,
          $context->attribute,
          $context->value,
        );
        $context = db_fetch_object(db_query("SELECT * FROM {context} WHERE namespace = '%s' AND attribute = '%s' AND value = '%s'", $args));
      }
    }
  }

  // Unserialize and populate associations
  if (!empty($context->data)) {
    $context = context_unpack_context($context);
    $cache[$context->cid] = $context;
    return $context;
  }
  return FALSE;
}