Rflickr search tool display total returned photos

I’m attempting to display the total images returned in a search using
the rflickr plugin. Let me know if i should provide more info, i think
i’ve included the relevant code.

I’m a total newbie and could use a hand.

Thanks in advance.

in my flickr/index.html

<%= form_remote_tag :url => {:action => ‘search’}, :update => ‘photos’,
:complete => visual_effect(:blind_down, ‘photos’),
:before => %(Element.show(‘spinner’)),
:success => %(Element.hide(‘spinner’)) %>

<%= image_tag 'spinner.gif', :id => 'spinner', :style => 'display:

none’ %>

Tags:
<%= text_field_tag ‘tags’ %>

    <%= submit_tag 'Find' %>
</fieldset>

<div id="photos" style="display: none"></div>

<%= end_form_tag %>

in my flickr.controller.rb

class FlickrController < ApplicationController
def search
flickr =
Flickr.new(’/www.rocketgofaster.com/development/rocketgofaster_machine/config/flickr.cache’,‘32dd6bece5332b32d1d4f8ab601290ab’,‘800c7f9d6e0012a8’)
render :partial => “photo”, :collection =>
flickr.photos.search(nil,params[:tags],nil,nil,nil,nil,nil,nil,nil,nil,‘100’)
end

def search_total

end

end

in rflickr plugin photos.rb

def search(user=nil,tags=nil,tag_mode=nil,text=nil,min_upload_date=nil,
max_upload_date=nil,min_taken_date=nil,max_taken_date=nil,
license=nil,extras=nil,per_page=nil,page=nil,sort=nil)

user = user.nsid if user.respond_to?(:nsid)
tags = tags.join(’,’) if tags.class == Array
min_upload_date = min_upload_date.to_i if
min_upload_date.class == Time
max_upload_date = max_upload_date.to_i if
max_upload_date.class == Time
min_taken_date = @flickr.mysql_datetime(min_taken_date) if
min_taken_date.class == Time
max_taken_date = @flickr.mysql_datetime(max_taken_date) if
max_taken_date.class == Time
license = license.id if license.class == Flickr::License
extras = extras.join(’,’) if extras.class == Array

args = {}
args[‘user_id’] = user if user
args[‘tags’] = tags if tags
args[‘tag_mode’] = tag_mode if tag_mode
args[‘text’] = text if text
args[‘min_upload_date’] = min_upload_date if min_upload_date
args[‘max_upload_date’] = max_upload_date if max_upload_date
args[‘min_taken_date’] = min_taken_date if min_taken_date
args[‘max_taken_date’] = max_taken_date if max_taken_date
args[‘license’] = license if license
args[‘extras’] = extras if extras
args[‘per_page’] = per_page if per_page
args[‘page’] = page if page
args[‘sort’] = sort if sort

res = @flickr.call_method(‘flickr.photos.search’,args)
return Flickr::PhotoList.from_xml(res,@flickr)
end

in rflickr plugin

class Flickr::PhotoList < Array
attr_reader :page,:pages,:perpage,:total

def initialize(page,pages,perpage,total)
@page = page
@pages = pages
@perpage = perpage
@total = total
end

def self.from_xml(xml,flickr=self)
att = xml.root.attributes
list = Flickr::PhotoList.new(att[‘page’].to_i,att[‘pages’].to_i,
att[‘perpage’].to_i,att[‘total’].to_i)
xml.elements[’/photos’].each_element do |e|
list << Flickr::Photo.from_xml(e,flickr)
end
return list
end
end

Hi, im not really sure I understand what you are looking for… its been
a
while since I worked with rflickr.

You seem to be passing a collection of objects to the view in your first
action - do you want the number of elements in that collection?

if so

flickr.photos.search
(nil,params[:tags],nil,nil,nil,nil,nil,nil,nil,nil,‘100’).size

if you are struggling to display this in the view I would do this.

in your view:

then in your search action

def search
your code up to before the render
render :update do |page|
page.replace_html “photos”, render :partial => “photo”, :collection
=>
#{that long line with the nils}
page.replace_html “image_count”, “#{(that long line with the
nils).size}
photos were found.”
end
end

this will add the count in the same action and negate the need for a
seperate action to do that.

am I missing something?

regards
ivor

Actually, Im looking to get the total number of images provided in the
xml response to the image search.

**the total parsed in the photolist below, or atleast i think so?

list = Flickr::PhotoList.new(att['page'].to_i,att['pages'].to_i,
  att['perpage'].to_i,att['total'].to_i)

**from the flickr api, the total below

Example Response

This method returns the standard photo list xml:

thanks in advance
rocket