|
|
|
@ -823,48 +823,56 @@ class UsersController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 删除用户资源,分为批量删除 和 单个删除
|
|
|
|
|
# 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源
|
|
|
|
|
def user_resource_delete
|
|
|
|
|
if params[:resource_id].present?
|
|
|
|
|
Attachment.delete(params[:resource_id])
|
|
|
|
|
Attachment.where("author_id = #{User.current.id}").delete(params[:resource_id])
|
|
|
|
|
elsif params[:checkbox1].present?
|
|
|
|
|
params[:checkbox1].each do |id|
|
|
|
|
|
Attachment.delete(id)
|
|
|
|
|
Attachment.where("author_id = #{User.current.id}").delete(id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#@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
|
|
|
|
|
@attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").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 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('Project','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]
|
|
|
|
|
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]
|
|
|
|
|
@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
|
|
|
|
|