diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb
index 5ad869462..b11b5d174 100644
--- a/app/controllers/challenges_controller.rb
+++ b/app/controllers/challenges_controller.rb
@@ -2,13 +2,16 @@
class ChallengesController < ApplicationController
layout "base_shixun"
before_filter :check_authentication
- before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation]
- before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation]
+ before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose]
+ before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose]
before_filter :build_challege_from_params, :only => [:new, :create]
before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create]
before_filter :allowed_view, :only => [:show]
before_filter :query_challeges, :only => [:show, :edit, :update, :update_evaluation]
before_filter :find_shixun_language, :only => [:show, :new, :edit]
+ #before_filter :default_format_js, only: :new_or_edit_choose_question
+
+ #skip_before_filter :verify_authenticity_token, :only => [:new_or_edit_choose_question]
include ApplicationHelper
@@ -30,6 +33,8 @@ class ChallengesController < ApplicationController
@challenge.shixun = @shixun
@challenge.user = User.current
@challenge.st = params[:st].to_i
+ @challenge.save!
+=begin
if @challenge.save!
if params[:st].to_i != 0
#创建选项
@@ -39,6 +44,7 @@ class ChallengesController < ApplicationController
end
end
end
+=end
# 实训是否需要重启
# 非实践任务创建第一个阶段时调用 publishGame, 避免不包含实践任务的实训进行模拟实战时报错
if @challenge.position == 1 && params[:st].to_i != 0
@@ -91,9 +97,117 @@ class ChallengesController < ApplicationController
if challenge_pos < challenge_num
@next_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos+1).first
end
- @prev_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos - 1).first if challenge_pos - 1 > 0
+ @prev_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos - 1).first if (challenge_pos - 1) > 0
@tab = params[:tab].blank? ? 1 : params[:tab].to_i
@editor = params[:editor] # 编辑模式
+ respond_to do |format|
+ format.html
+ format.js
+ end
+ end
+
+ def new_choose_question
+ ActiveRecord::Base.transaction do
+ begin
+ @challenge_choose = ChallengeChoose.new
+ @challenge_choose.challenge_id = @challenge.id
+ @challenge_choose.subject = params[:choose][:subject]
+ @challenge_choose.answer = params[:choose][:answer]
+ @challenge_choose.standard_answer = params[:standard_answer]
+ @challenge_choose.score = params[:challenge][:score].to_i
+ @challenge_choose.difficult = params[:challenge][:difficulty].to_i
+ @challenge_choose.position = params[:position].to_i
+ @challenge_choose.category = params[:category].to_i
+ if @challenge_choose.save!
+ # 创建选项
+ params[:question][:cnt].each_with_index do |test, index|
+ answer = params[:choice][:answer][index] == "0" ? false : true
+ ChallengeQuestion.create(:option_name => test, :challenge_choose_id => @challenge_choose.id, :position => index, :right_key => answer)
+ end
+ # 创建单选多选的技能标签
+ unless params[:knowledge].blank?
+ params[:knowledge][:input].each do |input|
+ ChallengeTag.create(:name => input, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id)
+ end
+ end
+ end
+ @index = params[:position].to_i - 1
+ respond_to do |format|
+ format.js
+ end
+ rescue Exception => e
+ flash[:error] = "#{e.message}"
+ redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)
+ raise ActiveRecord::Rollback
+ end
+ end
+ end
+
+ def update_choose_question
+ @challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
+ ActiveRecord::Base.transaction do
+ @challenge_choose.update_attributes(:subject => params[:choose][:subject],
+ :answer => params[:choose][:answer],
+ :standard_answer => params[:standard_answer],
+ :score => params[:challenge][:score].to_i,
+ :difficult => params[:challenge][:difficulty].to_i)
+ begin
+ @challenge_choose.challenge_questions.delete_all
+ params[:question][:cnt].each_with_index do |test, index|
+ answer = params[:choice][:answer][index] == "0" ? false : true
+ ChallengeQuestion.create(:option_name => test, :challenge_choose_id => @challenge_choose.id, :position => index, :right_key => answer)
+ end
+ @challenge_choose.challenge_tags.delete_all unless @challenge_choose.challenge_tags.blank?
+ unless params[:knowledge].blank?
+ params[:knowledge][:input].each do |input|
+ ChallengeTag.create(:name => input, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id)
+ end
+ end
+ @challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
+ @index = params[:index].to_i
+ respond_to do |format|
+ format.js
+ end
+ rescue Exception => e
+ flash[:error] = "#{e.message}"
+ format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
+ raise ActiveRecord::Rollback
+ end
+ end
+ end
+
+ def edit_choose_question
+ @challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
+ @category = @challenge_choose.category
+ @position = @challenge_choose.position.to_i
+ @index = params[:index].to_i
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def choose_type_show
+ @challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
+ @index = params[:index].to_i
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def destroy_challenge_choose
+ @challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
+ @challenge_choose.destroy
+
+ redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)
+ end
+
+ def add_choose_question
+ @category = params[:category].to_i
+ @position = params[:position]
+ #@challenge_choose = @challenge.challenge_chooses
+ respond_to do |format|
+ format.js
+ end
end
def destroy
@@ -108,22 +222,22 @@ class ChallengesController < ApplicationController
def update
ActiveRecord::Base.transaction do
@challenge.update_attributes(params[:challenge])
- if (params[:tab] == "1" || params[:tab].nil?) && @challenge.st != 0
- begin
- @challenge.challenge_questions.delete_all
- params[:question][:cnt].each_with_index do |test, index|
- answer = params[:choice][:answer][index] == "0" ? false : true
- ChallengeQuestion.create(:option_name => test, :challenge_id => @challenge.id, :position => index, :right_key => answer)
- end
- redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
- rescue Exception => e
- flash[:error] = "#{e.message}"
- format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
- raise ActiveRecord::Rollback
- end
- else
+ #if (params[:tab] == "1" || params[:tab].nil?) && @challenge.st != 0
+ # begin
+ # @challenge.challenge_questions.delete_all
+ # params[:question][:cnt].each_with_index do |test, index|
+ # answer = params[:choice][:answer][index] == "0" ? false : true
+ # ChallengeQuestion.create(:option_name => test, :challenge_id => @challenge.id, :position => index, :right_key => answer)
+ # end
+ # redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
+ # rescue Exception => e
+ # flash[:error] = "#{e.message}"
+ # format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
+ # raise ActiveRecord::Rollback
+ # end
+ #else
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
- end
+ #end
end
end
@@ -272,4 +386,8 @@ class ChallengesController < ApplicationController
@language = language_switch language
end
+ def default_format_js
+ response.headers['content--type'] = 'text/javascript'
+ request.format = 'js'
+ end
end
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index cbae9d708..0c011a047 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -49,7 +49,7 @@ class GamesController < ApplicationController
@type = params[:type]
challenge_path = @game_challenge.path
# 用户选项
- @user_answer = @game.outputs.first.actual_output.split("") unless @st == 0 || @game.outputs.blank?
+ #@user_answer = @game.outputs.first.actual_output.split("") unless @st == 0 || @game.outputs.blank?
# 默认打开文件
logger.info("repository id is #{@repository.try(:id)}, repository's shixun_id =#{@repository.try(:myshixun_id)} shixun_id =#{@repository.try(:shixun_id)}, project_id => #{@repository.try(:project_id)}")
# 验证challenge文件名的合法性
@@ -300,53 +300,42 @@ class GamesController < ApplicationController
end
# 选择题评测(选择题不需要重新评测)
+ # score 获得金币数 tag_count 技能数 right用户是否全对 answer_right全部选择题的正确性
def evaluating_choice
@game_challenge = @game.challenge
- user_answer = params[:answer]
- correct = true
+ @challenges = Challenge.where(:shixun_id => @myshixun.shixun_id)
+ @shixun = @myshixun.shixun
score = 0
tag_count = 0
- if !user_answer.blank?
- if user_answer.split("").count != @game_challenge.challenge_questions.where(:right_key => true).count
- correct = false
- else
- user_answer.split("").each do |answer|
- question = @game_challenge.challenge_questions.where(:position => answer.to_i).first
- unless question.right_key
- correct = false
- break
- end
- end
+ @right = true
+ answer_right = []
+ @game_challenge.challenge_chooses.each_with_index do |choose, index|
+ correct = (params[:answer][index] == choose.standard_answer) ? true : false
+ if choose.choose_outputs.blank?
+ ChooseOutputs.create(:challenge_choose_id => choose.id, :user_id => User.current.id, :answer => params[:answer][index], :correct => correct)
end
- else
- correct = false
+ if @shixun.status > 1 && !@game.answer_open
+ if correct
+ score += choose.score
+ tag_count += choose.challenge_tags.count
+ end
+ elsif @shixun.status > 1 && @game.answer_open
+ score -= choose.score
+ end
+ unless correct
+ @right = false
+ end
+ answer_right << correct
end
@game.update_attributes(:status => 2, :end_time => Time.now)
- had_done = @game.had_done
- shixun = @myshixun.shixun
- if shixun.status > 1 && !@game.answer_open
- if correct
- #User.current.update_attributes(:grade => (User.current.grade + @game.challenge.score), :experience => (User.current.experience + @game.challenge.score))
- reward_grade(@game.user, @game.id, 'Game', @game_challenge.score)
- reward_experience(@game.user, @game.id, 'Game', @game_challenge.score)
- @game.update_attribute(:final_score, @game_challenge.score)
- score = @game_challenge.score
- tag_count = @game_challenge.challenge_tags.count
- else
- score = "+0"
- tag_count = 0
- end
- elsif shixun.status > 1 && @game.answer_open
- score = -@game_challenge.score.to_i
- tag_count = 0
- else
- score = "+0"
- tag_count = 0
+ @had_done = @game.had_done
+ reward_grade(@game.user, @game.id, 'Game', score)
+ reward_experience(@game.user, @game.id, 'Game', score)
+ @game.update_attribute(:final_score, score)
+
+ respond_to do |format|
+ format.js{redirect_to myshixun_game_path(@game, :myshixun_id => @myshixun, :choose => 1)}
end
- if @game.outputs.blank?
- Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct)
- end
- render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count, position: @game_challenge.position}
end
@@ -407,9 +396,19 @@ class GamesController < ApplicationController
def answer
challenge = @game.challenge
@challenge_score = challenge.score.to_i
+ @answer = ""
# 已经开启过
@score = User.current.grade.to_i - @challenge_score
- @answer = challenge.answer
+ if(params[:choose] == "true")
+ challenge.challenge_chooses.each_with_index do |choose, index|
+ @answer += "第"+ ((index + 1).to_s) +"题:
"
+ @answer += choose.answer
+ @answer += "
"
+ end
+ else
+ @answer = challenge.answer
+ end
+
if challenge.shixun.status < 2 || @game.answer_open
@viewed = 1
else
diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb
index 4019e1110..b94f6fb8f 100644
--- a/app/controllers/homework_common_controller.rb
+++ b/app/controllers/homework_common_controller.rb
@@ -251,7 +251,7 @@ class HomeworkCommonController < ApplicationController
@homework_detail_programing.ta_proportion = 0 if @homework_detail_programing
end
if @homework_detail_manual.comment_status < 4
- if params[:homework_anonymous_appeal]
+ if params[:homework_anonymous_comment] && params[:homework_anonymous_appeal]
@homework.anonymous_appeal = 1
@homework_detail_manual.appeal_time = params[:homework_appeal_time] if params[:homework_appeal_time]
@homework_detail_manual.appeal_penalty = params[:homework_appeal_penalty] if params[:homework_appeal_penalty]
@@ -338,7 +338,6 @@ class HomeworkCommonController < ApplicationController
if @homework.end_time < Time.now
@homework.student_works.each do |student_work|
set_shixun_final_score @homework, student_work, @homework_detail_manual.answer_open_evaluation
- student_work.save
end
end
end
diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb
index 1a7906775..f3191d99b 100644
--- a/app/controllers/managements_controller.rb
+++ b/app/controllers/managements_controller.rb
@@ -700,7 +700,7 @@ end
@courses = @courses.where(:homepage_show => params[:homepage_show].to_i)
end
- if params[:course_list]&& params[:course_list]!=''
+ if params[:course_list] && params[:course_list] != ''
@courses = @courses.where(:course_list_id => courselist)
end
@@ -826,6 +826,18 @@ end
end
end
+ # 导出excel
+ def export_excel
+ @course = params[:course]
+ respond_to do |format|
+ format.xls {
+ @course = @course.reorder("#{Tracker.table_name}.position, #{Course.table_name}.id").all
+ filename = "#{l(:label_course_list_xls)}.xls"
+ send_data(course_list_xls(@course), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
+ }
+ end
+ end
+
# 0 全部;1 活动的; 2 已注册; 3 锁定
def users
@menu_type
@@ -1076,16 +1088,16 @@ end
user_id = s_user_id & d_user_id & apply_user_id
if params[:research_condition] == "name"
- @users = User.where(:id => user_id).where("concat(lastname, firstname) like '%#{params[:research_contents]}%'").order("created_on desc")
+ @users = User.where(:id => user_id).where("concat(lastname, firstname) like '%#{params[:research_contents]}%'").order("last_login_on desc")
elsif params[:research_condition] == "email"
- @users = User.where(:id => user_id).where("mail like '%#{params[:research_contents]}%'").order("created_on desc")
+ @users = User.where(:id => user_id).where("mail like '%#{params[:research_contents]}%'").order("last_login_on desc")
elsif params[:research_condition] == "phone"
- @users = User.where(:id => user_id).where("phone like '%#{params[:research_contents]}%'").order("created_on desc")
+ @users = User.where(:id => user_id).where("phone like '%#{params[:research_contents]}%'").order("last_login_on desc")
elsif params[:research_condition] == "nickname"
if params[:research_contents].blank?
- @users = User.where(:id => user_id).order("created_on desc")
+ @users = User.where(:id => user_id).order("last_login_on desc")
else
- @users = User.where(:id => user_id).where("nickname like '%#{params[:research_contents]}%'").order("created_on desc")
+ @users = User.where(:id => user_id).where("nickname like '%#{params[:research_contents]}%'").order("last_login_on desc")
end
end
@@ -1367,4 +1379,32 @@ end
render_404
end
+ def course_list_xls course
+ xls_report = StringIO.new
+ book = Spreadsheet::Workbook.new
+ sheet1 = book.create_worksheet :name => "course"
+ blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
+ sheet1.row(0).default_format = blue
+ sheet1.row(0).concat([l(:issue_xls_id),l(:issue_xls_tracker_id),l(:issue_xls_title),l(:issue_xls_description),l(:issue_xls_status),l(:issue_xls_assign),l(:issue_xls_priority),l(:issue_xls_author),l(:issue_xls_created_at),l(:milestone),l(:issue_xls_start),l(:issue_xls_due),l(:issue_xls_ratio)])
+ count_row = 1
+ issues.each do |issue|
+ sheet1[count_row,0] = issue.id
+ sheet1[count_row,1] = issue_tracker_change(issue.tracker_id)
+ sheet1[count_row,2] = issue.subject
+ sheet1[count_row,3] = (issue.description.gsub(/<\/?.*?>/,"")).html_safe
+ sheet1[count_row,4] = issue_status_change(issue.status_id)
+ sheet1[count_row,5] = issue.assigned_to.try(:show_name)
+ sheet1[count_row,6] = issue_priority_change(issue.priority_id)
+ sheet1[count_row,7] = issue.author.show_name
+ sheet1[count_row,8] = issue.created_on.nil? ? issue.created_on : issue.created_on.strftime('%Y-%m-%d %H:%M:%S')
+ sheet1[count_row,9] = issue.fixed_version.try(:name)
+ sheet1[count_row,10] = issue.start_date.nil? ? issue.start_date : issue.start_date.strftime('%Y-%m-%d')
+ sheet1[count_row,11] = issue.due_date.nil? ? issue.due_date : issue.due_date.strftime('%Y-%m-%d')
+ sheet1[count_row,12] = issue_ratio_change(issue.done_ratio, issue.status_id)
+ count_row += 1
+ end
+ book.write xls_report
+ xls_report.string
+ end
+
end
diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb
index b3d7ad491..46a11ef2e 100644
--- a/app/controllers/shixuns_controller.rb
+++ b/app/controllers/shixuns_controller.rb
@@ -14,6 +14,10 @@ class ShixunsController < ApplicationController
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
+
+ def statistics_students
+
+ end
# push代码的时候会触发gitlab hook
def ghook
shixun_modify_status_without_publish(@shixun, 1)
@@ -562,11 +566,14 @@ class ShixunsController < ApplicationController
# end
# @shixun.major_id = params[:major_id]
@shixun.shixun_major_courses.destroy_all
- if CourseList.where(:name => params[:course_list].strip).count > 0
- @shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => -1, :course_list_id => CourseList.where(:name => params[:course_list].strip).first.id)
- else
- course_list = CourseList.create(:name => params[:course_list].strip, :user_id => User.current.id, :is_admin => 0)
- @shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => -1, :course_list_id => course_list.id)
+ course_lists = params[:course_list].strip.split(",")
+ course_lists.each do |course|
+ if CourseList.where(:name => course).count > 0
+ @shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => -1, :course_list_id => CourseList.where(:name => course.strip).first.id)
+ else
+ course_list = CourseList.create(:name => course.strip, :user_id => User.current.id, :is_admin => 0)
+ @shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => -1, :course_list_id => course_list.id)
+ end
end
params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0
ActiveRecord::Base.transaction do
@@ -686,9 +693,9 @@ class ShixunsController < ApplicationController
@user = User.current
if !params[:search].nil?
search = "%#{params[:search].to_s.strip.downcase}%"
- @courses = @user.courses.not_deleted_not_end.where("#{Course.table_name}.name like :p",:p=>search).select{|course| @user.allowed_to?(:as_teacher,course)}
+ @courses = @user.courses.not_deleted_not_end.where("#{Course.table_name}.name like :p",:p=>search).select{|course| @user.has_teacher_role(course)}
else
- @courses = @user.courses.not_deleted_not_end.select{|course| @user.allowed_to?(:as_teacher,course)}
+ @courses = @user.courses.not_deleted_not_end.select{|course| @user.has_teacher_role(course)}
end
@pages = Paginator.new @courses.count, 8, params['page'] || 1
@offset ||= @pages.offset
@@ -718,11 +725,11 @@ class ShixunsController < ApplicationController
homework_detail_manual.evaluation_num = 0
homework_detail_manual.absence_penalty = 0
homework.homework_detail_manual = homework_detail_manual
- if homework.save
+ if homework.save!
homework_detail_manual.save if homework_detail_manual
HomeworkCommonsShixuns.create(:homework_common_id => homework.id, :shixun_id => @shixun.id)
+ redirect_to setting_homework_common_path(homework, :is_new => 1)
end
- redirect_to setting_homework_common_path(homework, :is_new => 1)
end
private
# REDO: 新增类型copy的时候
diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb
index a5ed47268..c82cc45ad 100644
--- a/app/controllers/student_work_controller.rb
+++ b/app/controllers/student_work_controller.rb
@@ -377,11 +377,11 @@ class StudentWorkController < ApplicationController
end
#开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表
- if (@homework.is_open == 1 && User.current.member_of_course?(@course) && @homework.homework_detail_manual.comment_status == 6) || @is_teacher || User.current.admin?
+ if (@homework.work_public && User.current.member_of_course?(@course) && @homework.homework_detail_manual.comment_status == 6) || @is_teacher || User.current.admin?
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}")
@show_all = true
elsif User.current.member_of_course?(@course)
- if @homework.homework_detail_manual.comment_status == 1 || @homework.homework_detail_manual.comment_status == 2 #学生 && 未开启匿评 只看到自己的
+ if @homework.homework_detail_manual.comment_status == 1 || @homework.homework_detail_manual.comment_status == 2 || @homework.homework_detail_manual.comment_status == 5 || @homework.homework_detail_manual.comment_status == 6 #学生 && 未开启匿评 只看到自己的
if @homework.homework_type == 3
my_work = @homework.student_works.where(:user_id => User.current.id)
@stundet_works = !my_work.balnk? ? (my_work.first.group_id != 0 ? @homework.student_works.select("student_works.*,student_works.work_score as score").where(:group_id => my_work.first.group_id) : my_work) : []
@@ -389,16 +389,16 @@ class StudentWorkController < ApplicationController
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
end
elsif @homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4 #学生 && 开启匿评 看到匿评列表
- my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id).first
+ my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
- elsif @homework.homework_detail_manual.comment_status == 5 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
- my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id).first
- if !my_work || my_work.status == 0
- @stundet_works = []
- else
- @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}")
- @show_all = true
- end
+ # elsif @homework.homework_detail_manual.comment_status == 5 || @homework.homework_detail_manual.comment_status == 6 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
+ # my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id).first
+ # if !my_work || my_work.status == 0
+ # @stundet_works = []
+ # else
+ # @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}")
+ # @show_all = true
+ # end
else
@stundet_works = []
end
@@ -408,11 +408,11 @@ class StudentWorkController < ApplicationController
end
else
- if (@homework.is_open == 1 && User.current.member_of_course?(@course) && @homework.homework_detail_manual.comment_status == 6) || @is_teacher || User.current.admin?
+ if (@homework.work_public && User.current.member_of_course?(@course) && @homework.homework_detail_manual.comment_status == 6) || @is_teacher || User.current.admin?
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :student_works_scores => {}).order("#{@order} #{@b_sort}")
@show_all = true
elsif User.current.member_of_course?(@course)
- if @homework.homework_detail_manual.comment_status == 1 || @homework.homework_detail_manual.comment_status == 2 #学生 && 未开启匿评 只看到自己的
+ if @homework.homework_detail_manual.comment_status == 1 || @homework.homework_detail_manual.comment_status == 2 || @homework.homework_detail_manual.comment_status == 5 || @homework.homework_detail_manual.comment_status == 6 #学生 && 未开启匿评 只看到自己的
if @homework.homework_type == 3
my_work = @homework.student_works.where(:user_id => User.current.id)
@stundet_works = !my_work.blank? ? (my_work.first.group_id != 0 ? @homework.student_works.select("student_works.*,student_works.work_score as score").where(:group_id => my_work.first.group_id) : my_work) : []
@@ -420,16 +420,16 @@ class StudentWorkController < ApplicationController
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
end
elsif @homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4 #学生 && 开启匿评 看到匿评列表
- my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id).first
+ my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
- elsif @homework.homework_detail_manual.comment_status == 5 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
- my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id).first
- if !my_work || my_work.status == 0
- @stundet_works = []
- else
- @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}")
- @show_all = true
- end
+ # elsif @homework.homework_detail_manual.comment_status == 5 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
+ # my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id).first
+ # if !my_work || my_work.work_status == 0
+ # @stundet_works = []
+ # else
+ # @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}")
+ # @show_all = true
+ # end
else
@stundet_works = []
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index f065461f1..1df371b9b 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -283,7 +283,7 @@ module ApplicationHelper
if myshixun.nil?
0
else
- myshixun.games.select{|game| game.status == 2 && game.answer_open == 0}.count
+ myshixun.games.select{|game| game.status == 2 && !game.answer_open}.count
end
end
@@ -358,18 +358,23 @@ module ApplicationHelper
day = time / 86400
hour = time % (24*60*60) / (60*60)
min = time % (24*60*60) % (60*60) / 60
+ sec = time % (24*60*60) % (60*60) % 60
if day < 1
if hour < 1
- if time < 1
- time = time == 0 ? "--" : "小于1分钟"
+ if min < 1
+ if sec < 1
+ time = "--"
+ else
+ time = "#{sec}秒"
+ end
else
- time = "#{min} 分钟"
+ time = "#{min}分钟 #{sec}秒"
end
else
- time = "#{hour}小时 #{min}分"
+ time = "#{hour}小时 #{min}分钟 #{sec}秒"
end
else
- time = "#{day}天 #{hour}小时 #{min}分"
+ time = "#{day}天 #{hour}小时 #{min}分钟 #{sec}秒"
end
return time
end
@@ -4736,6 +4741,7 @@ end
def get_hw_index(hw,is_teacher,type=0)
homework_commons = hw.course.homework_commons
+ Rails.logger.info("----------------------------------------------"+hw.course.to_s)
if is_teacher
if type != 0
homeworks = homework_commons.where("homework_commons.homework_type = #{type}").order("created_at asc")
@@ -4749,7 +4755,8 @@ def get_hw_index(hw,is_teacher,type=0)
homeworks = homework_commons.where("publish_time <= '#{Time.now}'").order("created_at asc")
end
end
- hw_ids = homeworks.map{|hw| hw.id} if !homeworks.empty?
+ Rails.logger.info("----------------------------------------------"+homeworks.count.to_s)
+ hw_ids = homeworks.map{|hw| hw.id} if !homeworks.blank?
index = hw_ids.index(hw.id)
return index
end
@@ -5224,9 +5231,9 @@ def set_shixun_final_score homework, student_work, answer_open_evaluation
shixun = homework.homework_commons_shixuns.shixun
passed_count = answer_open_evaluation ? had_passed_changllenge_num(shixun, student_work.user) : had_passed_no_ans_changllenge_num(shixun, student_work.user)
final_score =(passed_count.to_f / shixun.challenges.count) * 100
- student_work.final_score = format("%.2f",final_score.to_f)
+ student_work.update_column("final_score", format("%.2f",final_score.to_f))
score = student_work.final_score - student_work.late_penalty
- student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
+ student_work.update_column("work_score", format("%.2f",(score < 0 ? 0 : score).to_f)) if score
end
end
diff --git a/app/models/challenge.rb b/app/models/challenge.rb
index dcc50dd43..a9e74f77c 100644
--- a/app/models/challenge.rb
+++ b/app/models/challenge.rb
@@ -1,5 +1,5 @@
#coding=utf-8
-# st 0:实践任务;1:多选任务;2:单选任务
+# st 0:实践任务;1:选择题任务
class Challenge < ActiveRecord::Base
default_scope :order => 'position'
belongs_to :shixun,:touch=> true
@@ -8,7 +8,7 @@ class Challenge < ActiveRecord::Base
has_many :test_sets, :dependent => :destroy
has_many :challenge_tags, :dependent => :destroy
has_many :games, :dependent => :destroy
- has_many :challenge_questions, :dependent => :destroy
+ has_many :challenge_chooses, :dependent => :destroy
validates_presence_of :subject
# validates_presence_of :score
@@ -28,6 +28,35 @@ class Challenge < ActiveRecord::Base
str
end
+ def choose_correct_num
+ num = 0
+ self.challenge_chooses.each do |choose|
+ outputs = ChooseOutputs.where(:challenge_choose_id => choose.id).first
+ if outputs.nil?
+ num = nil
+ else
+ num += (outputs.correct ? 1 : 0)
+ end
+ end
+ return num
+ end
+
+ def choose_score
+ score = 0
+ self.challenge_chooses.each do |choose|
+ score += choose.score
+ end
+ return score
+ end
+
+ def choose_tags_num
+ num = 0
+ self.challenge_chooses.each do |choose|
+ num += choose.challenge_tags.count
+ end
+ return num
+ end
+
def next_challenge
challenge_count = Challenge.where(:shixun_id => self.shixun_id).count
render_404 if self.position ==challenge_count
diff --git a/app/models/challenge_choose.rb b/app/models/challenge_choose.rb
new file mode 100644
index 000000000..18d76790f
--- /dev/null
+++ b/app/models/challenge_choose.rb
@@ -0,0 +1,13 @@
+class ChallengeChoose < ActiveRecord::Base
+ # attr_accessible :title, :body
+ # category 1 单选, 2,多选
+ # standard_answer 正确答案 answer: 答题的思路
+ default_scope :order => 'position'
+ belongs_to :challenge
+ has_many :challenge_tags, :dependent => :destroy
+ has_many :challenge_questions, :dependent => :destroy
+ has_one :choose_outputs, :dependent => :destroy
+
+ validates_presence_of :subject
+
+end
diff --git a/app/models/challenge_question.rb b/app/models/challenge_question.rb
index eb835c32e..3540330b7 100644
--- a/app/models/challenge_question.rb
+++ b/app/models/challenge_question.rb
@@ -1,4 +1,6 @@
class ChallengeQuestion < ActiveRecord::Base
- belongs_to :challenge
- attr_accessible :challenge_id, :option_name, :position, :right_key
+ # 选择题的选项内容
+ belongs_to :challenge_choose
+ # right_key 选项是否是答案, position 选项的位置
+ attr_accessible :challenge_choose_id, :option_name, :position, :right_key
end
diff --git a/app/models/challenge_tag.rb b/app/models/challenge_tag.rb
index 5f5925f92..35b3f5be7 100644
--- a/app/models/challenge_tag.rb
+++ b/app/models/challenge_tag.rb
@@ -1,4 +1,5 @@
class ChallengeTag < ActiveRecord::Base
- attr_accessible :challenge_id, :name
+ attr_accessible :challenge_id, :name, :challenge_choose_id
belongs_to :challenge
+ belongs_to :challenge_choose
end
diff --git a/app/models/choose_outputs.rb b/app/models/choose_outputs.rb
new file mode 100644
index 000000000..9a47a3b25
--- /dev/null
+++ b/app/models/choose_outputs.rb
@@ -0,0 +1,5 @@
+class ChooseOutputs < ActiveRecord::Base
+ # attr_accessible :title, :body
+ # user_id 与 challenge_choose_id 唯一确定用户此题的选项
+ belongs_to :challenge_choose
+end
diff --git a/app/views/challenges/_answer_form.html.erb b/app/views/challenges/_answer_form.html.erb
index cbc31b01a..406f01fc8 100644
--- a/app/views/challenges/_answer_form.html.erb
+++ b/app/views/challenges/_answer_form.html.erb
@@ -20,7 +20,7 @@
+ 提交:
+ 1、每个黑色小方块代表一个空格,
+ 2、向下的黑色箭头代表测试集末尾的换行。
+
<%= test.input.gsub("\r\n", "
").html_safe unless test.input.blank? %>
<%= test.output.gsub("\r\n", "
").html_safe unless test.output.blank? %>
<%= test.input.gsub(" ", "").gsub(/\r\n$/, "
").html_safe unless test.input.blank? %>
<%= test.output.gsub(" ", "").gsub(/\r\n$/, "
").html_safe unless test.output.blank? %>
+
- diff --git a/app/views/challenges/add_choose_question.js.erb b/app/views/challenges/add_choose_question.js.erb new file mode 100644 index 000000000..55a88fe8d --- /dev/null +++ b/app/views/challenges/add_choose_question.js.erb @@ -0,0 +1 @@ +$("#task_content").html("<%= j(render :partial => "single_or_multiple_question") %>"); \ No newline at end of file diff --git a/app/views/challenges/choose_type_show.js.erb b/app/views/challenges/choose_type_show.js.erb new file mode 100644 index 000000000..e589ae71b --- /dev/null +++ b/app/views/challenges/choose_type_show.js.erb @@ -0,0 +1,2 @@ +$("#task_content").html("<%= j(render :partial => 'single_or_multiple_question_show')%>"); +$("#challenge_choose_tab").html("<%= j(render :partial => "challenges/choose_tab") %>"); \ No newline at end of file diff --git a/app/views/challenges/edit.html.erb b/app/views/challenges/edit.html.erb index 7c4253a8d..b0f6fec1c 100644 --- a/app/views/challenges/edit.html.erb +++ b/app/views/challenges/edit.html.erb @@ -22,13 +22,9 @@ - <% elsif @st == 1 %> + <% else %> - <% elsif @st == 2%> - <% end %>