diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 10fec7c1b..3114ef5e0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -26,6 +26,7 @@ class UsersController < ApplicationController menu_item :user_information, :only => :info menu_item :user_course, :only => :user_courses menu_item :user_homework, :only => :user_homeworks + menu_item :student_homework, :only => :student_homeworks menu_item :user_project, :only => [:user_projects, :watch_projects] menu_item :requirement_focus, :only => :watch_contests menu_item :user_newfeedback, :only => :user_newfeedback @@ -35,12 +36,12 @@ class UsersController < ApplicationController # before_filter :can_show_course, :only => [:user_courses,:user_homeworks] before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, - :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, + :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, - :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages] + :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -374,32 +375,130 @@ class UsersController < ApplicationController #用户作业列表 def user_homeworks - if User.current == @user - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" + @user = User.current + if(params[:type].blank? || params[:type] == "1") #公共题库 + visible_course = Course.where("is_public = 1 && is_delete = 0") + visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc") + elsif params[:type] == "2" #我的题库 + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("created_at desc") + end + @type = params[:type] + @limit = 15 + @is_remote = true + @hw_count = @homeworks.count + @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 + @offset ||= @hw_pages.offset + @homeworks = paginateHelper @homeworks,15 + respond_to do |format| + format.js + format.html {render :layout => 'static_base'} + end + end - #判断当前用户在当前课程的身份 - visibleCourse = @user.courses.empty? ? [] : @user.courses.visible - homework_ids = [] - visibleCourse.each do |course| - if User.current.allowed_to?(:as_teacher,course) - homeworks = HomeworkCommon.where("course_id = #{course.id}") - homework_ids << homeworks.pluck(:id) unless homeworks.empty? - else - homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'") - homework_ids << homeworks.pluck(:id) unless homeworks.empty? + def student_homeworks + if User.current == @user + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" + + #判断当前用户在当前课程的身份 + visibleCourse = @user.courses.empty? ? [] : @user.courses.visible + homework_ids = [] + visibleCourse.each do |course| + homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'") + homework_ids << homeworks.pluck(:id) unless homeworks.empty? + end + visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")" + @homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10) + @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) + @is_in_course = params[:is_in_course].to_i || 0 + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + else + render_403 + end + end + + def choose_user_course + if !params[:search].nil? + search = "%#{params[:search].to_s.strip.downcase}%" + @course = @user.courses.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)} + else + @course = @user.courses.select { |course| @user.allowed_to?(:as_teacher,course)} + end + @search = params[:search] + #这里仅仅是传递需要发送的资源id + @send_id = params[:send_id] + respond_to do |format| + format.js + end + end + + def send_homework_to_course + homework = HomeworkCommon.find params[:send_id].to_i + course_ids = params[:course_ids] + course_ids.each do |course_id| + course = Course.find course_id.to_i + new_homework = HomeworkCommon.new + new_homework.name = homework.name + new_homework.user_id = User.current.id + new_homework.description = homework.description + new_homework.homework_type = homework.homework_type + new_homework.late_penalty = homework.late_penalty + new_homework.course_id = course.id + new_homework.teacher_priority = homework.teacher_priority + new_homework.anonymous_comment = homework.anonymous_comment + new_homework.quotes = 0 + new_homework.is_open = homework.is_open + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.copy_from = attachment.id + att.save + new_homework.attachments << att + end + homework_detail_manual = homework.homework_detail_manual + homework_detail_programing = homework.homework_detail_programing + homework_detail_group = homework.homework_detail_group + if homework_detail_manual + new_homework.homework_detail_manual = HomeworkDetailManual.new + new_homework_detail_manual = new_homework.homework_detail_manual + new_homework_detail_manual.ta_proportion = homework_detail_manual.ta_proportion + new_homework_detail_manual.comment_status = 0 + new_homework_detail_manual.evaluation_num = homework_detail_manual.evaluation_num + new_homework_detail_manual.absence_penalty = homework_detail_manual.absence_penalty + end + if homework_detail_programing + new_homework.homework_detail_programing = HomeworkDetailPrograming.new + new_homework.homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion + new_homework.homework_detail_programing.language = homework_detail_programing.language + homework.homework_tests.each_with_index do |homework_test| + new_homework.homework_tests << HomeworkTest.new( + input: homework_test.input, + output: homework_test.output + ) end end - visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")" - @homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10) - @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) - @is_in_course = params[:is_in_course].to_i || 0 - respond_to do |format| - format.js - format.html {render :layout => 'new_base_user'} + + if homework_detail_group + new_homework.homework_detail_group = HomeworkDetailGroup.new + new_homework.homework_detail_group.min_num = homework_detail_group.min_num + new_homework.homework_detail_group.max_num = homework_detail_group.max_num + new_homework.homework_detail_group.base_on_project = homework_detail_group.base_on_project end - else - render_403 + if new_homework.save + new_homework_detail_manual.save if new_homework_detail_manual + new_homework.homework_detail_programing.save if new_homework.homework_detail_programing + new_homework.homework_detail_group.save if new_homework.homework_detail_group + end + homework.update_attribute(:quotes, homework.quotes+1) + end + @homework = homework + respond_to do |format| + format.js end end @@ -439,6 +538,7 @@ class UsersController < ApplicationController @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset @homeworks = paginateHelper @homeworks,15 + @is_import = params[:is_import] respond_to do |format| format.js end @@ -446,6 +546,7 @@ class UsersController < ApplicationController def show_homework_detail @homework = HomeworkCommon.find params[:homework].to_i + @is_import = params[:is_import] respond_to do |format| format.js end @@ -469,6 +570,7 @@ class UsersController < ApplicationController @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset @homeworks = paginateHelper @homeworks,15 + @is_import = params[:is_import] respond_to do |format| format.js end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0995a6289..c37d3ad55 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2521,7 +2521,7 @@ module ApplicationHelper #获取匿评相关连接代码 def homework_anonymous_comment (homework, is_in_course, user_activity_id = -1, course_activity = -1) - if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + if homework.homework_detail_manual.comment_status == 0 ||Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") link = link_to "启动匿评","javascript:void(0)", :class => "postOptionLink", :title => "作业截止日期之前不可以启动匿评" elsif homework.student_works.count >= 2 && homework.homework_detail_manual#作业份数大于2 case homework.homework_detail_manual.comment_status diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 8db852abd..6fb9380e7 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -116,7 +116,7 @@ module CoursesHelper @course.journals_for_messages.where('m_parent_id IS NULL').count end - #当前学期 + #当前学期(2015春季学期) def current_time_and_term course str = "" term = cur_course_term @@ -144,6 +144,22 @@ module CoursesHelper val end + #当前学期(2015春) + def current_time_and_term_short course + str = "" + term = cur_course_term + if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year + str = course.time.to_s + course.term[0] + elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term) + str = course.time.to_s + course.term[0] + elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term)) + str = course.end_time.to_s + course.end_term[0] + else + str = Time.now.year.to_s + cur_course_term[0] + end + str + end + # 返回学生数量,即roles表中定义的Reporter #def studentCount project # searchStudent(project).count diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index aba2fb58e..5792c6487 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -86,6 +86,31 @@ module ExerciseHelper return result end + def convert_to_chi_num num + result = "" + case num.to_i + when 1 + result = '一' + when 2 + result = '二' + when 3 + result = '三' + when 4 + result = '四' + when 5 + result = '五' + when 6 + result = '六' + when 7 + result = '七' + when 8 + result = '八' + when 9 + result = '九' + end + return result + end + def get_current_score exercise score = 0 unless exercise.nil? diff --git a/app/views/admin/latest_login_teachers.html.erb b/app/views/admin/latest_login_teachers.html.erb index 06c0386f5..a42e84369 100644 --- a/app/views/admin/latest_login_teachers.html.erb +++ b/app/views/admin/latest_login_teachers.html.erb @@ -59,17 +59,17 @@ <%=format_time(teacher.last_login_on) %>