Skip to content

Commit

Permalink
Merge pull request #4929 from samvera/fix/3820_replace_where
Browse files Browse the repository at this point in the history
replace AF.where in dashboard_helper_behavior
  • Loading branch information
jeremyf committed May 6, 2021
2 parents 6adbe21 + baf0a21 commit db4a50f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions app/helpers/hyrax/dashboard_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,40 @@ def on_the_dashboard?

# @param user [User]
# @param where [Hash] applied as the where clause when querying the Hyrax::WorkRelation
#
# @return [Integer] number of works matching the where that the user deposited
# @see Hyrax::WorkRelation
def number_of_works(user = current_user, where: { generic_type_sim: "Work" })
where_clause = where.merge(DepositSearchBuilder.depositor_field => user.user_key)
Hyrax::WorkRelation.new.where(where_clause).count
field_pairs = field_pairs(user)
field_pairs.merge!(where)
count(Hyrax::SolrQueryBuilderService.construct_query(field_pairs))
rescue RSolr::Error::ConnectionRefused
'n/a'
end

# @param user [User]
# @return [Integer] number of FileSets the user deposited
def number_of_files(user = current_user)
::FileSet.where(DepositSearchBuilder.depositor_field => user.user_key).count
count(Hyrax::SolrQueryBuilderService.construct_query_for_model(::FileSet, field_pairs(user)))
rescue RSolr::Error::ConnectionRefused
'n/a'
end

# @param user [User]
# @return [Integer] number of Collections the user created
def number_of_collections(user = current_user)
::Collection.where(DepositSearchBuilder.depositor_field => user.user_key).count
count(Hyrax::SolrQueryBuilderService.construct_query_for_model(::Collection, field_pairs(user)))
rescue RSolr::Error::ConnectionRefused
'n/a'
end

private

def field_pairs(user)
{ DepositSearchBuilder.depositor_field => user.user_key }
end

def count(query)
Hyrax::SolrService.count(query)
end
end
end

0 comments on commit db4a50f

Please sign in to comment.