You are here

public function PhotosRearrangeController::getAlbums in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 src/Controller/PhotosRearrangeController.php \Drupal\photos\Controller\PhotosRearrangeController::getAlbums()
  2. 6.0.x src/Controller/PhotosRearrangeController.php \Drupal\photos\Controller\PhotosRearrangeController::getAlbums()

Get user albums.

1 call to PhotosRearrangeController::getAlbums()
PhotosRearrangeController::albumRearrange in src/Controller/PhotosRearrangeController.php
Rearrange user albums.

File

src/Controller/PhotosRearrangeController.php, line 255

Class

PhotosRearrangeController
Re-arrange view controller.

Namespace

Drupal\photos\Controller

Code

public function getAlbums($uid) {
  $albums = [];
  $get_limit = $this->requestStack
    ->getCurrentRequest()->query
    ->get('limit');
  $limit = $get_limit ? Html::escape($get_limit) : 50;
  $query = $this->connection
    ->select('node_field_data', 'n');
  $query
    ->join('photos_album', 'p', 'p.pid = n.nid');
  $query
    ->fields('n', [
    'nid',
    'title',
  ]);
  $query
    ->fields('p', [
    'wid',
    'fid',
    'count',
  ]);
  $query
    ->condition('n.uid', $uid);
  $query
    ->range(0, $limit);
  $query
    ->orderBy('p.wid', 'ASC');
  $query
    ->orderBy('n.nid', 'DESC');
  $result = $query
    ->execute();
  foreach ($result as $data) {
    if (isset($data->fid) && $data->fid != 0) {
      $cover_fid = $data->fid;
    }
    else {
      $cover_fid = $this->connection
        ->query("SELECT fid FROM {photos_image} WHERE pid = :pid", [
        ':pid' => $data->nid,
      ])
        ->fetchField();
      if (empty($cover_fid)) {

        // Skip albums with no images.
        continue;
      }
    }
    $albums[] = [
      'wid' => $data->wid,
      'nid' => $data->nid,
      'fid' => $cover_fid,
      'count' => $data->count,
      'title' => $data->title,
    ];
  }
  return $albums;
}