Module: CatalogHelper

Includes:
Blacklight::SolrHelper
Defined in:
vendor/plugins/blacklight/app/helpers/catalog_helper.rb,
vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb

Constant Summary

Constants included from Blacklight::SolrHelper

MaxPerPage

Instance Method Summary (collapse)

Methods included from Blacklight::SolrHelper

#facet_limit_for, #facet_limit_hash, #get_facet_pagination, #get_opensearch_response, #get_search_results, #get_single_doc_via_search, #get_solr_response_for_doc_id, #get_solr_response_for_field_values, included, #max_per_page, #solr_doc_params, #solr_facet_params, #solr_opensearch_params, #solr_param_quote, #solr_search_params

Instance Method Details

- (Object) admin_info(doc)



71
72
73
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 71

def admin_info(doc)
  info ="Deposited: \#{format_date(DateTime.parse(doc.get(:system_create_dt)).to_time)}\n| By: \#{depositor_string(doc.get(:depositor_t))}\n| Status: Created\n"
end

- (Object) author_list(doc)



20
21
22
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 20

def author_list(doc)
  get_persons_from_roles(doc,['author','collaborator','creator','contributor']).map {|person| format_person_string(person[:first],person[:last],person[:institution])}
end

- (Object) depositor_string(depositor = nil)



8
9
10
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 8

def depositor_string depositor=nil
  "#{depositor}" unless depositor.nil? 
end

- (Object) format_date(date)



5
6
7
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 5

def format_date date
  date.strftime("%Y-%m-%d %I:%M%p").gsub(" 0", " ").gsub(/([AP])M/,'\1').downcase
end

- (Object) format_num(num)

shortcut for built-in Rails helper, “number_with_delimiter“



5
# File 'vendor/plugins/blacklight/app/helpers/catalog_helper.rb', line 5

def format_num(num) number_with_delimiter(num) end

- (Object) format_person_string(first_name, last_name, affiliation, opt = {})



42
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 42

def format_person_string first_name, last_name, affiliation, opt={}

- (Object) get_children(pid)



11
12
13
14
15
16
17
18
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 11

def get_children pid
  par = solr_facet_params(:is_part_of_s)
  query="_query_:\"{!dismax qf=$qf_dismax pf=$pf_dismax}is_part_of_s:info\\:fedora/#{pid.gsub(":",'\:')}\"" 
  # start query of with user supplied query term
    #q << "_query_:\"{!dismax qf=$qf_dismax pf=$pf_dismax}#{user_query}\""
  (response, document_list) = get_search_results( :q=>query )
  par.inspect
end

- (Object) get_persons_from_roles(doc, roles, opts = {})



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 28

def get_persons_from_roles(doc,roles,opts={})
  i = 0
  persons =[]
  while i < 10
    persons_roles = [] # reset the array
    persons_roles = doc["person_#{i}_role_t"].map{|w|w.strip.downcase} unless doc["person_#{i}_role_t"].nil?
    if persons_roles and (persons_roles & roles).length > 0
      persons << {:first => doc["person_#{i}_first_name_t"], :last=> doc["person_#{i}_last_name_t"], :institution => doc["person_#{i}_institution_t"]}
    end
    i += 1
  end
  return persons
end

- (Boolean) has_search_parameters?

Returns:

  • (Boolean)


61
62
63
# File 'vendor/plugins/blacklight/app/helpers/catalog_helper.rb', line 61

def has_search_parameters?
  !params[:q].blank? or !params[:f].blank? or !params[:search_field].blank?
end

- (Object) item_page_entry_info

Like the mysteriously named #page_entry_info above, but for an individual item show page. Displays “showing X of Y items” message. Code should call this method rather than interrogating session directly, because implementation of where this data is stored/retrieved may change.



38
39
40
# File 'vendor/plugins/blacklight/app/helpers/catalog_helper.rb', line 38

def 
  "Showing item <b>#{session[:search][:counter].to_i} of #{format_num(session[:search][:total])}</b> from your search."
