module Admin::AnnouncementsHelper def page_for_bulletin(bulletin) ann_page = nil pages = Page.where(:module=>'announcement') pages.each do |page| if page.categories.count ==1 if page.categories.include?(bulletin.category.id.to_s) ann_page = page end end break if !ann_page.nil? end if ann_page.nil? pages.each do |page| if page.categories.include?(bulletin.category.id.to_s) ann_page = page end break if !ann_page.nil? end end ann_page = pages.first if ann_page.nil? request.protocol+(request.host_with_port+ann_page.url+'/'+bulletin.to_param).gsub('//','/') rescue "/" end def import_this_announcement(row,categories,tags) value = {} anns = Bulletin.new row.cells.each_with_index do |cell,index| next if cell.nil? val = cell.value next if val.nil? || val == "" case index when 0 anns.category = categories[val.to_i] when 1 new_tags = [] if (val.include?(",") rescue false) ts = val.split(",") ts.each do |t| new_tags << tags[t.to_i] end else new_tags << tags[val.to_i] end anns.tags=new_tags when 2 anns.postdate = val when 3 anns.deadline = val when 4 anns.is_top = (val.to_i == 1 ? true : false) when 5 anns.is_hot = (val.to_i == 1 ? true : false) when 6 anns.is_hidden = (val.to_i == 1 ? true : false) when 7 anns.remote_image_url = val when 8 value["en"] = val when 9 value["zh_tw"] = val anns.image_description_translations = value value = {} when 10 value["en"] = val when 11 value["zh_tw"] = val anns.title_translations = value value = {} when 12 value["en"] = val when 13 value["zh_tw"] = val anns.subtitle_translations = value value = {} when 14 value["en"] = val when 15 value["zh_tw"] = val anns.text_translations = value value = {} end end anns.create_user_id = current_user.id.to_s anns.update_user_id = current_user.id.to_s anns.approved = true anns.save end def load_access_level if (current_user.is_admin? rescue false) @access_level = "admin" elsif (current_user.is_manager?(@module_app) rescue false) @access_level = "manager" else @access_level = "users" end end def user_can_approve? case @access_level when "admin" return true when "manager" return true else return false end end end