diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 57e365aff..2942ee598 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,3 +1,4 @@ +#encoding: utf-8 class CoursesController < ApplicationController # layout 'base_courses' include CoursesHelper @@ -436,6 +437,73 @@ class CoursesController < ApplicationController def create cs = CoursesService.new @course = cs.create_course(params,User.current)[:course] + if params[:copy_course] + copy_course = Course.find params[:copy_course].to_i + @course.update_attributes(:open_student => copy_course.open_student, :publish_resource => copy_course.publish_resource) + if params[:checkAll] + attachments = copy_course.attachments + attachments.each do |attachment| + attach_copied_obj = attachment.copy + attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联 + attach_copied_obj.container = @course + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + update_quotes attach_copied_obj + end + elsif params[:course_attachment_type] + copy_attachments = [] + params[:course_attachment_type].each do |type| + case type + when "1" + tag_name = l(:label_courseware) + when "2" + tag_name = l(:label_software) + when "3" + tag_name = l(:label_media) + when "4" + tag_name = l(:label_code) + when "6" + tag_name = "论文" + else + tag_name = "" + end + if tag_name == "" + tag_attachments = copy_course.attachments.select{|attachment| + !attachment.tag_list.include?('课件') && + !attachment.tag_list.include?('软件') && + !attachment.tag_list.include?('媒体') && + !attachment.tag_list.include?('代码') && + !attachment.tag_list.include?('论文') } + else + tag_attachments = copy_course.attachments.select{|attachment| attachment.tag_list.include?(tag_name)} + end + tag_attachments.each do |attach| + next if copy_attachments.include?(attach) + copy_attachments << attach + end + end + unless copy_attachments.blank? + copy_attachments.each do |c_attach| + attach_copied_obj = c_attach.copy + attach_copied_obj.tag_list.add(c_attach.tag_list) # tag关联 + attach_copied_obj.container = @course + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.copy_from = c_attach.copy_from.nil? ? c_attach.id : c_attach.copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + update_quotes attach_copied_obj + end + end + end + end if @course respond_to do |format| flash[:notice] = l(:notice_successful_create) @@ -751,6 +819,11 @@ class CoursesController < ApplicationController #param id:已有课程ID def copy_course if @course + @new_course = Course.new + respond_to do |format| + format.js + end +=begin @new_course = Course.new @course.attributes @new_course.tea_id = User.current.id @new_course.created_at = DateTime.now @@ -769,6 +842,7 @@ class CoursesController < ApplicationController @new_course.course_infos << course redirect_to settings_course_url @new_course end +=end else render_404 end @@ -829,6 +903,33 @@ class CoursesController < ApplicationController end private + def update_quotes attachment + if attachment.copy_from + attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}") + else + attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}") + end + attachment.quotes = get_qute_number attachment + attachment.save + attachments.each do |att| + att.quotes = attachment.quotes + att.save + end + end + + def get_qute_number attachment + if attachment.copy_from + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") + else + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") + end + if result.nil? || result.count <= 0 + return 0 + else + return result[0].number + end + end + def allow_join course if course_endTime_timeout? course respond_to do |format| diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 444446ef4..b1e5456c5 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,681 +1,709 @@ -class ExerciseController < ApplicationController - layout "base_courses" - - 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] - before_filter :find_course, :only => [:index,:new,:create] - include ExerciseHelper - - def index - publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - publish_exercises.each do |exercise| - exercise.update_column('exercise_status', 2) - 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 - end - - if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?) - render_403 - return - end - remove_invalid_exercise(@course) - @is_teacher = User.current.allowed_to?(:as_teacher,@course) - if @is_teacher || User.current.admin? - exercises = @course.exercises.order("created_at asc") - else - exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc") - end - @exercises = paginateHelper exercises,20 #分页 - respond_to do |format| - format.html - end - end - - def show - publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - publish_exercises.each do |exercise| - exercise.update_column('exercise_status', 2) - 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 - end - - unless User.current.member_of_course?(@course) || User.current.admin? - render_403 - return - end - @exercise = Exercise.find params[:id] - @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - exercise_end = @exercise.end_time > Time.now - if @exercise.time == -1 - @can_edit_excercise = exercise_end - else - @can_edit_excercise = !has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end - end - unless @is_teacher - @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first - if @exercise_user.nil? - 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) - end - # @percent = get_percent(@exercise,User.current) - @exercise_questions = @exercise.exercise_questions - respond_to do |format| - format.html {render :layout => 'base_courses'} - end - #end - end - - def new - option = { - :exercise_name => "", - :course_id => @course.id, - :exercise_status => 1, - :user_id => User.current.id, - :time => "", - :end_time => "", - :publish_time => "", - :exercise_description => "", - :show_result => 1 - } - @exercise = Exercise.create option - if @exercise - redirect_to edit_exercise_url @exercise.id - end - end - - def create - if params[:exercise] - exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id] - exercise ||= Exercise.new - exercise.exercise_name = params[:exercise][:exercise_name] - exercise.exercise_description = params[:exercise][:exercise_description] - 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.user_id = User.current.id - exercise.time = params[:exercise][:time] - exercise.course_id = params[:course_id] - exercise.exercise_status = 1 - if exercise.save - @exercise = exercise - respond_to do |format| - format.js - end - end - end - end - - def edit - respond_to do |format| - format.html{render :layout => 'base_courses'} - end - end - - def update - @exercise.exercise_name = params[:exercise][:exercise_name] - @exercise.exercise_description = params[:exercise][:exercise_description] - @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] - if @exercise.save - respond_to do |format| - format.js - end - else - render_404 - end - end - - def destroy - @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - if @exercise && @exercise.destroy - if @is_teacher - exercises = Exercise.where("course_id =?", @course.id) - else - exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2) - end - @exercises = paginateHelper exercises,20 #分页 - respond_to do |format| - format.js - end - end - end - - # 统计结果 - def statistics_result - @exercise = Exercise.find(params[:id]) - exercise_questions = @exercise.exercise_questions - @exercise_questions = paginateHelper exercise_questions, 5 - respond_to do |format| - format.html{render :layout => 'base_courses'} - end - end - - # 添加题目 - # question_type 1:单选 2:多选 3:填空题 - def create_exercise_question - question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] - option = { - :question_title => question_title, - :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), - :question_score => params[:question_score] - } - @exercise_questions = @exercise.exercise_questions.new option - # params[:question_answer] 题目选项 - if params[:question_answer] - for i in 1..params[:question_answer].count - answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] - question_option = { - :choice_position => i, - :choice_text => answer - } - @exercise_questions.exercise_choices.new question_option - end - end - # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 - if params[:quest_id] - @is_insert = true - if @exercise_questions.question_type == 1 - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1") - #@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 - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).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 - end - if @exercise_questions.save - # params[:exercise_choice] 标准答案参数 - # 问答题标准答案有三个,单独处理 - if @exercise_questions.question_type == 3 - for i in 1..params[:exercise_choice].count - standart_answer = ExerciseStandardAnswer.new - standart_answer.exercise_question_id = @exercise_questions.id - standart_answer.answer_text = params[:exercise_choice].values[i-1] - 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 - standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) - end - standart_answer.save - end - respond_to do |format| - format.js - end - end - - end - - # 修改题目 - # params[:exercise_question] The id of exercise_question - # params[:question_answer] eg:A、B、C选项 - def update_exercise_question - @exercise_question = ExerciseQuestion.find params[:exercise_question] - @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] - @exercise_question.question_score = params[:question_score] - # 处理选项:如果选了某个选项,那么则要删除之前的选项 - if params[:question_answer] - @exercise_question.exercise_choices.each do |answer| - answer.destroy unless params[:question_answer].keys.include? answer.id.to_s - end - for i in 1..params[:question_answer].count - question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] - answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] - if question - question.choice_position = i - question.choice_text = answer - question.save - else - question_option = { - :choice_position => i, - :choice_text => answer - } - @exercise_question.exercise_choices.new question_option - end - end - end - # 更新标准答案 - if params[:exercise_choice] - if @exercise_question.question_type == 3 - # 删除不合理的选项 - @exercise_question.exercise_standard_answers.each do |answer| - answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s - end - for i in 1..params[:exercise_choice].count - # 找到对应的标准答案 - question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1] - # 标准答案值 - answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1] - if question_standart - question_standart.answer_text = answer_standart - question_standart.save - else - standart_answer_option = { - :answer_text => answer_standart - } - @exercise_question.exercise_standard_answers.new standart_answer_option - end - 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 - respond_to do |format| - format.js - end - end - end - - # 删除题目 - def delete_exercise_question - @exercise_question = ExerciseQuestion.find params[:exercise_question] - @exercise = @exercise_question.exercise - - if @exercise_question.question_type == 1 - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1") - #@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 - ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).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 - # - # exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}") - # exercise_questions.each do |question| - # question.question_number -= 1 - # question.save - # end - if @exercise_question && @exercise_question.destroy - respond_to do |format| - format.js - end - end - end - - # 发布试卷 - def publish_exercise - @is_teacher = User.current.allowed_to?(:as_teacher,@course) - @index = params[:index] - @exercise.exercise_status = 2 - @exercise.publish_time = Time.now - if @exercise.save - @exercise.course.members.each do |m| - @exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2) - end - #redirect_to exercise_index_url(:course_id=> @course.id) - respond_to do |format| - format.js - end - end - end - - # 重新发布试卷 - # 重新发布的时候会删除所有的答题 - def republish_exercise - @is_teacher = User.current.allowed_to?(:as_teacher,@course) - @index = params[:index] - @exercise.exercise_questions.each do |exercise_question| - exercise_question.exercise_answers.destroy_all - end - @exercise.course_messages.destroy_all - @exercise.exercise_users.destroy_all - @exercise.exercise_status = 1 - @exercise.publish_time = nil - @exercise.save - respond_to do |format| - format.js - end - end - - def student_exercise_list -=begin - if @exercise.end_time <= Time.now - @course.student.each do |student| - if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,@exercise.id).empty? - ExerciseUser.create(:user_id => student.student_id, :exercise_id => @exercise.id, :start_at => @exercise.end_time, :status => true,:score=>0) - end - - s_score = calculate_student_score(@exercise, student.student) - exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", student.student_id, @exercise.id).first - exercise_user.update_attributes(:score => s_score) - end - end -=end - @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") - @exercise_count = @exercise.exercise_users.where('score is not NULL').count - if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now) - @exercise_users_list = @exercise.exercise_users.where('score is not NULL') - @show_all = true; - elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now - @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) - else - @exercise_users_list = [] - end - respond_to do |format| - format.html - end - end - - # 学生提交答卷,选中答案的过程中提交 - def commit_answer - eq = ExerciseQuestion.find(params[:exercise_question_id]) - # 已提交过的且是限时的则不允许答题 - if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now - render :json => {:text => "failure"} - return - end - if eq.question_type == 1 - # 单选题 - ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id) - if ea.nil? - # 尚未答该题,添加答案 - ea = ExerciseAnswer.new - ea.user_id = User.current.id - ea.exercise_question_id = params[:exercise_question_id] - end - #修改该题对应答案 - ea.exercise_choice_id = params[:exercise_choice_id] - if ea.save - # 保存成功返回成功信息及当前以答题百分比 - uncomplete_question = get_uncomplete_question(@exercise, User.current) - if uncomplete_question.count < 1 - complete = 1; - else - complete = 0; - end - @percent = get_percent(@exercise,User.current) - render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)} - else - #返回失败信息 - render :json => {:text => "failure"} - end - elsif eq.question_type == 2 - #多选题 - ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id) - if ea.nil? - #尚未答该题,添加答案 - ea = ExerciseAnswer.new - ea.user_id = User.current.id - ea.exercise_question_id = params[:exercise_question_id] - ea.exercise_choice_id = params[:exercise_choice_id] - if ea.save - uncomplete_question = get_uncomplete_question(@exercise, User.current) - if uncomplete_question.count < 1 - complete = 1; - else - complete = 0; - end - @percent = get_percent(@exercise,User.current) - render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)} - else - render :json => {:text => "failure"} - end - else - #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案 - if ea.delete - @percent = get_percent(@exercise, User.current) - render :json => {:text => "false" ,:percent => format("%.2f" , @percent)} - else - render :json => {:text => "failure"} - end - end - elsif eq.question_type == 3 - #单行文本,多行文本题 - ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id) - if ea.nil? - # ea为空之前尚未答题,添加答案 - if params[:answer_text].nil? || params[:answer_text].blank? - #用户提交空答案,视作不作答 - @percent = get_percent(@exercise,User.current) - render :json => {:text => "",:percent => format("%.2f", @percent)} - else - #添加答案 - ea = ExerciseAnswer.new - ea.user_id = User.current.id - ea.exercise_question_id = params[:exercise_question_id] - ea.answer_text = params[:answer_text] - if ea.save - uncomplete_question = get_uncomplete_question(@exercise, User.current) - if uncomplete_question.count < 1 - complete = 1; - else - complete = 0; - end - @percent = get_percent(@exercise,User.current) - render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)} - else - render :json => {:text => "failure"} - end - end - else - # ea不为空说明用户之前已作答 - if params[:answer_text].nil? || params[:answer_text].blank? - # 用户提交空答案,视为删除答案 - if ea.delete - @percent = get_percent(@exercise,User.current) - render :json => {:text => "",:percent => format("%.2f", @percent)} - else - render :json => {:text => "failure"} - end - else - #用户修改答案 - ea.answer_text = params[:answer_text] - if ea.save - @percent = get_percent(@exercise,User.current) - render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)} - else - render :json => {:text => "failure"} - end - end - end - - else - render :json => {:text => "failure"} - end - end - - # 提交问卷 - def commit_exercise - # 老师不需要提交 - if User.current.allowed_to?(:as_teacher,@course) - if @exercise.publish_time.nil? - @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) - # REDO: 提示提交成功 - else - # 更新提交状态 - cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first - cur_exercise_user.update_attributes(:status => 1) - # 答题过程中需要统计完成量 - @uncomplete_question = get_uncomplete_question(@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] - respond_to do |format| - format.js - end - 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) - @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first - respond_to do |format| - format.html {render :layout => 'base_courses'} - end - end - - # 计算学生得分 - def calculate_student_score(exercise, user) - score = 0 - score1 = 0 - score2 = 0 - score3 = 0 - exercise_qustions = exercise.exercise_questions - exercise_qustions.each do |question| - answer = get_user_answer(question, user) - standard_answer = get_user_standard_answer(question, user) - unless answer.empty? - # 问答题有多个答案 - if question.question_type == 3 && !standard_answer.empty? - if standard_answer.include?(answer.first.answer_text) - score1 = score1+ question.question_score unless question.question_score.nil? - end - elsif question.question_type == 1 && !standard_answer.nil? - if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id - score2 = score2 + question.question_score unless question.question_score.nil? - end - elsif question.question_type == 2 && !standard_answer.nil? - arr = get_mulscore(question, user) - if arr.to_i == standard_answer.exercise_choice_id - score3 = score3 + question.question_score unless question.question_score.nil? - end - # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) - # arr = [] - # ecs.each do |ec| - # arr << ec.exercise_choice.choice_position - # end - # arr.sort - # arr = arr.join("") - # if arr.to_i == standard_answer.exercise_choice_id - # score3 = score + question.question_score unless question.question_score.nil? - # end - end - end - end - score = score1 + score2 + score3 - end - - private - - # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 - def get_exercise_user exercise_id,user_id - eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id) - if eu.nil? - eu = ExerciseUser.new - end - eu - end - - # 获取当前学生回答问题的答案 - def get_user_answer(question,user) - # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first - user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") - user_answer - end - - # 获取问题的标准答案 - def get_user_standard_answer(question,user) - if question.question_type == 3 - standard_answer =[] - question.exercise_standard_answers.each do |answer| - standard_answer << answer.answer_text - end - else - standard_answer = question.exercise_standard_answers.first - end - standard_answer - end - # 是否完成了答题 - def get_complete_question(exercise,user) - questions = exercise.exercise_questions - complete_question = [] - questions.each do |question| - answers = get_user_answer(question,user) - if !(answers.nil? || answers.count < 1) - complete_question << question - end - end - complete_question - end - - # 获取答题百分比 - def get_percent exercise,user - complete_count = get_complete_question(exercise,user).count - if exercise.exercise_questions.count == 0 - return 0 - else - return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100 - end - end - - def remove_invalid_exercise(course) - exercises = course.exercises.where("exercise_name=?","") - unless exercises.empty? - exercises.each do |exercise| - if exercise.exercise_questions.empty? - exercise.destroy - end - end - end - end - - def find_exercise_and_course - @exercise = Exercise.find params[:id] - @course = Course.find @exercise.course_id - rescue Exception => e - render_404 - end - - def find_course - @course = Course.find params[:course_id] - rescue Exception => e - render_404 - end +class ExerciseController < ApplicationController + layout "base_courses" + + 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] + before_filter :find_course, :only => [:index,:new,:create] + include ExerciseHelper + + def index + publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) + publish_exercises.each do |exercise| + exercise.update_column('exercise_status', 2) + 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 + end + + if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?) + render_403 + return + end + remove_invalid_exercise(@course) + @is_teacher = User.current.allowed_to?(:as_teacher,@course) + if @is_teacher || User.current.admin? + exercises = @course.exercises.order("created_at asc") + else + exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc") + end + @exercises = paginateHelper exercises,20 #分页 + respond_to do |format| + format.html + end + end + + def show + publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) + publish_exercises.each do |exercise| + exercise.update_column('exercise_status', 2) + 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 + end + + unless User.current.member_of_course?(@course) || User.current.admin? + render_403 + return + end + @exercise = Exercise.find params[:id] + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + exercise_end = @exercise.end_time > Time.now + if @exercise.time == -1 + @can_edit_excercise = exercise_end + else + @can_edit_excercise = !has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end + end + unless @is_teacher + @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first + if @exercise_user.nil? + 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) + end + # @percent = get_percent(@exercise,User.current) + @exercise_questions = @exercise.exercise_questions + respond_to do |format| + format.html {render :layout => 'base_courses'} + end + #end + end + + def new + option = { + :exercise_name => "", + :course_id => @course.id, + :exercise_status => 1, + :user_id => User.current.id, + :time => "", + :end_time => "", + :publish_time => "", + :exercise_description => "", + :show_result => 1 + } + @exercise = Exercise.create option + if @exercise + redirect_to edit_exercise_url @exercise.id + end + end + + def create + if params[:exercise] + exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id] + exercise ||= Exercise.new + exercise.exercise_name = params[:exercise][:exercise_name] + exercise.exercise_description = params[:exercise][:exercise_description] + 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.user_id = User.current.id + exercise.time = params[:exercise][:time] + exercise.course_id = params[:course_id] + exercise.exercise_status = 1 + if exercise.save + @exercise = exercise + respond_to do |format| + format.js + end + end + end + end + + def edit + respond_to do |format| + format.html{render :layout => 'base_courses'} + end + end + + def update + @exercise.exercise_name = params[:exercise][:exercise_name] + @exercise.exercise_description = params[:exercise][:exercise_description] + @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] + if @exercise.save + respond_to do |format| + format.js + end + else + render_404 + end + end + + def destroy + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + if @exercise && @exercise.destroy + if @is_teacher + exercises = Exercise.where("course_id =?", @course.id) + else + exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2) + end + @exercises = paginateHelper exercises,20 #分页 + respond_to do |format| + format.js + end + end + end + + # 统计结果 + def statistics_result + @exercise = Exercise.find(params[:id]) + exercise_questions = @exercise.exercise_questions + @exercise_questions = paginateHelper exercise_questions, 5 + respond_to do |format| + format.html{render :layout => 'base_courses'} + end + end + + # 添加题目 + # question_type 1:单选 2:多选 3:填空题 + def create_exercise_question + question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] + option = { + :question_title => question_title, + :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), + :question_score => params[:question_score] + } + @exercise_questions = @exercise.exercise_questions.new option + # params[:question_answer] 题目选项 + if params[:question_answer] + for i in 1..params[:question_answer].count + answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + question_option = { + :choice_position => i, + :choice_text => answer + } + @exercise_questions.exercise_choices.new question_option + end + end + # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 + if params[:quest_id] + @is_insert = true + if @exercise_questions.question_type == 1 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1") + #@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 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).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 + end + if @exercise_questions.save + # params[:exercise_choice] 标准答案参数 + # 问答题标准答案有三个,单独处理 + if @exercise_questions.question_type == 3 + for i in 1..params[:exercise_choice].count + standart_answer = ExerciseStandardAnswer.new + standart_answer.exercise_question_id = @exercise_questions.id + standart_answer.answer_text = params[:exercise_choice].values[i-1] + 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 + standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) + end + standart_answer.save + end + respond_to do |format| + format.js + end + end + + end + + # 修改题目 + # params[:exercise_question] The id of exercise_question + # params[:question_answer] eg:A、B、C选项 + def update_exercise_question + @exercise_question = ExerciseQuestion.find params[:exercise_question] + @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] + @exercise_question.question_score = params[:question_score] + # 处理选项:如果选了某个选项,那么则要删除之前的选项 + if params[:question_answer] + @exercise_question.exercise_choices.each do |answer| + answer.destroy unless params[:question_answer].keys.include? answer.id.to_s + end + for i in 1..params[:question_answer].count + question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] + answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + if question + question.choice_position = i + question.choice_text = answer + question.save + else + question_option = { + :choice_position => i, + :choice_text => answer + } + @exercise_question.exercise_choices.new question_option + end + end + end + # 更新标准答案 + if params[:exercise_choice] + if @exercise_question.question_type == 3 + # 删除不合理的选项 + @exercise_question.exercise_standard_answers.each do |answer| + answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s + end + for i in 1..params[:exercise_choice].count + # 找到对应的标准答案 + question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1] + # 标准答案值 + answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1] + if question_standart + question_standart.answer_text = answer_standart + question_standart.save + else + standart_answer_option = { + :answer_text => answer_standart + } + @exercise_question.exercise_standard_answers.new standart_answer_option + end + 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 + respond_to do |format| + format.js + end + end + end + + # 删除题目 + def delete_exercise_question + @exercise_question = ExerciseQuestion.find params[:exercise_question] + @exercise = @exercise_question.exercise + + if @exercise_question.question_type == 1 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1") + #@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 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).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 + # + # exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}") + # exercise_questions.each do |question| + # question.question_number -= 1 + # question.save + # end + if @exercise_question && @exercise_question.destroy + respond_to do |format| + format.js + end + end + end + + # 发布试卷 + def publish_exercise + @is_teacher = User.current.allowed_to?(:as_teacher,@course) + @index = params[:index] + @exercise.exercise_status = 2 + @exercise.publish_time = Time.now + if @exercise.save + @exercise.course.members.each do |m| + @exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2) + end + #redirect_to exercise_index_url(:course_id=> @course.id) + respond_to do |format| + format.js + end + end + end + + # 重新发布试卷 + # 重新发布的时候会删除所有的答题 + def republish_exercise + @is_teacher = User.current.allowed_to?(:as_teacher,@course) + @index = params[:index] + @exercise.exercise_questions.each do |exercise_question| + exercise_question.exercise_answers.destroy_all + end + @exercise.course_messages.destroy_all + @exercise.exercise_users.destroy_all + @exercise.exercise_status = 1 + @exercise.publish_time = nil + @exercise.save + respond_to do |format| + format.js + end + end + + def student_exercise_list +=begin + if @exercise.end_time <= Time.now + @course.student.each do |student| + if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,@exercise.id).empty? + ExerciseUser.create(:user_id => student.student_id, :exercise_id => @exercise.id, :start_at => @exercise.end_time, :status => true,:score=>0) + end + + s_score = calculate_student_score(@exercise, student.student) + exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", student.student_id, @exercise.id).first + exercise_user.update_attributes(:score => s_score) + end + end +=end + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") + @exercise_count = @exercise.exercise_users.where('score is not NULL').count + if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now) + @exercise_users_list = @exercise.exercise_users.where('score is not NULL') + @show_all = true; + elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now + @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) + else + @exercise_users_list = [] + end + respond_to do |format| + format.html + format.xls { + filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@exercise.exercise_name}#{l(:excel_exercise_list)}.xls" + send_data(exercise_to_xls(@exercise_users_list), :type => "text/excel;charset=utf-8; header=present", + :filename => filename_for_content_disposition(filename)) + } + end + end + + # 学生提交答卷,选中答案的过程中提交 + def commit_answer + eq = ExerciseQuestion.find(params[:exercise_question_id]) + # 已提交过的且是限时的则不允许答题 + if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now + render :json => {:text => "failure"} + return + end + if eq.question_type == 1 + # 单选题 + ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id) + if ea.nil? + # 尚未答该题,添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + end + #修改该题对应答案 + ea.exercise_choice_id = params[:exercise_choice_id] + if ea.save + # 保存成功返回成功信息及当前以答题百分比 + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end + @percent = get_percent(@exercise,User.current) + render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)} + else + #返回失败信息 + render :json => {:text => "failure"} + end + elsif eq.question_type == 2 + #多选题 + ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id) + if ea.nil? + #尚未答该题,添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + ea.exercise_choice_id = params[:exercise_choice_id] + if ea.save + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end + @percent = get_percent(@exercise,User.current) + render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)} + else + render :json => {:text => "failure"} + end + else + #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案 + if ea.delete + @percent = get_percent(@exercise, User.current) + render :json => {:text => "false" ,:percent => format("%.2f" , @percent)} + else + render :json => {:text => "failure"} + end + end + elsif eq.question_type == 3 + #单行文本,多行文本题 + ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id) + if ea.nil? + # ea为空之前尚未答题,添加答案 + if params[:answer_text].nil? || params[:answer_text].blank? + #用户提交空答案,视作不作答 + @percent = get_percent(@exercise,User.current) + render :json => {:text => "",:percent => format("%.2f", @percent)} + else + #添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + ea.answer_text = params[:answer_text] + if ea.save + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end + @percent = get_percent(@exercise,User.current) + render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)} + else + render :json => {:text => "failure"} + end + end + else + # ea不为空说明用户之前已作答 + if params[:answer_text].nil? || params[:answer_text].blank? + # 用户提交空答案,视为删除答案 + if ea.delete + @percent = get_percent(@exercise,User.current) + render :json => {:text => "",:percent => format("%.2f", @percent)} + else + render :json => {:text => "failure"} + end + else + #用户修改答案 + ea.answer_text = params[:answer_text] + if ea.save + @percent = get_percent(@exercise,User.current) + render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)} + else + render :json => {:text => "failure"} + end + end + end + + else + render :json => {:text => "failure"} + end + end + + # 提交问卷 + def commit_exercise + # 老师不需要提交 + if User.current.allowed_to?(:as_teacher,@course) + if @exercise.publish_time.nil? + @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) + # REDO: 提示提交成功 + else + # 更新提交状态 + cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first + cur_exercise_user.update_attributes(:status => 1) + # 答题过程中需要统计完成量 + @uncomplete_question = get_uncomplete_question(@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] + respond_to do |format| + format.js + end + 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) + @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first + respond_to do |format| + format.html {render :layout => 'base_courses'} + end + end + + # 计算学生得分 + def calculate_student_score(exercise, user) + score = 0 + score1 = 0 + score2 = 0 + score3 = 0 + exercise_qustions = exercise.exercise_questions + exercise_qustions.each do |question| + answer = get_user_answer(question, user) + standard_answer = get_user_standard_answer(question, user) + unless answer.empty? + # 问答题有多个答案 + if question.question_type == 3 && !standard_answer.empty? + if standard_answer.include?(answer.first.answer_text) + score1 = score1+ question.question_score unless question.question_score.nil? + end + elsif question.question_type == 1 && !standard_answer.nil? + if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id + score2 = score2 + question.question_score unless question.question_score.nil? + end + elsif question.question_type == 2 && !standard_answer.nil? + arr = get_mulscore(question, user) + if arr.to_i == standard_answer.exercise_choice_id + score3 = score3 + question.question_score unless question.question_score.nil? + end + # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + # arr = [] + # ecs.each do |ec| + # arr << ec.exercise_choice.choice_position + # end + # arr.sort + # arr = arr.join("") + # if arr.to_i == standard_answer.exercise_choice_id + # score3 = score + question.question_score unless question.question_score.nil? + # end + end + end + end + score = score1 + score2 + score3 + end + + private + #测验列表转换为excel + def exercise_to_xls items + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + 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)]) + count_row = 1 + items.each do |exercise| + sheet1[count_row,0]=exercise.user.id + sheet1[count_row,1] = exercise.user.lastname.to_s + exercise.user.firstname.to_s + 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) + count_row += 1 + end + book.write xls_report + xls_report.string + end + + # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 + def get_exercise_user exercise_id,user_id + eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id) + if eu.nil? + eu = ExerciseUser.new + end + eu + end + + # 获取当前学生回答问题的答案 + def get_user_answer(question,user) + # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first + user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") + user_answer + end + + # 获取问题的标准答案 + def get_user_standard_answer(question,user) + if question.question_type == 3 + standard_answer =[] + question.exercise_standard_answers.each do |answer| + standard_answer << answer.answer_text + end + else + standard_answer = question.exercise_standard_answers.first + end + standard_answer + end + # 是否完成了答题 + def get_complete_question(exercise,user) + questions = exercise.exercise_questions + complete_question = [] + questions.each do |question| + answers = get_user_answer(question,user) + if !(answers.nil? || answers.count < 1) + complete_question << question + end + end + complete_question + end + + # 获取答题百分比 + def get_percent exercise,user + complete_count = get_complete_question(exercise,user).count + if exercise.exercise_questions.count == 0 + return 0 + else + return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100 + end + end + + def remove_invalid_exercise(course) + exercises = course.exercises.where("exercise_name=?","") + unless exercises.empty? + exercises.each do |exercise| + if exercise.exercise_questions.empty? + exercise.destroy + end + end + end + end + + def find_exercise_and_course + @exercise = Exercise.find params[:id] + @course = Course.find @exercise.course_id + rescue Exception => e + render_404 + end + + def find_course + @course = Course.find params[:course_id] + rescue Exception => e + render_404 + end end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 55a017019..98b72f67e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2757,4 +2757,11 @@ int main(int argc, char** argv){ ss.html_safe end + #代码提交数量 + def changesets_num project + g = Gitlab.client + project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count + # # commits_total_count(project.gpid) + # project.changesets.count + end end diff --git a/app/helpers/project_score_helper.rb b/app/helpers/project_score_helper.rb index d73e1592e..133212718 100644 --- a/app/helpers/project_score_helper.rb +++ b/app/helpers/project_score_helper.rb @@ -20,14 +20,6 @@ module ProjectScoreHelper project.documents.count end - #代码提交数量 - def changesets_num project - g = Gitlab.client - project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count - # # commits_total_count(project.gpid) - # project.changesets.count - end - #讨论区帖子数量 def board_message_num project board_message_count = 0 diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index d1ab6661a..bfc01a102 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -591,7 +591,7 @@ module UsersHelper option << "请选择发布作业的课程" option << -1 type << option - user.courses.visible.select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course| + user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course| option = [] option << course.name+"("+course.time.to_s+course.term+")" option << course.id diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index aabe1a921..6f2819f53 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -193,6 +193,7 @@ class CoursesService @course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.send(:safe_attributes=, params[:course], current_user) #@course.safe_attributes(current_user,params[:course]) + @course.password = params[:course][:password] @course.tea_id = current_user.id @course.term = params[:term] @course.time = params[:time] diff --git a/app/views/attachments/_activity_attach.html.erb b/app/views/attachments/_activity_attach.html.erb new file mode 100644 index 000000000..9bd7d9d2f --- /dev/null +++ b/app/views/attachments/_activity_attach.html.erb @@ -0,0 +1,19 @@ +<% if activity.attachments.any? %> + <% activity.attachments.each do |attachment| %> +
+ + + <%= link_to_short_attachment attachment,:length=> 58, :class => 'mw400 hidden link_file_a fl newsBlue', :download => true -%> + + + ( + <%= number_to_human_size attachment.filesize %>) + + + <%= link_to h(truncate(attachment.author.name, length: 10, omission: '...')),user_path(attachment.author),:class => "c_orange" %>, + <%= format_time(attachment.created_on) %> + +
+
+ <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/blog_comments/reply.js.erb b/app/views/blog_comments/reply.js.erb index fe46d870c..2a4e71f1c 100644 --- a/app/views/blog_comments/reply.js.erb +++ b/app/views/blog_comments/reply.js.erb @@ -5,20 +5,4 @@ $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'blogs/article', :locals => {:activity => @article,:user_activity_id =>@user_activity_id}) %>"); //init_activity_KindEditor_data(<%#= @user_activity_id%>,"","87%", 'UserActivity'); <% end %> -init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%", 'UserActivity'); -showNormalImage('activity_description_<%= @user_activity_id %>'); -if($("#intro_content_<%= @user_activity_id %>").height() > 810) { - $("#intro_content_show_<%= @user_activity_id %>").show(); -} -$("#intro_content_show_<%= @user_activity_id %>").click(function(){ - $("#activity_description_<%= @user_activity_id %>").toggleClass("maxh360"); - $("#activity_description_<%= @user_activity_id%>").toggleClass("lh18"); - $("#intro_content_show_<%= @user_activity_id %>").hide(); - $("#intro_content_hide_<%= @user_activity_id %>").show(); -}); -$("#intro_content_hide_<%= @user_activity_id %>").click(function(){ - $("#activity_description_<%= @user_activity_id %>").toggleClass("maxh360"); - $("#activity_description_<%= @user_activity_id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= @user_activity_id %>").hide(); - $("#intro_content_show_<%= @user_activity_id %>").show(); -}); \ No newline at end of file +init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%", 'UserActivity'); \ No newline at end of file diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 99c743a96..0048625d8 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -57,7 +57,7 @@
发帖时间:<%= format_time(activity.created_on) %>
-
+
<% if activity.parent_id.nil? %> <%= activity.content.to_s.html_safe%> @@ -67,17 +67,19 @@
-
- <% if activity.attachments.any?%> - <% options = {:author => true, :deletable => false } %> - <%= render :partial => 'blog_comments/attachments_links', :locals => {:attachments => activity.attachments, :options => options, :is_float => true} %> - <% end %> +
- +
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
+ diff --git a/app/views/blogs/_article_list.html.erb b/app/views/blogs/_article_list.html.erb index 62f1391b0..534c33609 100644 --- a/app/views/blogs/_article_list.html.erb +++ b/app/views/blogs/_article_list.html.erb @@ -75,22 +75,6 @@ $(function () { init_activity_KindEditor_data(<%= topic.id%>, null, "87%", "<%=topic.class.to_s%>"); - showNormalImage('activity_description_<%= topic.id %>'); - if($("#intro_content_<%= topic.id %>").height() > 810) { - $("#intro_content_show_<%= topic.id %>").show(); - } - $("#intro_content_show_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= topic.id %>").hide(); - $("#intro_content_hide_<%= topic.id %>").show(); - }); - $("#intro_content_hide_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= topic.id %>").hide(); - $("#intro_content_show_<%= topic.id %>").show(); - }); }); <% if topic %> diff --git a/app/views/boards/_course_show_detail.html.erb b/app/views/boards/_course_show_detail.html.erb index 8f50905c6..804f6543e 100644 --- a/app/views/boards/_course_show_detail.html.erb +++ b/app/views/boards/_course_show_detail.html.erb @@ -41,22 +41,6 @@ $(function () { init_activity_KindEditor_data(<%= topic.id%>, null, "87%"); - showNormalImage('activity_description_<%= topic.id %>'); - if($("#intro_content_<%= topic.id %>").height() > 810) { - $("#intro_content_show_<%= topic.id %>").show(); - } - $("#intro_content_show_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= topic.id %>").hide(); - $("#intro_content_hide_<%= topic.id %>").show(); - }); - $("#intro_content_hide_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= topic.id %>").hide(); - $("#intro_content_show_<%= topic.id %>").show(); - }); }); <% if topic %> diff --git a/app/views/boards/_project_show_detail.html.erb b/app/views/boards/_project_show_detail.html.erb index 5b266b90c..367f0552c 100644 --- a/app/views/boards/_project_show_detail.html.erb +++ b/app/views/boards/_project_show_detail.html.erb @@ -40,22 +40,6 @@ $(function () { init_activity_KindEditor_data(<%= topic.id%>, null, "87%"); - showNormalImage('activity_description_<%= topic.id %>'); - if($("#intro_content_<%= topic.id %>").height() > 810) { - $("#intro_content_show_<%= topic.id %>").show(); - } - $("#intro_content_show_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= topic.id %>").hide(); - $("#intro_content_hide_<%= topic.id %>").show(); - }); - $("#intro_content_hide_<%= topic.id %>").click(function(){ - $("#activity_description_<%= topic.id %>").toggleClass("maxh360"); - $("#activity_description_<%= topic.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= topic.id %>").hide(); - $("#intro_content_show_<%= topic.id %>").show(); - }); }); <% if topic %> diff --git a/app/views/courses/_copy_course.html.erb b/app/views/courses/_copy_course.html.erb new file mode 100644 index 000000000..d4debb601 --- /dev/null +++ b/app/views/courses/_copy_course.html.erb @@ -0,0 +1,142 @@ + + +
+
信息配置
+
+ +
+ 完成 + 取消 +
+
diff --git a/app/views/courses/_course_activity.html.erb b/app/views/courses/_course_activity.html.erb index ea41787d5..f0ae33996 100644 --- a/app/views/courses/_course_activity.html.erb +++ b/app/views/courses/_course_activity.html.erb @@ -73,22 +73,6 @@ $(function () { init_activity_KindEditor_data(<%= activity.id%>, null, "87%", "<%= activity.class.to_s %>"); - showNormalImage('activity_description_<%= activity.id %>'); - if($("#intro_content_<%= activity.id %>").height() > 360) { - $("#intro_content_show_<%= activity.id %>").show(); - } - $("#intro_content_show_<%= activity.id %>").click(function(){ - $("#activity_description_<%= activity.id %>").toggleClass("maxh360"); - $("#activity_description_<%= activity.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= activity.id %>").hide(); - $("#intro_content_hide_<%= activity.id %>").show(); - }); - $("#intro_content_hide_<%= activity.id %>").click(function(){ - $("#activity_description_<%= activity.id %>").toggleClass("maxh360"); - $("#activity_description_<%= activity.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= activity.id %>").hide(); - $("#intro_content_show_<%= activity.id %>").show(); - }); }); <% if activity && activity.course_act%> diff --git a/app/views/courses/copy_course.js.erb b/app/views/courses/copy_course.js.erb new file mode 100644 index 000000000..e31e423ba --- /dev/null +++ b/app/views/courses/copy_course.js.erb @@ -0,0 +1,10 @@ +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'copy_course') %>'); +showModal('ajax-modal', '730px'); +$('#ajax-modal').css('height','530px').css('width','730px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("
" + +"
"); +$('#ajax-modal').parent().css("top","30%").css("left","").css("position","fixed"); +$('#ajax-modal').parent().addClass("popbox").addClass("copyCoursePopup"); + + diff --git a/app/views/exercise/student_exercise_list.html.erb b/app/views/exercise/student_exercise_list.html.erb index 2e51d61af..c96f8156a 100644 --- a/app/views/exercise/student_exercise_list.html.erb +++ b/app/views/exercise/student_exercise_list.html.erb @@ -5,29 +5,6 @@ $("#Container").css("width","1000px"); }); - // 匿评弹框提示 - <%# if @is_evaluation && !@stundet_works.empty?%> - // $(function(){ - // $('#ajax-modal').html('<%#= escape_javascript(render :partial => 'student_work/praise_alert') %>'); - // showModal('ajax-modal', '500px'); - // $('#ajax-modal').siblings().remove(); - // $('#ajax-modal').before("" + - // ""); - // $('#ajax-modal').parent().css("top","").css("left",""); - // $('#ajax-modal').parent().addClass("anonymos"); - // }); - <%# end%> - - //设置评分规则 - function set_score_rule(){ - $('#ajax-modal').html('<%#= escape_javascript(render :partial => 'student_work/set_score_rule',:locals => {:homework => @homework,:student_path => true}) %>'); - showModal('ajax-modal', '350px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before("" + - ""); - $('#ajax-modal').parent().css("top","25%").css("left","35%").css("position","fixed"); - } - $(function(){ $("#homework_info_hidden").click(function(){ $("#homeworkInformation").hide(); @@ -84,6 +61,20 @@
+ <% if @is_teacher%> +
+ +
+ <% end%>
diff --git a/app/views/homework_common/_alert_anonyoms.html.erb b/app/views/homework_common/_alert_anonyoms.html.erb index 3b1f6f692..79840cb35 100644 --- a/app/views/homework_common/_alert_anonyoms.html.erb +++ b/app/views/homework_common/_alert_anonyoms.html.erb @@ -3,9 +3,7 @@ <% if @homework_detail_manual.comment_status == 1%>

