src/libraries/controllers/ApiPhotoController.php
/**
    * Retrieve a list of the user's photos from the remote datasource.
    * The $filterOpts are values from the path but can also be in _GET.
    * /photos/page-2/tags-favorites.json is identical to /photos.json?page=2&tags=favorites
    *
    * @param string $filterOpts Options on how to filter the list of photos.
    * @return string Standard JSON envelope
    */
Retrieve a list of the user's photos from the remote datasource.
The $filterOpts are values from the path but can also be in _GET.

@param string $filterOpts Options on how to filter the list of photos.
@return string Standard JSON envelope
Retrieve a list of the user ' s photos from the remote datasource . The $filterOpts are values from the path but can also be in _GET . @param string $filterOpts Options on how to filter the list of photos . @return string Standard JSON envelope
public function list_($filterOpts = null)
  {
    extract($this->parseFilters($filterOpts));
    $db = getDb();
    $photos = $db->getPhotos($filters, $pageSize);
    if(empty($photos))
      return $this->success('Your search did not return any photos', null);
    $sizes = array();
    if(isset($filters['returnSizes']))
      $sizes = (array)explode(',', $filters['returnSizes']);
    $generate = $requery = false;
    if(isset($_GET['generate']) && $_GET['generate'] == 'true')
      $generate = true;
    if($photos[0]['totalRows'] > 0)
    {
      foreach($photos as $key => $photo)
      {
        $photos[$key] = $this->pruneSizes($photo, $sizes);
        if(!empty($sizes))
        {
          foreach($sizes as $size)
          {
            $options = $this->photo->generateFragmentReverse($size);
            if($generate && !isset($photo["path{$size}"]))
            {
              $hash = $this->photo->generateHash($photo['id'], $options['width'], $options['height'], $options['options']);
              $this->photo->generate($photo['id'], $hash, $options['width'], $options['height'], $options['options']);
              $requery = true;
            }
          }
        }
      }
      if($requery)
      {
        $photos = $db->getPhotos($filters, $pageSize);
        foreach($photos as $key => $photo)
          $photos[$key] = $this->pruneSizes($photo, $sizes);
      }
      foreach($photos as $key => $photo)
        $photos[$key] = $this->photo->addApiUrls($photos[$key], $sizes);
    }
    $photos[0]['pageSize'] = intval($pageSize);
    $photos[0]['currentPage'] = intval($page);
    $photos[0]['totalPages'] = ceil($photos[0]['totalRows'] / $pageSize);
    return $this->success("Successfully retrieved user's photos", $photos);
  }
public function list_ ( $ filterOpts = null ) { extract ( $ this -> parseFilters ( $ filterOpts ) ) ; $ db = getDb ( ) ; $ photos = $ db -> getPhotos ( $ filters , $ pageSize ) ; if ( empty ( $ photos ) ) return $ this -> success ( 'Your search did not return any photos' , null ) ; $ sizes = array ( ) ; if ( isset ( $ filters [ 'returnSizes' ] ) ) $ sizes = ( array ) explode ( ',' , $ filters [ 'returnSizes' ] ) ; $ generate = $ requery = false ; if ( isset ( $ _GET [ 'generate' ] ) && $ _GET [ 'generate' ] == 'true' ) $ generate = true ; if ( $ photos [ 0 ] [ 'totalRows' ] > 0 ) { foreach ( $ photos as $ key => $ photo ) { $ photos [ $ key ] = $ this -> pruneSizes ( $ photo , $ sizes ) ; if ( ! empty ( $ sizes ) ) { foreach ( $ sizes as $ size ) { $ options = $ this -> photo -> generateFragmentReverse ( $ size ) ; if ( $ generate && ! isset ( $ photo [ " path { $ size } " ] ) ) { $ hash = $ this -> photo -> generateHash ( $ photo [ 'id' ] , $ options [ 'width' ] , $ options [ 'height' ] , $ options [ 'options' ] ) ; $ this -> photo -> generate ( $ photo [ 'id' ] , $ hash , $ options [ 'width' ] , $ options [ 'height' ] , $ options [ 'options' ] ) ; $ requery = true ; } } } } if ( $ requery ) { $ photos = $ db -> getPhotos ( $ filters , $ pageSize ) ; foreach ( $ photos as $ key => $ photo ) $ photos [ $ key ] = $ this -> pruneSizes ( $ photo , $ sizes ) ; } foreach ( $ photos as $ key => $ photo ) $ photos [ $ key ] = $ this -> photo -> addApiUrls ( $ photos [ $ key ] , $ sizes ) ; } $ photos [ 0 ] [ 'pageSize' ] = intval ( $ pageSize ) ; $ photos [ 0 ] [ 'currentPage' ] = intval ( $ page ) ; $ photos [ 0 ] [ 'totalPages' ] = ceil ( $ photos [ 0 ] [ 'totalRows' ] / $ pageSize ) ; return $ this -> success ( " Successfully retrieved user's photos " , $ photos ) ; }
Retrieve a list of the user's photos from the remote datasource.
Retrieve a list of the user ' s photos from the remote datasource .
// this extracts local variables $permission, $filter, $pageSize, etc // we remove all path* entries to keep the interface clean and only return sizes explicitly requested // we need to leave the 'locally scoped' $photo in since we may put it back into the $photos array if requested // TODO call API // we do this to put a previously deleted key (pruneSizes) back in - ah, the things we do for consistency // requery to get generated paths // we have to merge to retain multiple sizes else the last one overwrites the rest // we also can't pass in $photo since it doesn't persist over iterations and removes returnSizes