debshots/app/helpers/packages_helper.rb

26 lines
808 B
Ruby

module PackagesHelper
# Return a query of all screenshots that the current user may see
# Consists of:
# - approved (public) screenshots
# - screenshots uploaded by the user (determined by cookie session)
# - all screenshots if the user is logged in
def screenshots_visible_to_user(package)
if user_signed_in?
# User is an admin
package.screenshots.order('created_at DESC')
else
package.screenshots.where(
"approved=true OR uploaderhash=?", session[:token]
).order('created_at DESC')
end
end
# Show filled/empty star icons from FontAwesome
# depending on the rating (1-5)
def star_rating(rating)
filled_stars = fa_icon('star') * rating
empty_stars = fa_icon('star-o') * (5-rating)
(filled_stars+empty_stars).html_safe
end
end