117 lines
3.5 KiB
Ruby
117 lines
3.5 KiB
Ruby
class ContestsController < ApplicationController
|
|
|
|
before_filter :find_contest, :only => [:show, :settings]
|
|
before_filter :is_logged, :only => [:index, :new, :create]
|
|
layout "base_contests"
|
|
|
|
def show
|
|
respond_to do |format|
|
|
format.js
|
|
format.html
|
|
end
|
|
end
|
|
|
|
def new
|
|
if User.current.login?
|
|
@contest = Contest.new
|
|
render :layout => 'new_base'
|
|
else
|
|
redirect_to signin_url
|
|
end
|
|
end
|
|
|
|
def create
|
|
@contest = Contest.new
|
|
@contest.name = params[:contest][:name]
|
|
params[:contest][:is_public] ? @contest.is_public = 1 : @contest.is_public = 0
|
|
@contest.user_id = User.current.id
|
|
if @contest && @contest.save
|
|
#unless User.current.admin?
|
|
member = ContestMember.new(:user_id => User.current.id)
|
|
|
|
@contest.contest_members << member
|
|
ContestMemberRole.create(:contest_member_id => member.id, :role_id => 13)
|
|
|
|
@contest.contest_acts << ContestActivity.new(:user_id => @contest.user_id,:contest_id => @contest.id)
|
|
respond_to do |format|
|
|
format.html {redirect_to contest_url(@contest)}
|
|
end
|
|
end
|
|
end
|
|
|
|
def join_contest
|
|
|
|
end
|
|
|
|
def join_contest_multi_role
|
|
if User.current.logged?
|
|
cs = ContestsService.new
|
|
@user = User.current
|
|
join = cs.join_contest_roles params,@user
|
|
@state = join[:state]
|
|
@contest = join[:contest]
|
|
else
|
|
@state = 5 #未登录
|
|
end
|
|
@object_id = @contest.id if @contest
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
#处理加入竞赛成为管理员、评委、参赛者的请求
|
|
#status 1 同意 2 拒绝
|
|
def dealwith_apply_request
|
|
@msg = AppliedMessage.find(params[:msg_id])
|
|
#AppliedMessage role 13 管理员 14 评委 15 参赛者
|
|
applied_contest = @msg.applied
|
|
apply_user = User.find(applied_contest.user_id)
|
|
ids = applied_contest.role.split(",") # [@msg.content] msg content保存的是申请的职位角色
|
|
integer_ids = []
|
|
ids.each do |role_id|
|
|
integer_ids << role_id.to_i
|
|
end
|
|
case params[:agree]
|
|
when 'Y'
|
|
members = []
|
|
members << ContestMember.new(:role_ids => integer_ids, :user_id => apply_user.id)
|
|
Contest.find(applied_contest.contest_id).contest_members << members
|
|
ContestMessage.create(:user_id => apply_user.id, :contest_id => applied_contest.contest_id, :viewed => false,:contest_message_id=>User.current.id,:content=>applied_contest.role,:contest_message_type=>'ContestRequestDealResult',:status=>1)
|
|
applied_contest.applied_messages.update_all(:status => 1, :viewed => 1)
|
|
applied_contest.update_attributes(:status => 1)
|
|
if integer_ids.include?("15")
|
|
ContestantForContest.create(:student_id => apply_user.id, :contest_id =>applied_contest.contest_id)
|
|
end
|
|
|
|
when 'N'
|
|
ContestMessage.create(:user_id => apply_user.id, :contest_id => applied_contest.contest_id, :viewed => false,:contest_message_id=>User.current.id,:content=>applied_contest.role,:contest_message_type=>'ContestRequestDealResult',:status=>2)
|
|
applied_contest.applied_messages.update_all(:status => 2, :viewed => 1)
|
|
applied_contest.update_attributes(:status => 2)
|
|
end
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def find_contest
|
|
if params[:id].to_i < 780
|
|
render_403
|
|
return
|
|
end
|
|
@contest = Contest.find(params[:id])
|
|
rescue ActiveRecord::RecordNotFound
|
|
render_404
|
|
end
|
|
|
|
def is_logged
|
|
redirect_to signin_path unless User.current.logged?
|
|
end
|
|
|
|
def settings
|
|
|
|
end
|
|
|
|
end
|