开启匿评功能

- 开启匿评后学生将不能对作品进行 - 修改、删除 - 等操作,开启匿评后的提交作品,将 + 开启匿评后提交的作品将 不能参与匿评, 匿评评分将被记为 0分 diff --git a/app/views/issues/_list.html.erb b/app/views/issues/_list.html.erb index 58fbda6d6..e47967099 100644 --- a/app/views/issues/_list.html.erb +++ b/app/views/issues/_list.html.erb @@ -19,22 +19,6 @@ $(function () { init_activity_KindEditor_data(<%= issue.id%>, null, "87%", "<%= issue.class.name %>"); - showNormalImage('activity_description_<%= issue.id %>'); - if ($("#intro_content_<%= issue.id %>").height() > 360) { - $("#intro_content_show_<%= issue.id %>").show(); - } - $("#intro_content_show_<%= issue.id %>").click(function () { - $("#activity_description_<%= issue.id %>").toggleClass("maxh360"); - $("#activity_description_<%= issue.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= issue.id %>").hide(); - $("#intro_content_hide_<%= issue.id %>").show(); - }); - $("#intro_content_hide_<%= issue.id %>").click(function () { - $("#activity_description_<%= issue.id %>").toggleClass("maxh360"); - $("#activity_description_<%= issue.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= issue.id %>").hide(); - $("#intro_content_show_<%= issue.id %>").show(); - }); }); <%= render :partial => 'users/project_issue', :locals => {:activity => issue, :user_activity_id => issue.id} %> diff --git a/app/views/layouts/_project_info.html.erb b/app/views/layouts/_project_info.html.erb index b4a2996d0..51758ea4c 100644 --- a/app/views/layouts/_project_info.html.erb +++ b/app/views/layouts/_project_info.html.erb @@ -84,7 +84,7 @@ ID:<%= @course.id%>

