olympiamanagement/app/models/sign_up_setting.rb

72 lines
11 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class SignUpSetting
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitModel::Impression
# encoding: utf-8
include OrbitTag::Taggable
include OrbitCategory::Categorizable
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
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)">11677台北市文山區汀州路4段88號科教中心收件人 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=>""}
field :active , type: Boolean , default: true
after_save :change_all_password , :check_active
after_destroy do |record|
OlympiaSchoolDataFields.where(:sign_up_setting_id => record.id).destroy_all
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|
OlympiaSchoolDataFields.create(school.attributes.except(*['_id','enrollment',"view_count","created_at","updated_at","sign_up_setting_id"]).merge({:sign_up_setting_id => record.id}))
end
end
def change_all_password
if self.set_default_password && !self.default_password.blank?
OlympiaSchoolDataFields.where(:sign_up_setting_id=>self.id).each do |school_field|
school_field.password = self.default_password
school_field.save
end
self.set_default_password = false
self.save
end
end
def check_active
if self.active
SignUpSetting.where(:id.ne=>self.id).each do |setting|
setting_copy = setting
setting_copy.active = false
setting_copy.save!
end
end
end
end