ref: master
app/models/profile_list_block.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
class ProfileListBlock < Block attr_accessible :prioritize_profiles_with_image settings_items :limit, :type => :integer, :default => 6 settings_items :prioritize_profiles_with_image, :type => :boolean, :default => true def self.description _('Random profiles') end # override in subclasses! def profiles if owner.is_a? Environment owner.profiles.is_public else owner.profiles.visible end end def profile_list result = nil public_profiles = profiles.includes([:image,:domains,:preferred_domain,:environment]) if !prioritize_profiles_with_image result = public_profiles.limit(get_limit).order('profiles.updated_at DESC').sort_by{ rand } elsif profiles.visible.with_image.count >= get_limit result = public_profiles.with_image.limit(get_limit * 5).order('profiles.updated_at DESC').sort_by{ rand } else result = public_profiles.with_image.sort_by{ rand } + public_profiles.without_image.limit(get_limit * 5).order('profiles.updated_at DESC').sort_by{ rand } end result.slice(0..get_limit-1) end def profile_count profiles.count end # the title of the block. Probably will be overriden in subclasses. def default_title _('{#} People or Groups') end def help _('Clicking on the people or groups will take you to their home page.') end def view_title title.gsub('{#}', profile_count.to_s) end # override in subclasses! See MembersBlock for example def extra_option {} end end |