ObiruLabs / craft-flickr-photopicker

Flickr photo picker for the Craft CMS.
MIT License
9 stars 3 forks source link

[Enhancement] Ability to get descriptions from both photos and photosets #15

Open ncksnydr opened 8 years ago

ncksnydr commented 8 years ago

Hello,

I'd love to be able to grab the descriptions of both the photos and photosets. I realize that it's a bit annoying that two additional calls are needed in-order to get one piece of information, but I believe that there is a certain amount of value there.

I attempted to add this feature myself, but I am not that familiar with Craft plugins or Angular. I added functions, but could not get the returns to append the array on getPhotoSetPhotos()

Here are the new info functions that I added:

public function photoSetInfo($apiKey, $photoSetId, $userId)
    {
        $url = $this->apiUrl('flickr.photosets.getInfo', $apiKey);
        $url .= '&user_id='. $userId;
        $url .= '&photoset_id='.$photoSetId;
        return $url;
    }

    public function photoInfo($apiKey, $photoId)
    {
        $url = $this->apiUrl('flickr.photos.getPhotos', $apiKey);
        $url .= '&photo_id='.$photoId;
        return $url;
    }

and the edited getPhotoSetPhotos():

public function getPhotoSetPhotos($photoSetId)
    {
        $settings = craft()->plugins->getPlugin('flickrPhotoPicker')->getSettings();
        $apiKey = $settings['apiKey'];
        $userId = $settings['userId'];
        $allPhotos = array();

        $url = $this->photosForPhotoSetUrl($apiKey, $photoSetId);
        $url .= '&extras=date_upload,date_taken,owner_name';

        $photos = $this->getFromUrl($url, 'photoset', 'photo');
        foreach ($photos as $photoId => $photoDetails) {
            $photoInfo = $this->photoInfo($apiKey, $photoId);
            $allPhotos[$photoId] = $photoDetails;
            $allPhotos[$photoId]['details'] = $photoInfo;
        }

        return $allPhotos;
    }

Just for good measure, here are the URLs to the API methods, via Flickr:

I really appreciate the work on this plugin; please let me know if there is anything that I can do to help with getting these features added.

janrubio commented 8 years ago

Can you link to a branch that has your changes?

ncksnydr commented 8 years ago

@janrubio I did not create/submit a PR, but I could. I figured that it would be more work to clean up my mess of console.log() and var_dump() calls.

janrubio commented 8 years ago

np, I'm more interested in the diff

ncksnydr commented 8 years ago

@janrubio https://github.com/ncksnydr/craft-flickr-photopicker/tree/feature-descriptions