diff --git a/plugins/communities_ratings/db/migrate/20150716143312_ratings_block.rb b/plugins/communities_ratings/db/migrate/20150716143312_ratings_block.rb new file mode 100644 index 0000000..a821ac8 --- /dev/null +++ b/plugins/communities_ratings/db/migrate/20150716143312_ratings_block.rb @@ -0,0 +1,7 @@ +class RatingsBlock < ActiveRecord::Migration + def up + end + + def down + end +end diff --git a/plugins/communities_ratings/lib/ratings_block.rb b/plugins/communities_ratings/lib/ratings_block.rb new file mode 100644 index 0000000..59a1d30 --- /dev/null +++ b/plugins/communities_ratings/lib/ratings_block.rb @@ -0,0 +1,68 @@ +class RatingsBlock < Block + + attr_accessible :ratings, :order + + settings_items :order, :type => string + settings_items :ratings, :type => Array, :default => [] + before_save :get_ratings + + def self.description + _('Community Ratings') + end + + def help + _('This block displays the community ratings.') + end + + def content(args = {}) + block = self + block.ratings = get_ratings + s = show_name + lambda do |object| + render( + :file => 'blocks/download', + :locals => { + :block => block, + :show_name => s + } + ) + end + end + + def get_ratings + self.ratings = CommunityRating.where(community_id: owner.id) + end + + def limit_number_of_downloads + if default_release + ratings = default_release.count + ratings > 3 ? 3 : ratings + end + end + + def release + if self.current_release.downcase == "use last release" + self.owner.software_info.releases.last + else + self.owner.software_info.releases.find_by_id(self.current_release.to_i) + end + end + + def cacheable? + false + end + + def software_releases + releases_options_to_select = [] + releases = self.owner.software_info.releases + return [] if releases.blank? + releases.each_with_index do |release, index| + sub_list = [] + release_index = release.name + sub_list << release_index + sub_list << release.id + releases_options_to_select << sub_list + end + releases_options_to_select + end +end diff --git a/plugins/communities_ratings/views/blocks/ratings.html.erb b/plugins/communities_ratings/views/blocks/ratings.html.erb new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugins/communities_ratings/views/blocks/ratings.html.erb diff --git a/plugins/communities_ratings/views/box_organizer/_ratings_block.html.erb b/plugins/communities_ratings/views/box_organizer/_ratings_block.html.erb new file mode 100644 index 0000000..3b85ea0 --- /dev/null +++ b/plugins/communities_ratings/views/box_organizer/_ratings_block.html.erb @@ -0,0 +1,6 @@ +
\ No newline at end of file -- libgit2 0.21.2