Skip to content

Commit

Permalink
MDL-32417: Fixed pagination bug in Flickr search results, also return…
Browse files Browse the repository at this point in the history
… thumbnail sizes
  • Loading branch information
marinaglancy committed Apr 23, 2012
1 parent ead4f18 commit 6819c42
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions repository/flickr/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,20 @@ public function print_login() {
}

/**
* Converts result received from phpFlickr::photo_search to Filepicker/repository format
*
* @param mixed $photos
* @param int $page
* @return array
*/
private function build_list($photos, $page = 1) {
private function build_list($photos) {
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
$ret = array();
$ret['manage'] = $photos_url;
$ret['list'] = array();
$ret['pages'] = $photos['pages'];
$ret['total'] = $photos['total'];
$ret['perpage'] = $photos['perpage'];
if($page <= $ret['pages']) {
$ret['page'] = $page;
} else {
$ret['page'] = 1;
}
$ret['page'] = $photos['page'];
if (!empty($photos['photo'])) {
foreach ($photos['photo'] as $p) {
if(empty($p['title'])) {
Expand All @@ -189,6 +185,7 @@ private function build_list($photos, $page = 1) {
}
$ret['list'][] = array('title'=>$p['title'],'source'=>$p['id'],
'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'),
'thumbnail_width'=>75, 'thumbnail_height'=>75,
'date'=>'', 'size'=>'unknown', 'url'=>$photos_url.$p['id']);
}
}
Expand All @@ -198,17 +195,19 @@ private function build_list($photos, $page = 1) {
/**
*
* @param string $search_text
* @param int $page
* @return array
*/
public function search($search_text, $page = 0) {
$photos = $this->flickr->photos_search(array(
'user_id'=>$this->nsid,
'per_page'=>24,
'extras'=>'original_format',
'page'=>$page,
'text'=>$search_text
));
$ret = $this->build_list($photos);
$ret['list'] = array_filter($ret['list'], array($this, 'filter'));
$ret['list'] = array_filter($ret['list'], array($this, 'filter')); // TODO this breaks pagination
return $ret;
}

Expand All @@ -218,16 +217,8 @@ public function search($search_text, $page = 0) {
* @param int $page
* @return array
*/
public function get_listing($path = '', $page = '1') {
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);

$photos = $this->flickr->photos_search(array(
'user_id'=>$this->nsid,
'per_page'=>24,
'page'=>$page,
'extras'=>'original_format'
));
return $this->build_list($photos, $page);
public function get_listing($path = '', $page = '') {
return $this->search('', $page);
}

public function get_link($photo_id) {
Expand Down

0 comments on commit 6819c42

Please sign in to comment.