diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 334101bb0..3f49abb23 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -599,8 +599,19 @@ class AdminController < ApplicationController #学校列表 def schools - + @order = "" + @sort = "" @schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC") + if params[:sort] && (params[:order] == 'num') + @order = params[:order] + @sort = params[:sort] + @schools.each do |school| + count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count + school[:infocount] = count.to_i + end + @sort == 'asc' ? (@schools = @schools.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@schools = @schools.sort{|x,y| y[:infocount] <=> x[:infocount]}) + end + @school_count = @schools.count @school_pages = Paginator.new @school_count, 30, params['page'] || 1 diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index 9d90cb9f2..e80c56e49 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -40,7 +40,7 @@ class AvatarController < ApplicationController @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) # 用户头像上传时进行特别处理 - if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project') + if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project' || @source_type == 'Organization') diskfile += "temp" @urlfile += "temp" end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2614b6271..e542d1e1d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -331,7 +331,7 @@ class CoursesController < ApplicationController @all_members = searchTeacherAndAssistant(@course) @members = @all_members when '2' - if @course.open_student == 1 || User.current.member_of_course?(@course) + if @course.open_student == 1 || User.current.member_of_course?(@course) || User.current.admin? @subPage_title = l :label_student_list page = params[:page].nil? ? 0 : (params['page'].to_i - 1) @all_members = student_homework_score(0,page, 10,@score_sort_by,@sort_type) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 4c9411538..b97699058 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -196,8 +196,9 @@ class IssuesController < ApplicationController priority_id = params[:issue][:priority_id] ps = ProjectsService.new - ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id - + if senduser.id != User.current.id + ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id + end call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) respond_to do |format| format.html { diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index c4935a1af..ca6484e49 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -96,6 +96,9 @@ class MyController < ApplicationController elsif params[:project] @project = Project.find params[:project] diskfile = disk_filename('Project', @project.id) + elsif params[:organization] + @organization = Organization.find params[:organization] + diskfile = disk_filename('Organization', @organization.id) else @user = User.current diskfile = disk_filename('User', @user.id) @@ -116,6 +119,9 @@ class MyController < ApplicationController when 'Project' @project = Project.find params[:source_id] diskfile = disk_filename('Project', @project.id) + when 'Organization' + @organization = Organization.find params[:source_id] + diskfile = disk_filename('Organization', @organization.id) end end diskfile1 = diskfile + 'temp' diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 5e13149df..d1835408f 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -410,11 +410,11 @@ class StudentWorkController < ApplicationController #开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?) if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name end @show_all = true elsif User.current.member_of_course?(@course) @@ -476,11 +476,11 @@ class StudentWorkController < ApplicationController else if (@homework.is_open == 1 &&@course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?) if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name end @show_all = true elsif User.current.member_of_course?(@course) @@ -613,33 +613,21 @@ class StudentWorkController < ApplicationController student_work.work_status = 1 end if student_work.save - if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 - @student_work_project.student_work_id = student_work.id - @student_work_project.save - members = params[:group_member_ids].split(',') - for i in 1 .. members.count-1 - stu_project = StudentWorkProject.new - stu_project.homework_common_id = @homework.id - stu_project.student_work_id = student_work.id - stu_project.project_id = @student_work_project.project_id - stu_project.user_id = members[i].to_i - stu_project.is_leader = 0 + if @homework.homework_type == 3 + if @homework.homework_detail_group.base_on_project == 1 + @student_work_project.student_work_id = student_work.id + @student_work_project.save + elsif @homework.homework_detail_group.base_on_project == 0 + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => student_work.project_id, :user_id => student_work.user_id, :is_leader => 1) stu_project.save end - elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 members = params[:group_member_ids].split(',') - for i in 0 .. members.count-1 - stu_project = StudentWorkProject.new - stu_project.homework_common_id = @homework.id - stu_project.student_work_id = student_work.id - stu_project.project_id = -1 - stu_project.user_id = members[i].to_i - if i == 0 - stu_project.is_leader = 1 - else - stu_project.is_leader = 0 + for i in 1 .. members.count-1 + stu_work = StudentWork.new(:name => student_work.name, :description => student_work.description,:user_id =>members[i].to_i, :homework_common_id => @homework.id,:project_id => student_work.project_id, :late_penalty => student_work.late_penalty,:work_status => 3, :commit_time => student_work.commit_time) + if stu_work.save + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0) + stu_project.save end - stu_project.save end end @homework.update_column(:updated_at, Time.now) @@ -687,20 +675,17 @@ class StudentWorkController < ApplicationController if @homework.homework_type == 3 @student_work_project = @homework.student_work_projects.where("user_id=?",User.current.id).first student_work_projects = @homework.student_work_projects.where("student_work_id=? and is_leader =?",@work.id,0) + user_ids = student_work_projects.empty? ? "(-1)" : "(" + student_work_projects.map{|stu|stu.user_id}.join(",") + ")" + student_works = @homework.student_works.where("user_id in #{user_ids}") + student_works.delete_all student_work_projects.delete_all members = params[:group_member_ids].split(',') for i in 1 .. members.count-1 - stu_project = StudentWorkProject.new - stu_project.homework_common_id = @homework.id - stu_project.student_work_id = @work.id - if @homework.homework_detail_group.base_on_project == 1 - stu_project.project_id = @student_work_project.project_id - else @homework.homework_detail_group.base_on_project == 0 - stu_project.project_id = -1 + stu_work = StudentWork.new(:name => @work.name, :description => @work.description,:user_id=> members[i].to_i, :homework_common_id => @homework.id, :project_id => @work.project_id, :late_penalty => @work.late_penalty,:work_status => 3, :commit_time => @work.commit_time) + if stu_work.save + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => @work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0) + stu_project.save end - stu_project.user_id = members[i].to_i - stu_project.is_leader = 0 - stu_project.save end end @@ -735,26 +720,25 @@ class StudentWorkController < ApplicationController def destroy if @homework.homework_type == 3 - if @work.destroy - if @homework.homework_detail_group.base_on_project == 1 - pros = @work.student_work_projects.where("is_leader = 0") - pros.each do |pro| - pro.destroy - end - project = @work.student_work_projects.where("is_leader = 1").first - project.update_attributes(:student_work_id => nil) - elsif @homework.homework_detail_group.base_on_project == 0 - @work.student_work_projects.each do |pro2| - pro2.destroy - end - end + pros = @work.student_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = @homework.student_works.where("user_id in #{user_ids}") + student_works.delete_all + pros.delete_all + + project = @work.student_work_projects.where("is_leader = 1").first + if @homework.homework_detail_group.base_on_project == 1 + project.update_attributes(:student_work_id => nil) + else + project.destroy end + @work.destroy else @work.attachments.destroy_all @work.student_works_scores.destroy_all @work.course_messages.destroy_all @work.student_work_tests.destroy_all - @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil,:final_score => nil,:teacher_score => nil,:student_score => nil,:teaching_asistant_score => nil,:system_score => 0,:work_score => nil) + @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil,:final_score => nil,:teacher_score => nil,:student_score => nil,:teaching_asistant_score => nil,:system_score => 0,:work_score => nil, :project_id => 0) @work.update_column("work_score",nil) end respond_to do |format| @@ -786,22 +770,21 @@ class StudentWorkController < ApplicationController def retry_work if @homework.homework_type == 3 - if @work.destroy - if @homework.homework_detail_group.base_on_project == 1 - pros = @work.student_work_projects.where("is_leader = 0") - pros.each do |pro| - pro.destroy - end - project = @work.student_work_projects.where("is_leader = 1").first - project.update_attributes(:student_work_id => nil) - elsif @homework.homework_detail_group.base_on_project == 0 - @work.student_work_projects.each do |pro2| - pro2.destroy - end - end + pros = @work.student_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = @homework.student_works.where("user_id in #{user_ids}") + student_works.delete_all + pros.delete_all + + project = @work.student_work_projects.where("is_leader = 1").first + if @homework.homework_detail_group.base_on_project == 1 + project.update_attributes(:student_work_id => nil) + else + project.destroy end - elsif @homework.homework_type == 1 - @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil) + @work.destroy + else + @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil, :project_id => 0) @work.attachments.destroy_all @work.course_messages.destroy_all end @@ -1096,9 +1079,13 @@ class StudentWorkController < ApplicationController #创建作业的关联项目 def student_work_project + @work = @homework.student_works.where("user_id = #{User.current.id} and work_status = 0").first + if @work + @work.update_column('project_id', params[:projectName].to_i) + end @project = StudentWorkProject.new @project.homework_common_id = @homework.id - @project.project_id = (Project.find params[:projectName].to_i).id + @project.project_id = params[:projectName].to_i @project.user_id = User.current.id @project.is_leader = 1 if @project.save @@ -1139,7 +1126,7 @@ class StudentWorkController < ApplicationController end all_students = User.where("id in #{all_student_ids}") student_work_id = @homework.student_work_projects.where("user_id=? and student_work_id is not null",User.current.id).first.nil? ? -1 : @homework.student_work_projects.where("user_id=?",User.current.id).first.student_work_id - @commit_student_ids = @homework.student_work_projects.where("student_work_id != #{student_work_id}").map{|student| student.user_id} + @commit_student_ids = @homework.student_works.where("id != #{student_work_id}").map{|student| student.user_id} @users = searchstudent_by_name all_students,name respond_to do |format| format.js @@ -1147,6 +1134,10 @@ class StudentWorkController < ApplicationController end def cancel_relate_project + @work = @homework.student_works.where("user_id = #{User.current.id} and work_status = 0").first + if @work + @work.update_column('project_id', 0) + end relate_pro = StudentWorkProject.where("user_id = #{User.current.id} and homework_common_id = #{@homework.id}").first if relate_pro.destroy @user_activity_id = params[:user_activity_id].to_i @@ -1402,7 +1393,7 @@ class StudentWorkController < ApplicationController end def find_or_save_student_work(is_test) - student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first + student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id, is_test: is_test).first if student_work.nil? @homework.student_works.build( name: params[:title], @@ -1413,7 +1404,7 @@ class StudentWorkController < ApplicationController unless @homework.save logger.debug @homework.errors.full_messages else - student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first + student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id, is_test: is_test).first end end student_work @@ -1586,6 +1577,10 @@ class StudentWorkController < ApplicationController end end end + if homework.homework_type == 3 + student_works = group_student_works student_work, homework + student_works.update_all(:final_score => student_work.final_score,:teacher_score => student_work.teacher_score,:student_score => student_work.student_score,:teaching_asistant_score => student_work.teaching_asistant_score,:work_score => student_work.work_score) + end end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b385fe610..5aab1df49 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -983,7 +983,7 @@ class UsersController < ApplicationController @user = User.current @homework = HomeworkCommon.find(params[:homework_id]) @is_test = params[:is_test] == 'true' - @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first + @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id, is_test: @is_test).first if @student_work.nil? @student_work = StudentWork.new end @@ -1660,55 +1660,117 @@ class UsersController < ApplicationController course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" project_types = "('Message','Issue','Project')" principal_types = "JournalsForMessage" + container_type = '' + act_type = '' if params[:type].present? case params[:type] when "course_homework" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'HomeworkCommon' when "course_news" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'News' when "course_message" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'Message' when "course_poll" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'Poll' when "course_journals" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'JournalsForMessage' when "project_issue" - @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Project' + act_type = 'Issue' when "project_message" - @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'Message' when "user_journals" - @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Principal' + act_type = 'JournalsForMessage' when "current_user" - @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10) - else - if @user == User.current - blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - else - blog_ids = "("+@user.blog.id.to_s+")" - end - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Principal' + act_type = 'Principal' + end + end + if container_type != '' && act_type != '' + if container_type == 'Course' + sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" + elsif container_type == 'Project' + sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'JournalsForMessage' + sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))" + end + if User.current != @user + sql += " and user_id = #{@user.id}" end else - # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) - # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - # 减少数据库交互 - if @user == User.current - watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(',')) - user_ids = "(" + @user.id.to_s + watched_user_ids + ")" + if User.current != @user + blog_ids = "("+@user.blog.id.to_s+")" + sql = "user_id = #{@user.id} and((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids}))" else - user_ids = "(" + @user.id.to_s + ")" - end - watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}") - blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| blog.id}.join(",") + ")" - - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) - end + blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})" + end + end + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + # if params[:type].present? + # case params[:type] + # when "course_homework" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10) + # when "course_news" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10) + # when "course_message" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + # when "course_poll" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) + # when "course_journals" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10) + # when "project_issue" + # @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) + # when "project_message" + # @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + # when "user_journals" + # @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10) + # when "current_user" + # @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10) + # else + # if @user == User.current + # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + # else + # blog_ids = "("+@user.blog.id.to_s+")" + # end + # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + # "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + # "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + # "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + # end + # else + # # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) + # # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + # # 减少数据库交互 + # if @user == User.current + # watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(',')) + # user_ids = "(" + @user.id.to_s + watched_user_ids + ")" + # else + # user_ids = "(" + @user.id.to_s + ")" + # end + # watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}") + # blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| blog.id}.join(",") + ")" + # + # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + # "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + # "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + # "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + # end # @user_activities = paginateHelper @user_activities,500 @type = params[:type] respond_to do |format| diff --git a/app/helpers/school_helper.rb b/app/helpers/school_helper.rb index 075d2b039..daa0550ef 100644 --- a/app/helpers/school_helper.rb +++ b/app/helpers/school_helper.rb @@ -1,6 +1,6 @@ module SchoolHelper def schoolMember_num school - count = student_num(school) + teacher_num(school) + count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count count.to_s end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 4f0a2ca6d..1e7df6466 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -22,8 +22,12 @@ module StudentWorkHelper end #获取指定用户对某一作业的评分结果 - def student_work_score work,user - StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).last + def student_work_score work,user,reviewer_role=0 + if reviewer_role != 0 + StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id,:reviewer_role => reviewer_role).last + else + StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).last + end end #获取指定评分的角色 @@ -154,4 +158,11 @@ module StudentWorkHelper end return status end + + def group_student_works student_work, homework + pros = student_work.student_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = homework.student_works.where("user_id in #{user_ids}") + return student_works + end end \ No newline at end of file diff --git a/app/models/at_message.rb b/app/models/at_message.rb index 4c3ca9b74..5a175fe76 100644 --- a/app/models/at_message.rb +++ b/app/models/at_message.rb @@ -184,8 +184,10 @@ class AtMessage < ActiveRecord::Base when 'JournalsForMessage' if at_message.jour_type == 'Principal' {controller: :users, action: :user_messages, id: at_message.at_user} - else + elsif at_message.jour_type == 'HomeworkCommon' {controller: :homework_common, action: :index, course: at_message.jour.course_id} + elsif at_message.jour_type == 'Course' + {controller: :courses, action: :feedback, id: at_message.jour_id} end else diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 183570081..59e5b76bc 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -1,4 +1,4 @@ -#学生提交作品表 +#学生提交作品表 #work_status :0 未提交 1 已提交 2 迟交 3 分组作品复制的组员作品 class StudentWork < ActiveRecord::Base attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time @@ -13,7 +13,8 @@ class StudentWork < ActiveRecord::Base has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :attachments, :dependent => :destroy - scope :has_committed, lambda{where("work_status != 0")} + scope :has_committed, lambda{where("work_status != 0 and work_status != 3")} + scope :no_copy, lambda{where("work_status != 3")} before_destroy :delete_praise before_save :set_program_score, :set_src @@ -31,7 +32,7 @@ class StudentWork < ActiveRecord::Base private def set_program_score - if homework_common.is_program_homework? #编程作业,学生提交作品后计算系统得分 + if self.homework_common.is_program_homework? #编程作业,学生提交作品后计算系统得分 #根据最后一次测试计算得分 unless last_test self.system_score = 0 @@ -169,6 +170,12 @@ class StudentWork < ActiveRecord::Base end end end + if homework.homework_type == 3 + pros = student_work.student_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = homework.student_works.where("user_id in #{user_ids}") + student_works.update_all(:final_score => student_work.final_score,:teacher_score => student_work.teacher_score,:student_score => student_work.student_score,:teaching_asistant_score => student_work.teaching_asistant_score,:work_score => student_work.work_score) + end end end diff --git a/app/views/admin/leave_messages.html.erb b/app/views/admin/leave_messages.html.erb index 986823faa..a9acba903 100644 --- a/app/views/admin/leave_messages.html.erb +++ b/app/views/admin/leave_messages.html.erb @@ -62,9 +62,9 @@ <%case journal.jour_type %> <% when 'Principal' %> - <%= link_to(strip_html(journal.notes), feedback_path(journal.jour_id)) %> + <%= link_to(journal.m_parent_id.nil? ? strip_html(journal.notes) : 'RE: ' + strip_html(journal.notes), feedback_path(journal.jour_id)) %> <% when 'Course' %> - <%= link_to(strip_html(journal.notes), course_feedback_path(journal.jour_id)) %> + <%= link_to(journal.m_parent_id.nil? ? strip_html(journal.notes) : 'RE: ' + strip_html(journal.notes), course_feedback_path(journal.jour_id)) %> <% end %> diff --git a/app/views/admin/schools.html.erb b/app/views/admin/schools.html.erb index f52d1f060..42bec6551 100644 --- a/app/views/admin/schools.html.erb +++ b/app/views/admin/schools.html.erb @@ -20,8 +20,8 @@ 学校名称 - - 用户数 + + <%= link_to '用户数', admin_schools_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'num') %> 创建时间 diff --git a/app/views/avatar/upload.js.erb b/app/views/avatar/upload.js.erb index c2fa23242..2c7411629 100644 --- a/app/views/avatar/upload.js.erb +++ b/app/views/avatar/upload.js.erb @@ -1,4 +1,4 @@ -<% if @is_direct == '1' && (@source_type=='User'|| @source_type == 'Course' || @source_type == 'Project') %> +<% if @is_direct == '1' && (@source_type=='User'|| @source_type == 'Course' || @source_type == 'Project' || @source_type == 'Organization') %> var imgSpan = $("img[nhname='avatar_image']"); imgSpan.attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'}); <% else %> diff --git a/app/views/blog_comments/show.html.erb b/app/views/blog_comments/show.html.erb index f5c7c9094..45a621816 100644 --- a/app/views/blog_comments/show.html.erb +++ b/app/views/blog_comments/show.html.erb @@ -134,7 +134,7 @@
<%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 33, :height => 33, :alt => "用户头像"), user_url_in_org(comment.creator_user.id) %>
-
+
<%= render :partial => 'users/message_contents', :locals => {:comment => comment}%> <% if !comment.content_detail.blank? %> @@ -161,7 +161,8 @@ l(:button_delete), {:controller => 'blog_comments', :action => 'destroy', :id => comment.id}, :method => :delete, - :class => 'fr mr20', + :id => "delete_reply_#{comment.id}", + :class => 'fr mr20 undis', :data => {:confirm => l(:text_are_you_sure)}, :title => l(:button_delete) ) %> diff --git a/app/views/courses/_course_activity.html.erb b/app/views/courses/_course_activity.html.erb index 993c767d6..c71e5ade4 100644 --- a/app/views/courses/_course_activity.html.erb +++ b/app/views/courses/_course_activity.html.erb @@ -11,27 +11,27 @@ $("#relateProject,.relatePInfo").mouseout(function(){ $(".relatePInfo").css("display","none"); }) - $(".homepagePostPortrait").mouseover(function(){ - onImage = true; - $(this).children(".userCard").css("display","block"); - }) - $(".homepagePostPortrait").mouseout(function(){ - var cur = $(this); - onImage = false; - setTimeout(function(){ - if (onUserCard == false && onImage == false){ - $(cur).children(".userCard").css("display", "none"); - } - }, 500); - }) - $(".userCard").mouseover(function(){ - onUserCard = true; - $(this).css("display","block"); - }) - $(".userCard").mouseout(function(){ - onUserCard = false; - $(this).css("display","none"); - }) +// $(".homepagePostPortrait").mouseover(function(){ +// onImage = true; +// $(this).children(".userCard").css("display","block"); +// }) +// $(".homepagePostPortrait").mouseout(function(){ +// var cur = $(this); +// onImage = false; +// setTimeout(function(){ +// if (onUserCard == false && onImage == false){ +// $(cur).children(".userCard").css("display", "none"); +// } +// }, 500); +// }) +// $(".userCard").mouseover(function(){ +// onUserCard = true; +// $(this).css("display","block"); +// }) +// $(".userCard").mouseout(function(){ +// onUserCard = false; +// $(this).css("display","none"); +// }); $(".coursesLineGrey").mouseover(function(){ $(this).css("color","#ffffff"); }) diff --git a/app/views/courses/_history.html.erb b/app/views/courses/_history.html.erb index 067064c07..35e0726a8 100644 --- a/app/views/courses/_history.html.erb +++ b/app/views/courses/_history.html.erb @@ -5,7 +5,7 @@
<%= link_to image_tag(url_to_avatar(journal.user),:width => '46',:height => '46'), user_path(journal.user) %>
-
+
@@ -28,17 +28,17 @@ <%=render :partial=> "praise_tread/praise", :locals => {:activity=>journal, :user_activity_id=>journal.id,:type=>"reply"}%> - <% if journal.user == User.current|| User.current.admin? || (@course && User.current.allowed_to?(:as_teacher,@course)) %> - <%= link_to(l(:label_bid_respond_delete), - {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => @user}, - :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', - :class => "delete", :title => l(:button_delete)) %> - <% end %> <% if reply_allow %> <%#= link_to l(:label_bid_respond_quote),'', {:focus => 'project_respond',:nhname=>"reply_btn", :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea')); $('##{ids} textarea') ;return false;"} %> <%= link_to l(:label_bid_respond_quote),'javascript:;',{:nhname=>"reply_btn"} %> <% end %> + <% if journal.user == User.current|| User.current.admin? || (@course && User.current.allowed_to?(:as_teacher,@course)) %> + <%= link_to(l(:label_bid_respond_delete), + {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => @user}, + :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :id => "delete_reply_#{journal.id}", + :class => "delete undis", :title => l(:button_delete)) %> + <% end %>
<% ids = 'project_respond_form_'+ journal.id.to_s%> diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index e157ea155..02db5e766 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -218,8 +218,12 @@ <% end %>
- <%= link_to "保存",commit_exercise_exercise_path(exercise,:save => 1),:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:format => 'js',:remote=>true %> - <%= link_to "提交",commit_exercise_exercise_path(exercise), :data => {:confirm => "您确定要提交吗?"},:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:style => "margin-left:20px;",:format => 'js',:remote=>true %> + <% if exercise.time == -1 %> + <%= link_to "保存",commit_exercise_exercise_path(exercise,:save => 1),:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:format => 'js',:remote=>true %> + <%= link_to "提交",commit_exercise_exercise_path(exercise), :data => {:confirm => "您确定要提交吗?"},:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:style => "margin-left:20px;",:format => 'js',:remote=>true %> + <% else %> + <%= link_to "提交",commit_exercise_exercise_path(exercise), :data => {:confirm => "您确定要提交吗?"},:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:style => "margin-left:84px;",:format => 'js',:remote=>true %> + <% end %>
diff --git a/app/views/exercise/_student_table.html.erb b/app/views/exercise/_student_table.html.erb index bdfd2c96f..c917cb03e 100644 --- a/app/views/exercise/_student_table.html.erb +++ b/app/views/exercise/_student_table.html.erb @@ -1,71 +1,71 @@ - - - - - - - - - - - - - <% @exercise_users_list.each_with_index do |exercise, index|%> - - - - - - - - - - - - - - -<% end%> +
序号  姓名学号班级   - <%= link_to "时间",'',:class => "c_dark f14 fb" ,:remote => true%> - - <%= link_to "成绩",'',:class => "c_dark f14 fb",:remote => true%> -
<%=index + 1 %> - <%= link_to(image_tag(url_to_avatar(exercise.user),:width =>"40",:height => "40",:style => "display:block;", :class => "mt15"),user_activities_path(exercise.user)) %> - - <%=exercise.user.show_name %> - - - - -- -   - <% if exercise.created_at%> - <%= Time.parse(format_time(exercise.created_at)).strftime("%m-%d %H:%M")%>  - <% if @exercise.end_time <= exercise.created_at %> - [未答] - <% end %> - <% end %> - - <%= exercise.score.nil? ? "--" : format("%.1f",exercise.score)%> -
+ + + + + + + + + + + + <% @exercise_users_list.each_with_index do |exercise, index|%> + + + + + + + + + + + + + + +<% end%>
序号  姓名学号班级   + <%= link_to "时间",'',:class => "c_dark f14 fb" ,:remote => true%> + + <%= link_to "成绩",'',:class => "c_dark f14 fb",:remote => true%> +
<%=index + 1 %> + <%= link_to(image_tag(url_to_avatar(exercise.user),:width =>"40",:height => "40",:style => "display:block;", :class => "mt15"),user_activities_path(exercise.user)) %> + + <%=exercise.user.show_name %> + + + + -- +   + <% if exercise.created_at%> + <%= Time.parse(format_time(exercise.created_at)).strftime("%m-%d %H:%M")%>  + <% if @exercise.end_time <= exercise.created_at %> + [未答] + <% end %> + <% end %> + + <%= exercise.score.nil? ? "--" : format("%.1f",exercise.score)%> +
\ No newline at end of file diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index d3cc58c71..045eec6f7 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -124,12 +124,14 @@
-
- - -

