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

View File

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

View File

@ -12,8 +12,8 @@
<div class="tag_cloud">
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
<div class="cloud">
<% @tags.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} " %>
<% @tags_and_class.each do |tag| %>
<%= 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 %>
</div>
</div>

View File

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

View File

@ -12,8 +12,8 @@
<div class="tag_cloud">
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
<div class="cloud">
<% @tags.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} " %>
<% @tags_and_class.each do |tag| %>
<%= 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 %>
</div>
</div>