diff --git a/app/views/messages/reply.js.erb b/app/views/messages/reply.js.erb index ea848439f..f61de74f0 100644 --- a/app/views/messages/reply.js.erb +++ b/app/views/messages/reply.js.erb @@ -5,20 +5,4 @@ <% elsif @org_subfield %> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'organizations/org_subfield_message', :locals => {:activity => @topic,:user_activity_id =>@user_activity_id}) %>"); <%end%> -init_activity_KindEditor_data(<%= @user_activity_id %>,"","87%", "UserActivity"); -showNormalImage('activity_description_<%= @user_activity_id %>'); -if($("#intro_content_<%= @user_activity_id %>").height() > 810) { - $("#intro_content_show_<%= @user_activity_id %>").show(); -} -$("#intro_content_show_<%= @user_activity_id %>").click(function(){ - $("#activity_description_<%= @user_activity_id %>").toggleClass("maxh360"); - $("#activity_description_<%= @user_activity_id %>").toggleClass("lh18"); - $("#intro_content_show_<%= @user_activity_id %>").hide(); - $("#intro_content_hide_<%= @user_activity_id %>").show(); -}); -$("#intro_content_hide_<%= @user_activity_id %>").click(function(){ - $("#activity_description_<%= @user_activity_id %>").toggleClass("maxh360"); - $("#activity_description_<%= @user_activity_id %>").toggleClass("lh18"); - $("#intro_content_hide_<%= @user_activity_id %>").hide(); - $("#intro_content_show_<%= @user_activity_id %>").show(); -}); \ No newline at end of file +init_activity_KindEditor_data(<%= @user_activity_id %>,"","87%", "UserActivity"); \ No newline at end of file diff --git a/app/views/organizations/_org_course_homework.html.erb b/app/views/organizations/_org_course_homework.html.erb index 22b0b2cb4..658fa82e6 100644 --- a/app/views/organizations/_org_course_homework.html.erb +++ b/app/views/organizations/_org_course_homework.html.erb @@ -92,7 +92,7 @@
匿评截止时间:<%= activity.homework_detail_manual.evaluation_end.to_s %> 23:59
<% end %> -
+
<%= activity.description.html_safe %>
@@ -101,6 +101,9 @@
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
迟交扣分:<%= activity.late_penalty%>分 @@ -141,16 +144,13 @@ <% end %> <% end %>
-
- <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => activity.attachments} %> -
-
<% if activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 1 %>
<% projects = activity.student_work_projects.where("is_leader = 1") %>
已关联项目:<%='各小组尚未将小组项目关联到本次作业。' if projects.empty? %>
+
<% projects.each do |pro| %> <% project = Project.find pro.project_id %> -
+
<% if project.is_public || User.current.member_of?(project) || User.current.admin? %> <%= link_to image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius"),project_path(project.id,:host=>Setting.host_name),:id=>"project_img_"+project.id.to_s+"_"+activity.id.to_s,:alt =>"项目头像" %> <% else %> @@ -172,7 +172,7 @@ <% time=project.updated_on %> <% time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %>

