diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 562804abe..368ed3c4a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -817,7 +817,46 @@ class UsersController < ApplicationController #@user.save_attachments(params[:attachments],User.current) # Container_type为Principal Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type]) - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + if(params[:type].nil? || params[:type] == "1") #全部 + 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 in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.join(',')}))").order("created_on desc") + else + user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源 + @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " + + "and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " + + "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.join(',')}))").order("created_on desc") + end + elsif params[:type] == "2" #课程资源 + if User.current.id.to_i == params[:id].to_i + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') ").order("created_on desc") + 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.join(',')}))").order("created_on desc") + 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'").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' ").order("created_on desc") + 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('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") + end + end + @type = params[:type] || 1 + @limit = 10 + @is_remote = true + @obj_count = @attachments.count + @obj_pages = Paginator.new @obj_count, @limit, params['page'] || 1 + @offset ||= @obj_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,10 respond_to do |format| format.js end diff --git a/app/views/users/user_resource_create.js.erb b/app/views/users/user_resource_create.js.erb index 7e7cd2919..a5de94552 100644 --- a/app/views/users/user_resource_create.js.erb +++ b/app/views/users/user_resource_create.js.erb @@ -1,3 +1,4 @@ closeModal(); $("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments})%>'); +