function ctools_export_load_object

cis7 export.inc ctools_export_load_object($table, $type = 'all', $args = array())
cle7 export.inc ctools_export_load_object($table, $type = 'all', $args = array())
elmsmedia7 export.inc ctools_export_load_object($table, $type = 'all', $args = array())
icor7 export.inc ctools_export_load_object($table, $type = 'all', $args = array())
meedjum_blog7 export.inc ctools_export_load_object($table, $type = 'all', $args = array())
mooc7 export.inc ctools_export_load_object($table, $type = 'all', $args = array())

Load some number of exportable objects.

This function will cache the objects, load subsidiary objects if necessary, check default objects in code and properly set them up. It will cache the results so that multiple calls to load the same objects will not cause problems.

It attempts to reduce, as much as possible, the number of queries involved.

Parameters

$table: The name of the table to be loaded from. Data is expected to be in the schema to make all this work.

$type: A string to notify the loader what the argument is

  • all: load all items. This is the default. $args is unused.
  • names: $args will be an array of specific named objects to load.
  • conditions: $args will be a keyed array of conditions. The conditions must be in the schema for this table or errors will result.

$args: An array of arguments whose actual use is defined by the $type argument.

40 calls to ctools_export_load_object()
boxes_box::load in sites/all/modules/ulmus/boxes/plugins/boxes_box.inc
Load existing box by its unique identifier $delta.
boxes_box_load in sites/all/modules/ulmus/boxes/boxes.module
Load a box.
breakpoints_breakpoint_group_load in sites/all/modules/local_contrib/breakpoints/breakpoints.module
Load a single breakpoint group.
breakpoints_breakpoint_load_by_fullkey in sites/all/modules/local_contrib/breakpoints/breakpoints.module
Load a single breakpoint using the full config key.
context_load in sites/all/modules/ulmus/context/context.module
Context loader.

... See full list

4 string references to 'ctools_export_load_object'
ctools_export_load_object_reset in sites/all/modules/ulmus/ctools/includes/export.inc
Reset all static caches in ctools_export_load_object() or static caches for a given table in ctools_export_load_object().
field_group_info_groups in sites/all/modules/ulmus/field_group/field_group.module
Get all groups.
views_get_view in sites/all/modules/ulmus/views/views.module
Get a view from the database or from default views.
_data_load_table in sites/all/modules/local_contrib/data/data.module
Loads data table info from the database and from CTools exportables.

File

sites/all/modules/ulmus/ctools/includes/export.inc, line 387
Contains code to make it easier to have exportable objects.

Code

