added random annoucment picker method

This commit is contained in:
Harry Bomrah 2015-10-29 16:42:42 +08:00
parent 8cfc89abcc
commit 2e8bca12af
2 changed files with 15 additions and 1 deletions

View File

@ -91,10 +91,24 @@ class AnnouncementsController < ApplicationController
fans
end
def random_announcement_widget
uid = OrbitHelper.params[:uid] rescue ""
tags = ["all"] if OrbitHelper.widget_tags.empty?
categories = OrbitHelper.widget_categories || []
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:uid.ne => uid, :category_id.in => categories).and(:title.ne => nil).can_display.is_approved.filter_by_tags(tags).sample(OrbitHelper.widget_data_count)
pack_data(announcements)
end
def widget
uid = OrbitHelper.params[:uid] rescue ""
tags = ["all"] if OrbitHelper.widget_tags.empty?
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:uid.ne => uid).and(:title.ne => nil).can_display.is_approved.filter_by_widget_categories.filter_by_tags(tags)
pack_data(announcements)
end
def pack_data(announcements)
page = Page.where(:module => "announcement").first rescue nil
anns = announcements.collect do |a|
statuses = a.statuses_with_classname.collect do |status|

View File

@ -5,7 +5,7 @@ module Announcement
OrbitApp.registration "Announcement", :type => "ModuleApp" do
module_label "announcement.announcement"
base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget"]
widget_methods ["widget","random_announcement_widget"]
widget_settings [{"data_count"=>30}]
taggable "Bulletin"
categorizable