socialforge/app/controllers/school_controller.rb

114 lines
2.9 KiB
Ruby
Raw Normal View History

class SchoolController < ApplicationController
2014-04-23 21:20:03 +08:00
2014-04-25 09:29:18 +08:00
before_filter :require_admin, :only => :upload_logo
def upload
uploaded_io = params[:logo]
school_id = 0
schools = School.where("name = ?", params[:school])
schools.each do |s|
school_id = s.id
end
2014-04-25 09:29:18 +08:00
unless uploaded_io.nil?
File.open(Rails.root.join('public', 'images', 'school', school_id.to_s+'.png'), 'wb') do |file|
file.write(uploaded_io.read)
end
s1 = School.find(school_id)
s1.logo_link = '/images/school/'+school_id.to_s+'.png'
s1.save
end
end
def upload_logo
2014-04-25 09:29:18 +08:00
end
#获取制定学校开设的课程数
def course_count school_id
School.find(school_id).courses.count
end
2014-04-25 09:29:18 +08:00
2014-04-23 21:20:03 +08:00
def index
end
2014-04-30 20:26:15 +08:00
def get_province
@provinces = School.find_by_sql("select distinct province from schools")
options = ""
@provinces.each do |p|
options << "<option value = '#{p.province}' >#{p.province}</option>"
end
2014-05-15 11:45:49 +08:00
# 取id取学校名
2014-05-15 13:53:06 +08:00
# 连接子表: 查询已添加用户的学校
school = School.select("id, name").
joins("RIGHT JOIN (
SELECT DISTINCT school_id
FROM #{UserExtensions.table_name}
WHERE school_id IS NOT NULL) AS sids ON schools.id = sids.school_id").
where("#{School.table_name}.id IS NOT NULL")
2014-05-15 11:45:49 +08:00
options_s = ""
2014-05-15 11:45:49 +08:00
school.each do |s|
options_s << "<li style = 'width: 33%; float: left'><a id=#{s.id} onclick='test(this.id, this.text)'>#{s.name}</a></li>"
end
2014-05-15 11:45:49 +08:00
res = Hash.new
res[:text] = options
res[:text_s] = options_s
render :json => res
2014-04-30 20:26:15 +08:00
end
2014-04-23 21:20:03 +08:00
2014-04-15 16:57:19 +08:00
def get_options
@school = School.where("province = ?", params[:province])
p = params[:province]
##@school = School.all
options = ""
@school.each do |s|
2014-04-23 09:22:13 +08:00
#options << "<option value=#{s.id}>#{s.name}</option>"
2014-04-23 21:20:03 +08:00
options << "<li style = 'width: 33%; float: left'><a id=#{s.id} onclick='test(this.id, this.text)'>#{s.name}</a></li>"
2014-04-15 16:57:19 +08:00
end
2014-04-23 09:22:13 +08:00
2014-04-15 16:57:19 +08:00
render :text => options
end
2014-04-23 21:20:03 +08:00
def get_schoollist
@school = School.where("province = ?", params[:province])
options = ""
@school.each do |s|
options << "<li style = 'width: 33%; float: left'><a id=#{s.id} onclick='test(this.id)'>#{s.name}</a></li>"
end
render :text => options
end
2014-04-24 08:58:24 +08:00
def search_school
if params[:province].nil? or params[:province] == "0"
@school = School.where("name LIKE '%"+params[:key_word]+"%'");
else
@school = School.where("province = ? AND name LIKE '%"+params[:key_word]+"%'", params[:province]);
end
2014-04-24 08:58:24 +08:00
options = ""
@school.each do |s|
2014-07-03 18:11:10 +08:00
options << "<li style = 'width: 33%; float: left'> <a id=#{s.id} onclick='test(this.id)'>#{s.name}</a></li>"
2014-04-24 08:58:24 +08:00
end
render :text => options
end
end