|
|
|
@ -817,18 +817,18 @@ class UsersController < ApplicationController
|
|
|
|
|
# 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)
|
|
|
|
|
@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)
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "3" # 项目资源
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids)
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "4" #附件
|
|
|
|
|
@attachments = get_attch_resources params[:id]
|
|
|
|
|
@attachments = get_attch_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:type] == "5" #用户资源
|
|
|
|
|
@attachments = get_principal_resources params[:id]
|
|
|
|
|
@attachments = get_principal_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:type] == "6" # 公共资源
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
end
|
|
|
|
|
@type = params[:type]
|
|
|
|
|
@limit = 7
|
|
|
|
@ -938,12 +938,7 @@ class UsersController < ApplicationController
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
# 自己访问自己的页面才更新消息状态
|
|
|
|
|
if User.current == @user
|
|
|
|
|
journals_messages = UserFeedbackMessage.where("user_id =? and journals_for_message_type =? and viewed =?", User.current.id, "JournalsForMessage", 0)
|
|
|
|
|
journals_messages.each do |journals_message|
|
|
|
|
|
journals_message.update_attributes(:viewed => true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true)
|
|
|
|
|
# end
|
|
|
|
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
|
|
|
|
if params[:type].present?
|
|
|
|
@ -1551,37 +1546,37 @@ class UsersController < ApplicationController
|
|
|
|
|
if(params[:type].blank? || params[:type] == "1") # 我的资源
|
|
|
|
|
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
|
|
|
|
if params[:status] == 2
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids)
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "3"
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids)
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "4"
|
|
|
|
|
@attachments = get_attch_resources params[:id]
|
|
|
|
|
@attachments = get_attch_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:status] == "5"
|
|
|
|
|
@attachments = get_principal_resources params[:id]
|
|
|
|
|
@attachments = get_principal_resources params[:id], params[:order]
|
|
|
|
|
else
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
|
|
|
|
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
end
|
|
|
|
|
elsif params[:type] == "2" # 课程资源
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids)
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "3" # 项目资源
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids)
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "4" #附件
|
|
|
|
|
@attachments = get_attch_resources params[:id]
|
|
|
|
|
@attachments = get_attch_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:type] == "5" #用户资源
|
|
|
|
|
@attachments = get_principal_resources params[:id]
|
|
|
|
|
@attachments = get_principal_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:type] == "6" # 公共资源
|
|
|
|
|
if params[:status] == "2"
|
|
|
|
|
@attachments = get_course_resources_public( user_course_ids)
|
|
|
|
|
@attachments = get_course_resources_public( user_course_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "3"
|
|
|
|
|
@attachments = get_project_resources_public(user_project_ids)
|
|
|
|
|
@attachments = get_project_resources_public(user_project_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "4"
|
|
|
|
|
@attachments = get_attch_resources_public
|
|
|
|
|
@attachments = get_attch_resources_public params[:order]
|
|
|
|
|
elsif params[:status] == "5"
|
|
|
|
|
@attachments = get_principal_resources_public
|
|
|
|
|
@attachments = get_principal_resources_public params[:order]
|
|
|
|
|
else
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@status = params[:status]
|
|
|
|
@ -1613,37 +1608,37 @@ class UsersController < ApplicationController
|
|
|
|
|
if(params[:type].blank? || params[:type] == "1") # 我的资源
|
|
|
|
|
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
|
|
|
|
if params[:status] == 2
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids)
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "3"
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids)
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "4"
|
|
|
|
|
@attachments = get_attch_resources params[:id]
|
|
|
|
|
@attachments = get_attch_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:status] == "5"
|
|
|
|
|
@attachments = get_principal_resources params[:id]
|
|
|
|
|
@attachments = get_principal_resources params[:id], params[:order]
|
|
|
|
|
else
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
|
|
|
|
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
end
|
|
|
|
|
elsif params[:type] == "2" # 课程资源
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids)
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "3" # 项目资源
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids)
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "4" #附件
|
|
|
|
|
@attachments = get_attch_resources params[:id]
|
|
|
|
|
@attachments = get_attch_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:type] == "5" #用户资源
|
|
|
|
|
@attachments = get_principal_resources params[:id]
|
|
|
|
|
@attachments = get_principal_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:type] == "6" # 公共资源
|
|
|
|
|
if params[:status] == "2"
|
|
|
|
|
@attachments = get_course_resources_public( user_course_ids)
|
|
|
|
|
@attachments = get_course_resources_public( user_course_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "3"
|
|
|
|
|
@attachments = get_project_resources_public(user_project_ids)
|
|
|
|
|
@attachments = get_project_resources_public(user_project_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "4"
|
|
|
|
|
@attachments = get_attch_resources_public
|
|
|
|
|
@attachments = get_attch_resources_public params[:order]
|
|
|
|
|
elsif params[:status] == "5"
|
|
|
|
|
@attachments = get_principal_resources_public
|
|
|
|
|
@attachments = get_principal_resources_public params[:order]
|
|
|
|
|
else
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@status = params[:status]
|
|
|
|
@ -2331,61 +2326,70 @@ class UsersController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取公共资源
|
|
|
|
|
def get_public_resources user_course_ids, user_project_ids
|
|
|
|
|
def get_public_resources user_course_ids, user_project_ids, order
|
|
|
|
|
attachments = Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','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)" +
|
|
|
|
|
"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)" ).order("created_on desc")
|
|
|
|
|
"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)" ).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取我的资源
|
|
|
|
|
def get_my_resources author_id, user_course_ids, user_project_ids
|
|
|
|
|
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')) "+
|
|
|
|
|
"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)" ).order("created_on desc")
|
|
|
|
|
"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)" ).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取我的资源查询结果
|
|
|
|
|
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')) "+
|
|
|
|
|
"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
|
|
|
|
|
|
|
|
|
|
# 获取我的课程资源
|
|
|
|
|
def get_course_resources author_id, user_course_ids
|
|
|
|
|
attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
|
|
|
|
|
def get_course_resources author_id, user_course_ids, order
|
|
|
|
|
attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取公共资源课程
|
|
|
|
|
def get_course_resources_public user_course_ids
|
|
|
|
|
attchments = Attachment.where("(container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
|
|
|
|
|
def get_course_resources_public user_course_ids, order
|
|
|
|
|
attchments = Attachment.where("(container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取我的项目资源
|
|
|
|
|
def get_project_resources author_id, user_project_ids
|
|
|
|
|
attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Project') or (container_type = 'Course' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
|
|
|
|
|
def get_project_resources author_id, user_project_ids, order
|
|
|
|
|
attchments = Attachment.where("(author_id = #{author_id} 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) ").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取公共资源的项目资源
|
|
|
|
|
def get_project_resources_public user_project_ids
|
|
|
|
|
attchments = Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
|
|
|
|
|
def get_project_resources_public user_project_ids, order
|
|
|
|
|
attchments = Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取我上传的附件
|
|
|
|
|
def get_attch_resources author_id
|
|
|
|
|
attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
|
|
|
|
|
def get_attch_resources author_id, order
|
|
|
|
|
attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取公共资源中我上传的附件
|
|
|
|
|
def get_attch_resources_public
|
|
|
|
|
attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
|
|
|
|
|
def get_attch_resources_public order
|
|
|
|
|
attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取我的用户类型资源
|
|
|
|
|
def get_principal_resources author_id
|
|
|
|
|
attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc")
|
|
|
|
|
def get_principal_resources author_id, order
|
|
|
|
|
attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取我的用户类型资源
|
|
|
|
|
def get_principal_resources_public
|
|
|
|
|
attchments = Attachment.where("container_type = 'Principal'").order("created_on desc")
|
|
|
|
|
def get_principal_resources_public order
|
|
|
|
|
attchments = Attachment.where("container_type = 'Principal'").order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 资源库 分为全部 课程资源 项目资源 附件
|
|
|
|
|
def user_resource
|
|
|
|
|
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
|
|
|
|
|
@score = @b_sort == "desc" ? "asc" : "desc"
|
|
|
|
|
# 别人的资源库是没有权限去看的
|
|
|
|
|
if User.current.id.to_i != params[:id].to_i
|
|
|
|
|
render_403
|
|
|
|
@ -2397,37 +2401,37 @@ class UsersController < ApplicationController
|
|
|
|
|
if(params[:type].blank? || params[:type] == "1") # 我的资源
|
|
|
|
|
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
|
|
|
|
if params[:status] == "2"
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids)
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids, @order)
|
|
|
|
|
elsif params[:status] == "3"
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids)
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids, @order)
|
|
|
|
|
elsif params[:status] == "4"
|
|
|
|
|
@attachments = get_attch_resources params[:id]
|
|
|
|
|
@attachments = get_attch_resources params[:id], @order
|
|
|
|
|
elsif params[:status] == "5"
|
|
|
|
|
@attachments = get_principal_resources params[:id]
|
|
|
|
|
@attachments = get_principal_resources params[:id], @order
|
|
|
|
|
else
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
|
|
|
|
@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)
|
|
|
|
|
@attachments = get_course_resources(params[:id], user_course_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "3" # 项目资源
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids)
|
|
|
|
|
@attachments = get_project_resources(params[:id], user_project_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "4" #附件
|
|
|
|
|
@attachments = get_attch_resources params[:id]
|
|
|
|
|
@attachments = get_attch_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:type] == "5" #用户资源
|
|
|
|
|
@attachments = get_principal_resources params[:id]
|
|
|
|
|
@attachments = get_principal_resources params[:id], params[:order]
|
|
|
|
|
elsif params[:type] == "6" # 公共资源
|
|
|
|
|
if params[:status] == "2"
|
|
|
|
|
@attachments = get_course_resources_public( user_course_ids)
|
|
|
|
|
@attachments = get_course_resources_public( user_course_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "3"
|
|
|
|
|
@attachments = get_project_resources_public(user_project_ids)
|
|
|
|
|
@attachments = get_project_resources_public(user_project_ids, params[:order])
|
|
|
|
|
elsif params[:status] == "4"
|
|
|
|
|
@attachments = get_attch_resources_public
|
|
|
|
|
@attachments = get_attch_resources_public params[:order]
|
|
|
|
|
elsif params[:status] == "5"
|
|
|
|
|
@attachments = get_principal_resources_public
|
|
|
|
|
@attachments = get_principal_resources_public params[:order]
|
|
|
|
|
else
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@status = params[:status]
|
|
|
|
@ -2457,10 +2461,10 @@ class UsersController < ApplicationController
|
|
|
|
|
# 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)
|
|
|
|
|
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
elsif params[:type] == "6" # 公共资源
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
end
|
|
|
|
|
@type = params[:type]
|
|
|
|
|
@limit = 10
|
|
|
|
@ -2493,10 +2497,10 @@ class UsersController < ApplicationController
|
|
|
|
|
# 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("created_on desc")
|
|
|
|
|
"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")
|
|
|
|
|
elsif params[:type] == "6" # 公共资源
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
|
|
|
|
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order])
|
|
|
|
|
end
|
|
|
|
|
@type = params[:type]
|
|
|
|
|
@limit = 10
|
|
|
|
@ -2566,57 +2570,74 @@ class UsersController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 根据资源关键字进行搜索
|
|
|
|
|
def resource_search
|
|
|
|
|
search = "%#{params[:search].strip.downcase}%"
|
|
|
|
|
@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}
|
|
|
|
|
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 User.current.id.to_i == params[:id].to_i
|
|
|
|
|
|
|
|
|
|
@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("created_on desc")
|
|
|
|
|
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}")
|
|
|
|
|
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}")
|
|
|
|
|
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}")
|
|
|
|
|
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}")
|
|
|
|
|
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.empty? ? '0': user_course_ids.join(',')})) )" +
|
|
|
|
|
" and (filename like :p) ",:p=>search).order("created_on desc")
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
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("created_on desc")
|
|
|
|
|
@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("created_on desc")
|
|
|
|
|
" and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
elsif params[:type] == "3" #项目资源
|
|
|
|
|
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("created_on desc")
|
|
|
|
|
@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("created_on desc")
|
|
|
|
|
@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" #附件
|
|
|
|
|
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("created_on desc")
|
|
|
|
|
@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("created_on desc")
|
|
|
|
|
@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}")
|
|
|
|
|
end
|
|
|
|
|
elsif params[:type] == "5" #用户资源
|
|
|
|
|
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("created_on desc")
|
|
|
|
|
@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("created_on desc")
|
|
|
|
|
@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" # 全部资源
|
|
|
|
|
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}")
|
|
|
|
|
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}")
|
|
|
|
|
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}")
|
|
|
|
|
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}")
|
|
|
|
|
else
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','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)" +
|
|
|
|
|
"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]} #{@score}")
|
|
|
|
|
end
|
|
|
|
|
elsif params[:type] == "6" #全部资源
|
|
|
|
|
# 公共资源库:所有公开资源或者我上传的私有资源
|
|
|
|
|
@attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','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)" +
|
|
|
|
|
"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("created_on desc")
|
|
|
|
|
end
|
|
|
|
|
@status = params[:status]
|
|
|
|
|
@type = params[:type]
|
|
|
|
|
@type = params[:type]
|
|
|
|
|
@limit = 25
|
|
|
|
|
@is_remote = true
|
|
|
|
|