You are here

function _node_gallery_api_cache_sorted_item_nids in Node Gallery 7

Builds the caches for a gallery and saves them to the db.

There are two caches stored for each gallery. One is a sorted array of nids that represents the items in proper search order. The second is an associative array where the key is the nid of the image and the value is that nid's respective position in the list (1-based).

Parameters

int $ngid: The nid of the gallery to build caches for.

2 calls to _node_gallery_api_cache_sorted_item_nids()
node_gallery_api_get_item_list in ./node_gallery_api.inc
Gets a sorted list of images nids within a gallery.
node_gallery_api_get_item_position in ./node_gallery_api.inc
Returns the position (starting at one) of the image in the gallery list.

File

./node_gallery_api.inc, line 584
Node Gallery API function

Code

function _node_gallery_api_cache_sorted_item_nids($ngid) {
  $item_list = node_gallery_api_get_item_nids($ngid, TRUE, TRUE);
  $item_position = array();
  $position = 1;
  foreach ($item_list as $nid) {
    $item_position[$nid] = $position;
    $position++;
  }
  cache_set('node_gallery:' . $ngid . ':item_position', $item_position, 'cache', CACHE_TEMPORARY);
  cache_set('node_gallery:' . $ngid . ':item_list', $item_list, 'cache', CACHE_TEMPORARY);
}