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 @@ - +
+
+

作业积分

+ +
+
<% act_score = CourseContributorScore.where("user_id = ? and course_id = ?", member.user_id, member.course_id).first %>

<%= member.user.show_name %> 活跃度计算

<% if act_score.nil? %> -
+
资源发布数 x 5 = 0 x 5 = 0
问答发布数 x 2 = 0 x 2 = 0
通知发布数 x 1 = 0 x 1 = 0
@@ -23,7 +28,7 @@ act_score.message_reply_num.to_i * 1 + act_score.journal_num.to_i * 1 + + act_score.homework_journal_num.to_i * 1 + act_score.news_reply_num.to_i * 1 + act_score.news_num.to_i * 1 %> -
+
资源发布数 x 5 = <%= act_score.resource_num.to_i %> x 5 = <%= act_score.resource_num.to_i * 5 %>
问答发布数 x 2 = <%= act_score.message_num.to_i %> x 2 = <%= act_score.message_num.to_i * 2 %>
通知发布数 x 1 = <%= act_score.news_num.to_i %> x 1 = <%= act_score.news_num.to_i %>
@@ -36,3 +41,4 @@ <% end %>
+
\ No newline at end of file diff --git a/app/views/courses/_show_member_score.html.erb b/app/views/courses/_show_member_score.html.erb index 80c2ef5cc..19e07ad5a 100644 --- a/app/views/courses/_show_member_score.html.erb +++ b/app/views/courses/_show_member_score.html.erb @@ -1,22 +1,24 @@ +
+
+

作业积分

+ +
+
-

<%= @member_score.user.name %> 历次作业积分

+

<%= @member_score.user.show_name %> 历次作业积分

    -
  • 作业名称得分
  • +
  • 作业名称得分
  • <% @member_score.homework_common_list.each_with_index do |homework_common, index| %>
  • @@ -28,7 +30,8 @@
  • <% end %> -
  • 作业积分(总分)<%= format("%0.2f",(@member_score.student_work_score_sum).first.score.nil? ? 0 : (@member_score.student_work_score_sum).first.score) %>
  • +
  • 作业积分(总分)<%= format("%0.2f",(@member_score.student_work_score_sum).first.score.nil? ? 0 : (@member_score.student_work_score_sum).first.score) %>
