@ -320,7 +320,7 @@ class UsersController < ApplicationController
case params [ :agree ]
when 'Y'
ar . update_column ( 'status' , 2 )
@msg . update_attributes ( :apply_result = > 1 , :viewed = > 1 )
@msg . update_attributes ( :apply_result = > 1 , :viewed = > 1 )
ar . course_messages << CourseMessage . new ( :user_id = > ar . user_id , :course_id = > - 1 , :viewed = > false , :apply_result = > 2 , :status = > 1 )
when 'N'
ar . update_column ( 'status' , 3 )
@ -534,28 +534,28 @@ class UsersController < ApplicationController
end
def student_homeworks
if User . current == @user
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
user_course_ids = @user . courses . empty? ? " (-1) " :" ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
#判断当前用户在当前课程的身份
visibleCourse = @user . courses . empty? ? [ ] : @user . courses . where ( " is_delete = 0 " ) . visible
homework_ids = [ ]
visibleCourse . each do | course |
homeworks = HomeworkCommon . where ( " course_id = #{ course . id } and publish_time <= ' #{ Date . today } ' " )
homework_ids << homeworks . pluck ( :id ) unless homeworks . empty?
end
visible_homework_ids = homework_ids . size == 0 ? " (-1) " :" ( " + homework_ids . join ( " , " ) + " ) "
@homework_commons = HomeworkCommon . where ( " id in #{ visible_homework_ids } " ) . order ( " created_at desc " ) . limit ( 10 ) . offset ( @page * 10 )
@is_teacher = User . current . user_extensions && User . current . user_extensions . identity == 0 && User . current . allowed_to? ( :add_course , nil , :global = > true )
@is_in_course = params [ :is_in_course ] . to_i || 0
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
end
else
render_403
if User . current == @user
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
user_course_ids = @user . courses . empty? ? " (-1) " :" ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
#判断当前用户在当前课程的身份
visibleCourse = @user . courses . empty? ? [ ] : @user . courses . where ( " is_delete = 0 " ) . visible
homework_ids = [ ]
visibleCourse . each do | course |
homeworks = HomeworkCommon . where ( " course_id = #{ course . id } and publish_time <= ' #{ Date . today } ' " )
homework_ids << homeworks . pluck ( :id ) unless homeworks . empty?
end
visible_homework_ids = homework_ids . size == 0 ? " (-1) " :" ( " + homework_ids . join ( " , " ) + " ) "
@homework_commons = HomeworkCommon . where ( " id in #{ visible_homework_ids } " ) . order ( " created_at desc " ) . limit ( 10 ) . offset ( @page * 10 )
@is_teacher = User . current . user_extensions && User . current . user_extensions . identity == 0 && User . current . allowed_to? ( :add_course , nil , :global = > true )
@is_in_course = params [ :is_in_course ] . to_i || 0
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
end
else
render_403
end
end
def choose_user_course
@ -1017,34 +1017,20 @@ class UsersController < ApplicationController
#用户从资源库导入资源到作业
def user_import_resource
if User . current . id . to_i != params [ :id ] . to_i
render_403
return
end
@resource_id = params [ :project_id ] . nil? ? ( params [ :course_id ] . nil? ? params [ :subfield_file_id ] : params [ :course_id ] ) : params [ :project_id ]
@resource_type = params [ :project_id ] . nil? ? ( params [ :course_id ] . nil? ? " SubfieldFile " : " Course " ) : " Project "
@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 . is_delete == 0 && c . id }
user_project_ids = User . current . projects . map { | p | p . status != 9 && p . id } # user_org_ids = User.current.organizations.map {|o| o.id}
if ( params [ :type ] == " 1 " ) # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
@attachments = get_my_resources ( params [ :id ] , user_course_ids , user_project_ids , @order , @score )
elsif ( params [ :type ] . blank? || params [ :type ] == " 6 " ) # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
@status = params [ :status ]
@user = User . current
user_course_ids = @user . 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 . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
@type = params [ :type ]
@homework_id = params [ :homework_id ]
@limit = 10
@limit = 7
@is_remote = true
@seleted_resources = session [ :seleted_resource_ids ] . nil? ? [ ] : session [ :seleted_resource_ids ]
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
@seleted_resources = session [ :seleted_resource_ids ] . nil? ? [ ] : session [ :seleted_resource_ids ]
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments , 10
@attachments = paginateHelper @attachments , 7
respond_to do | format |
format . js
end
@ -1052,10 +1038,10 @@ class UsersController < ApplicationController
#引入资源列表根据类型过滤
def user_resource_type
# if User.current.id.to_i != params[:id]. to_i
# render_403
# return
# end
if User . current . id . to_i != params [ :id ] . to_i
render_403
return
end
user_course_ids = User . current . courses . map { | c | c . is_delete == 0 && c . id }
user_project_ids = User . current . projects . map { | p | p . status != 9 && p . id }
# user_org_ids = User.current.organizations.map {|o| o.id}
@ -1104,27 +1090,22 @@ class UsersController < ApplicationController
#引入资源列表根据关键词过滤
def user_ref_resource_search
if User . current . id . to_i != params [ :id ] . to_i
render_403
return
end
@resource_id = params [ :mul_id ]
@resource_type = params [ :mul_type ]
@order , @b_sort = params [ :order ] || " created_on " , params [ :sort ] || " asc "
@score = @b_sort == " desc " ? " asc " : " desc "
@user = User . current
@switch_search = params [ :search ] . nil? ? " " : params [ :search ]
search = " % #{ @switch_search . strip . downcase } % "
# 别人的资源库是没有权限去看的
if ( params [ :type ] == " 1 " ) # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
search = params [ :search ] . to_s . strip . downcase
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
user_course_ids = User . current . courses . map { | c | c . is_delete == 0 && 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 . empty? ? '0' : user_course_ids . join ( ',' ) } ))) and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 2 " #课程资源
user_course_ids = User . current . courses . map { | c | c . is_delete == 0 && c . id }
user_project_ids = User . current . projects . map { | p | p . status != 9 && p . id }
# user_org_ids = User.current.organizations.map {|o| o.id}
@attachments = get_my_resources_search ( params [ :id ] , user_course_ids , user_project_ids , @order , @score , search )
elsif ( params [ :type ] . blank? || params [ :type ] == " 6 " ) # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources_search ( user_course_ids , user_project_ids , @order , @score , search )
@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 '% #{ search } %') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 3 " #项目资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 4 " #附件
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 5 " #用户资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 6 " #公共资源
@attachments = Attachment . where ( " (is_public =1 and is_publish = 1 and container_id is not null) " + " or (author_id = #{ params [ :id ] } and is_publish = 0) " ) . order ( " created_on desc " )
end
@type = params [ :type ]
@limit = 7
@ -1134,7 +1115,7 @@ class UsersController < ApplicationController
@offset || = @atta_pages . offset
@seleted_resources = session [ :seleted_resource_ids ] . nil? ? [ ] : session [ :seleted_resource_ids ]
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments , 7
@attachments = paginateHelper @attachments , 7
respond_to do | format |
format . js
end
@ -2072,18 +2053,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
# elsif params[:type] == "2"
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
# elsif params[:type] == "2"
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
end
@type = params [ :type ]
@limit = 25
@ -2225,18 +2206,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
# elsif params[:type] == "2"
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
# elsif params[:type] == "2"
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
end
@status = params [ :status ]
@type = params [ :type ]
@ -2366,18 +2347,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
# elsif params[:type] == "2"
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
# elsif params[:type] == "2"
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
end
@type = params [ :type ]
@limit = 25
@ -2739,7 +2720,7 @@ class UsersController < ApplicationController
# 获取我的课程资源
def get_course_resources author_id , user_course_ids , order , score
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 ( ',' ) } )
" 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 ) " ).order( " #{order.nil? ? 'created_on' : order} #{score}")
end
@ -2773,7 +2754,7 @@ class UsersController < ApplicationController
# 获取我的项目资源
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') " +
" or (container_type = 'Project' and container_id in ( #{ user_project_ids . empty? ? '0' : user_project_ids . join ( ',' ) } )
" 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( " #{order.nil? ? 'created_on' : order} #{score}")
end
@ -2877,18 +2858,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
# elsif params[:type] == "2" # 私有资源
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
# elsif params[:type] == "2" # 私有资源
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
end
@status = params [ :status ]
@type = params [ :type ]
@ -3066,21 +3047,21 @@ class UsersController < ApplicationController
@attachments = get_principal_resources_public_search ( @order , @score , search )
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources_search ( user_course_ids , user_project_ids , @order , @score , search )
end
# elsif params[:type] == "2" # 私有资源
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search)
# @attachments
@attachments = get_public_resources_search ( user_course_ids , user_project_ids , @order , @score , search )
end
# elsif params[:type] == "2" # 私有资源
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
# if params[:status] == "2"
# resource_type = "'Course'"
# elsif params[:status] == "3"
# resource_type = "'Project'"
# elsif params[:status] == "5"
# resource_type = "'Principal'"
# else
# resource_type = "'Project','OrgSubfield','Principal','Course'"
# end
# @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search)
# @attachments
end
@status = params [ :status ]
@type = params [ :type ]