120 lines
3.1 KiB
Ruby
120 lines
3.1 KiB
Ruby
|
#encoding: utf-8
|
||
|
class ContestantWorksController < ApplicationController
|
||
|
include ContestantWorksHelper
|
||
|
include ApplicationHelper
|
||
|
require 'bigdecimal'
|
||
|
require "base64"
|
||
|
before_filter :find_contestwork, :only => [:new, :index, :create, :new_student_work_project,:student_work_project,:cancel_relate_project,
|
||
|
:search_course_students,:work_canrepeat,:add_group_member,:change_project]
|
||
|
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment]
|
||
|
before_filter :member_of_contest, :only => [:new, :create, :show]
|
||
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
||
|
before_filter :admin_of_contest, :only => []
|
||
|
before_filter :is_logged, :only => [:index]
|
||
|
|
||
|
def new
|
||
|
|
||
|
end
|
||
|
|
||
|
def index
|
||
|
|
||
|
end
|
||
|
|
||
|
def show
|
||
|
|
||
|
end
|
||
|
|
||
|
def create
|
||
|
|
||
|
end
|
||
|
|
||
|
def edit
|
||
|
|
||
|
end
|
||
|
|
||
|
def update
|
||
|
|
||
|
end
|
||
|
|
||
|
def destroy
|
||
|
|
||
|
end
|
||
|
|
||
|
def new_student_work_project
|
||
|
@user_activity_id = params[:user_activity_id].to_i
|
||
|
@hw_status = params[:hw_status].to_i
|
||
|
respond_to do |format|
|
||
|
format.js
|
||
|
end
|
||
|
end
|
||
|
|
||
|
#创建作业的关联项目
|
||
|
def student_work_project
|
||
|
@project = ContestantWorkProject.new
|
||
|
@project.work_id = @contestwork.id
|
||
|
@project.project_id = params[:projectName].to_i
|
||
|
@project.user_id = User.current.id
|
||
|
@project.is_leader = 1
|
||
|
@project.contest_id = @contestwork.contest_id
|
||
|
if @project.save
|
||
|
@user_activity_id = params[:user_activity_id].to_i
|
||
|
@hw_status = params[:hw_status].to_i
|
||
|
@is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin?
|
||
|
respond_to do |format|
|
||
|
format.js
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
# 取消关联项目
|
||
|
def cancel_relate_project
|
||
|
relate_pro = ContestantWorkProject.where("user_id = #{User.current.id} and work_id = #{@contestwork.id}").first
|
||
|
if relate_pro.destroy
|
||
|
@user_activity_id = params[:user_activity_id].to_i
|
||
|
@hw_status = params[:hw_status].to_i
|
||
|
@is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin?
|
||
|
respond_to do |format|
|
||
|
format.js
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
private
|
||
|
#获取题目
|
||
|
def find_contestwork
|
||
|
@contestwork = Work.find params[:work]
|
||
|
@contest = @contestwork.contest
|
||
|
rescue
|
||
|
render_404
|
||
|
end
|
||
|
|
||
|
#获取作品
|
||
|
def find_work
|
||
|
@work = ContestantWork.find params[:id]
|
||
|
@contestwork = @work.work
|
||
|
@contest = @contestwork.contest
|
||
|
rescue
|
||
|
render_404
|
||
|
end
|
||
|
|
||
|
#是不是当前竞赛的成员
|
||
|
#当前竞赛成员才可以看到作品列表
|
||
|
def member_of_contest
|
||
|
render_403 unless User.current.member_of_contest?(@contest) || User.current.admin?
|
||
|
end
|
||
|
|
||
|
#判断是不是当前作品的提交者
|
||
|
#提交者 && (非匿评作业 || 未开启匿评) 可以编辑作品
|
||
|
def author_of_work
|
||
|
render_403 unless User.current.admin? || User.current.id == @work.user_id
|
||
|
end
|
||
|
|
||
|
def admin_of_contest
|
||
|
render_403 unless User.current.admin_of_contest?(@contest) || User.current.admin?
|
||
|
end
|
||
|
|
||
|
def is_logged
|
||
|
redirect_to signin_path unless User.current.logged?
|
||
|
end
|
||
|
end
|