私有资源:
仅对本班级成员可见

-

公共资源:
对所有用户可见

-
+ <% if !User.current.member_of_course?(@course) && show_attachment_tip(@course.id, "Course") %> +
+ + +

私有资源:
仅对本班级成员可见

+

公共资源:
对所有用户可见

+
+ <% end %>
<%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} %> diff --git a/app/views/files/_tip_attachment_count.html.erb b/app/views/files/_tip_attachment_count.html.erb index 6a21f36be..edcbbea98 100644 --- a/app/views/files/_tip_attachment_count.html.erb +++ b/app/views/files/_tip_attachment_count.html.erb @@ -1,15 +1,18 @@ 共有 <%= @tip_all_attachments %> 个资源 -公共资源:<%= @tip_all_public_attachments %>个 -<% if @project %> - <% if !User.current.member_of?(@project) && params[:tag_name] %> - 私有资源:0个 - <% else %> - 私有资源:<%= @tip_all_private_attachments %>个 - <% end %> -<% elsif @course %> - <% if !User.current.member_of_course?(@course) && params[:tag_name] %> - 私有资源:0个 - <% else %> - 私有资源:<%= @tip_all_private_attachments %>个 +<% if @tip_all_private_attachments != 0 %> + 公共资源:<%= @tip_all_public_attachments %>个 + <% if @project %> + <% if !User.current.member_of?(@project) && params[:tag_name] %> + 私有资源:0个 + <% else %> + 私有资源:<%= @tip_all_private_attachments %>个 + <% end %> + <% elsif @course %> + <% if !User.current.member_of_course?(@course) && params[:tag_name] %> + 私有资源:0个 + <% else %> + 私有资源:<%= @tip_all_private_attachments %>个 + <% end %> <% end %> + <% end %> diff --git a/app/views/issues/_issue_replies.html.erb b/app/views/issues/_issue_replies.html.erb index 070238a81..1bc8dc132 100644 --- a/app/views/issues/_issue_replies.html.erb +++ b/app/views/issues/_issue_replies.html.erb @@ -10,7 +10,7 @@
<%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33"), user_path(comment.user_id), :alt => "用户头像" %>
-
+
<%= render :partial => 'users/news_contents', :locals => {:comment => comment}%>
@@ -40,7 +40,8 @@ l(:button_delete), {:controller => 'issues',:action => 'delete_journal', :id => issue.id,:journal_id=>comment.id}, :method => :get, - :class => 'fr mr20', + :id => "delete_reply_#{comment.id}", + :class => 'fr mr20 undis', :data => {:confirm => l(:text_are_you_sure)}, :title => l(:button_delete) ) if comment.user_id == User.current.id %> diff --git a/app/views/issues/update.js.erb b/app/views/issues/update.js.erb index 16ca863e4..bd4385340 100644 --- a/app/views/issues/update.js.erb +++ b/app/views/issues/update.js.erb @@ -6,7 +6,7 @@ $("#issue_detail").show(); $("#issue_edit").hide(); $("#reply_div_<%= @issue.id %>").html("<%= escape_javascript(render :partial => 'issues/issue_replies', :locals => {:issue => @issue,:replies_all_i=>0}) %>"); sd_create_editor_from_data(<%= @issue.id%>, null, "100%","<%=@issue.class.name%>"); -$(".homepagePostReplyBannerCount").html('回复(<%= @issue.journals.count %>)') +$(".homepagePostReplyBannerCount").html('<%= escape_javascript(render :partial => 'issues/issue_reply_banner') %>'); //edit里的编辑器貌似显示不出来,所以手动js生成。 issue_desc_editor = KindEditor.create('#issue_description', {"width":"85%", diff --git a/app/views/layouts/_course_base_info.html.erb b/app/views/layouts/_course_base_info.html.erb index c2fe181fe..65c065672 100644 --- a/app/views/layouts/_course_base_info.html.erb +++ b/app/views/layouts/_course_base_info.html.erb @@ -31,7 +31,7 @@