Sha256: ee3f2ef843787f8dcd926d59a3b76e60de26b47e72b18138ff5730bb46fff696

Contents?: true

Size: 926 Bytes

Versions: 6

Compression:

Stored size: 926 Bytes

Contents

# frozen_string_literal: true
module Hyrax
  class TrophyPresenter
    include ModelProxy
    def initialize(solr_document)
      @solr_document = solr_document
    end

    attr_reader :solr_document

    delegate :to_s, :thumbnail_path, to: :solr_document

    # @param user [User] the user to find the TrophyPresentes for.
    # @return [Array<TrophyPresenter>] a list of all the trophy presenters for the user
    def self.find_by_user(user)
      work_ids = user.trophies.pluck(:work_id)
      query = Hyrax::SolrQueryBuilderService.construct_query_for_ids(work_ids)
      results = Hyrax::WorkRelation.new.search_with_conditions(query)
      results.map { |result| TrophyPresenter.new(document_model.new(result)) }
    rescue RSolr::Error::ConnectionRefused
      []
    end

    def self.document_model
      CatalogController.blacklight_config.document_model
    end
    private_class_method :document_model
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hyrax-3.0.2 app/presenters/hyrax/trophy_presenter.rb
hyrax-3.0.1 app/presenters/hyrax/trophy_presenter.rb
hyrax-3.0.0 app/presenters/hyrax/trophy_presenter.rb
hyrax-3.0.0.pre.rc4 app/presenters/hyrax/trophy_presenter.rb
hyrax-3.0.0.pre.rc3 app/presenters/hyrax/trophy_presenter.rb
hyrax-3.0.0.pre.rc2 app/presenters/hyrax/trophy_presenter.rb