+
\ No newline at end of file diff --git a/app/views/courses/show_member_act_score.js.erb b/app/views/courses/show_member_act_score.js.erb index c6327d164..fc386ddf3 100644 --- a/app/views/courses/show_member_act_score.js.erb +++ b/app/views/courses/show_member_act_score.js.erb @@ -1,7 +1,2 @@ -$('#ajax-modal').html('<%= escape_javascript(render :partial => 'courses/show_member_act_score', :locals => {:member => @member}) %>'); -showModal('ajax-modal', '300px'); -$('#ajax-modal').siblings().remove(); -$('#ajax-modal').before("" + - ""); -$('#ajax-modal').parent().css("top","30%").css("left","40%").css("position","fixed").css("border","3px solid #269ac9"); -$('#ajax-modal').parent().addClass("new-watcher"); \ No newline at end of file +var htmlvalue = "<%= escape_javascript(render :partial => 'courses/show_member_act_score', :locals => {:member => @member}) %>"; +pop_box_new(htmlvalue, 280, 235); \ No newline at end of file diff --git a/app/views/courses/show_member_score.js.erb b/app/views/courses/show_member_score.js.erb index d30c69f03..ce32a192c 100644 --- a/app/views/courses/show_member_score.js.erb +++ b/app/views/courses/show_member_score.js.erb @@ -1,13 +1,2 @@ -//$('#ajax-modal').html('<%#= escape_javascript(render :partial => 'courses/show_member_score', :locals => {:member => @member_score}) %>'); -//showModal('ajax-modal', '400px'); -//$('#ajax-modal').addClass('new-watcher'); - -$('#ajax-modal').html('<%= escape_javascript(render :partial => 'courses/show_member_score', :locals => {:member => @member_score}) %>'); -showModal('ajax-modal', '400px'); -//$('#ajax-modal').css('height','569px'); -$('#ajax-modal').siblings().remove(); -$('#ajax-modal').before("" + -""); -//$('#ajax-modal').parent().removeClass(); -$('#ajax-modal').parent().css("top","30%").css("left","40%").css("position","fixed").css("border","3px solid #269ac9"); -$('#ajax-modal').parent().addClass("new-watcher"); +var htmlvalue = "<%= escape_javascript(render :partial => 'courses/show_member_score', :locals => {:member => @member_score}) %>"; +pop_box_new(htmlvalue, 430, 520); \ No newline at end of file diff --git a/app/views/exercise/_edit_MC.html.erb b/app/views/exercise/_edit_MC.html.erb index af1446342..8a6057b87 100644 --- a/app/views/exercise/_edit_MC.html.erb +++ b/app/views/exercise/_edit_MC.html.erb @@ -3,58 +3,64 @@
+
+ + 分 + <%=convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> + 标准答案: +
+
- +
+
+
diff --git a/app/views/exercise/_edit_MCQ.html.erb b/app/views/exercise/_edit_MCQ.html.erb index 68737bb57..738416a69 100644 --- a/app/views/exercise/_edit_MCQ.html.erb +++ b/app/views/exercise/_edit_MCQ.html.erb @@ -3,56 +3,64 @@
+
+ + 分 + <%=convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> + 标准答案: +
+
- +
+
diff --git a/app/views/exercise/_edit_head.html.erb b/app/views/exercise/_edit_head.html.erb index a071904ce..6c8e165a0 100644 --- a/app/views/exercise/_edit_head.html.erb +++ b/app/views/exercise/_edit_head.html.erb @@ -16,13 +16,15 @@
- diff --git a/app/views/exercise/_edit_multi.html.erb b/app/views/exercise/_edit_multi.html.erb new file mode 100644 index 000000000..2e2721282 --- /dev/null +++ b/app/views/exercise/_edit_multi.html.erb @@ -0,0 +1,39 @@ +<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%> + + + +
+
+ + 分 +
+
+
+ + + +
+ +
+
+ + +
+
+
+ +
+
+ +<% end%> \ No newline at end of file diff --git a/app/views/exercise/_edit_single.html.erb b/app/views/exercise/_edit_single.html.erb index d1b8cd155..3645b0825 100644 --- a/app/views/exercise/_edit_single.html.erb +++ b/app/views/exercise/_edit_single.html.erb @@ -3,52 +3,57 @@
-
- - - +
+ + 分 +
+
+ + + +
+
    -
  • - - 分 -
  • -
    <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> -
  • - - - +
  • + +
  • <% end %> +
  • +
    新建参考答案
    +
  • +
diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb index 0def72c12..ac19d1908 100644 --- a/app/views/exercise/_exercise.html.erb +++ b/app/views/exercise/_exercise.html.erb @@ -1,10 +1,10 @@ <%# has_commit = has_commit_poll?(poll.id ,User.current)%> <% exercise_name = exercise.exercise_name.empty? ? l(:label_poll_new) : exercise.exercise_name%> <% if @is_teacher%> -
-
-
- <%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_w fl c_dblue mw450", :title => "#{exercise_name}" %> +
+
+
+ <%= link_to (index.to_i+1).to_s+". "+exercise_name, student_exercise_list_exercise_path(exercise.id,:course_id => @course.id), :class => "polls_title polls_title_w fl c_dblue mw450", :title => "#{exercise_name}" %> <% if exercise.exercise_status == 1 %> <% elsif exercise.exercise_status == 2 %> @@ -12,23 +12,34 @@ <% else %> <% end%> -
+
- <% if exercise.exercise_status == 1 %> - <% end_time_status = exercise.end_time.nil? ? 1 : (exercise.end_time <= Time.now ? 2 : 3) %> - - <% elsif exercise.exercise_status == 2%> - - <% else%> -
发布试卷
- <% end%> - - <% if exercise.exercise_status == 1%> -
统计结果
- <% else %> -
<%= link_to l(:label_statistical_results), student_exercise_list_exercise_path(exercise.id,:course_id => @course.id), :class => "pollsbtn fr mr10"%>
- <% end%> + +
@@ -39,15 +50,11 @@ <% if exercise.exercise_status > 1 %> 已提交:<%= exercise.exercise_users.where("commit_status = 1").count %> 未提交:<%= exercise.course.student.count - exercise.exercise_users.where("commit_status = 1").count %> + <% if exercise.exercise_status == 3 %> + <% count = exercise.exercise_users.where("commit_status = 1 and subjective_score = -1").count %> + 未批:<%= count %> + <% end %> <% end %> - -
- - <% if exercise.exercise_status == 1 %> - <%= link_to '', edit_exercise_path(exercise.id), :title => "编辑试卷", :class => "ex_icon_edit mt0"%> - <% end%> -
-
<% else%> diff --git a/app/views/exercise/_exercise_content.html.erb b/app/views/exercise/_exercise_content.html.erb index 14add37ec..92cc2f0dd 100644 --- a/app/views/exercise/_exercise_content.html.erb +++ b/app/views/exercise/_exercise_content.html.erb @@ -1,11 +1,12 @@ <% mc_question_list = exercise.exercise_questions.where("question_type=1") %> <% mcq_question_list = exercise.exercise_questions.where("question_type=2") %> <% single_question_list = exercise.exercise_questions.where("question_type=3") %> +<% multi_question_list = exercise.exercise_questions.where("question_type=4") %>
">

