You are here

function node_gallery_get_relationship in Node Gallery 6.3

Fetches a gallery-to-image relationship from the database.

If one of either $gallery_type or $image_type are supplied, this function returns a single relationship. If neither are specified, it returns all relationships, keyed by the gallery content type. If both are supplied, $image_type will be ignored.

Parameters

$gallery_type: (optional) The content type of the gallery in the relationship. If this is an int, we'll use that as the rid. Defaults to NULL.

$image_type: (optional) The content type of the image in the relationship. Defaults to NULL.

$reset: (optional) Boolean which if set to TRUE, clears the cache. Defaults to FALSE.

Return value

An associative array containing:

  • rid: An integer representing the rid column in the database.
  • gallery_type: A string that is the content type of the gallery.
  • image_type: A string that is the content type of the image.
  • imagefield_name: A string that is the name of the imagefield for the image.
  • settings: An associative array of settings for the relationship.
24 calls to node_gallery_get_relationship()
node_gallery_apply_cck_settings_to_image_types in ./node_gallery.inc
Given a settings associative array uses content_crud to apply settings to the widget for all image types
node_gallery_change_gallery_action_form in ./node_gallery.actions.inc
Builds the form to allow a user to change the gallery of an image.
node_gallery_create_new_gallery_submit in ./node_gallery.module
If the user selected the option to create a new gallery, create a stub gallery, assign the images to that gallery, and redirect them to the gallery edit form.
node_gallery_delete_image in ./node_gallery.inc
Deletes an image from the database, cleans the filesystem of imagecache files.
node_gallery_get_all_relationships in ./node_gallery.inc
Convenience wrapper for getting all relationships.

... See full list

File

./node_gallery.inc, line 77
Shared functions for node_gallery

Code

function node_gallery_get_relationship($gallery_type = NULL, $image_type = NULL, $reset = FALSE) {
  static $ng_relationships = array();
  static $all_fetched = FALSE;

  //Our var to track whether or not $ng_relationships contains all records
  $sql = "SELECT rid, gallery_type, image_type, imagefield_name, settings from {node_gallery_relationships} ";
  $result = NULL;
  if (isset($image_type)) {

    // Get the single relationship keyed on the image type
    $i2g = node_gallery_get_image_to_gallery_types($reset);
    if (empty($i2g[$image_type])) {
      return array();
    }
    $gallery_type = $i2g[$image_type];
  }
  if (isset($gallery_type)) {
    if (is_numeric($gallery_type)) {

      // Get the single relationship keyed on the rid
      $r2g = node_gallery_get_rid_to_gallery_types($reset);
      if (empty($r2g[$gallery_type])) {
        return array();
      }
      $gallery_type = $r2g[$gallery_type];
    }

    // We want a single relationship
    if (!empty($ng_relationships[$gallery_type]) && !isset($reset)) {

      // It's cached, return it
      return $ng_relationships[$gallery_type];
    }

    // We need a single relationship not cached
    $sql .= "WHERE gallery_type = '%s'";
    $result = db_query($sql, $gallery_type);
  }
  else {

    // We want all relationships
    if (!empty($ng_relationships) && !isset($reset) && $all_fetched) {

      // It's cached, return it
      return $ng_relationships;
    }

    // We need all relationships not cached
    $result = db_query($sql);
  }
  while ($r = db_fetch_array($result)) {
    $ng_relationships[$r['gallery_type']]['rid'] = $r['rid'];
    $ng_relationships[$r['gallery_type']]['gallery_type'] = $r['gallery_type'];
    $ng_relationships[$r['gallery_type']]['image_type'] = $r['image_type'];
    $ng_relationships[$r['gallery_type']]['imagefield_name'] = $r['imagefield_name'];
    $ng_relationships[$r['gallery_type']]['settings'] = array_merge(node_gallery_relationship_settings_defaults(), unserialize($r['settings']));
  }
  if (!empty($gallery_type)) {
    return $ng_relationships[$gallery_type];
  }

  // If we get here, we have a newly fetched, fully populated array
  $all_fetched = TRUE;
  return $ng_relationships;
}