2021-02-07 14:56:22 +00:00
|
|
|
module Admin::AcademicAdvisingsHelper
|
2014-12-04 09:55:01 +00:00
|
|
|
|
|
|
|
def get_paper_list
|
|
|
|
user = current_user.nil? ? OrbitHelper.current_user : current_user
|
|
|
|
user_profile = user.member_profile
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advisings = Advising.where(:member_profile_id => user_profile.id)
|
|
|
|
academic_advisings = academic_advisings.collect do |h|
|
2014-12-04 09:55:01 +00:00
|
|
|
{
|
|
|
|
"id" => h.id.to_s,
|
2021-02-07 14:56:22 +00:00
|
|
|
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/academic_advisings/#{h.to_param}/edit",
|
|
|
|
"delete_url" => "/#{I18n.locale.to_s}/admin/academic_advisings/#{h.id.to_s}",
|
2014-12-04 09:55:01 +00:00
|
|
|
"paper_title" => h.award_name,
|
|
|
|
"keywords" => h.keywords,
|
|
|
|
"files" => []
|
|
|
|
}
|
|
|
|
end
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advisings
|
2014-12-04 09:55:01 +00:00
|
|
|
end
|
2015-12-14 07:18:27 +00:00
|
|
|
|
2021-02-07 14:56:22 +00:00
|
|
|
def import_this_academic_advising(row,mp)
|
2015-12-14 07:18:27 +00:00
|
|
|
value = nil
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising = Advising.new
|
2015-12-14 07:18:27 +00:00
|
|
|
row.cells.each_with_index do |cell,index|
|
|
|
|
next if index < 2
|
|
|
|
next if cell.nil?
|
|
|
|
val = cell.value
|
|
|
|
next if val.nil? || val == ""
|
|
|
|
case index
|
|
|
|
when 2
|
|
|
|
value = {"en" => val}
|
|
|
|
when 3
|
2015-12-14 08:12:52 +00:00
|
|
|
begin
|
|
|
|
value["zh_tw"] = val
|
|
|
|
rescue
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
end
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising.award_name_translations = value
|
2015-12-14 07:18:27 +00:00
|
|
|
when 4
|
|
|
|
value = {"en" => val}
|
|
|
|
when 5
|
2015-12-14 08:12:52 +00:00
|
|
|
begin
|
|
|
|
value["zh_tw"] = val
|
|
|
|
rescue
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
end
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising.awarding_unit_translations = value
|
2015-12-14 07:18:27 +00:00
|
|
|
when 6
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising.year = val
|
2015-12-14 07:18:27 +00:00
|
|
|
when 7
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising.language = val
|
2015-12-14 07:18:27 +00:00
|
|
|
when 8
|
2021-02-07 14:56:22 +00:00
|
|
|
hts = AdvisingType.asc(:created_at).all.to_a
|
|
|
|
academic_advising.academic_advising_type = hts[val.to_i] if val.to_s.is_i? && val.to_i < hts.count
|
2015-12-14 07:18:27 +00:00
|
|
|
when 9
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising.url = val
|
2015-12-14 07:18:27 +00:00
|
|
|
when 10
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising.keywords = val
|
2015-12-14 07:18:27 +00:00
|
|
|
when 11
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising.note = val
|
2015-12-14 07:18:27 +00:00
|
|
|
end
|
|
|
|
end
|
2021-02-07 14:56:22 +00:00
|
|
|
academic_advising.member_profile = mp
|
|
|
|
academic_advising.save
|
2015-12-14 07:18:27 +00:00
|
|
|
end
|
2016-06-06 09:15:12 +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
|
|
|
|
# d1 = DateTime.new(year_start,1,1,0,0)
|
|
|
|
# d2 = DateTime.new(year_end,12,31,23,59)
|
2021-02-07 14:56:22 +00:00
|
|
|
d["data"] = Advising.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue []
|
2016-06-06 09:15:12 +00:00
|
|
|
data << d
|
|
|
|
end
|
|
|
|
return data
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_chart_data(year_start,year_end,role,type)
|
|
|
|
case type
|
|
|
|
when "category"
|
2021-02-07 14:56:22 +00:00
|
|
|
jls = AdvisingType.all
|
2016-06-06 09:15:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
finaldata = []
|
|
|
|
role = Role.find(role) rescue nil
|
|
|
|
mps = []
|
|
|
|
if !role.nil?
|
|
|
|
mps = role.member_profile_ids
|
|
|
|
end
|
|
|
|
jls.each do |jl|
|
|
|
|
data = {}
|
|
|
|
data["name"] = jl.title
|
|
|
|
data["data"] = {}
|
|
|
|
(year_start..year_end).each do |year|
|
|
|
|
# d1 = DateTime.new(year,1,1,0,0)
|
|
|
|
# d2 = DateTime.new(year,12,31,23,59)
|
2021-03-04 11:09:06 +00:00
|
|
|
t = jl.advisings.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0
|
2016-06-06 09:15:12 +00:00
|
|
|
data["data"][year.to_s] = t
|
|
|
|
end
|
|
|
|
finaldata << data
|
|
|
|
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)
|
|
|
|
case type
|
|
|
|
when "category"
|
2021-03-04 11:09:06 +00:00
|
|
|
t = Advising.where(:year => year, :member_profile_id.in => mps, :advising_type_id => nil).count rescue 0
|
2016-06-06 09:15:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
data["data"][year.to_s] = t
|
|
|
|
end
|
|
|
|
finaldata << data
|
|
|
|
finaldata
|
|
|
|
end
|
2014-12-04 09:55:01 +00:00
|
|
|
end
|