You are here

function _photos_block_album in Album Photos 7.3

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

User photos.

1 call to _photos_block_album()
photos_page_default in inc/photos.page.inc
Default page, list recent photos and galleries.

File

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

Code

function _photos_block_album($type, $limit, $url = 0, $uid = 0, $sort = ' n.nid DESC') {
  $query = db_select('photos_album', 'p');
  $query
    ->join('node', 'n', 'n.nid = p.pid');
  $query
    ->join('users', 'u', 'u.uid = n.uid');
  $query
    ->fields('p', array(
    'count',
    'fid',
  ))
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->fields('u', array(
    'uid',
    'name',
  ));
  $query
    ->condition('n.status', 1);
  if ($type == 'user') {
    $query
      ->condition('n.uid', $uid);
  }
  if ($type == 'rand') {
    $query
      ->orderRandom();
  }
  else {
    $query
      ->orderBy('n.nid', 'DESC');
  }
  $query
    ->range(0, $limit);
  $query
    ->addTag('node_access');
  $result = $query
    ->execute();
  $i = 0;
  foreach ($result as $node) {
    if ($node->fid) {
      $view = photos_get_info($node->fid, 0, array(
        'href' => 'photos/album/' . $node->nid,
        'filename' => $node->title,
      ));
    }
    else {
      $query = db_select('file_managed', 'f');
      $query
        ->join('photos_image', 'p', 'p.fid = f.fid');
      $query
        ->fields('f', array(
        'fid',
        'uri',
        'filename',
      ));
      $query
        ->condition('p.pid', $node->nid);
      $query
        ->orderBy('f.fid', 'DESC');
      $image = $query
        ->execute()
        ->fetchObject();
      if (isset($image->fid)) {
        $view = photos_get_info($image->fid, $image, array(
          'href' => 'photos/album/' . $node->nid,
          'filename' => $node->title,
        ));
      }
      else {
        $view = '';
      }
    }
    $album[] = array(
      'node' => $node,
      'view' => $view,
    );
    ++$i;
  }
  if ($i) {
    $content = theme('photos_block', array(
      'images' => $album,
      'type' => 'album',
    ));
    if ($url && $i >= $limit) {
      $content .= theme('more_link', array(
        'url' => url($url),
        'title' => t('View more'),
      ));
    }
    if ($type == 'user') {
      return array(
        $content,
        $album[0]['node']->name,
      );
    }
    else {
      return $content;
    }
  }
}