单选题

- <% mc_question_list.each do |exercise_question| %> + <% mc_question_list.each_with_index do |exercise_question, index| %>
-
+
<%= render :partial => 'show_MC', :locals => {:exercise_question => exercise_question} %>
">

多选题

- <% mcq_question_list.each do |exercise_question| %> + <% mcq_question_list.each_with_index do |exercise_question, index| %>
-
+
<%= render :partial => 'show_MCQ', :locals => {:exercise_question => exercise_question} %>
">

填空题

- <% single_question_list.each do |exercise_question| %> + <% single_question_list.each_with_index do |exercise_question, index| %>
-
+
<%= render :partial => 'show_single', :locals => {:exercise_question => exercise_question} %>
<% end %> +
+
"> +

问答题

+ <% multi_question_list.each_with_index do |exercise_question, index| %> +
+
+ <%= render :partial => 'show_multi', :locals => {:exercise_question => exercise_question} %> +
+ +
+ <% end %>
\ No newline at end of file diff --git a/app/views/exercise/_exercise_course_list.html.erb b/app/views/exercise/_exercise_course_list.html.erb new file mode 100644 index 000000000..26c3f282b --- /dev/null +++ b/app/views/exercise/_exercise_course_list.html.erb @@ -0,0 +1,10 @@ +<% if !courses.empty? %> + <% courses.each do |course| %> +
    +
  • + + +
  • +
