From 2e8bca12affd18ef600324cef02abd3176786dbf Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 29 Oct 2015 16:42:42 +0800 Subject: [PATCH] added random annoucment picker method --- app/controllers/announcements_controller.rb | 14 ++++++++++++++ lib/announcement/engine.rb | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 140477c..f4ff538 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -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| diff --git a/lib/announcement/engine.rb b/lib/announcement/engine.rb index 1e46f16..a26cada 100644 --- a/lib/announcement/engine.rb +++ b/lib/announcement/engine.rb @@ -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