olympiamanagement/app/models/sign_up_setting.rb

69 lines
11 KiB
Ruby
Raw Normal View History

2020-01-31 10:52:53 +00:00
class SignUpSetting
include Mongoid::Document
include Mongoid::Timestamps
# encoding: utf-8
field :start_year , type: String , default: Time.now.strftime("%Y")
field :end_year , type: String , default: Time.now.strftime("%Y")
field :start_month , type: String , default: Time.now.strftime("%m")
field :end_month , type: String , default: Time.now.strftime("%m")
field :start_day , type: String , default: Time.now.strftime("%d")
field :end_day , type: String , default: Time.now.strftime("%d")
field :start_o_clock , type: String , default: Time.now.strftime("%H")
field :end_o_clock , type: String , default: Time.now.strftime("%H")
field :start_minute , type: String , default: Time.now.strftime("%M")
field :end_minute , type: String , default: Time.now.strftime("%M")
field :default_password , type: String , default: ""
field :set_default_password , type: Boolean , default: false
2020-02-05 13:44:49 +00:00
field :remark_field , type: Hash , default: {:zh_tw=>'<strong><span style="font-size: 14pt"><span style="font-family: arial, helvetica, sans-serif">:</span></span></strong><span style="font-size: 14pt"><br />
<strong><span style="color: rgb(255,0,0)">{{end_year}}{{end_month}}{{end_day}}</span></strong>()()<strong><span style="color: rgb(0,0,255)">11677488 IJSO選訓委員會</span></strong> <br />
<br type="_moz" /></span><br />',:en=>""}
field :registration_instructions , type: Hash , default: {:zh_tw=>'<p class="MsoListParagraph" style="margin-left: 18pt; text-indent: -18pt; mso-list: l0 level1 lfo2"><span lang="EN-US" style="font-size: 9pt; color: #333333"><span style="color: rgb(255, 0, 0);"><span style="font-size: 16pt;">{{start_year}}/{{start_month}}/{{start_day}}{{end_year}}/{{end_month}}/{{end_day}}</span></span></span><br />
<br /><span style="font-size: 10pt;"><span lang="EN-US" style="color: rgb(51, 51, 51);">1.<span style="font-family: &quot;Times New Roman&quot;; font-stretch: normal;">&nbsp;</span></span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">線上報名系統之各校登入帳號為學校代碼,密碼隨公文發至各校。</span><span lang="EN-US" style="font-family: Arial, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(</span></span><b><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif; color: blue; background-size: initial; background-origin: initial; background-clip: initial"><span lang="EN-US" style="text-decoration: none; font-family: &quot;新細明體&quot;,serif; color: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; text-underline: none"><span lang="EN-US"><span style="font-size: 10pt;"><a href="/olympiamanagements/download_school_code"></a></span></span></span></span></b><span style="font-size: 10pt;"><span lang="EN-US" style="font-family: Arial, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">)</span></span><br />
<br /><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif; color: rgb(51,51,51); background-size: initial; background-origin: initial; background-clip: initial"><o:p></o:p></span><span style="font-size: 10pt;"><!--[if !supportLists]--><span lang="EN-US" style="color: rgb(51, 51, 51);">2.<span style="font-family: &quot;Times New Roman&quot;; font-stretch: normal;">&nbsp;</span></span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">登入系統後,請先填</span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;"><span style="color: rgb(255, 0, 0);"></span>」</span></span><br />
<br /><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif; color: rgb(51,51,51); background-size: initial; background-origin: initial; background-clip: initial"><o:p></o:p></span><span style="font-size: 10pt;"><!--[if !supportLists]--><span lang="EN-US" style="color: rgb(51, 51, 51);">3.<span style="font-family: &quot;Times New Roman&quot;; font-stretch: normal;">&nbsp;</span></span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">新增報名學生資料:</span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(1)</span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">學生姓名</span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(2)</span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">性別</span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(3)</span><span lang="EN-US" style="color: rgb(51, 51, 51);"> </span><span style="color: rgb(51, 51, 51);"></span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(4)</span><span lang="EN-US" style="color: rgb(51, 51, 51);"> </span><span style="color: rgb(51, 51, 51);"></span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(5)</span><span lang="EN-US" style="color: rgb(51, 51, 51);"> </span><span style="color: rgb(51, 51, 51);"></span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(6)</span><span lang="EN-US" style="color: rgb(51, 51, 51);"> </span><span style="color: rgb(51, 51, 51);"></span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(7)</span><span lang="EN-US" style="color: rgb(51, 51, 51);"> </span><span style="color: rgb(51, 51, 51);"></span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(8)</span><span lang="EN-US" style="color: rgb(51, 51, 51);"> </span><span style="color: rgb(51, 51, 51);"></span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(9)</span><span lang="EN-US" style="color: rgb(51, 51, 51);"> </span><span style="color: rgb(51, 51, 51);"></span><span lang="EN-US" style="font-family: Arial, sans-serif; color: rgb(51, 51, 51);">(</span><span style="color: rgb(51, 51, 51);"></span><span lang="EN-US" style="font-family: Arial, sans-serif; color: rgb(51, 51, 51);">) :&nbsp;</span><span style="color: rgb(51, 51, 51);"></span><br />
<span lang="EN-US" style="font-family: &quot;Segoe UI Symbol&quot;, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">(10)</span><span lang="EN-US" style="color: rgb(51, 51, 51);"> </span><span style="color: rgb(51, 51, 51);"></span><br />
<br /><span lang="EN-US" style="color: rgb(51, 51, 51);">4.<span style="font-family: &quot;Times New Roman&quot;; font-stretch: normal;">&nbsp;</span></span><span style="color: rgb(255, 0, 0);"><span style="background-size: initial; background-origin: initial; background-clip: initial;">列印報名表,由校長及教務主任核章後</span></span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">,以掛號郵寄至【</span><span lang="EN-US" style="font-family: Arial, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">11677</span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">台北市文山區汀州路</span><span lang="EN-US" style="font-family: Arial, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">4</span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">段</span><span lang="EN-US" style="font-family: Arial, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">88</span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">號科教中心,收件人:</span><span lang="EN-US" style="font-family: Arial, sans-serif; color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">IJSO</span><span style="color: rgb(51, 51, 51); background-size: initial; background-origin: initial; background-clip: initial;">選訓委員會】。</span></span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif; color: rgb(51,51,51); background-size: initial; background-origin: initial; background-clip: initial"><o:p></o:p></span></p>',
:en=>""}
2020-02-05 07:37:10 +00:00
field :active , type: Boolean , default: true
after_save :change_all_password , :check_active
2020-02-05 16:16:48 +00:00
after_destroy do |record|
OlympiaSchoolDataFields.where(:sign_up_setting_id => record.id.to_s).destroy
StudentDataField.where(:sign_up_setting_id => record.id.to_s).destroy
2020-02-05 16:16:48 +00:00
end
after_create do |record|
SignUpSetting.where(:id.ne=>record.id).each{|record| record.update(:active=>false)}
@sign_up_setting = SignUpSetting.where(:id.ne=>record.id).last
@schools = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).take_while{true}
@schools.each do |school|
2020-02-28 02:26:14 +00:00
OlympiaSchoolDataFields.create(school.attributes.slice(*["account_number","password","school_name","school_code","school_address","class_number"]).merge({:sign_up_setting_id => record.id}))
2020-02-05 16:16:48 +00:00
end
end
2020-01-31 10:52:53 +00:00
def change_all_password
2020-02-05 13:44:49 +00:00
if self.set_default_password && !self.default_password.blank?
OlympiaSchoolDataFields.where(:sign_up_setting_id=>self.id).each do |school_field|
2020-02-28 02:26:14 +00:00
school_field.password = ""
2020-01-31 10:52:53 +00:00
school_field.save
end
self.set_default_password = false
self.save
end
end
2020-02-05 07:37:10 +00:00
def check_active
if self.active
2020-02-05 13:44:49 +00:00
SignUpSetting.where(:id.ne=>self.id).each do |setting|
setting_copy = setting
setting_copy.active = false
setting_copy.save!
2020-02-05 07:37:10 +00:00
end
end
end
2020-01-31 10:52:53 +00:00
end