Browse files

MDL-32417: Fixed pagination bug in Flickr search results, also return…

… thumbnail sizes
  • Loading branch information...
1 parent 9a2bb1e commit 7546de2e7a980829181a06a9f1ab552872dc9f41 @marinaglancy marinaglancy committed with stronk7 Apr 12, 2012
Showing with 9 additions and 18 deletions.
  1. +9 −18 repository/flickr/lib.php
View
27 repository/flickr/lib.php
@@ -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'])) {
@@ -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']);
}
}
@@ -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) {
$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;
}
@@ -218,16 +217,8 @@ public function search($search_text) {
* @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) {

0 comments on commit 7546de2

Please sign in to comment.