diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index a429a8397..911df776e 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -695,7 +695,7 @@ class AttachmentsController < ApplicationController
@attachment.container.board.course)
@course = @attachment.container.board.course
else
- unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' || @attachment.container_type == 'Work'|| @attachment.container_type == 'ContestantWork'|| @attachment.container_type == 'Contest'
+ unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' || @attachment.container_type == 'Work'|| @attachment.container_type == 'ContestantWork'|| @attachment.container_type == 'Contest' || @attachment.container_type == 'HomeworkBank'
@project = @attachment.project
end
end
diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb
index 79a32fc76..7b7fd4384 100644
--- a/app/controllers/exercise_controller.rb
+++ b/app/controllers/exercise_controller.rb
@@ -3,7 +3,8 @@ class ExerciseController < ApplicationController
before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy,
:commit_exercise, :commit_answer,:publish_exercise,:republish_exercise,
- :show_student_result,:student_exercise_list]
+ :show_student_result,:student_exercise_list, :update_question_num,
+ :send_to_course, :get_student_uncomplete_question, :edit_question_score]
before_filter :find_course, :only => [:index,:new,:create]
include ExerciseHelper
@@ -68,8 +69,8 @@ class ExerciseController < ApplicationController
eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
end
- score = calculate_student_score(@exercise, User.current)
- @exercise_user.update_attributes(:score => score)
+ #score = calculate_student_score(@exercise, User.current)
+ #@exercise_user.update_attributes(:objective_score => score, :score => (score + (@exercise_user.subjective_score > 0 ? @exercise_user.subjective_score : 0)))
end
# @percent = get_percent(@exercise,User.current)
@exercise_questions = @exercise.exercise_questions
@@ -132,7 +133,9 @@ class ExerciseController < ApplicationController
@exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time]
@exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
@exercise.publish_time = params[:exercise][:publish_time]
- @exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result]
+ @exercise.show_result = params[:show_result].blank? ? 1 : params[:show_result]
+ @exercise.question_random = params[:question_random] ? 0 : 1
+ @exercise.choice_random = params[:choice_random] ? 0 : 1
if @exercise.save
respond_to do |format|
format.js
@@ -177,7 +180,8 @@ class ExerciseController < ApplicationController
:question_type => params[:question_type] || 1,
:question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 :
(params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) :
- @exercise.exercise_questions.where("question_type = 3").count + 1),
+ (params[:question_type] == "3" ? (@exercise.exercise_questions.where("question_type = 3").count + 1) :
+ @exercise.exercise_questions.where("question_type = 4").count + 1)),
:question_score => params[:question_score]
}
@exercise_questions = @exercise.exercise_questions.new option
@@ -200,8 +204,10 @@ class ExerciseController < ApplicationController
#@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
elsif @exercise_questions.question_type == 2
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1")
- else
+ elsif @exercise_questions.question_type == 3
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1")
+ else
+ ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 4).update_all(" question_number = question_number + 1")
end
# @exercise_question_num = params[:quest_num].to_i
@exercise_questions.question_number = params[:quest_num].to_i + 1
@@ -216,12 +222,19 @@ class ExerciseController < ApplicationController
standart_answer.answer_text = params[:exercise_choice].values[i-1]
standart_answer.save
end
+ elsif @exercise_questions.question_type == 4
+ unless params[:exercise_choice] == ""
+ standart_answer = ExerciseStandardAnswer.new
+ standart_answer.exercise_question_id = @exercise_questions.id
+ standart_answer.answer_text = params[:exercise_choice]
+ standart_answer.save
+ end
else
standart_answer = ExerciseStandardAnswer.new
standart_answer.exercise_question_id = @exercise_questions.id
if @exercise_questions.question_type == 1
standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice])
- else
+ elsif @exercise_questions.question_type == 2
standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice])
end
standart_answer.save
@@ -283,12 +296,26 @@ class ExerciseController < ApplicationController
@exercise_question.exercise_standard_answers.new standart_answer_option
end
end
+ elsif @exercise_question.question_type == 4
+ answer_standart = @exercise_question.exercise_standard_answers.empty? ? nil : @exercise_question.exercise_standard_answers.first
+ if params[:exercise_choice] == "" && !answer_standart.nil?
+ answer_standart.destroy
+ elsif params[:exercise_choice] != "" && !answer_standart.nil?
+ answer_standart.answer_text = params[:exercise_choice]
+ answer_standart.save
+ elsif params[:exercise_choice] != "" && answer_standart.nil?
+ standart_answer_option = {
+ :answer_text => params[:exercise_choice]
+ }
+ @exercise_question.exercise_standard_answers.new standart_answer_option
+ end
else
answer_standart = @exercise_question.exercise_standard_answers.first
answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice])
answer_standart.save
end
@exercise_question.save
+ @exercise = @exercise_question.exercise
respond_to do |format|
format.js
end
@@ -305,8 +332,10 @@ class ExerciseController < ApplicationController
#@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
elsif @exercise_question.question_type == 2
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1")
- else
+ elsif @exercise_question.question_type == 3
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1")
+ else
+ ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 4).update_all(" question_number = question_number - 1")
end
# @exercise_question_num = params[:quest_num].to_i
# @exercise_questions.question_number = params[:quest_num].to_i - 1
@@ -323,6 +352,88 @@ class ExerciseController < ApplicationController
end
end
+ #题目上移/下移
+ def update_question_num
+ @exercise_question = ExerciseQuestion.find params[:ques_id]
+ exercise_questions = @exercise.exercise_questions
+ if @exercise_question
+ if params[:opr] == 'up' && @exercise_question.question_number > 1
+ @before_que = exercise_questions.where("question_type = #{@exercise_question.question_type} and question_number = #{@exercise_question.question_number - 1}").first
+ if @before_que && @exercise_question.update_attribute('question_number', @exercise_question.question_number - 1)
+ @before_que.update_attribute('question_number', @before_que.question_number + 1)
+ end
+ elsif params[:opr] == 'down' && @exercise_question.question_number < exercise_questions.count
+ @after_que = exercise_questions.where("question_type = #{@exercise_question.question_type} and question_number = #{@exercise_question.question_number + 1}").first
+ if @after_que && @exercise_question.update_attribute('question_number', @exercise_question.question_number + 1)
+ @after_que.update_attribute('question_number', @after_que.question_number - 1)
+ end
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+ end
+
+ # 发送试卷
+ def send_to_course
+ params[:course_ids].each do |course|
+ option = {
+ :exercise_name => @exercise.exercise_name,
+ :exercise_status => 1,
+ :user_id => User.current.id,
+ :show_result => 1,
+ :course_id => course.to_i,
+ :time => @exercise.time,
+ :exercise_description => @exercise.exercise_description
+ }
+ exercise = Exercise.create option
+
+ @exercise.exercise_questions.each do |q|
+ option = {
+ :question_title => q[:question_title],
+ :question_type => q[:question_type] || 1,
+ :question_number => q[:question_number],
+ :question_score => q[:question_score]
+ }
+ exercise_question = exercise.exercise_questions.new option
+
+ for i in 1..q.exercise_choices.count
+ choice_option = {
+ :choice_position => i,
+ :choice_text => q.exercise_choices[i-1][:choice_text]
+ }
+ exercise_question.exercise_choices.new choice_option
+ end
+
+ for i in 1..q.exercise_standard_answers.count
+ standard_answer_option = {
+ :exercise_choice_id => q.exercise_standard_answers[i-1][:exercise_choice_id],
+ :answer_text => q.exercise_standard_answers[i-1][:answer_text]
+ }
+ exercise_question.exercise_standard_answers.new standard_answer_option
+ end
+ end
+ exercise.save
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ # 搜索当前用户任教的班级(不包含该试卷所在的班级)
+ def search_courses
+ @user = User.current
+ if !params[:name].nil?
+ search = "%#{params[:name].to_s.strip.downcase}%"
+ @courses = @user.courses.not_deleted.where("courses.id != #{params[:course].to_i} and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).reorder("created_at desc").select {|course| @user.allowed_to?(:as_teacher,course)}
+ else
+ @courses = @user.courses.not_deleted.where("courses.id != #{params[:course].to_i}").reorder("created_at desc").select {|course| @user.allowed_to?(:as_teacher,course)}
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
# 发布试卷
def publish_exercise
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
@@ -375,12 +486,12 @@ class ExerciseController < ApplicationController
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
@all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc")
student_id = @course.student.blank? ? "(-1)" : "(" + @course.student.map{|student| student.student_id}.join(",") + ")"
- @exercise_count = @exercise.exercise_users.where("score is not NULL and user_id in #{student_id}").count
+ @exercise_count = @exercise.exercise_users.where("commit_status = 1 and user_id in #{student_id}").count
if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time <= Time.now)
- @exercise_users_list = @exercise.exercise_users.where("score is not NULL and user_id in #{student_id}")
+ @exercise_users_list = @exercise.exercise_users.where("user_id in #{student_id}")
@show_all = true;
elsif !@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time > Time.now
- @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL and user_id in #{student_id}",User.current.id)
+ @exercise_users_list = @exercise.exercise_users.where("user_id = ? and user_id in #{student_id}",User.current.id)
else
@exercise_users_list = []
end
@@ -444,21 +555,23 @@ class ExerciseController < ApplicationController
else
complete = 0;
end
+ is_answer = User.current.exercise_answer.where(:exercise_question_id => params[:exercise_question_id].to_i).count > 0
@percent = get_percent(@exercise,User.current)
- render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)}
+ render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent),:is_answer => is_answer}
else
render :json => {:text => "failure"}
end
else
#pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案
if ea.delete
+ is_answer = User.current.exercise_answer.where(:exercise_question_id => params[:exercise_question_id].to_i).count > 0
@percent = get_percent(@exercise, User.current)
- render :json => {:text => "false" ,:percent => format("%.2f" , @percent)}
+ render :json => {:text => "false" ,:percent => format("%.2f" , @percent),:is_answer => is_answer}
else
render :json => {:text => "failure"}
end
end
- elsif eq.question_type == 3
+ elsif eq.question_type == 3 || eq.question_type == 4
#单行文本,多行文本题
ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id)
if ea.nil?
@@ -486,6 +599,7 @@ class ExerciseController < ApplicationController
render :json => {:text => "failure"}
end
end
+
else
# ea不为空说明用户之前已作答
if params[:answer_text].nil? || params[:answer_text].blank?
@@ -517,60 +631,84 @@ class ExerciseController < ApplicationController
def commit_exercise
# 老师不需要提交
if User.current.allowed_to?(:as_teacher,@course)
- if @exercise.publish_time.nil? || @exercise.publish_time <= Time.now
- @exercise.update_attributes(:show_result => params[:show_result])
- @exercise.update_attributes(:exercise_status => 2)
- @exercise.update_attributes(:publish_time => Time.now)
- course = @exercise.course
- course.members.each do |m|
- @exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
- end
- redirect_to exercise_url(@exercise)
- return
- elsif @exercise.publish_time > Time.now
- @exercise.update_attributes(:show_result => params[:show_result])
- redirect_to exercise_url(@exercise)
- return
- end
- @exercise.update_attributes(:show_result => params[:show_result])
- redirect_to exercise_url(@exercise)
+ # if @exercise.publish_time.nil? || @exercise.publish_time <= Time.now
+ # @exercise.update_attributes(:exercise_status => 2)
+ # @exercise.update_attributes(:publish_time => Time.now)
+ # course = @exercise.course
+ # course.members.each do |m|
+ # @exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
+ # end
+ # redirect_to exercise_url(@exercise)
+ # return
+ # elsif @exercise.publish_time > Time.now
+ # redirect_to exercise_url(@exercise)
+ # return
+ # end
+ # redirect_to exercise_url(@exercise)
# REDO: 提示提交成功
else
# 更新提交状态
cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first
cur_exercise_user.update_attributes(:status => 1, :commit_status => 1)
# 答题过程中需要统计完成量
- @uncomplete_question = get_uncomplete_question(@exercise, User.current)
+ #@uncomplete_question = get_uncomplete_question(@exercise, User.current)
# 获取改学生的考试得分
- @score = calculate_student_score(@exercise, User.current)
+ #@score = calculate_student_score(@exercise, User.current)
# @score = 100
- if @uncomplete_question.count < 1
- # 查看是否有已提交记录
- cur_exercise_user.score = @score
- if cur_exercise_user.save
- #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
- @status = 0 #提交成功
- else
- @status = 2 #未知错误
- end
- else
- @status = 1 #有未做得必答题
- end
- @save = params[:save].to_i if params[:save]
+ # if @uncomplete_question.count < 1
+ # # 查看是否有已提交记录
+ # cur_exercise_user.score = @score
+ # if cur_exercise_user.save
+ # #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
+ # @status = 0 #提交成功
+ # else
+ # @status = 2 #未知错误
+ # end
+ # else
+ # @status = 1 #有未做得必答题
+ # end
+ # @save = params[:save].to_i if params[:save]
respond_to do |format|
format.js
end
end
end
+ # 获取学生未答情况
+ def get_student_uncomplete_question
+ time_limit = @exercise.time == -1 || @exercise.time.nil?
+ uncomplete_count = get_uncomplete_question(@exercise, User.current).count
+ render :json => {:time_limit => time_limit, :uncomplete_count => uncomplete_count}
+ end
+
+ # 主观题打分
+ def edit_question_score
+ exercise_user = @exercise.exercise_users.where(:user_id => params[:user_id].to_i).first
+ exercise_answer = ExerciseAnswer.where(:user_id => params[:user_id].to_i, :exercise_question_id => params[:exercise_question_id].to_i).first
+ exercise_question = ExerciseQuestion.where(:id => params[:exercise_question_id].to_i).first
+ if exercise_user && exercise_answer && exercise_question
+ score = params[:score].to_i
+ unless score > exercise_question.question_score || score < 0
+ exercise_answer.update_attributes(:score => score)
+ exercise_user.update_attributes(:subjective_score => calculate_subjective_score(@exercise, exercise_user.user))
+ exercise_user.update_attributes(:score => ((exercise_user.objective_score > 0 ? exercise_user.objective_score : 0) + (exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
+ render :json => {:status => 1, :score => score, :total_score => exercise_user.score}
+ else
+ render :json => {:status => 2}
+ end
+ else
+ render :json => {:status => 0}
+ end
+ end
+
#查看学生的答卷情况
def show_student_result
@user = User.find params[:user_id]
@can_edit_excercise = false
@exercise_questions = @exercise.exercise_questions
- score = calculate_student_score(@exercise, @user)
- eu = get_exercise_user(@exercise.id, @user.id)
- eu.update_attributes(:score => score)
+ #score = calculate_student_score(@exercise, @user)
+ #eu = get_exercise_user(@exercise.id, @user.id)
+ #eu.update_attributes(:score => score)
@exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first
@left_nav_type = 8
respond_to do |format|
@@ -619,6 +757,19 @@ class ExerciseController < ApplicationController
score = score1 + score2 + score3
end
+ # 计算主观题总分
+ def calculate_subjective_score exercise, user
+ score = 0
+ exercise_questions = exercise.exercise_questions.where(:question_type => 4)
+ exercise_answers = user.exercise_answer.where(:exercise_question_id => exercise_questions.map(&:id))
+ exercise_answers.each do |ea|
+ if ea.score != -1
+ score += ea.score
+ end
+ end
+ score
+ end
+
#导入试卷的弹框
def other_exercise
# 查作者是我,或者作者是当前课程的老师,且不在当前课程内的试卷 进行导入
@@ -716,7 +867,7 @@ class ExerciseController < ApplicationController
sheet1 = book.create_worksheet :name => "exercise"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
sheet1.row(0).default_format = blue
- sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
+ sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_objective_score),l(:excel_subjective_score),l(:excel_f_score),l(:excel_answer_time)])
count_row = 1
items.each do |exercise|
sheet1[count_row,0]=exercise.user.id
@@ -724,9 +875,10 @@ class ExerciseController < ApplicationController
sheet1[count_row,2] = exercise.user.login
sheet1[count_row,3] = exercise.user.user_extensions.student_id
sheet1[count_row,4] = exercise.user.mail
- sheet1[count_row,5] = ""
- sheet1[count_row,6] = exercise.score
- sheet1[count_row,7] = format_time(exercise.created_at)
+ sheet1[count_row,5] = exercise.objective_score == -1 ? "0.0" : format("%.1f",exercise.objective_score)
+ sheet1[count_row,6] = exercise.subjective_score == -1 ? "0.0" : format("%.1f",exercise.subjective_score)
+ sheet1[count_row,7] = exercise.score
+ sheet1[count_row,8] = exercise.commit_status == 0 ? l(:excel_no_answer) : format_time(exercise.created_at)
count_row += 1
end
book.write xls_report
diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb
index 031a228ce..cb6c1505b 100644
--- a/app/controllers/homework_common_controller.rb
+++ b/app/controllers/homework_common_controller.rb
@@ -105,8 +105,8 @@ class HomeworkCommonController < ApplicationController
else
@homework.publish_time = params[:homework_common][:publish_time]
end
- param_end_time = Time.parse(params[:homework_common][:end_time])
- homework_end_time = @homework.end_time ? @homework.end_time : ''
+ param_end_time = Time.parse(params[:homework_common][:end_time]).to_s
+ homework_end_time = @homework.end_time ? @homework.end_time.to_s : ''
if homework_end_time != param_end_time
if homework_end_time > param_end_time
@homework.student_works.where("work_status = 1").each do |st|
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 1e30e6618..41c62cf85 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1009,14 +1009,15 @@ class UsersController < ApplicationController
new_homework.anonymous_comment = 1
new_homework.quotes = 0
new_homework.is_open = 0
- # homework.attachments.each do |attachment|
- # att = attachment.copy
- # att.container_id = nil
- # att.container_type = nil
- # att.copy_from = attachment.id
- # att.save
- # new_homework.attachments << att
- # end
+ new_homework.homework_bank_id = homework.id
+ homework.attachments.each do |attachment|
+ att = attachment.copy
+ att.container_id = nil
+ att.container_type = nil
+ att.copy_from = attachment.id
+ att.save
+ new_homework.attachments << att
+ end
#homework_detail_manual = homework.homework_detail_manual
#homework_detail_programing = homework.homework_detail_programing
#homework_detail_group = homework.homework_detail_group
@@ -1268,14 +1269,14 @@ class UsersController < ApplicationController
#@homework.end_time = homework.end_time
@homework.homework_type = homework.homework_type
#@homework.course_id = homework.course_id
- # homework.attachments.each do |attachment|
- # att = attachment.copy
- # att.container_id = nil
- # att.container_type = nil
- # att.copy_from = attachment.id
- # att.save
- # @homework.attachments << att
- # end
+ homework.attachments.each do |attachment|
+ att = attachment.copy
+ att.container_id = nil
+ att.container_type = nil
+ att.copy_from = attachment.id
+ att.save
+ @homework.attachments << att
+ end
#if homework_detail_programing
if homework.homework_type == 2
@@ -1494,6 +1495,7 @@ class UsersController < ApplicationController
if params[:quotes] && !params[:quotes].blank?
quotes_homework = HomeworkBank.find params[:quotes].to_i
quotes_homework.update_column(:quotes, quotes_homework.quotes+1)
+ homework.update_attributes(:homework_bank_id => quotes_homework.id)
end
if params[:add_to_bank]
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 6dd20aceb..0ddca7032 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -2532,6 +2532,8 @@ module ApplicationHelper
candown = true
elsif attachment.container.class.to_s=="ContestantWork"
candown = true
+ elsif attachment.container.class.to_s=="HomeworkBank"
+ candown = true
elsif attachment.container.class.to_s=="BlogComment" #博客资源允许下载
candown = true
elsif attachment.container.class.to_s=="Memo" #论坛资源允许下载
@@ -3123,77 +3125,85 @@ module ApplicationHelper
#根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量
def user_for_homework_common homework,is_teacher,work
count = homework.student_works.has_committed.count
- if User.current.member_of_course?(homework.course)
- if is_teacher #老师显示作品数量
- link_to "作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => "c_blue"
- else #学生显示提交作品、修改作品等按钮
- work = cur_user_works_for_homework homework
- project = cur_user_projects_for_homework homework
- if work.nil? && homework.end_time >= Time.now
- if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
- link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
- else
- link_to "提交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
- end
- elsif work.nil? && homework.end_time < Time.now
- if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
- link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
- else
- link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red'
- end
- else
- if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前
- if homework.homework_type != 3
- link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "开启匿评后不可修改作品"
+ if User.current.logged?
+ if User.current.member_of_course?(homework.course)
+ if is_teacher #老师显示作品数量
+ link_to "作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => "c_blue"
+ else #学生显示提交作品、修改作品等按钮
+ work = cur_user_works_for_homework homework
+ project = cur_user_projects_for_homework homework
+ if work.nil? && homework.end_time >= Time.now
+ if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
+ link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
else
- work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")"
- if User.current.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count > 0
+ link_to "提交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
+ end
+ elsif work.nil? && homework.end_time < Time.now
+ if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
+ link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
+ else
+ link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red'
+ end
+ else
+ if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前
+ if homework.homework_type != 3
link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "开启匿评后不可修改作品"
else
- link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "匿评开启后提交的作品不参与匿评"
+ work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")"
+ if User.current.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count > 0
+ link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "开启匿评后不可修改作品"
+ else
+ link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "匿评开启后提交的作品不参与匿评"
+ end
end
+ elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3
+ link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "匿评已结束"
+ elsif homework.homework_type == 2 && homework.end_time >= Time.now#编程作业不能修改作品
+ link_to "修改作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
+ elsif homework.end_time >= Time.now && work.user_id == User.current.id
+ link_to "修改作品(#{count})", edit_student_work_url_without_domain(work.id),:class => 'c_blue'
+ else
+ link_to "查看作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "作业截止后不可修改作品"
end
- elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3
- link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "匿评已结束"
- elsif homework.homework_type == 2 && homework.end_time >= Time.now#编程作业不能修改作品
- link_to "修改作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
- elsif homework.end_time >= Time.now && work.user_id == User.current.id
- link_to "修改作品(#{count})", edit_student_work_url_without_domain(work.id),:class => 'c_blue'
- else
- link_to "查看作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "作业截止后不可修改作品"
end
end
+ else
+ link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue", :onclick => "notice_sure_box('您不是班级成员,不能提交作品
请先从老师处获取邀请码后加入班级,再提交作品')"
end
else
- link_to "作品(#{count})",student_work_index_url_in_org(homework.id, 2),:class => "c_blue"
+ link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue", :onclick => "login_notice_box('#{signin_url_without_domain}');"
end
end
#根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量
def user_for_contest_work homework,is_contestant,work
count = homework.contestant_works.has_committed.count
- if User.current.member_of_contest?(homework.contest)
- if !is_contestant #老师显示作品数量
- link_to "作品(#{count})", contestant_works_path(:work =>homework.id, :tab => 2), :class => "c_blue"
- else #学生显示提交作品、修改作品等按钮
- work = cur_user_works_for_work homework
- project = cur_user_projects_for_work homework
- if work.nil? && homework.work_status == 1
- if homework.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project
- link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
+ if User.current.logged?
+ if User.current.member_of_contest?(homework.contest)
+ if !is_contestant #老师显示作品数量
+ link_to "作品(#{count})", contestant_works_path(:work =>homework.id, :tab => 2), :class => "c_blue"
+ else #学生显示提交作品、修改作品等按钮
+ work = cur_user_works_for_work homework
+ project = cur_user_projects_for_work homework
+ if work.nil? && homework.work_status == 1
+ if homework.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project
+ link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
+ else
+ link_to "提交作品(#{count})", new_contestant_work_path(:work => homework.id),:class => 'c_blue'
+ end
else
- link_to "提交作品(#{count})", new_contestant_work_path(:work => homework.id),:class => 'c_blue'
- end
- else
- if homework.work_status == 1 && work.user_id == User.current.id
- link_to "修改作品(#{count})", edit_contestant_work_path(work.id),:class => 'c_blue'
- else
- link_to "查看作品(#{count})", contestant_works_path(:work =>homework.id, :tab => 2), :class => 'c_blue', :title => "不可修改作品"
+ if homework.work_status == 1 && work.user_id == User.current.id
+ link_to "修改作品(#{count})", edit_contestant_work_path(work.id),:class => 'c_blue'
+ else
+ link_to "查看作品(#{count})", contestant_works_path(:work =>homework.id, :tab => 2), :class => 'c_blue', :title => "不可修改作品"
+ end
end
end
+ else
+ link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue", :onclick => "notice_sure_box('您不是参赛者,不能提交作品
请加入竞赛,待审批通过后再提交作品')"
end
else
- link_to "作品(#{count})",contestant_works_path(:work =>homework.id, :tab => 2),:class => "c_blue"
+ link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue", :onclick => "login_notice_box('#{signin_url_without_domain}');"
end
end
@@ -4141,6 +4151,15 @@ def add_to_homework_bank_f homework
homework_bank.max_num = homework.homework_detail_group.max_num
homework_bank.base_on_project = homework.homework_detail_group.base_on_project
end
+ homework.attachments.each do |attachment|
+ att = attachment.copy
+ att.container_id = nil
+ att.container_type = nil
+ att.author_id = homework_bank.user_id
+ att.copy_from = attachment.id
+ att.save
+ homework_bank.attachments << att
+ end
homework_bank
end
diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb
index 6dadf92b5..6216d6aee 100644
--- a/app/helpers/exercise_helper.rb
+++ b/app/helpers/exercise_helper.rb
@@ -112,16 +112,30 @@ module ExerciseHelper
end
def get_current_score exercise
- score = 0
+ total_score = 0
+ mc_score = 0
+ mcq_score = 0
+ single_score = 0
+ multi_score = 0
unless exercise.nil?
exercise.exercise_questions.each do |exercise_question|
unless exercise_question.question_score.nil?
- score += exercise_question.question_score
+ total_score += exercise_question.question_score
+ case exercise_question.question_type
+ when 1
+ mc_score += exercise_question.question_score
+ when 2
+ mcq_score += exercise_question.question_score
+ when 3
+ single_score += exercise_question.question_score
+ when 4
+ multi_score += exercise_question.question_score
+ end
end
end
- return score
+ return total_score, mc_score, mcq_score, single_score, multi_score
end
- return score
+ return total_score, mc_score, mcq_score, single_score, multi_score
end
def answer_be_selected?(answer,user)
@@ -175,4 +189,43 @@ module ExerciseHelper
standard_answer
end
+ # 问题随机的下拉列表
+ def question_random_select
+ type = []
+ option1 = []
+ option1 << "题目不随机打乱"
+ option1 << 0
+ type << option1
+ option2 = []
+ option2 << "题目随机打乱"
+ option2 << 1
+ type << option2
+ end
+
+ # 选项随机的下拉列表
+ def choice_random_select
+ type = []
+ option1 = []
+ option1 << "选项不随机打乱"
+ option1 << 0
+ type << option1
+ option2 = []
+ option2 << "选项随机打乱"
+ option2 << 1
+ type << option2
+ end
+
+ #允许学生查看结果的下拉列表
+ def show_result_select
+ type = []
+ option1 = []
+ option1 << "允许学生查看测验结果"
+ option1 << 1
+ type << option1
+ option2 = []
+ option2 << "不允许学生查看测验结果"
+ option2 << 0
+ type << option2
+ end
+
end
\ No newline at end of file
diff --git a/app/models/homework_bank.rb b/app/models/homework_bank.rb
index e55f8ac16..b1e908a1d 100644
--- a/app/models/homework_bank.rb
+++ b/app/models/homework_bank.rb
@@ -2,6 +2,7 @@ class HomeworkBank < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :user
has_many :homework_bank_tests
+ acts_as_attachable
def language_name
%W(C C++ Python Java).at(self.language.to_i - 1)
diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb
index 92d47bcdc..3323fb331 100644
--- a/app/models/homework_common.rb
+++ b/app/models/homework_common.rb
@@ -10,6 +10,7 @@ class HomeworkCommon < ActiveRecord::Base
belongs_to :course
belongs_to :user
+ belongs_to :homework_bank
has_one :homework_detail_manual, :dependent => :destroy
has_one :homework_detail_programing, :dependent => :destroy
has_one :homework_detail_group, :dependent => :destroy
diff --git a/app/views/courses/_show_member_act_score.html.erb b/app/views/courses/_show_member_act_score.html.erb
index 8a113c31e..5fa4eb273 100644
--- a/app/views/courses/_show_member_act_score.html.erb
+++ b/app/views/courses/_show_member_act_score.html.erb
@@ -1,14 +1,19 @@
-
+
<%= exercise.exercise_description.nil? ? "" :exercise.exercise_description.html_safe%>