+ <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index cb41cf26b..5ffec6604 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -84,19 +84,19 @@ { var title = $.trim($("#poll_questions_title").val()); var score = $.trim($("#question_score").val()); - var standard_ans = $.trim($("#question_standard_ans").val()); + var standard_ans = $.trim($("#exercise_choice_" + quest_type).val()); if(title.length == 0 || score.length == 0){ - alert("题目标题/分数不能为空"); + notice_box("题目标题/分数不能为空"); doc.one('click', function(){ add_poll_question($(this),quest_type); }); }else if(!/^[1-9][0-9]*$/.test(score)) { - alert("分数必须是非零开头的数字"); + notice_box("分数必须是非零开头的数字"); doc.one('click', function(){ add_poll_question($(this),quest_type); }); - }else if(quest_type !=3 && standard_ans.length == 0) { - alert("标准答案不能为空"); + }else if(quest_type !=3 && quest_type !=4 && standard_ans.length == 0) { + notice_box("标准答案不能为空"); doc.one('click', function(){ add_poll_question($(this),quest_type); }); @@ -108,13 +108,13 @@ { var title = $.trim($("#poll_questions_title_" + id).val()); var score = $.trim($("#poll_question_score_"+ id).val()); - var standard_ans = $.trim($("#poll_question_standard_answer_" + id).val()); + var standard_ans = $.trim($("#exercise_choice_" + id).val()); if(title.length == 0 || score.length == 0){ - alert("题目标题/分数不能为空"); + notice_box("题目标题/分数不能为空"); }else if(!/^[1-9][0-9]*$/.test(score)) { - alert("分数必须是非零开头的数字"); - }else if(quest_type !=3 && standard_ans.length == 0) { - alert("标准答案不能为空"); + notice_box("分数必须是非零开头的数字"); + }else if(quest_type !=3 && quest_type !=4 && standard_ans.length == 0) { + notice_box("标准答案不能为空"); }else if(quest_type ==3) { var div = $("#poll_answers_" + id); var candiate_answer = $(".candiate_answer",div); @@ -123,7 +123,7 @@ if(i" + - ""+ - "
"); - var select_items =$("label[name='select_items']",li.parent()); - for(var i=0; i:   "); + // 选项的选择 + function toggle_select(doc, type, id){ + if(doc.hasClass("question_choice_blue")){ + doc.removeClass("question_choice_blue").addClass("question_choice_white"); + if(type == "1"){ + $("#question_standard_answer_" + id).html("请点击选项"); + $("#exercise_choice_" + id).val(""); + }else{ + var eles = doc.parent().parent().find("a.question_choice_blue"); + var str = ""; + if(eles.length > 0){ + for(var i=0; i" + + ""+ + "
"); + var select_items =$("li.new_answer",li.parent()); + li.prev().prev().find("a.question_choice_white").html(String.fromCharCode(64 + select_items.length)); + doc.prev("a.question_choice_dash").html(String.fromCharCode(64 + select_items.length + 1)); + } function add_candidate_answer(doc) { - doc.parent().after("
  • " + - ""+ + var select_items =$("li.new_answer",doc.parent().parent()); + var li = doc.parent().before("
  • " + + ""+ "
  • "); - var select_items =$("label[name='candiate_items']",doc.parent().parent()); - for(var i=0; i:   "); - } } function revert_to_chinese_num(num){ var s_num = ""; @@ -208,19 +243,20 @@ { if(doc.parent().siblings("li").length == 0) { - alert("至少有一个选项或一个候选答案"); + notice_box("至少有一个选项或一个参考答案"); } else { var parent = doc.parent().parent(); doc.parent().remove(); - var select_items =$("label[name='select_items']",parent); + + var select_items =$("li.ur_item",parent); var candiate_items =$("label[name='candiate_items']",parent); for(var i=0; i:   "); + $(select_items[i]).find("a.choice_btn").html(String.fromCharCode(64 + parseInt(i+1))); } for(var i=0; i:   "); + $(candiate_items[i]).html("参考答案"+revert_to_chinese_num(i + 1)+":   "); } } } @@ -234,9 +270,7 @@
    <%= render :partial => 'edit_head', :locals => {:exercise => @exercise} %>
    - <% current_score = get_current_score @exercise %> -
    " id="current_score_div">目前试卷总分:<%= current_score %> - 分
    +
    <%= render :partial => 'exercise_content', :locals => {:exercise => @exercise} %> @@ -251,6 +285,11 @@
    + <% current_score = get_current_score @exercise %> +
    + <%= render :partial => 'exercise/total_questions_score', :locals => {:exercise => @exercise, :current_score => current_score} %> +
    +
    <%= render :partial => 'exercise_submit', :locals => {:exercise => @exercise} %>
    diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index 02db5e766..bae12dab5 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -57,26 +57,40 @@ 剩余时长: 小时  分钟  秒 -->
    -
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    -
    +
    <%= exercise.exercise_description.nil? ? "" :exercise.exercise_description.html_safe%>
    - <% mc_question_list = exercise.exercise_questions.where("question_type=1").shuffle %> - <% mcq_question_list = exercise.exercise_questions.where("question_type=2").shuffle %> - <% single_question_list = exercise.exercise_questions.where("question_type=3").shuffle %> + + <% current_score = get_current_score exercise %> +
    + <%= render :partial => 'exercise/total_questions_score', :locals => {:exercise => exercise, :current_score => current_score} %> +
    + + <% mc_question_list = exercise.exercise_questions.where("question_type=1") %> + <% mcq_question_list = exercise.exercise_questions.where("question_type=2") %> + <% single_question_list = exercise.exercise_questions.where("question_type=3") %> + <% multi_question_list = exercise.exercise_questions.where("question_type=4") %> + <% if exercise.question_random == 1 %> + <% mc_question_list = mc_question_list.shuffle %> + <% mcq_question_list = mcq_question_list.shuffle %> + <% single_question_list = single_question_list.shuffle %> + <% multi_question_list =multi_question_list.shuffle %> + <% end %>
    ">

    单选题

    <% mc_question_list.each_with_index do |exercise_question, list_index| %>
    -
    +
    -
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) +
    + 第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分)
    -
    - +
    +
    - <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + <% exercise_choices = exercise.choice_random == 1 ? exercise_question.exercise_choices.shuffle : exercise_question.exercise_choices.reorder("choice_position") %> + <% exercise_choices.each_with_index do |exercise_choice,index| %>