You are here

function node_gallery_api_set_gallery_cover_item in Node Gallery 7

Sets the cover image in the DB if necessary.

Parameters

int $item_nid: A reference to the node object of a node gallery image.

4 calls to node_gallery_api_set_gallery_cover_item()
node_gallery_api_manage_items_submit in ./node_gallery_api.pages.inc
Submit handler for Manage Items form.
node_gallery_api_node_insert in ./node_gallery_api.module
Implements hook_node_insert().
node_gallery_api_node_update in ./node_gallery_api.module
Implements hook_node_update().
node_gallery_api_rules_gallery_set_cover in ./node_gallery_api.rules.inc
Rules action for setting the cover item of a gallery.

File

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

Code

function node_gallery_api_set_gallery_cover_item($item_nid, $ngid = NULL) {
  if (empty($ngid)) {
    $relationships = node_gallery_api_get_relationships(NULL, $item_nid);
    if (!empty($relationships)) {
      $relationship = array_shift($relationships);
      $ngid = $relationships->ngid;
    }
    if (empty($ngid)) {
      return FALSE;
    }
  }
  db_update('node_gallery_galleries')
    ->fields(array(
    'cover_item' => $item_nid,
  ))
    ->condition('ngid', $ngid)
    ->execute();
  return TRUE;
}