You are here

function photos_set_count in Album Photos 6.2

Same name and namespace in other branches
  1. 7.3 photos.module \photos_set_count()
9 calls to photos_set_count()
photos_editlist_submit in inc/photos.edit.inc
photos_editlist_submit_node in inc/photos.edit.inc
photos_edit_delete in inc/photos.edit.inc
photos_file_del in ./photos.module
photos_image_date in ./photos.module

... See full list

File

./photos.module, line 1123

Code

function photos_set_count($type, $id = 0) {
  switch ($type) {
    case 'user_image':
      $count = db_result(db_query('SELECT count(x.fid) FROM {x_image} x INNER JOIN {files} f ON x.fid = f.fid WHERE f.uid = %d', $id));
      db_query("UPDATE {x_count} SET value = %d, changed = %d WHERE cid = %d AND type = '%s'", $count, time(), $id, $type);
      if (!db_affected_rows()) {
        db_query("INSERT INTO {x_count} (cid, changed, type, value) VALUES (%d, %d, '%s', %d)", $id, time(), 'user_image', $count);
      }
      break;
    case 'user_album':
      $count = db_result(db_query('SELECT count(x.pid) FROM {x_album} x INNER JOIN {node} n ON x.pid = n.nid WHERE n.uid = %d', $id));
      db_query("UPDATE {x_count} SET value = %d, changed = %d WHERE cid = %d AND type = '%s'", $count, time(), $id, $type);
      if (!db_affected_rows()) {
        db_query("INSERT INTO {x_count} (cid, changed, type, value) VALUES (%d, %d, '%s', %d)", $id, time(), 'user_album', $count);
      }
      break;
    case 'site_album':
      $count = db_result(db_query('SELECT COUNT(pid) FROM {x_album}'));
      db_query("UPDATE {x_count} SET value = %d, changed = '%s' WHERE cid = 0 AND type = '%s'", $count, time(), $type);
      if (!db_affected_rows()) {
        db_query("INSERT INTO {x_count} (cid, changed, type, value) VALUES (0, %d, '%s', %d)", time(), 'site_album', $count);
      }
      break;
    case 'site_image':
      $count = db_result(db_query('SELECT COUNT(fid) FROM {x_image}'));
      db_query("UPDATE {x_count} SET value = %d, changed = '%s' WHERE cid = 0 AND type = '%s'", $count, time(), $type);
      if (!db_affected_rows()) {
        db_query("INSERT INTO {x_count} (cid, changed, type, value) VALUES (0, %d, '%s', %d)", time(), 'site_image', $count);
      }
      break;
    case 'node_node':
      $count = db_result(db_query('SELECT COUNT(nid) FROM {x_node} WHERE nid = %d', $id));
      db_query("UPDATE {x_count} SET value = %d, changed = %d WHERE cid = %d AND type = '%s'", $count, time(), $id, $type);
      if (!db_affected_rows()) {
        db_query("INSERT INTO {x_count} (cid, changed, type, value) VALUES (%d, %d, '%s', %d)", $id, time(), 'node_node', $count);
      }
      break;
    case 'node_album':
      db_query("UPDATE {x_album} SET count = (SELECT COUNT(fid) FROM {x_image} WHERE pid = %d) WHERE pid = %d", $id, $id);
  }
}