Skip to content

Commit

Permalink
MDL-15488, use paging in tag searching
Browse files Browse the repository at this point in the history
  • Loading branch information
dongsheng committed Sep 19, 2008
1 parent 1baac46 commit 86e68c2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
32 changes: 26 additions & 6 deletions repository/flickr_public/repository.class.php
Expand Up @@ -120,19 +120,39 @@ public function print_login($ajax = true) {
* @return <type>
*/
public function search($search_text) {
global $SESSION;
$people = $this->flickr->people_findByEmail($this->flickr_account);
$sess_tag = 'flickr_public_'.$this->id.'_tag';
$sess_text = 'flickr_public_'.$this->id.'_text';
$this->nsid = $people['nsid'];
$tag = optional_param('tag', '', PARAM_CLEANHTML);
$is_paging = optional_param('search_paging', '', PARAM_RAW);
$page = 1;
if (!empty($is_paging)) {
$page = optional_param('p', '', PARAM_INT);
if (!empty($SESSION->$sess_tag)) {
$tag = $SESSION->$sess_tag;
}
if (!empty($SESSION->$sess_text)) {
$search_text = $SESSION->$sess_text;
}
}
if (!empty($tag)) {
$photos = $this->flickr->photos_search(array(
'tags'=>$tag
'tags'=>$tag,
'page'=>$page
));
$SESSION->$sess_tag = $tag;

} else {
$photos = $this->flickr->photos_search(array(
'user_id'=>$this->nsid,
'text'=>$search_text));
$SESSION->$sess_text = $search_text;
}
return $this->build_list($photos);
$ret = array();
$ret['search_result'] = true;
return $this->build_list($photos, $page, &$ret);
}

/**
Expand All @@ -144,8 +164,9 @@ public function get_listing($path = '1') {
$people = $this->flickr->people_findByEmail($this->flickr_account);
$this->nsid = $people['nsid'];
$photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format', 25, $path);
$ret = array();

return $this->build_list($photos, $path);
return $this->build_list($photos, $path, &$ret);
}

/**
Expand All @@ -154,9 +175,8 @@ public function get_listing($path = '1') {
* @param <type> $path
* @return <type>
*/
private function build_list($photos, $path = 1) {
private function build_list($photos, $path = 1, $ret) {
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
$ret = array();
$ret['manage'] = $photos_url;
$ret['list'] = array();
$ret['pages'] = $photos['pages'];
Expand Down Expand Up @@ -284,7 +304,7 @@ public static function get_type_option_names() {
*/
public static function plugin_init() {
//here we create a default instance for this type
repository_static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name' => get_string('repositoryname', 'repository_public'),'email_address' => null),1);
repository_static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name' => get_string('repositoryname', 'repository_flickr_public'),'email_address' => null),1);
}

}
Expand Down
24 changes: 21 additions & 3 deletions repository/javascript.php
Expand Up @@ -407,7 +407,7 @@ function _client() {
search.innerHTML = '<img src="$CFG->pixpath/a/search.png" /> $strsearch';
oDiv.appendChild(search);
search.onclick = function() {
repository_client_$suffix.search(repository_client_$suffix.repositoryid);
repository_client_$suffix.search_form(repository_client_$suffix.repositoryid);
}
}
// weather we use cache for this instance, this button will reload listing anyway
Expand Down Expand Up @@ -666,14 +666,32 @@ function _client() {
if(_client.ds.pages) {
str += '<div class="fp-paging" id="paging-$suffix">';
for(var i = 1; i <= _client.ds.pages; i++) {
str += '<a onclick="repository_client_$suffix.req('+_client.repositoryid+', '+i+', 0)" href="###">';
if(!_client.ds.search_result){
str += '<a onclick="repository_client_$suffix.req('+_client.repositoryid+', '+i+', 0)" href="###">';
} else {
str += '<a onclick="repository_client_$suffix.search_paging('+_client.repositoryid+', '+i+')" href="###">';
}
str += String(i);
str += '</a> ';
}
str += '</div>';
}
return str;
}
_client.search_paging = function(id, path) {
_client.viewbar.set('disabled', false);
_client.loading('load');
_client.repositoryid = id;
var params = [];
params['p'] = path;
params['env']=_client.env;
params['action']='search';
params['search_paging']='true';
params['sesskey']='$sesskey';
params['ctx_id']=$context->id;
params['repo_id']=id;
var trans = YAHOO.util.Connect.asyncRequest('POST', '$CFG->httpswwwroot/repository/ws.php?action='+action, _client.req_cb, _client.postdata(params));
}
_client.makepath = function() {
if(_client.viewmode == 0) {
return;
Expand Down Expand Up @@ -823,7 +841,7 @@ function _client() {
dlg.show();
}
}
_client.search = function(id) {
_client.search_form = function(id) {
var params = [];
params['env']=_client.env;
params['sesskey']='$sesskey';
Expand Down

0 comments on commit 86e68c2

Please sign in to comment.