end

- (Object) journal_info(doc)



48
49
50
51
52
53
54
55
56
57
58
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 48

def journal_info(doc)
  title = doc.get(:journal_title_info_main_title_t)
  pub_date = doc.get(:journal_issue_publication_date_t)
  volume = doc.get(:journal_issue_volume_t)
  issue = doc.get(:journal_issue_volume_t)
  start_page = doc.get(:journal_issue_pages_start_t) 
  end_page = doc.get(:journal_issue_end_page_t)
  journal_info = "#{title}. #{pub_date}; #{volume} ( #{issue} ): #{start_page} - #{end_page}"
  journal_info = "" if journal_info.match(/^\.\s+;\s+\(\s+\)\:\s+-\s*$/)
  journal_info
end

- (Object) page_entries_info(collection, options = {})

Displays the “showing X through Y of N” message. Not sure why that’s called “page_entries_info”. Not entirely sure what collection argument is supposed to duck-type too, but an RSolr::Ext::Response works. Perhaps it duck-types to something from will_paginate?



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'vendor/plugins/blacklight/app/helpers/catalog_helper.rb', line 13

def page_entries_info(collection, options = {})
    start = collection.next_page == 2 ? 1 : collection.previous_page * collection.per_page + 1
    total_hits = @response.total
    start_num = format_num(start)
    end_num = format_num(start + collection.per_page - 1)
    total_num = format_num(total_hits)

    entry_name = options[:entry_name] ||
      (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))

    if collection.total_pages < 2
      case collection.size
      when 0; "No #{entry_name.pluralize} found"
      when 1; "Displaying <b>1</b> #{entry_name}"
      else;   "Displaying <b>all #{total_num}</b> #{entry_name.pluralize}"
      end
    else
      "Displaying #{entry_name.pluralize} <b>#{start_num} - #{end_num}</b> of <b>#{total_num}</b>"
    end
end

- (Object) refworks_export_url(document = @document)

Export to Refworks URL, called in _show_tools



49
50
51
# File 'vendor/plugins/blacklight/app/helpers/catalog_helper.rb', line 49

def refworks_export_url(document = @document)
  "http://www.refworks.com/express/expressimport.asp?vendor=#{CGI.escape(application_name)}&filter=MARC%20Format&encoding=65001&url=#{CGI.escape(catalog_path(document[:id], :format => 'refworks_marc_txt', :only_path => false))}"        
end

- (Object) render_document_class(document = @document)



53
54
55
# File 'vendor/plugins/blacklight/app/helpers/catalog_helper.rb', line 53

def render_document_class(document = @document)
 'blacklight-' + document.get(Blacklight.config[:index][:record_display_type]).parameterize rescue nil
end

- (Object) render_document_sidebar_partial(document = @document)



57
58
59
# File 'vendor/plugins/blacklight/app/helpers/catalog_helper.rb', line 57

def render_document_sidebar_partial(document = @document)
  render :partial => 'show_sidebar'
end

- (Object) researcher_list(doc)



24
25
26
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 24

def researcher_list(doc)
  get_persons_from_roles(doc,['research team head']).map {|person| format_person_string(person[:first],person[:last],person[:institution])}
end

- (Object) search_field_label(params)

Look up search field user-displayable label based on params[:qt] and configuration.



44
45
46
# File 'vendor/plugins/blacklight/app/helpers/catalog_helper.rb', line 44

def search_field_label(params)
  h( Blacklight.label_for_search_field(params[:search_field]) )
end

- (Object) short_abstract(doc, max = 250)



60
61
62
63
64
65
66
67
68
69
# File 'vendor/plugins/hydra_repository/app/helpers/catalog_helper.rb', line 60

def short_abstract(doc,max=250)
  abstract = doc.get(:abstract_t)
  if abstract.blank?
    return ""
  elsif abstract.length < max
    return abstract
  else
    return abstract[0..max].strip.concat("...")
  end
end