@ -422,11 +422,12 @@ class UsersController < ApplicationController
end
end
def choose_user_course
def choose_user_course
homework = HomeworkCommon . find params [ :homework ] . to_i
if ! params [ :search ] . nil?
if ! params [ :search ] . nil?
search = " % #{ params [ :search ] . to_s . strip . downcase } % "
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 ) }
@course = @user . courses . where ( " #{ Course . table_name } .id != #{ homework . course_id } and #{ 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 ) }
else
else
@course = @user . courses . select { | course | @user . allowed_to? ( :as_teacher , course ) }
@course = @user . courses . where( " #{ Course . table_name } .id != #{ homework . course_id } " ) . select { | course | @user . allowed_to? ( :as_teacher , course ) }
end
end
@search = params [ :search ]
@search = params [ :search ]
#这里仅仅是传递需要发送的资源id
#这里仅仅是传递需要发送的资源id
@ -531,7 +532,15 @@ class UsersController < ApplicationController
elsif params [ :type ] == " 2 " #我的题库
elsif params [ :type ] == " 2 " #我的题库
@homeworks = HomeworkCommon . where ( " user_id = #{ @user . id } and publish_time <= ' #{ Date . today } ' " ) . order ( " created_at desc " )
@homeworks = HomeworkCommon . where ( " user_id = #{ @user . id } and publish_time <= ' #{ Date . today } ' " ) . order ( " created_at desc " )
end
end
if params [ :property ] && params [ :property ] == " 1 "
@homeworks = @homeworks . where ( " homework_type = 1 " ) . reorder ( " created_at desc " )
elsif params [ :property ] && params [ :property ] == " 2 "
@homeworks = @homeworks . where ( " homework_type = 2 " ) . reorder ( " created_at desc " )
elsif params [ :property ] && params [ :property ] == " 3 "
@homeworks = @homeworks . where ( " homework_type = 3 " ) . reorder ( " created_at desc " )
end
@type = params [ :type ]
@type = params [ :type ]
@property = params [ :property ]
@limit = 15
@limit = 15
@is_remote = true
@is_remote = true
@hw_count = @homeworks . count
@hw_count = @homeworks . count
@ -559,10 +568,21 @@ class UsersController < ApplicationController
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
visible_course = Course . where ( " is_public = 1 && is_delete = 0 " )
visible_course = Course . where ( " is_public = 1 && is_delete = 0 " )
visible_course_ids = visible_course . empty? ? " (-1) " : " ( " + visible_course . map { | course | course . id } . join ( " , " ) + " ) "
visible_course_ids = visible_course . empty? ? " (-1) " : " ( " + visible_course . map { | course | course . id } . join ( " , " ) + " ) "
@homeworks = HomeworkCommon . where ( " course_id in #{ visible_course_ids } and publish_time <= ' #{ Date . today } ' and (name like '% #{ search } %') " ) . order ( " created_at desc " )
all_homeworks = HomeworkCommon . where ( " course_id in #{ visible_course_ids } and publish_time <= ' #{ Date . today } ' " )
all_user_ids = all_homeworks . map { | hw | hw . user_id }
user_str_ids = search_user_by_name all_user_ids , search
user_ids = user_str_ids . empty? ? " (-1) " : " ( " + user_str_ids . join ( " , " ) + " ) "
@homeworks = HomeworkCommon . where ( " course_id in #{ visible_course_ids } and publish_time <= ' #{ Date . today } ' and (name like '% #{ search } %' or user_id in #{ user_ids } ) " ) . order ( " created_at desc " )
elsif params [ :type ] == " 2 " #课程资源
elsif params [ :type ] == " 2 " #课程资源
@homeworks = HomeworkCommon . where ( " user_id = #{ @user . id } and publish_time <= ' #{ Date . today } ' and (name like '% #{ search } %') " ) . order ( " created_at desc " )
@homeworks = HomeworkCommon . where ( " user_id = #{ @user . id } and publish_time <= ' #{ Date . today } ' and (name like '% #{ search } %') " ) . order ( " created_at desc " )
end
end
if params [ :property ] && params [ :property ] == " 1 "
@homeworks = @homeworks . where ( " homework_type = 1 " ) . reorder ( " created_at desc " )
elsif params [ :property ] && params [ :property ] == " 2 "
@homeworks = @homeworks . where ( " homework_type = 2 " ) . reorder ( " created_at desc " )
elsif params [ :property ] && params [ :property ] == " 3 "
@homeworks = @homeworks . where ( " homework_type = 3 " ) . reorder ( " created_at desc " )
end
@type = params [ :type ]
@type = params [ :type ]
@limit = 15
@limit = 15
@is_remote = true
@is_remote = true
@ -1518,9 +1538,20 @@ class UsersController < ApplicationController
#@user.save_attachments(params[:attachments],User.current)
#@user.save_attachments(params[:attachments],User.current)
# Container_type为Principal
# Container_type为Principal
Attachment . attach_filesex ( @user , params [ :attachments ] , params [ :attachment_type ] )
Attachment . attach_filesex ( @user , params [ :attachments ] , params [ :attachment_type ] )
if ( params [ :type ] . nil? || params [ :type ] . blank? || params [ :type ] == " 1 " || params [ :type ] == 'all' ) #全部
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params [ :status ] == 2
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
elsif params [ :status ] == " 3 "
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
elsif params [ :status ] == " 4 "
@attachments = get_attch_resources params [ :id ]
elsif params [ :status ] == " 5 "
@attachments = get_principal_resources params [ :id ]
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 )
end
elsif params [ :type ] == " 2 " # 课程资源
elsif params [ :type ] == " 2 " # 课程资源
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
elsif params [ :type ] == " 3 " # 项目资源
elsif params [ :type ] == " 3 " # 项目资源
@ -1530,10 +1561,21 @@ class UsersController < ApplicationController
elsif params [ :type ] == " 5 " #用户资源
elsif params [ :type ] == " 5 " #用户资源
@attachments = get_principal_resources params [ :id ]
@attachments = get_principal_resources params [ :id ]
elsif params [ :type ] == " 6 " # 公共资源
elsif params [ :type ] == " 6 " # 公共资源
if params [ :status ] == " 2 "
@attachments = get_course_resources_public ( user_course_ids )
elsif params [ :status ] == " 3 "
@attachments = get_project_resources_public ( user_project_ids )
elsif params [ :status ] == " 4 "
@attachments = get_attch_resources_public
elsif params [ :status ] == " 5 "
@attachments = get_principal_resources_public
else
# 公共资源库:所有公开资源或者我上传的私有资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids )
@attachments = get_public_resources ( user_course_ids , user_project_ids )
end
end
@type = params [ :type ] || 1
end
@status = params [ :status ]
@type = params [ :type ]
@limit = 25
@limit = 25
@is_remote = true
@is_remote = true
@atta_count = @attachments . count
@atta_count = @attachments . count
@ -1558,9 +1600,20 @@ class UsersController < ApplicationController
user_course_ids = User . current . courses . map { | c | c . id }
user_course_ids = User . current . courses . map { | c | c . id }
user_project_ids = User . current . projects . map { | p | p . id }
user_project_ids = User . current . projects . map { | p | p . id }
# user_org_ids = User.current.organizations.map {|o| o.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 [ :type ] . blank? || params [ :type ] == " 1 " ) # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params [ :status ] == 2
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
elsif params [ :status ] == " 3 "
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
elsif params [ :status ] == " 4 "
@attachments = get_attch_resources params [ :id ]
elsif params [ :status ] == " 5 "
@attachments = get_principal_resources params [ :id ]
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 )
end
elsif params [ :type ] == " 2 " # 课程资源
elsif params [ :type ] == " 2 " # 课程资源
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
elsif params [ :type ] == " 3 " # 项目资源
elsif params [ :type ] == " 3 " # 项目资源
@ -1570,9 +1623,20 @@ class UsersController < ApplicationController
elsif params [ :type ] == " 5 " #用户资源
elsif params [ :type ] == " 5 " #用户资源
@attachments = get_principal_resources params [ :id ]
@attachments = get_principal_resources params [ :id ]
elsif params [ :type ] == " 6 " # 公共资源
elsif params [ :type ] == " 6 " # 公共资源
if params [ :status ] == " 2 "
@attachments = get_course_resources_public ( user_course_ids )
elsif params [ :status ] == " 3 "
@attachments = get_project_resources_public ( user_project_ids )
elsif params [ :status ] == " 4 "
@attachments = get_attch_resources_public
elsif params [ :status ] == " 5 "
@attachments = get_principal_resources_public
else
# 公共资源库:所有公开资源或者我上传的私有资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids )
@attachments = get_public_resources ( user_course_ids , user_project_ids )
end
end
end
@status = params [ :status ]
@type = params [ :type ]
@type = params [ :type ]
@limit = 25
@limit = 25
@is_remote = true
@is_remote = true
@ -2320,7 +2384,7 @@ class UsersController < ApplicationController
# user_org_ids = User.current.organizations.map {|o| o.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 " ) # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params [ :status ] == 2
if params [ :status ] == " 2 "
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
elsif params [ :status ] == " 3 "
elsif params [ :status ] == " 3 "
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
@attachments = get_project_resources ( params [ :id ] , user_project_ids )