<%=(User.find project.user_id).show_name %>(组长)

-

<%=time_from_now time %>

+

<%=time_from_now time %>  <%=changesets_num project %>提交

项目名称:<%=project.name %>
创建者:<%=(User.find project.user_id).show_name %>(组长)
@@ -290,4 +290,7 @@
-
\ No newline at end of file +
+ \ No newline at end of file diff --git a/app/views/organizations/_org_course_message.html.erb b/app/views/organizations/_org_course_message.html.erb index 9ca8f5d10..3b63d6495 100644 --- a/app/views/organizations/_org_course_message.html.erb +++ b/app/views/organizations/_org_course_message.html.erb @@ -30,7 +30,7 @@
发帖时间:<%= format_time(activity.created_on) %>
-
+
<% if activity.parent_id.nil? %> <%= activity.content.to_s.html_safe%> @@ -43,6 +43,9 @@
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
+ diff --git a/app/views/organizations/_org_course_news.html.erb b/app/views/organizations/_org_course_news.html.erb index 475a982e5..2903e83f2 100644 --- a/app/views/organizations/_org_course_news.html.erb +++ b/app/views/organizations/_org_course_news.html.erb @@ -22,7 +22,7 @@
发布时间:<%= format_time(activity.created_on) %>
-
+
<%= activity.description.html_safe %>
@@ -31,6 +31,9 @@
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
@@ -103,4 +106,7 @@
-
\ No newline at end of file +
+ \ No newline at end of file diff --git a/app/views/organizations/_org_course_poll.html.erb b/app/views/organizations/_org_course_poll.html.erb index c363909d9..d8907f4a9 100644 --- a/app/views/organizations/_org_course_poll.html.erb +++ b/app/views/organizations/_org_course_poll.html.erb @@ -29,7 +29,7 @@
发布时间:<%= format_time(activity.published_at) %>
-
+
<%= activity.polls_description.html_safe %>
@@ -53,4 +53,7 @@
-<% end %> \ No newline at end of file +<% end %> + \ No newline at end of file diff --git a/app/views/organizations/_org_project_issue.html.erb b/app/views/organizations/_org_project_issue.html.erb index e29994967..41d134b9d 100644 --- a/app/views/organizations/_org_project_issue.html.erb +++ b/app/views/organizations/_org_project_issue.html.erb @@ -33,7 +33,7 @@ <%=format_time(activity.created_on) %>
-
+
<% if activity.description? %> <%= textAreailizable activity, :description, :attachments => activity.attachments %> @@ -45,32 +45,7 @@
- <% if activity.attachments.any? %> - <% activity.attachments.each do |attachment| %> -
- - - <%= link_to_short_attachment attachment,:length=> 58, :class => 'link_file_a fl newsBlue', :download => true -%> - - <% if attachment.is_text? %> - <%= link_to image_tag('magnifier.png'), - :controller => 'attachments', - :action => 'show', - :id => attachment, - :class => 'fl', - :filename => attachment.filename %> - <% end %> - - ( - <%= number_to_human_size attachment.filesize %>) - - - <%= link_to h(truncate(attachment.author.name, length: 10, omission: '...')),user_path(attachment.author),:class => "c_orange" %>, - <%= format_time(attachment.created_on) %> - -
- <% end %> - <% end %> + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %>
@@ -150,3 +125,6 @@
+ diff --git a/app/views/organizations/_org_subfield_message.html.erb b/app/views/organizations/_org_subfield_message.html.erb index e6bee8000..74596b0d0 100644 --- a/app/views/organizations/_org_subfield_message.html.erb +++ b/app/views/organizations/_org_subfield_message.html.erb @@ -26,7 +26,7 @@
时间:<%= format_time(activity.created_on) %>
-
+
<% if activity.parent_id.nil? %> <%= activity.content.to_s.html_safe%> @@ -39,6 +39,9 @@
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
@@ -115,4 +118,7 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/organizations/_project_message.html.erb b/app/views/organizations/_project_message.html.erb index 037dfe61b..85cfb2921 100644 --- a/app/views/organizations/_project_message.html.erb +++ b/app/views/organizations/_project_message.html.erb @@ -26,7 +26,7 @@
时间:<%= format_time(activity.created_on) %>
-
+
<% if activity.parent_id.nil? %> <%= activity.content.to_s.html_safe%> @@ -39,6 +39,9 @@
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
@@ -115,4 +118,7 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/projects/_attachment_acts.html.erb b/app/views/projects/_attachment_acts.html.erb index bb62eee55..737473e76 100644 --- a/app/views/projects/_attachment_acts.html.erb +++ b/app/views/projects/_attachment_acts.html.erb @@ -21,7 +21,7 @@ 发布时间:<%= format_time(activity.created_on) %>

