Class: Hyrax::TrophyPresenter

Inherits:
Object
  • Object
show all
Includes:
ModelProxy
Defined in:
app/presenters/hyrax/trophy_presenter.rb

Overview

Presents works in context as “trophied” for a given user.

Examples:

my_user = User.find(user_id)

trophies = Hyrax::TrophyPresenter.find_by_user(my_user)
trophies.each do |trophy|
  puts "Object name/title: #{trophy}"
  puts "Thumbnail path: #{trophy.thumbnail_path}"
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModelProxy

#persisted?, #to_model, #valid_child_concerns

Constructor Details

#initialize(solr_document) ⇒ TrophyPresenter

Returns a new instance of TrophyPresenter.

Parameters:

  • solr_document (::SolrDocument)

22
23
24
# File 'app/presenters/hyrax/trophy_presenter.rb', line 22

def initialize(solr_document)
  @solr_document = solr_document
end

Instance Attribute Details

#solr_documentObject (readonly)


29
30
31
# File 'app/presenters/hyrax/trophy_presenter.rb', line 29

def solr_document
  @solr_document
end

#SolrDocument::SolrDocument (readonly)

Returns:

  • (::SolrDocument)

29
# File 'app/presenters/hyrax/trophy_presenter.rb', line 29

attr_reader :solr_document

Class Method Details

.find_by_user(user) ⇒ Array<TrophyPresenter>

Returns a list of all the trophy presenters for the user.

Parameters:

  • user (User)

    the user to find the TrophyPresentes for.

Returns:

  • (Array<TrophyPresenter>)

    a list of all the trophy presenters for the user


37
38
39
40
41
42
43
44
45
46
# File 'app/presenters/hyrax/trophy_presenter.rb', line 37

def self.find_by_user(user)
  ids = user.trophies.pluck(:work_id)
  return ids if ids.empty?

  documents = Hyrax::SolrQueryService.new.with_ids(ids: ids).solr_documents

  documents.map { |doc| new(doc) }
rescue RSolr::Error::ConnectionRefused
  []
end