You are here

function node_gallery_api_update_image_counts in Node Gallery 7

Update image counts related to the Node Gallery node.

Parameters

int $ngid: a gallery or an image node object

3 calls to node_gallery_api_update_image_counts()
NodeGalleryBehaviorHandler::NodeGalleryRelationshipCrud in plugins/entityreference/behavior/NodeGalleryBehaviorHandler.class.php
Create, update or delete Node Gallery relationships based on field values.
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().

File

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

Code

function node_gallery_api_update_image_counts($ngid) {
  $res = db_query("SELECT n.status AS status, COUNT(*) AS num\n     FROM {node_gallery_relationship} ngi\n     INNER JOIN {node} n ON ngi.nid = n.nid\n     WHERE ngi.ngid = :ngid GROUP BY n.status", array(
    ':ngid' => $ngid,
  ));
  $counts = array(
    0 => 0,
    1 => 0,
  );
  foreach ($res as $row) {
    $counts[(int) $row->status] = (int) $row->num;
  }
  db_update('node_gallery_galleries')
    ->fields(array(
    'item_count' => $counts[0] + $counts[1],
    'pub_item_count' => $counts[1],
  ))
    ->condition('ngid', $ngid)
    ->execute();
}