diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 68386de44..01703f679 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -469,6 +469,23 @@ class AdminController < ApplicationController end end + #最近登录老师列表 + def latest_login_teachers + scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 ORDER BY last_login_on DESC") + if params[:startdate].present? + scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 and last_login_on>= '#{params[:startdate]} 00:00:00' ORDER BY last_login_on DESC") + end + if params[:enddate].present? + scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 and last_login_on <= '#{params[:enddate]} 23:59:59' ORDER BY last_login_on DESC") + end + @teachers = scope + @teachers = paginateHelper @teachers,30 + @page = (params['page'] || 1).to_i - 1 + respond_to do |format| + format.html + end + end + #作业 def homework @homework = HomeworkCommon.order('end_time desc') diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 36060d41c..be96124c2 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -450,6 +450,93 @@ class CoursesController < ApplicationController #copy avatar copy_avatar(@course, copy_course) + if params[:course_content_type] + params[:course_content_type].each do |type| + case type + when "0" + homeworks = copy_course.homework_commons + homeworks.each do |homework| + new_homework = HomeworkCommon.new + new_homework.name = homework.name + new_homework.user_id = User.current.id + new_homework.description = homework.description + new_homework.publish_time = Date.today + 30 + new_homework.end_time = Date.today + 60 + 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_start = Date.today + 67 + new_homework_detail_manual.evaluation_end = Date.today + 74 + 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 + + 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 + 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 + when "1" + 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 + attach_copied_obj.is_publish = 0 + attach_copied_obj.publish_time = Date.today + 30 + 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 + +=begin if params[:checkAll] attachments = copy_course.attachments attachments.each do |attachment| @@ -513,6 +600,7 @@ class CoursesController < ApplicationController end end end +=end end if @course respond_to do |format| diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index a891d3354..00b11323b 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -6,8 +6,8 @@ class HomeworkCommonController < ApplicationController include StudentWorkHelper before_filter :find_course, :only => [:index,:new,:create] - before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment] - before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment] + before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] + before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] before_filter :member_of_course, :only => [:index] def index @@ -261,6 +261,30 @@ class HomeworkCommonController < ApplicationController end end + def open_student_works + if @homework.is_open == 0 + @homework.update_attribute(:is_open, 1) + else + @homework.update_attribute(:is_open, 0) + end + @user_activity_id = params[:user_activity_id] + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + end + + def alert_open_student_works + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + respond_to do |format| + format.js + end + end + def programing_test test = {language:params[:language],src:Base64.encode64(params[:src]),input:[params[:input]],output:[params[:output]]} @index = params[:index] diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 7ccb3177c..a38d83851 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -6,9 +6,10 @@ class StudentWorkController < ApplicationController require "base64" before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] - before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] + before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment] + before_filter :is_logged, :only => [:index] ### def program_test @@ -91,101 +92,119 @@ class StudentWorkController < ApplicationController student_in_group = '(' + group_students.map{|user| user.id}.join(',') + ')' end #老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 - if @is_teacher || @homework.homework_detail_manual.nil? || - (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) + if @homework.is_open == 1 @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name @show_all = true - elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - @stundet_works = [] - else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) - end - else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) - end - elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] - else - my_work = @homework.student_works.where(:id => pro.student_work_id) - end - else - my_work = @homework.student_works.where(:user_id => User.current.id) - end - @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} - elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] - else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) - end - else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) - end - if my_work.empty? - @stundet_works = [] - else + elsif @homework.is_open == 0 && User.current.member_of_course?(@course) || User.current.admin? + if @is_teacher || @homework.homework_detail_manual.nil? || + (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name @show_all = true - end - else - @stundet_works = [] - end - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count - else - if @is_teacher || @homework.homework_detail_manual.nil? || (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) #老师 || 超级管理员 显示所有列表 - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name - @show_all = true - elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? + elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + @stundet_works = [] + else + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + end + else + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end + elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + my_work = [] + else + my_work = @homework.student_works.where(:id => pro.student_work_id) + end + else + my_work = @homework.student_works.where(:user_id => User.current.id) + end + @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} + elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + my_work = [] + else + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + end + else + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end + if my_work.empty? @stundet_works = [] else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @show_all = true end else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) - end - elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] - else - my_work = @homework.student_works.where(:id => pro.student_work_id) - end - else - my_work = @homework.student_works.where(:user_id => User.current.id) - end - @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} - elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] - else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) - end - else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) - end - if my_work.empty? @stundet_works = [] - else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name - @show_all = true end else - @stundet_works = [] + render_403 + return end + + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count + else + if @homework.is_open == 1 + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name + @show_all = true + elsif @homework.is_open == 0 && User.current.member_of_course?(@course) || User.current.admin? + if @is_teacher || @homework.homework_detail_manual.nil? || (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) #老师 || 超级管理员 显示所有列表 + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name + @show_all = true + elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + @stundet_works = [] + else + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + end + else + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end + elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + my_work = [] + else + my_work = @homework.student_works.where(:id => pro.student_work_id) + end + else + my_work = @homework.student_works.where(:user_id => User.current.id) + end + @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} + elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + my_work = [] + else + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + end + else + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end + if my_work.empty? + @stundet_works = [] + else + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name + @show_all = true + end + else + @stundet_works = [] + end + else + render_403 + return + end + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name).count end @@ -802,6 +821,10 @@ class StudentWorkController < ApplicationController render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? end + def is_logged + redirect_to signin_path unless User.current.logged? + end + #根据条件过滤作业结果 def search_homework_member homeworks,name if name == "" diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f99df07c3..82f648ad9 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -88,7 +88,8 @@ class Attachment < ActiveRecord::Base cattr_accessor :thumbnails_storage_path @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") - before_save :files_to_final_location,:act_as_course_activity + before_save :files_to_final_location + after_save :act_as_course_activity after_create :office_conver, :be_user_score,:act_as_forge_activity,:create_attachment_ealasticsearch_index after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count @@ -606,8 +607,14 @@ class Attachment < ActiveRecord::Base #课程动态公共表记录 def act_as_course_activity - if self.container_type == "Course" && self.course_acts.empty? - self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id) + if self.container_type == "Course" + if self.is_publish == 0 + self.course_acts.destroy_all + else + if self.is_publish == 1 && self.course_acts.empty? + self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id) + end + end end end diff --git a/app/views/admin/_tab_users.erb b/app/views/admin/_tab_users.erb new file mode 100644 index 000000000..2cda0c61c --- /dev/null +++ b/app/views/admin/_tab_users.erb @@ -0,0 +1,7 @@ +
+ 序号 + | ++ 登录时间 + | ++ 用户id + | ++ 用户姓名 + | ++ 用户登录名 + | ++ 用户身份 + | +
---|---|---|---|---|---|
+ <%=@count %> + | ++ <%=format_time(teacher.last_login_on) %> + | ++ <%=teacher.id %> + | + ++ <%=link_to(teacher.login, user_path(teacher)) %> + | ++ 老师 + | +