You are here

function photos_set_count in Album Photos 7.3

Same name and namespace in other branches
  1. 6.2 photos.module \photos_set_count()

Calculate number of $type.

10 calls to photos_set_count()
photos_editlist_submit in inc/photos.edit.inc
Submit modifications to existing images.
photos_editlist_submit_node in inc/photos.edit.inc
Edit list form submit for sub-album.
photos_edit_confirm_delete_submit in inc/photos.edit.inc
Submit confirm delete photo.
photos_file_del in ./photos.module
Photos - image removal.
photos_image_date in ./photos.module
Image written to database.

... See full list

File

./photos.module, line 1820
Implementation of photos.module.

Code

function photos_set_count($type, $id = 0) {
  switch ($type) {
    case 'user_image':
      $count = db_query('SELECT count(p.fid) FROM {photos_image} p INNER JOIN {file_managed} f ON p.fid = f.fid WHERE f.uid = :id', array(
        ':id' => $id,
      ))
        ->fetchField();
      $query = db_update('photos_count');
      $query
        ->fields(array(
        'value' => $count,
        'changed' => REQUEST_TIME,
      ));
      $query
        ->condition('cid', $id);
      $query
        ->condition('type', $type);
      $affected_rows = $query
        ->execute();
      if (!$affected_rows) {
        db_insert('photos_count')
          ->fields(array(
          'cid' => $id,
          'changed' => REQUEST_TIME,
          'type' => $type,
          'value' => $count,
        ))
          ->execute();
      }
      break;
    case 'user_album':
      $count = db_query('SELECT count(p.pid) FROM {photos_album} p INNER JOIN {node} n ON p.pid = n.nid WHERE n.uid = :uid', array(
        ':uid' => $id,
      ))
        ->fetchField();
      $query = db_update('photos_count')
        ->fields(array(
        'value' => $count,
        'changed' => REQUEST_TIME,
      ))
        ->condition('cid', $id)
        ->condition('type', $type);
      $affected_rows = $query
        ->execute();
      if (!$affected_rows) {
        db_insert('photos_count')
          ->fields(array(
          'cid' => $id,
          'changed' => REQUEST_TIME,
          'type' => $type,
          'value' => $count,
        ))
          ->execute();
      }
      break;
    case 'site_album':
      $count = db_query('SELECT COUNT(pid) FROM {photos_album}')
        ->fetchField();
      $query = db_update('photos_count')
        ->fields(array(
        'value' => $count,
        'changed' => REQUEST_TIME,
      ))
        ->condition('cid', 0)
        ->condition('type', $type);
      $affected_rows = $query
        ->execute();
      if (!$affected_rows) {
        db_insert('photos_count')
          ->fields(array(
          'cid' => 0,
          'changed' => REQUEST_TIME,
          'type' => $type,
          'value' => $count,
        ))
          ->execute();
      }
      break;
    case 'site_image':
      $count = db_query('SELECT COUNT(fid) FROM {photos_image}')
        ->fetchField();
      $query = db_update('photos_count')
        ->fields(array(
        'value' => $count,
        'changed' => REQUEST_TIME,
      ))
        ->condition('cid', 0)
        ->condition('type', $type);
      $affected_rows = $query
        ->execute();
      if (!$affected_rows) {
        db_insert('photos_count')
          ->fields(array(
          'cid' => 0,
          'changed' => REQUEST_TIME,
          'type' => $type,
          'value' => $count,
        ))
          ->execute();
      }
      break;
    case 'node_node':
      $count = db_query('SELECT COUNT(nid) FROM {photos_node} WHERE nid = :nid', array(
        ':nid' => $id,
      ))
        ->fetchField();
      $query = db_update('photos_count')
        ->fields(array(
        'value' => $count,
        'changed' => REQUEST_TIME,
      ))
        ->condition('cid', $id)
        ->condition('type', $type);
      $affected_rows = $query
        ->execute();
      if (!$affected_rows) {
        db_insert('photos_count')
          ->fields(array(
          'cid' => $id,
          'changed' => REQUEST_TIME,
          'type' => $type,
          'value' => $count,
        ))
          ->execute();
      }
      break;
    case 'node_album':
      db_query("UPDATE {photos_album} SET count = (SELECT COUNT(fid) FROM {photos_image} WHERE pid = :pid) WHERE pid = :pid", array(
        ':pid' => $id,
      ));
      break;
  }
}