<%= textAreailizable activity, :description %>

-
+
<%#= activity.description.html_safe %>
@@ -32,4 +32,7 @@
-
\ No newline at end of file + + \ No newline at end of file diff --git a/app/views/projects/_project_activities.html.erb b/app/views/projects/_project_activities.html.erb index 781b65810..2926747e4 100644 --- a/app/views/projects/_project_activities.html.erb +++ b/app/views/projects/_project_activities.html.erb @@ -33,22 +33,6 @@ $(function () { init_activity_KindEditor_data(<%= activity.id%>, null, "87%", "<%= activity.class.to_s %>"); - showNormalImage('activity_description_<%= activity.id %>'); - if ($("#intro_content_<%= activity.id %>").height() > 810) { - $("#intro_content_show_<%= activity.id %>").show(); - } - $("#intro_content_show_<%= activity.id %>").click(function () { - $("#activity_description_<%= activity.id %>").toggleClass("maxh360"); - $("#activity_description_<%= activity.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= activity.id %>").hide(); - $("#intro_content_hide_<%= activity.id %>").show(); - }); - $("#intro_content_hide_<%= activity.id %>").click(function () { - $("#activity_description_<%= activity.id %>").toggleClass("maxh360"); - $("#activity_description_<%= activity.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= activity.id %>").hide(); - $("#intro_content_show_<%= activity.id %>").show(); - }); }); diff --git a/app/views/projects/_project_news.html.erb b/app/views/projects/_project_news.html.erb index 919abc11e..7336adc29 100644 --- a/app/views/projects/_project_news.html.erb +++ b/app/views/projects/_project_news.html.erb @@ -22,7 +22,7 @@
发布时间:<%= format_time(activity.created_on) %>
-
+
<%= activity.description.html_safe %>
@@ -31,6 +31,9 @@
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
@@ -103,4 +106,7 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/student_work/_programing_work_show.html.erb b/app/views/student_work/_programing_work_show.html.erb index f7ecb0ccf..d98a9fe0f 100644 --- a/app/views/student_work/_programing_work_show.html.erb +++ b/app/views/student_work/_programing_work_show.html.erb @@ -31,52 +31,50 @@
- <% if @is_teacher%> -
  • - - 测试结果: - -
    - <% work.student_work_tests.each_with_index do |test, index| %> -
    -

    - 第<%= work.student_work_tests.count - index%>次测试 -

    - - <%= test.created_at.to_s(:db) %> - -
    +
  • + + 测试结果: + +
    + <% work.student_work_tests.each_with_index do |test, index| %> +
    +

    + 第<%= work.student_work_tests.count - index%>次测试 +

    + + <%= test.created_at.to_s(:db) %> + +
    +
    + <% if test.status.to_i == -2 %> +
    + <%= test.results.first %> +
    + <% else %> +
    +
      + <% test.results.each_with_index do |x, i| %> +
    • + 测试<%=i+1%> + <% if x["status"].to_i != 0 %> + 测试错误! + 您的输出: + <%=x["result"]%> + 正确输出: + <%=x["output"]%> +
      + <% else %> + 测试正确! +
      + <% end %> +
    • + <% end %> +
    - <% if test.status.to_i == -2 %> -
    - <%= test.results.first %> -
    - <% else %> -
    -
      - <% test.results.each_with_index do |x, i| %> -
    • - 测试<%=i+1%> - <% if x["status"].to_i != 0 %> - 测试错误! - 您的输出: - <%=x["result"]%> - 正确输出: - <%=x["output"]%> -
      - <% else %> - 测试正确! -
      - <% end %> -
    • - <% end %> -
    -
    - <% end %> <% end %> -
    -
  • - <% end%> + <% end %> + +
  • <% if @is_teacher || (@homework.homework_detail_manual.comment_status == 2 && work.user != User.current )%> diff --git a/app/views/student_work/_student_work_list.html.erb b/app/views/student_work/_student_work_list.html.erb index 5598092e9..371334be1 100644 --- a/app/views/student_work/_student_work_list.html.erb +++ b/app/views/student_work/_student_work_list.html.erb @@ -40,18 +40,48 @@ <% end%>
    - <% if @homework.homework_type != 3 && student_work.user == User.current && !@is_evaluation %> - <% if @homework.homework_type == 2%> - <%=render :partial => 'programing_work_show', :locals=> {:work => student_work, :score =>student_work_score(student_work,User.current),:student_work_scores => student_work.student_works_scores.order("updated_at desc")} %> - <% else %> - <%=render :partial => 'show' , :locals=> {:work => student_work, :score =>student_work_score(student_work,User.current),:student_work_scores => student_work.student_works_scores.order("updated_at desc")} %> - <% end %> - <% elsif @homework.homework_type == 3 %> - <% pro = @homework.student_work_projects.where(:user_id => User.current.id).first %> - <% if pro && pro.student_work_id == student_work.id && !@is_evaluation %> - <%=render :partial => 'show' , :locals=> {:work => student_work, :score =>student_work_score(student_work,User.current),:student_work_scores => student_work.student_works_scores.order("updated_at desc")} %> - <% end %> - <% end %>
    -<% end%> \ No newline at end of file +<% end%> + \ No newline at end of file diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index db276d88b..99315d5af 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -92,7 +92,7 @@
    匿评截止时间:<%= activity.homework_detail_manual.evaluation_end.to_s %> 23:59
    <% end %> -
    +
    <%= activity.description.html_safe %>
    @@ -101,7 +101,9 @@
    - +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
    迟交扣分:<%= activity.late_penalty%>分 @@ -142,16 +144,13 @@ <% end %> <% end %>
    -
    - <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => activity.attachments} %> -
    -
    <% if activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 1 %>
    <% projects = activity.student_work_projects.where("is_leader = 1") %>
    已关联项目:<%='各小组尚未将小组项目关联到本次作业。' if projects.empty? %>
    +
    <% projects.each do |pro| %> <% project = Project.find pro.project_id %> -
    +
    <% if project.is_public || User.current.member_of?(project) || User.current.admin? %> <%= link_to image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius"),project_path(project.id,:host=>Setting.host_name),:id=>"project_img_"+project.id.to_s+"_"+activity.id.to_s,:alt =>"项目头像" %> <% else %> @@ -173,7 +172,7 @@ <% time=project.updated_on %> <% time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %>

    <%=(User.find project.user_id).show_name %>(组长)

    -

    <%=time_from_now time %>

    +

    <%=time_from_now time %>  <%=changesets_num project %>提交

    项目名称:<%=project.name %>
    创建者:<%=(User.find project.user_id).show_name %>(组长)
    @@ -297,4 +296,7 @@
    -
    \ No newline at end of file +
    + \ No newline at end of file diff --git a/app/views/users/_course_message.html.erb b/app/views/users/_course_message.html.erb index 22a4bcf57..9b2fd328d 100644 --- a/app/views/users/_course_message.html.erb +++ b/app/views/users/_course_message.html.erb @@ -30,7 +30,7 @@
    发帖时间:<%= format_time(activity.created_on) %>
    -
    +
    <% if activity.parent_id.nil? %> <%= activity.content.to_s.html_safe%> @@ -43,7 +43,9 @@
    - +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
    + diff --git a/app/views/users/_course_news.html.erb b/app/views/users/_course_news.html.erb index 475a982e5..2903e83f2 100644 --- a/app/views/users/_course_news.html.erb +++ b/app/views/users/_course_news.html.erb @@ -22,7 +22,7 @@
    发布时间:<%= format_time(activity.created_on) %>
    -
    +
    <%= activity.description.html_safe %>
    @@ -31,6 +31,9 @@
    +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
    @@ -103,4 +106,7 @@
    -
    \ No newline at end of file +
    + \ No newline at end of file diff --git a/app/views/users/_course_poll.html.erb b/app/views/users/_course_poll.html.erb index 48ab5d2f2..6ecd72cfb 100644 --- a/app/views/users/_course_poll.html.erb +++ b/app/views/users/_course_poll.html.erb @@ -29,7 +29,7 @@
    发布时间:<%= format_time(activity.published_at) %>
    -
    +
    <%= activity.polls_description.html_safe %>
    @@ -53,4 +53,7 @@
    -<% end %> \ No newline at end of file +<% end %> + \ No newline at end of file diff --git a/app/views/users/_project_issue.html.erb b/app/views/users/_project_issue.html.erb index cd9704186..77d2f2fde 100644 --- a/app/views/users/_project_issue.html.erb +++ b/app/views/users/_project_issue.html.erb @@ -45,7 +45,7 @@ <%=format_time(activity.created_on) %>
    -
    +
    <% if activity.description? %> <%= textAreailizable activity, :description, :attachments => activity.attachments %> @@ -57,33 +57,7 @@
    - <% if activity.attachments.any? %> - <% activity.attachments.each do |attachment| %> -
    - - - <%= link_to_short_attachment attachment,:length=> 58, :class => 'link_file_a fl newsBlue', :download => true -%> - - <% if attachment.is_text? %> - <%= link_to image_tag('magnifier.png'), - :controller => 'attachments', - :action => 'show', - :id => attachment, - :class => 'fl', - :filename => attachment.filename %> - <% end %> - - ( - <%= number_to_human_size attachment.filesize %>) - - - <%= link_to h(truncate(attachment.author.name, length: 10, omission: '...')),user_path(attachment.author),:class => "c_orange" %>, - <%= format_time(attachment.created_on) %> - -
    -
    - <% end %> - <% end %> + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %>
    @@ -163,3 +137,6 @@
    + diff --git a/app/views/users/_project_message.html.erb b/app/views/users/_project_message.html.erb index 5a9f7e398..87ed5a6e2 100644 --- a/app/views/users/_project_message.html.erb +++ b/app/views/users/_project_message.html.erb @@ -31,7 +31,7 @@
    发帖时间:<%= format_time(activity.created_on) %>
    -
    +
    <% if activity.parent_id.nil? %> <%= activity.content.to_s.html_safe%> @@ -44,7 +44,9 @@
    - +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
    - -
    -
    \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/_user_activities.html.erb b/app/views/users/_user_activities.html.erb index bb1a42f58..2941394da 100644 --- a/app/views/users/_user_activities.html.erb +++ b/app/views/users/_user_activities.html.erb @@ -40,22 +40,6 @@ $(function() { init_activity_KindEditor_data(<%= user_activity.id%>, null, "87%", "<%=user_activity.class.to_s%>"); - showNormalImage('activity_description_<%= user_activity.id %>'); - if($("#intro_content_<%= user_activity.id %>").height() > 360) { - $("#intro_content_show_<%= user_activity.id %>").show(); - } - $("#intro_content_show_<%= user_activity.id %>").click(function(){ - $("#activity_description_<%= user_activity.id %>").toggleClass("maxh360"); - $("#activity_description_<%= user_activity.id%>").toggleClass("lh18"); - $("#intro_content_show_<%= user_activity.id %>").hide(); - $("#intro_content_hide_<%= user_activity.id %>").show(); - }); - $("#intro_content_hide_<%= user_activity.id %>").click(function(){ - $("#activity_description_<%= user_activity.id %>").toggleClass("maxh360"); - $("#activity_description_<%= user_activity.id%>").toggleClass("lh18"); - $("#intro_content_hide_<%= user_activity.id %>").hide(); - $("#intro_content_show_<%= user_activity.id %>").show(); - }); }); <% unless user_activity.act_type == "ProjectCreateInfo" %> diff --git a/app/views/users/_user_blog.html.erb b/app/views/users/_user_blog.html.erb index c1219eb25..fd864e4d9 100644 --- a/app/views/users/_user_blog.html.erb +++ b/app/views/users/_user_blog.html.erb @@ -28,7 +28,7 @@
    发布时间:<%= format_time(activity.created_on) %>
    -
    +
    <%= activity.content.html_safe %>
    @@ -37,6 +37,9 @@
    +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
    @@ -116,4 +119,7 @@ <% end %> - \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/_user_homework_detail.html.erb b/app/views/users/_user_homework_detail.html.erb index 6cb502d77..d2420491c 100644 --- a/app/views/users/_user_homework_detail.html.erb +++ b/app/views/users/_user_homework_detail.html.erb @@ -95,7 +95,7 @@ <% end %> -
    +
    <%= homework_common.description.html_safe %>
    @@ -104,7 +104,9 @@
    - +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => homework_common} %> +
    迟交扣分:<%= homework_common.late_penalty%>分 @@ -145,16 +147,13 @@ <% end %> <% end %>
    -
    - <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => homework_common.attachments} %> -
    -
    <% if homework_common.homework_type == 3 && homework_common.homework_detail_group.base_on_project == 1 %>
    <% projects = homework_common.student_work_projects.where("is_leader = 1") %>
    已关联项目:<%='各小组尚未将小组项目关联到本次作业。' if projects.empty? %>
    +
    <% projects.each do |pro| %> <% project = Project.find pro.project_id %> -
    +
    <% if project.is_public || User.current.member_of?(project) || User.current.admin? %> <%= link_to image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius"),project_path(project.id,:host=>Setting.host_name),:id=>"project_img_"+project.id.to_s+"_"+homework_common.id.to_s,:alt =>"项目头像" %> <% else %> @@ -175,7 +174,7 @@ <% time=project.updated_on %> <% time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %>

    <%=(User.find project.user_id).show_name %>(组长)

    -

    <%=time_from_now time %>

    +

    <%=time_from_now time %>  <%=changesets_num project %>提交

    项目名称:<%=project.name %>
    创建者:<%=(User.find project.user_id).show_name %>(组长)
    @@ -301,4 +300,7 @@
    -
    \ No newline at end of file +
    + \ No newline at end of file diff --git a/app/views/users/_user_homework_list.html.erb b/app/views/users/_user_homework_list.html.erb index f00900488..efe9216df 100644 --- a/app/views/users/_user_homework_list.html.erb +++ b/app/views/users/_user_homework_list.html.erb @@ -18,22 +18,6 @@