This commit is contained in:
Christophe Vilayphiou 2012-08-03 01:35:41 +08:00
parent 1b29eb5de4
commit 4127d7f2eb
5 changed files with 27 additions and 32 deletions

View File

@ -10,36 +10,31 @@ class Tag
#field :cloud_amper,:type: Integer,:default=> 0 #field :cloud_amper,:type: Integer,:default=> 0
belongs_to :module_app belongs_to :module_app
def cloud_amper def self.sorted_for_cloud
for_now = {:start_at=>14.days.ago,:end_at=>Time.now} tags = {}
for_yesterday = {:start_at=>15.days.ago,:end_at=>1.days.ago} self.all.each{ |tag|
tags.merge!({tag => self.get_impressionist(tag)})
range = self.class.all.collect{ |tag|
get_impressionist(tag)
} }
range.sort!.reverse!.uniq! if !tags.blank?
offset_size = range.size+4 sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse
section_3 = range.first..range[(offset_size/4)] sorted_tags[0][1] = :hot1
section_2 = range[(offset_size/4)+1]..range[2*(offset_size/4)] rescue nil offset = (sorted_tags.size - 1) / 3
section_1 = range[2*(offset_size/4)+1]..last rescue nil i = 1
class_i = 2
sorted_tags[1..-1].collect!{ |x|
case get_impressionist x[1] = "hot#{class_i}"
when range.first i == offset ? i = 1 : i += 1 if class_i < 4
return :hot1 class_i += 1 if i == offset && class_i < 4
when section_1 }
return :hot2 sorted_tags
when section_2 else
return :hot3 []
when section_3 end
return :hot4
end end
end protected
protected def self.get_impressionist(item_tag = self)
def get_impressionist(item_tag = self)
item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count
end end

View File

@ -43,7 +43,7 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
end end
def bulletins_side_bar def bulletins_side_bar
@tags = AnnouncementTag.all @tags_and_class = AnnouncementTag.sorted_for_cloud
get_categorys get_categorys
end end

View File

@ -12,8 +12,8 @@
<div class="tag_cloud"> <div class="tag_cloud">
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3> <h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
<div class="cloud"> <div class="cloud">
<% @tags.each do |tag| %> <% @tags_and_class.each do |tag| %>
<%= link_to tag[I18n.locale], panel_announcement_front_end_bulletins_path(:tag_id => tag.id, :category_id => params[:category_id]), :class => "#{tag.cloud_amper} hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil} " %> <%= link_to tag[0][I18n.locale], panel_announcement_front_end_bulletins_path(:tag_id => tag[0].id, :category_id => params[:category_id]), :class => "#{tag[1]} #{(tag[0].id.to_s.eql?(params[:tag_id]) || tag[0].key.eql?(params[:tag_id])) ? 'active' : nil} " %>
<% end %> <% end %>
</div> </div>
</div> </div>

View File

@ -43,7 +43,7 @@ class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController
end end
def news_bulletins_side_bar def news_bulletins_side_bar
@tags = NewsTag.all @tags_and_class = NewsTag.sorted_for_cloud
get_categorys get_categorys
end end

View File

@ -12,8 +12,8 @@
<div class="tag_cloud"> <div class="tag_cloud">
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3> <h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
<div class="cloud"> <div class="cloud">
<% @tags.each do |tag| %> <% @tags_and_class.each do |tag| %>
<%= link_to tag[I18n.locale], panel_news_front_end_news_bulletins_path(:tag_id => tag.id, :category_id => params[:category_id]),:class => "#{tag.cloud_amper} hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil} " %> <%= link_to tag[0][I18n.locale], panel_news_front_end_news_bulletins_path(:tag_id => tag[0].id, :category_id => params[:category_id]),:class => "#{tag[1]} #{(tag[0].id.to_s.eql?(params[:tag_id]) || tag[0].key.eql?(params[:tag_id])) ? 'active' : nil} " %>
<% end %> <% end %>
</div> </div>
</div> </div>