socialforge/app/controllers/student_work_controller.rb

139 lines
3.5 KiB
Ruby
Raw Normal View History

class StudentWorkController < ApplicationController
layout "base_courses"
include StudentWorkHelper
before_filter :find_homework, :only => [:new, :index, :create]
2015-05-23 11:24:24 +08:00
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
@score = student_work_score @work,User.current
respond_to do |format|
format.js
end
end
def destroy
end
#评分
def add_score
score = student_work_score @work,User.current
if score
if params[:new_form] && params[:new_form][:user_message]
score.score = params[:score]
score.comment = params[:new_form][:user_message]
end
else
if params[:new_form] && params[:new_form][:user_message]
score = StudentWorksScore.new
score.score = params[:score]
score.comment = params[:new_form][:user_message]
score.user_id = User.current.id
score.student_work_id = @work.id
score.reviewer_role = 1
end
end
score.save_attachments(params[:attachments])
render_attachment_warning_if_needed(score)
if score.save
respond_to do |format|
format.js
end
2015-05-23 11:24:24 +08:00
end
end
2015-05-23 11:24:24 +08:00
#评分的回复
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