personal-activity/app/helpers/admin/personal_activities_helper.rb

74 lines
1.9 KiB
Ruby
Raw Permalink Normal View History

module Admin::PersonalActivitiesHelper
def get_chart_data(year_start,year_end,role,type)
type = nil
finaldata = []
role = Role.find(role) rescue nil
mps = []
if !role.nil?
mps = role.member_profile_ids
end
data = {"name" => "N/A", "data" => {}}
(year_start..year_end).each do |year|
d1 = DateTime.new(year,1,1,0,0)
d2 = DateTime.new(year,12,31,23,59)
t = Activity.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps).count rescue 0
data["data"][year.to_s] = t
end
finaldata << data
finaldata
end
2020-02-06 10:10:34 +00:00
def get_data_for_excel(year_start,year_end)
data = []
roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key)
roles.each do |role|
d = {}
d["name"] = role.title
mps = role.member_profile_ids
d["data"] = Activity.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue []
data << d
end
return data
end
2020-02-10 07:25:48 +00:00
def import_this_activity(row, mp)
value = {}
activity = Activity.new
row.cells.each_with_index do |cell,index|
next if index < 2
val = cell.value rescue nil
case index
when 2
value["en"] = val
when 3
value["zh_tw"] = val
activity.activity_name_translations = value
value = {}
when 4
value["en"] = val
when 5
value["zh_tw"] = val
activity.activity_organizer_translations = value
value = {}
when 6
value["en"] = val
when 7
value["zh_tw"] = val
activity.activity_area_translations = value
value = {}
when 8
activity.year = val
when 9
activity.activity_start_date = val
when 10
activity.activity_end_date = val
when 11
activity.note = val
end
end
activity.member_profile = mp
activity.save
end
end