115 lines
2.7 KiB
Ruby
115 lines
2.7 KiB
Ruby
class StudentWorkController < ApplicationController
|
|
layout "base_courses"
|
|
before_filter :find_homework, :only => [:new, :index, :create]
|
|
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score]
|
|
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score]
|
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
|
|
|
def index
|
|
@stundet_works = @homework.student_works.order("final_score desc")
|
|
respond_to do |format|
|
|
format.html
|
|
end
|
|
end
|
|
|
|
def new
|
|
student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
|
if student_work.nil?
|
|
@stundet_work = StudentWork.new
|
|
respond_to do |format|
|
|
format.html
|
|
end
|
|
else
|
|
render_403
|
|
end
|
|
end
|
|
|
|
def create
|
|
if params[:student_work]
|
|
stundet_work = StudentWork.new
|
|
stundet_work.name = params[:student_work][:name]
|
|
stundet_work.description = params[:student_work][:description]
|
|
stundet_work.project_id = params[:student_work][:project_id]
|
|
stundet_work.homework_common_id = @homework.id
|
|
stundet_work.user_id = User.current.id
|
|
stundet_work.save_attachments(params[:attachments])
|
|
render_attachment_warning_if_needed(stundet_work)
|
|
if stundet_work.save
|
|
respond_to do |format|
|
|
format.html {
|
|
flash[:notice] = l(:notice_successful_create)
|
|
redirect_to student_work_index_url(:homework => @homework.id)
|
|
}
|
|
end
|
|
return
|
|
end
|
|
end
|
|
respond_to do |format|
|
|
format.html {
|
|
flash[:notice] = l(:notice_failed_create)
|
|
redirect_to new_student_work_url(:homework => @homework.id)
|
|
}
|
|
end
|
|
end
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
def update
|
|
|
|
end
|
|
|
|
def show
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
|
|
end
|
|
|
|
#评分
|
|
def add_score
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
#评分的回复
|
|
def add_score_reply
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
private
|
|
#获取作业
|
|
def find_homework
|
|
@homework = HomeworkCommon.find params[:homework]
|
|
@course = @homework.course
|
|
rescue
|
|
render_404
|
|
end
|
|
#获取作品
|
|
def find_work
|
|
@work = StudentWork.find params[:id]
|
|
@homework = @work.homework_common
|
|
@course = @homework.course
|
|
rescue
|
|
render_404
|
|
end
|
|
|
|
#是不是当前课程的成员
|
|
#当前课程成员才可以看到作品列表
|
|
def member_of_course
|
|
render_403 unless User.current.member_of_course? @course
|
|
end
|
|
|
|
#判断是不是当前作品的提交者
|
|
#提交者可以编辑作品
|
|
def author_of_work
|
|
render_403 unless User.current.id == @work.user_id && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 )
|
|
end
|
|
end |