You are here

function _ccl_update_cache in Custom Contextual Links 7

Same name and namespace in other branches
  1. 8 ccl.module \_ccl_update_cache()

Helper function to write ccl settings into the cache.

3 calls to _ccl_update_cache()
ccl_add_form_submit in ./ccl.admin.inc
Submit handler for ccl_add_form().
ccl_cache_get in ./ccl.module
Helper function to get ccl settings out of the cache.
ccl_delete_confirm_submit in ./ccl.admin.inc
Submit handler for link deletion page.

File

./ccl.module, line 210
Main CCL module file.

Code

function _ccl_update_cache() {

  // Create entry for nodes.
  $nodes = db_query("SELECT * FROM {ccl} WHERE type = :type", array(
    ':type' => 'node',
  ));
  $node_cache = array(
    'global' => array(),
    'ct' => array(),
    'ids' => array(),
  );
  foreach ($nodes as $node) {
    $node->options = unserialize($node->options);
    $advanced = array();
    if (isset($node->options['advanced_css'])) {
      $advanced['class'] = $node->options['advanced_css'];
    }
    if (isset($node->options['advanced_anchor'])) {
      $advanced['anchor'] = $node->options['advanced_anchor'];
    }
    if (isset($node->options['advanced_query'])) {
      $advanced['query'] = $node->options['advanced_query'];
    }
    if (isset($node->options['advanced_target']) && $node->options['advanced_target'] != "default") {
      $advanced['target'] = $node->options['advanced_target'];
    }
    if (isset($node->options['advanced_destination'])) {
      $advanced['destination'] = $node->options['advanced_destination'];
    }
    if ($node->options['node_options'] == 'global') {
      $node_cache['global'][] = array(
        'title' => $node->title,
        'href' => $node->link,
        'advanced' => $advanced,
      );
    }
    elseif ($node->options['node_options'] == 'node') {
      $node_cache['ids'][$node->options['node_id']][] = array(
        'title' => $node->title,
        'href' => $node->link,
        'advanced' => $advanced,
      );
    }
    else {
      $node_cache['ct'][$node->options['node_type']][] = array(
        'title' => $node->title,
        'href' => $node->link,
        'advanced' => $advanced,
      );
    }
  }
  cache_set('ccl_nodes', $node_cache);

  // Invoke cache_update hook for submodules.
  foreach (module_implements('ccl_cache_update') as $module) {
    module_invoke($module, 'ccl_cache_update');
  }
}