You are here

function photos_image_pager in Album Photos 7.3

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

Photos image view pager block.

2 calls to photos_image_pager()
photos_block_view in ./photos.module
Implements hook_block_view().
photos_image_page in inc/photos.image.inc
Image page.

File

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

Code

function photos_image_pager($fid, $id, $type = 'pid') {
  $query = db_select('file_managed', 'f');
  $query
    ->join('photos_image', 'p', 'f.fid = p.fid');
  $query
    ->fields('p', array(
    'pid',
  ))
    ->fields('f', array(
    'fid',
    'uri',
    'filename',
  ));

  // Default order by fid.
  $order = array(
    'column' => 'f.fid',
    'sort' => 'DESC',
  );
  if ($type == 'pid') {

    // Viewing album.
    // Order images by album settings.
    $album_data = db_query('SELECT data FROM {photos_album} WHERE pid = :pid', array(
      ':pid' => $id,
    ))
      ->fetchField();
    $album_data = unserialize($album_data);
    $default_order = variable_get('photos_display_imageorder', 'weight|asc');
    $image_order = isset($album_data['imageorder']) ? $album_data['imageorder'] : $default_order;
    $order = explode('|', $image_order);
    $order = _photos_order_value_change($order[0], $order[1]);
    $query
      ->condition('p.pid', $id);
  }
  elseif ($type == 'uid') {

    // Viewing all user images.
    $query
      ->condition('f.uid', $id);
  }
  elseif ($type == 'sub') {

    // Viewing sub-album.
    // Default order by wid.
    $order = array(
      'column' => 's.wid',
      'sort' => 'ASC',
    );
    $query
      ->join('photos_node', 's', 's.fid = p.fid');
    $query
      ->condition('s.nid', $id);
  }
  else {

    // Show all.
  }
  $query
    ->orderBy($order['column'], $order['sort']);
  $result = $query
    ->execute();
  $stop = $t['prev'] = $t['next'] = 0;
  $num = 0;
  foreach ($result as $image) {
    $num++;
    if ($stop == 1) {
      $t['next'] = $image;
      $t['next_view'] = photos_get_info(0, $t['next'], array(
        'style_name' => variable_get('photos_pager_imagesize', 'thumbnail'),
      ));
      if ($type == 'uid') {

        // User next image.
        $t['next_url'] = url('photos/user/' . $id . '/image/' . $image->fid);
      }
      elseif ($type == 'sub') {

        // Sub-album next image.
        $t['next_url'] = url('photos/image/' . $image->fid, array(
          'query' => array(
            'photos_sub' => $id,
          ),
        ));
      }
      else {

        // Next image.
        $t['next_url'] = url('photos/image/' . $image->fid);
      }
      break;
    }
    if ($image->fid == $fid) {
      $t['current'] = $image;
      $t['current_view'] = photos_get_info(0, $t['current'], array(
        'style_name' => variable_get('photos_pager_imagesize', 'thumbnail'),
      ));
      $stop = 1;
    }
    else {
      $t['prev'] = $image;
    }
  }
  if ($t['prev']) {
    $t['prev_view'] = photos_get_info(0, $t['prev'], array(
      'style_name' => variable_get('photos_pager_imagesize', 'thumbnail'),
    ));
    if ($type == 'uid') {

      // User previous image.
      $t['prev_url'] = url('photos/user/' . $id . '/image/' . $t['prev']->fid);
    }
    elseif ($type == 'sub') {

      // Sub-album previous image.
      $t['prev_url'] = url('photos/image/' . $t['prev']->fid, array(
        'query' => array(
          'photos_sub' => $id,
        ),
      ));
    }
    else {

      // Previous image.
      $t['prev_url'] = url('photos/image/' . $t['prev']->fid);
    }
  }
  return $t;
}