You are here

function _photos_get_photos in Album Photos 7.3

Get photos that are in albums.

Can get all photos (for search status) or a subset of new photos for indexing.

Also can "wrap" selection to gather new photos for indexing PLUS oldest photos for re-indexing (using UNION query).

@returns array of DB records containing info on photos.

Parameters

string $where: (optional) An SQL WHERE clause; usually to grab new photos where pid > last indexed pid

string $limit: (optional) A LIMIT clause: for getting status, use no limit, else it's set to search_cron_limit

string $wrap: (optional) Indicates whether to make a union query to grab newest photos, THEN union them with the oldest photos (for re-indexing those). This behaviour is controlled on the /admin/config/search/settings page.

2 calls to _photos_get_photos()
photos_search_status in ./photos.module
Implements hook_search_status().
photos_update_index in ./photos.module
Implements hook_update_index().

File

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

Code

function _photos_get_photos($where = 'WHERE 1 = 1', $limit = NULL, $wrap = '') {
  $photos_search_max_id_reindex = (int) variable_get('photos_search_max_id_reindex', 0);

  // If "wrap around past newest photo" is TRUE, then
  // a) grab new photos
  // b) grab photos NEWER than last reindex run
  // c) also grab oldest photos with lowest pid numbers (starting with 1)
  // So if 10 new photos have been added, making total 210, and re-indexed
  // number 190 already, get 201-210, 191-200, 1-80.
  // Titles and descriptions can (and do) change.
  if ($wrap !== '') {

    // UNION newest NOT RE-INDEXED...
    $wrap = "UNION DISTINCT " . "SELECT pi.fid, pi.des, pi.title AS Title, n.title AS AlbumTitle " . "FROM {photos_image} AS pi " . "LEFT JOIN {file_managed} AS fm ON fm.fid = pi.fid " . "LEFT JOIN {photos_album} AS pa ON pi.pid = pa.pid  " . "LEFT JOIN {node} AS n ON n.nid = pa.pid " . "WHERE pi.fid > {$photos_search_max_id_reindex} " . "UNION DISTINCT " . "SELECT pi.fid, pi.des, pi.title AS Title, n.title AS AlbumTitle " . "FROM {photos_image} AS pi " . "LEFT JOIN {file_managed} AS fm ON fm.fid = pi.fid " . "LEFT JOIN {photos_album} AS pa ON pi.pid = pa.pid  " . "LEFT JOIN {node} AS n ON n.nid = pa.pid " . "WHERE pi.fid > 0 ";
  }

  // Grab all photos available, depending on criteria passed as arguments:
  $sql = "SELECT pi.fid, pi.des, pi.title AS Title, n.title AS AlbumTitle " . "FROM {photos_image} AS pi " . "LEFT JOIN {file_managed} AS fm ON fm.fid = pi.fid " . "LEFT JOIN {photos_album} AS pa ON pi.pid = pa.pid  " . "LEFT JOIN {node} AS n ON n.nid = pa.pid " . "{$where} " . $wrap . " {$limit} ";
  $result = db_query($sql);
  return $result;
}