You are here

function node_gallery_update_image_counts in Node Gallery 6.3

Update image counts related to the Node Gallery node.

Parameters

$node a gallery or an image node object:

1 call to node_gallery_update_image_counts()
node_gallery_nodeapi in ./node_gallery.module
Implements hook_nodeapi().

File

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

Code

function node_gallery_update_image_counts($node) {
  if (in_array($node->type, (array) node_gallery_get_types('image'))) {
    $gid = $node->gid;
  }
  elseif (in_array($node->type, (array) node_gallery_get_types('gallery'))) {
    $gid = $node->nid;
  }
  else {
    return;
  }
  $res = db_query("SELECT n.status AS status, COUNT(*) AS num\n     FROM {node_gallery_images} ngi\n     INNER JOIN {node} n ON ngi.nid = n.nid\n     WHERE ngi.gid = %d GROUP BY n.status", $gid);
  $counts = array(
    0 => 0,
    1 => 0,
  );
  while ($row = db_fetch_array($res)) {
    $row = array_map('intval', $row);
    $counts[$row['status']] = $row['num'];
  }
  db_query("UPDATE {node_gallery_galleries}\n     SET img_count = %d, pub_img_count = %d\n     WHERE gid = %d", $counts[0] + $counts[1], $counts[1], $gid);
}