diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index b878a14ac..e974f26b4 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -572,6 +572,15 @@ class AttachmentsController < ApplicationController end end + #找到文件的所有的历史版本及当前版本 + def attachment_history_download + @attachment = Attachment.find(params[:id]) + @attachment_histories = @attachment.attachment_histories + respond_to do |format| + format.js + end + end + private def find_project @attachment = Attachment.find(params[:id]) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index db81dd985..06b2df862 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -110,8 +110,7 @@ class UsersController < ApplicationController elsif @user != User.current && !User.current.admin? return render_403 end - # 初始化/更新 点击按钮时间 - # 24小时内显示系统消息 + # 初始化/更新 点击按钮时间, 24小时内显示系统消息 update_onclick_time # 全部设为已读 if params[:viewed] == "all" @@ -190,17 +189,19 @@ class UsersController < ApplicationController # 消息设置为已读 def update_message_viewed(user) - course_querys = CourseMessage.where("user_id =? and viewed =?", user, 0) - forge_querys = ForgeMessage.where("user_id =? and viewed =?", user, 0) - user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0) - forum_querys = MemoMessage.where("user_id =? and viewed =?", user, 0) - org_querys = OrgMessage.where("user_id=? and viewed=0", user) if User.current.id == @user.id - course_querys.update_all(:viewed => true) - forge_querys.update_all(:viewed => true) - user_querys.update_all(:viewed => true) - forum_querys.update_all(:viewed => true) - org_querys.update_all(:viewed => true) + course_querys = CourseMessage.where("user_id =? and viewed =?", user, 0) + forge_querys = ForgeMessage.where("user_id =? and viewed =?", user, 0) + user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0) + forum_querys = MemoMessage.where("user_id =? and viewed =?", user, 0) + org_querys = OrgMessage.where("user_id=? and viewed=0", user) + at_querys = AtMessage.where("user_id=? and viewed=0", user) + course_querys.update_all(:viewed => true) unless course_querys.nil? + forge_querys.update_all(:viewed => true) unless forge_querys.nil? + user_querys.update_all(:viewed => true) unless user_querys.nil? + forum_querys.update_all(:viewed => true) unless forum_querys.nil? + org_querys.update_all(:viewed => true) unless org_querys.nil? + at_querys.update_all(:viewed => true) unless at_querys.nil? end end @@ -823,20 +824,33 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.id} user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].blank? || params[:type] == "1") #全部 + if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) - elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) - elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) - elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id], params[:order] - elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id], params[:order] + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(params[:id], @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(params[:id], @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + end elsif params[:type] == "6" # 公共资源 - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end end @type = params[:type] @limit = 7 @@ -1548,43 +1562,39 @@ class UsersController < ApplicationController user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} @user = User.find(params[:id]) - #@user.save_attachments(params[:attachments],User.current) - # Container_type为Principal + # 保存文件 attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true) + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == 2 - @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id], params[:order] + @attachments = get_attch_resources(params[:id], @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources params[:id], params[:order] + @attachments = get_principal_resources(params[:id], @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) - elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) - elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id], params[:order] - elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, params[:order]) + @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, params[:order]) + @attachments = get_project_resources_public(user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources_public params[:order] + @attachments = get_attch_resources_public(@order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources_public params[:order] + @attachments = get_principal_resources_public(@order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end end @status = params[:status] @@ -1604,49 +1614,44 @@ class UsersController < ApplicationController # 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源 def user_resource_delete if params[:resource_id].present? - Attachment.where("author_id = #{User.current.id}").delete(params[:resource_id]) + Attachment.where("author_id =? and id =?", User.current.id, params[:resource_id]).first.destroy elsif params[:checkbox1].present? params[:checkbox1].each do |id| - Attachment.where("author_id = #{User.current.id}").delete(id) + Attachment.where("author_id =? and id =?", User.current.id, id).first.destroy end end + @user = User.current + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" user_course_ids = User.current.courses.map { |c| c.id} user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == 2 - @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id], params[:order] + @attachments = get_attch_resources(params[:id], @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources params[:id], params[:order] + @attachments = get_principal_resources(params[:id], @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) - elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) - elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id], params[:order] - elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, params[:order]) + @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, params[:order]) + @attachments = get_project_resources_public(user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources_public params[:order] + @attachments = get_attch_resources_public(@order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources_public params[:order] + @attachments = get_principal_resources_public(@order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end end @status = params[:status] @@ -1669,10 +1674,10 @@ class UsersController < ApplicationController 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)} + .select { |course| @user.allowed_to?(:as_teacher,course) and course.is_delete == 0 } else @course = @user.courses - .select { |course| @user.allowed_to?(:as_teacher,course)} + .select { |course| @user.allowed_to?(:as_teacher,course) and course.is_delete == 0 } end @search = params[:search] #这里仅仅是传递需要发送的资源id @@ -1690,7 +1695,7 @@ class UsersController < ApplicationController search = "%#{params[:search].to_s.strip.downcase}%" @projects = @user.projects.where(" #{Project.table_name}.id = #{params[:search].to_i } or #{Project.table_name}.name like :p",:p=>search) else - @projects = @user.projects + @projects = @user.projects.visible end @search = params[:search] #这里仅仅是传递需要发送的资源id @@ -2338,6 +2343,11 @@ class UsersController < ApplicationController attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") end + # 获取公共资源搜索 + def get_public_resources_search user_course_ids, user_project_ids, order, score, search + attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + end + # 获取我的资源 def get_my_resources author_id, user_course_ids, user_project_ids, order, score attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ @@ -2347,7 +2357,7 @@ class UsersController < ApplicationController # 获取我的资源查询结果 def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search) - @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + @attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end @@ -2359,11 +2369,23 @@ class UsersController < ApplicationController and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") end - # 获取公共资源课程 + # 获取我的课程资源中搜索结果 + def get_course_resources_search author_id, user_course_ids, order, score, search + attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) + and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取公共资源中课程资源 def get_course_resources_public user_course_ids, order, score attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}") end + # 获取公共资源中课程资源搜索结果 + def get_course_resources_public_search user_course_ids, order, score, search + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + end + # 获取我的项目资源 def get_project_resources author_id, user_project_ids, order, score attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ @@ -2371,25 +2393,55 @@ class UsersController < ApplicationController and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}") end + # 获取我的项目资源搜索 + def get_project_resources_search author_id, user_project_ids, order, score, search + attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) + and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + end + # 获取公共资源的项目资源 def get_project_resources_public user_project_ids, order, score attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") end + # 获取公共资源的项目资源搜索 + def get_project_resources_public_search user_project_ids, order, score, search + attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + end + # 获取我上传的附件 def get_attch_resources author_id, order, score attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', - 'Document','Message','News','StudentWorkScore','HomewCommon')) ").order("#{order.nil? ? 'created_on' : order} #{score}") + 'Document','Message','News','StudentWorkScore','HomewCommon'))").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我上传的附件搜索结果 + def get_attch_resources_search author_id, order, score, search + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', + 'Document','Message','News','StudentWorkScore','HomewCommon')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源中我上传的附件 def get_attch_resources_public order, score - attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') + and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取公共资源中我上传的附件 + def get_attch_resources_public_search order, score, search + attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') + and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 def get_principal_resources author_id, order, score - attchments = Attachment.where("author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我的用户类型资源搜索 + def get_principal_resources_search author_id, order, score, search + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 @@ -2397,6 +2449,11 @@ class UsersController < ApplicationController attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") end + # 获取我的用户类型资源 + def get_principal_resources_public_search order, score, search + attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + end + # 资源库 分为全部 课程资源 项目资源 附件 def user_resource @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @@ -2423,23 +2480,15 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids, params[:order], @score) - elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids, params[:order], @score) - elsif params[:type] == "4" #附件 - @attachments = get_attch_resources(params[:id], params[:order], @score) - elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources(params[:id], params[:order], @score) elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, params[:order], @score) + @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, params[:order], @score) + @attachments = get_project_resources_public(user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources_public(params[:order], @score) + @attachments = get_attch_resources_public(@order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources_public(params[:order], @score) + @attachments = get_principal_resources_public(@order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) @@ -2467,16 +2516,19 @@ class UsersController < ApplicationController render_403 return end + @user = User.find(params[:id]) + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} - # user_org_ids = User.current.organizations.map {|o| o.id} + user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + @status = params[:status] @type = params[:type] @limit = 10 @is_remote = true @@ -2492,26 +2544,25 @@ class UsersController < ApplicationController end def import_resources_search - search = "%#{params[:search].strip.downcase}%" + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + @user = User.current + @switch_search = params[:name].nil? ? " " : params[:name] + search = "%#{@switch_search.strip.downcase}%" # 别人的资源库是没有权限去看的 if User.current.id.to_i != params[:id].to_i render_403 return end - user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} - # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 user_course_ids = User.current.courses.map { |c| c.id} user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} - @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{params[:order].nil? ? 'created_on' : params[:order]} desc") + @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) + @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) end @type = params[:type] @limit = 10 @@ -2520,10 +2571,10 @@ class UsersController < ApplicationController @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 @offset ||= @atta_pages.offset #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,10 + @attachments = paginateHelper @attachments, 10 respond_to do |format| format.js - format.html {render :layout => 'new_base'} + # format.html {render :layout => 'new_base'} end end @@ -2584,69 +2635,39 @@ class UsersController < ApplicationController @order, @b_sort = params[:order] || "created_on", params[:sort] || "desc" @score = @b_sort == "desc" ? "asc" : "desc" @user = User.current - switch_search = params[:search].nil? ? " " : params[:search] - search = "%#{switch_search.strip.downcase}%" - user_course_ids = User.current.courses.map { |c| c.id} + @switch_search = params[:search].nil? ? " " : params[:search] + search = "%#{@switch_search.strip.downcase}%" + user_course_ids = User.current.courses.map {|c| c.id} user_project_ids = User.current.projects.map {|p| p.id} - # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部 if params[:status] == "2" - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_course_resources_search(params[:id], user_course_ids, @order, @score, search) elsif params[:status] == "3" - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_project_resources_search(params[:id], user_project_ids, @order, @score, search) elsif params[:status] == "4" - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_attch_resources_search(params[:id], @order, @score, search) elsif params[:status] == "5" - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_principal_resources_search(params[:id], @order, @score, search) else # 公共资源库:所有公开资源或者我上传的私有资源 - get_my_resources_search(@user.id, user_course_ids, user_project_ids, @order, @score, search) - end - elsif params[:type] == "2" #课程资源 - if User.current.id.to_i == params[:id].to_i - user_course_ids = User.current.courses.map { |c| c.id} - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type = 'Course') "+ - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) )"+ - " and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") - end - elsif params[:type] == "3" # 项目资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") - end - elsif params[:type] == "4" # 附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) end - elsif params[:type] == "5" # 用户资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") - end - elsif params[:type] == "6" # 全部资源 + elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_course_resources_public_search(user_course_ids, @order, @score, search) elsif params[:status] == "3" - @attachments = Attachment.where("container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_project_resources_public_search(user_project_ids, @order, @score, search) elsif params[:status] == "4" - @attachments = Attachment.where("container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_attch_resources_public_search(@order, @score, search) elsif params[:status] == "5" - @attachments = Attachment.where("container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + @attachments = get_principal_resources_public_search(@order, @score, search) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("created_on desc") + @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) end end @status = params[:status] @type = params[:type] - @type = params[:type] @limit = 25 @is_remote = true @atta_count = @attachments.count diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 1cc0d3b7a..714da9920 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -90,8 +90,8 @@ class Attachment < ActiveRecord::Base @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") 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_save :act_as_course_activity,:act_as_forge_activity + after_create :office_conver, :be_user_score,: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, :down_course_score @@ -606,7 +606,7 @@ class Attachment < ActiveRecord::Base # Author lizanle # Description 上传该项目的文档资料也要保存一份在公共表中 def act_as_forge_activity - if self.container_type == 'Project' + if self.container_type == 'Project' && self.forge_acts.empty? self.forge_acts << ForgeActivity.new(:user_id => self.author_id, :project_id => self.container_id) end diff --git a/app/views/attachments/_attachment_history_download.html.erb b/app/views/attachments/_attachment_history_download.html.erb new file mode 100644 index 000000000..c805960f0 --- /dev/null +++ b/app/views/attachments/_attachment_history_download.html.erb @@ -0,0 +1,30 @@ + +选择版本 +
注:该文件有历史版本,请选择您需要的文件,点击文件名下载。
+版本及序号
+ +","").gsub("
","").gsub("","").gsub("
","").gsub("