function ctools_export_load_object($table, $type = 'all', $args = array()) {
  $cache = &drupal_static(__FUNCTION__);
  $cache_table_exists = &drupal_static(__FUNCTION__ . '_table_exists', array());
  $cached_database = &drupal_static('ctools_export_load_object_all');

  if (!array_key_exists($table, $cache_table_exists)) {
    $cache_table_exists[$table] = db_table_exists($table);
  }

  $schema = ctools_export_get_schema($table);
  if (empty($schema) || !$cache_table_exists[$table]) {
    return array();
  }

  $export = $schema['export'];

  if (!isset($cache[$table])) {
    $cache[$table] = array();
  }

  // If fetching all and cached all, we've done so and we are finished.
  if ($type == 'all' && !empty($cached_database[$table])) {
    return $cache[$table];
  }

  $return = array();

  // Don't load anything we've already cached.
  if ($type == 'names' && !empty($args)) {
    foreach ($args as $id => $name) {
      if (isset($cache[$table][$name])) {
        $return[$name] = $cache[$table][$name];
        unset($args[$id]);
      }
    }

    // If nothing left to load, return the result.
    if (empty($args)) {
      return $return;
    }
  }

  // Build the query
  $query = db_select($table, 't__0')->fields('t__0');
  $alias_count = 1;
  if (!empty($schema['join'])) {
    foreach ($schema['join'] as $join_key => $join) {
      if ($join_schema = drupal_get_schema($join['table'])) {
        $query->join($join['table'], 't__' . $alias_count, 't__0.' . $join['left_key'] . ' = ' . 't__' . $alias_count . '.' . $join['right_key']);
        $query->fields('t__' . $alias_count);
        $alias_count++;

        // Allow joining tables to alter the query through a callback.
        if (isset($join['callback']) && function_exists($join['callback'])) {
          $join['callback']($query, $schema, $join_schema);
        }
      }
    }
  }

  $conditions = array();
  $query_args = array();

  // If they passed in names, add them to the query.
  if ($type == 'names') {
    $query->condition($export['key'], $args, 'IN');
  }
  else if ($type == 'conditions') {
    foreach ($args as $key => $value) {
      if (isset($schema['fields'][$key])) {
        $query->condition($key, $value);
      }
    }
  }

  $result = $query->execute();

  $status = variable_get($export['status'], array());
  // Unpack the results of the query onto objects and cache them.
  foreach ($result as $data) {
    if (isset($schema['export']['object factory']) && function_exists($schema['export']['object factory'])) {
      $object = $schema['export']['object factory']($schema, $data);
    }
    else {
      $object = _ctools_export_unpack_object($schema, $data, $export['object']);
    }
    $object->table = $table;
    $object->{$export['export type string']} = t('Normal');
    $object->export_type = EXPORT_IN_DATABASE;
    // Determine if default object is enabled or disabled.
    if (isset($status[$object->{$export['key']}])) {
      $object->disabled = $status[$object->{$export['key']}];
    }

    $cache[$table][$object->{$export['key']}] = $object;
    if ($type == 'conditions') {
      $return[$object->{$export['key']}] = $object;
    }
  }

  // Load subrecords.
  if (isset($export['subrecords callback']) && function_exists($export['subrecords callback'])) {
    $export['subrecords callback']($cache[$table]);
  }

  if ($type == 'names' && !empty($args) && !empty($export['cache defaults'])) {
    $defaults = _ctools_export_get_some_defaults($table, $export, $args);
  }
  else {
    $defaults = _ctools_export_get_defaults($table, $export);
  }

  if ($defaults) {
    foreach ($defaults as $object) {
      if ($type == 'conditions') {
        // if this does not match all of our conditions, skip it.
        foreach ($args as $key => $value) {
          if (!isset($object->$key)) {
            continue 2;
          }
          if (is_array($value)) {
            if (!in_array($object->$key, $value)) {
              continue 2;
            }
          }
          else if ($object->$key != $value) {
            continue 2;
          }
        }
      }
      else if ($type == 'names') {
        if (!in_array($object->{$export['key']}, $args)) {
          continue;
        }
      }

      // Determine if default object is enabled or disabled.
      if (isset($status[$object->{$export['key']}])) {
        $object->disabled = $status[$object->{$export['key']}];
      }

      if (!empty($cache[$table][$object->{$export['key']}])) {
        $cache[$table][$object->{$export['key']}]->{$export['export type string']} = t('Overridden');
        $cache[$table][$object->{$export['key']}]->export_type |= EXPORT_IN_CODE;
        $cache[$table][$object->{$export['key']}]->export_module = isset($object->export_module) ? $object->export_module : NULL;
        if ($type == 'conditions') {
          $return[$object->{$export['key']}] = $cache[$table][$object->{$export['key']}];
        }
      }
      else {
        $object->{$export['export type string']} = t('Default');
        $object->export_type = EXPORT_IN_CODE;
        $object->in_code_only = TRUE;
        $object->table = $table;

        $cache[$table][$object->{$export['key']}] = $object;
        if ($type == 'conditions') {
          $return[$object->{$export['key']}] = $object;
        }
      }
    }
  }

  // If fetching all, we've done so and we are finished.
  if ($type == 'all') {
    $cached_database[$table] = TRUE;
    return $cache[$table];
  }

  if ($type == 'names') {
    foreach ($args as $name) {
      if (isset($cache[$table][$name])) {
        $return[$name] = $cache[$table][$name];
      }
    }
  }

  // For conditions,
  return $return;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.