@ -26,6 +26,7 @@ class UsersController < ApplicationController
menu_item :user_information , :only = > :info
menu_item :user_information , :only = > :info
menu_item :user_course , :only = > :user_courses
menu_item :user_course , :only = > :user_courses
menu_item :user_homework , :only = > :user_homeworks
menu_item :user_homework , :only = > :user_homeworks
menu_item :student_homework , :only = > :student_homeworks
menu_item :user_project , :only = > [ :user_projects , :watch_projects ]
menu_item :user_project , :only = > [ :user_projects , :watch_projects ]
menu_item :requirement_focus , :only = > :watch_contests
menu_item :requirement_focus , :only = > :watch_contests
menu_item :user_newfeedback , :only = > :user_newfeedback
menu_item :user_newfeedback , :only = > :user_newfeedback
@ -35,12 +36,12 @@ class UsersController < ApplicationController
#
#
before_filter :can_show_course , :only = > [ :user_courses , :user_homeworks ]
before_filter :can_show_course , :only = > [ :user_courses , :user_homeworks ]
before_filter :find_user , :only = > [ :user_fanslist , :user_watchlist , :show , :edit , :update , :destroy , :edit_membership , :user_courses ,
before_filter :find_user , :only = > [ :user_fanslist , :user_watchlist , :show , :edit , :update , :destroy , :edit_membership , :user_courses ,
:user_homeworks , :destroy_membership , :user_activities , :user_projects , :user_newfeedback , :user_comments ,
:user_homeworks , :student_homeworks , :destroy_membership , :user_activities , :user_projects , :user_newfeedback , :user_comments ,
:watch_contests , :info , :watch_projects , :show_score , :topic_score_index , :project_score_index ,
:watch_contests , :info , :watch_projects , :show_score , :topic_score_index , :project_score_index ,
:activity_score_index , :influence_score_index , :score_index , :show_new_score , :topic_new_score_index , :project_new_score_index ,
:activity_score_index , :influence_score_index , :score_index , :show_new_score , :topic_new_score_index , :project_new_score_index ,
:activity_new_score_index , :influence_new_score_index , :score_new_index , :user_projects_index , :user_resource ,
:activity_new_score_index , :influence_new_score_index , :score_new_index , :user_projects_index , :user_resource ,
:user_courses4show , :user_projects4show , :user_course_activities , :user_project_activities , :user_feedback4show , :user_visitorlist , :user_messages , :edit_brief_introduction ,
:user_courses4show , :user_projects4show , :user_course_activities , :user_project_activities , :user_feedback4show , :user_visitorlist , :user_messages , :edit_brief_introduction ,
:user_import_homeworks , :user_search_homeworks , :user_import_resource , :user_system_messages ]
:user_import_homeworks , :user_search_homeworks , :user_import_resource , :user_system_messages , :choose_user_course ]
before_filter :auth_user_extension , only : :show
before_filter :auth_user_extension , only : :show
#before_filter :rest_user_score, only: :show
#before_filter :rest_user_score, only: :show
#before_filter :select_entry, only: :user_projects
#before_filter :select_entry, only: :user_projects
@ -374,6 +375,28 @@ class UsersController < ApplicationController
#用户作业列表
#用户作业列表
def user_homeworks
def user_homeworks
@user = User . current
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #公共题库
visible_course = Course . where ( " is_public = 1 && is_delete = 0 " )
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 } ' " ) . order ( " created_at desc " )
elsif params [ :type ] == " 2 " #我的题库
@homeworks = HomeworkCommon . where ( " user_id = #{ @user . id } and publish_time <= ' #{ Date . today } ' " ) . order ( " created_at desc " )
end
@type = params [ :type ]
@limit = 15
@is_remote = true
@hw_count = @homeworks . count
@hw_pages = Paginator . new @hw_count , @limit , params [ 'page' ] || 1
@offset || = @hw_pages . offset
@homeworks = paginateHelper @homeworks , 15
respond_to do | format |
format . js
format . html { render :layout = > 'static_base' }
end
end
def student_homeworks
if User . current == @user
if User . current == @user
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
user_course_ids = @user . courses . empty? ? " (-1) " :" ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
user_course_ids = @user . courses . empty? ? " (-1) " :" ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
@ -382,14 +405,9 @@ class UsersController < ApplicationController
visibleCourse = @user . courses . empty? ? [ ] : @user . courses . visible
visibleCourse = @user . courses . empty? ? [ ] : @user . courses . visible
homework_ids = [ ]
homework_ids = [ ]
visibleCourse . each do | course |
visibleCourse . each do | course |
if User . current . allowed_to? ( :as_teacher , course )
homeworks = HomeworkCommon . where ( " course_id = #{ course . id } " )
homework_ids << homeworks . pluck ( :id ) unless homeworks . empty?
else
homeworks = HomeworkCommon . where ( " course_id = #{ course . id } and publish_time <= ' #{ Date . today } ' " )
homeworks = HomeworkCommon . where ( " course_id = #{ course . id } and publish_time <= ' #{ Date . today } ' " )
homework_ids << homeworks . pluck ( :id ) unless homeworks . empty?
homework_ids << homeworks . pluck ( :id ) unless homeworks . empty?
end
end
end
visible_homework_ids = homework_ids . size == 0 ? " (-1) " :" ( " + homework_ids . join ( " , " ) + " ) "
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 )
@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_teacher = User . current . user_extensions && User . current . user_extensions . identity == 0 && User . current . allowed_to? ( :add_course , nil , :global = > true )
@ -403,6 +421,88 @@ class UsersController < ApplicationController
end
end
end
end
def choose_user_course
homework = HomeworkCommon . find params [ :homework ] . to_i
if ! params [ :search ] . nil?
search = " % #{ params [ :search ] . to_s . strip . downcase } % "
@course = @user . courses . where ( " is_delete = 0 and #{ 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
@course = @user . courses . where ( " is_delete = 0 and #{ Course . table_name } .id != #{ homework . course_id } " ) . select { | course | @user . allowed_to? ( :as_teacher , course ) }
end
@search = params [ :search ]
#这里仅仅是传递需要发送的资源id
@send_id = params [ :send_id ]
respond_to do | format |
format . js
end
end
def send_homework_to_course
homework = HomeworkCommon . find params [ :send_id ] . to_i
course_ids = params [ :course_ids ]
course_ids . each do | course_id |
course = Course . find course_id . to_i
new_homework = HomeworkCommon . new
new_homework . name = homework . name
new_homework . user_id = User . current . id
new_homework . description = homework . description
new_homework . homework_type = homework . homework_type
new_homework . late_penalty = homework . late_penalty
new_homework . course_id = course . id
new_homework . teacher_priority = homework . teacher_priority
new_homework . anonymous_comment = homework . anonymous_comment
new_homework . quotes = 0
new_homework . is_open = homework . is_open
homework . attachments . each do | attachment |
att = attachment . copy
att . container_id = nil
att . container_type = nil
att . copy_from = attachment . id
att . save
new_homework . attachments << att
end
homework_detail_manual = homework . homework_detail_manual
homework_detail_programing = homework . homework_detail_programing
homework_detail_group = homework . homework_detail_group
if homework_detail_manual
new_homework . homework_detail_manual = HomeworkDetailManual . new
new_homework_detail_manual = new_homework . homework_detail_manual
new_homework_detail_manual . ta_proportion = homework_detail_manual . ta_proportion
new_homework_detail_manual . comment_status = 0
new_homework_detail_manual . evaluation_num = homework_detail_manual . evaluation_num
new_homework_detail_manual . absence_penalty = homework_detail_manual . absence_penalty
end
if homework_detail_programing
new_homework . homework_detail_programing = HomeworkDetailPrograming . new
new_homework . homework_detail_programing . ta_proportion = homework_detail_programing . ta_proportion
new_homework . homework_detail_programing . language = homework_detail_programing . language
homework . homework_tests . each_with_index do | homework_test |
new_homework . homework_tests << HomeworkTest . new (
input : homework_test . input ,
output : homework_test . output
)
end
end
if homework_detail_group
new_homework . homework_detail_group = HomeworkDetailGroup . new
new_homework . homework_detail_group . min_num = homework_detail_group . min_num
new_homework . homework_detail_group . max_num = homework_detail_group . max_num
new_homework . homework_detail_group . base_on_project = homework_detail_group . base_on_project
end
if new_homework . save
new_homework_detail_manual . save if new_homework_detail_manual
new_homework . homework_detail_programing . save if new_homework . homework_detail_programing
new_homework . homework_detail_group . save if new_homework . homework_detail_group
end
homework . update_attribute ( :quotes , homework . quotes + 1 )
end
@homework = homework
respond_to do | format |
format . js
end
end
#导入作业
#导入作业
def user_import_homeworks
def user_import_homeworks
@user = User . current
@user = User . current
@ -432,13 +532,22 @@ 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
@hw_pages = Paginator . new @hw_count , @limit , params [ 'page' ] || 1
@hw_pages = Paginator . new @hw_count , @limit , params [ 'page' ] || 1
@offset || = @hw_pages . offset
@offset || = @hw_pages . offset
@homeworks = paginateHelper @homeworks , 15
@homeworks = paginateHelper @homeworks , 15
@is_import = params [ :is_import ]
respond_to do | format |
respond_to do | format |
format . js
format . js
end
end
@ -446,6 +555,7 @@ class UsersController < ApplicationController
def show_homework_detail
def show_homework_detail
@homework = HomeworkCommon . find params [ :homework ] . to_i
@homework = HomeworkCommon . find params [ :homework ] . to_i
@is_import = params [ :is_import ]
respond_to do | format |
respond_to do | format |
format . js
format . js
end
end
@ -458,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
@ -469,6 +590,7 @@ class UsersController < ApplicationController
@hw_pages = Paginator . new @hw_count , @limit , params [ 'page' ] || 1
@hw_pages = Paginator . new @hw_count , @limit , params [ 'page' ] || 1
@offset || = @hw_pages . offset
@offset || = @hw_pages . offset
@homeworks = paginateHelper @homeworks , 15
@homeworks = paginateHelper @homeworks , 15
@is_import = params [ :is_import ]
respond_to do | format |
respond_to do | format |
format . js
format . js
end
end
@ -642,8 +764,8 @@ class UsersController < ApplicationController
homework_detail_programing . save if homework_detail_programing
homework_detail_programing . save if homework_detail_programing
homework_detail_group . save if homework_detail_group
homework_detail_group . save if homework_detail_group
if params [ :quotes ] && ! params [ :quotes ] . blank?
if params [ :quotes ] && ! params [ :quotes ] . blank?
homework = HomeworkCommon . find params [ :quotes ] . to_i
quotes_ homework = HomeworkCommon . find params [ :quotes ] . to_i
homework. update_attribute ( :quotes , homework. quotes + 1 )
quotes_ homework. update_attribute ( :quotes , quotes_ homework. quotes + 1 )
end
end
if params [ :is_in_course ] == " 1 "
if params [ :is_in_course ] == " 1 "
redirect_to homework_common_index_path ( :course = > homework . course_id )
redirect_to homework_common_index_path ( :course = > homework . course_id )
@ -684,19 +806,23 @@ class UsersController < ApplicationController
render_403
render_403
return
return
end
end
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 ] . blank? || params [ :type ] == " 1 " ) #全部
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@attachments = get_my_resources ( params [ :id ] , user_course_ids , user_project_ids )
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
elsif params [ :type ] == " 2 " # 课程资源
elsif params [ :type ] == " 2 " # 课程资源
user_course_ids = User . current . courses . map { | c | c . id }
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
@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 ( ',' ) } )) " ) . order ( " created_on desc " )
elsif params [ :type ] == " 3 " # 项目资源
elsif params [ :type ] == " 3 " # 项目资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' " ) . order ( " created_on desc " )
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
elsif params [ :type ] == " 4 " #附件
elsif params [ :type ] == " 4 " #附件
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
@attachments = get_attch_resources params [ :id ]
elsif params [ :type ] == " 5 " #用户资源
elsif params [ :type ] == " 5 " #用户资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' " ) . order ( " created_on desc " )
@attachments = get_principal_resources params [ :id ]
elsif params [ :type ] == " 6 " # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids )
end
end
@type = params [ :type ]
@type = params [ :type ]
@limit = 7
@limit = 7
@ -729,6 +855,8 @@ class UsersController < ApplicationController
@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 " )
@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 " #用户资源
elsif params [ :type ] == " 5 " #用户资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
@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
end
@type = params [ :type ]
@type = params [ :type ]
@limit = 7
@limit = 7
@ -1403,50 +1531,51 @@ class UsersController < ApplicationController
# 上传用户资源
# 上传用户资源
def user_resource_create
def user_resource_create
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}
@user = User . find ( params [ :id ] )
@user = User . find ( params [ :id ] )
#@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 ] . blank? || params [ :type ] == " 1 " ) #全部
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) # 我的资源
if User . current . id . to_i == params [ :id ] . to_i
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
if params [ :status ] == 2
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
elsif params [ :status ] == " 3 "
else
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #Ta的资源库的话, 应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源
elsif params [ :status ] == " 4 "
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 " +
@attachments = get_attch_resources params [ :id ]
" and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
elsif params [ :status ] == " 5 "
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
@attachments = get_principal_resources params [ :id ]
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources ( params [ :id ] , user_course_ids , user_project_ids )
end
end
elsif params [ :type ] == " 2 " # 课程资源
elsif params [ :type ] == " 2 " # 课程资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
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 ( ',' ) } )) " ) . 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 . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
end
elsif params [ :type ] == " 3 " # 项目资源
elsif params [ :type ] == " 3 " # 项目资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
@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 " #附件
elsif params [ :type ] == " 4 " #附件
if User . current . id . to_i == params [ :id ] . to_i
@attachments = get_attch_resources params [ :id ]
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 5 " #用户资源
else
@attachments = get_principal_resources params [ :id ]
@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 " )
elsif params [ :type ] == " 6 " # 公共资源
end
if params [ :status ] == " 2 "
elsif params [ :type ] == " 5 " #附件
@attachments = get_course_resources_public ( user_course_ids )
if User . current . id . to_i == params [ :id ] . to_i
elsif params [ :status ] == " 3 "
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type ='Principal' " ) . order ( " created_on desc " )
@attachments = get_project_resources_public ( user_project_ids )
else
elsif params [ :status ] == " 4 "
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type ='Principal' " ) . order ( " created_on desc " )
@attachments = get_attch_resources_public
end
elsif params [ :status ] == " 5 "
end
@attachments = get_principal_resources_public
@type = params [ :type ] || 1
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids )
end
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
@ -1468,46 +1597,46 @@ class UsersController < ApplicationController
Attachment . where ( " author_id = #{ User . current . id } " ) . delete ( id )
Attachment . where ( " author_id = #{ User . current . id } " ) . delete ( id )
end
end
end
end
if ( params [ :type ] . nil? || params [ :type ] . blank? || params [ :type ] == " 1 " || params [ :type ] == 'all' ) #全部
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','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 ( ',' ) } )) " ) . 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','OrgSubfield','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 ( ',' ) } )) " ) . order ( " created_on desc " )
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 }
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 ( ',' ) } )) " ) . order ( " created_on desc " )
user_project_ids = User . current . projects . map { | p | p . id }
else
# user_org_ids = User.current.organizations.map {|o| o.id}
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) # 我的资源
@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 ( ',' ) } )) " ) . order ( " created_on desc " )
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 )
end
end
elsif params [ :type ] == " 2 " # 课程资源
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
elsif params [ :type ] == " 3 " # 项目资源
elsif params [ :type ] == " 3 " # 项目资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
@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 " #附件
elsif params [ :type ] == " 4 " #附件
if User . current . id . to_i == params [ :id ] . to_i
@attachments = get_attch_resources params [ :id ]
@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
elsif params [ :type ] == " 5 " #用户资源
elsif params [ :type ] == " 5 " #用户资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = get_principal_resources params [ :id ]
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type ='Principal' " ) . order ( " created_on desc " )
elsif params [ :type ] == " 6 " # 公共资源
else
if params [ :status ] == " 2 "
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type ='Principal' " ) . order ( " created_on desc " )
@attachments = get_course_resources_public ( user_course_ids )
end
elsif params [ :status ] == " 3 "
end
@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 )
end
end
@status = params [ :status ]
@type = params [ :type ]
@type = params [ :type ]
@limit = 25
@limit = 25
@is_remote = true
@is_remote = true
@ -1564,17 +1693,17 @@ class UsersController < ApplicationController
@flag = true
@flag = true
if params [ :send_id ] . present?
if params [ :send_id ] . present?
send_id = params [ :send_id ]
send_id = params [ :send_id ]
ori = Attachment . find_by_id ( send_id )
@ ori = Attachment . find_by_id ( send_id )
course_ids = params [ :course_ids ]
course_ids = params [ :course_ids ]
if course_ids . nil?
if course_ids . nil?
@flag = false
@flag = false
end
end
unless course_ids . nil?
unless course_ids . nil?
course_ids . each do | id |
course_ids . each do | id |
next if ori. blank?
next if @ ori. blank?
@exist = false
@exist = false
Course . find ( id ) . attachments . each do | att | #如果课程中包含该资源
Course . find ( id ) . attachments . each do | att | #如果课程中包含该资源
if att . id == ori. id || ( ! att . copy_from . nil? && ! ori. copy_from . nil? && att . copy_from == ori. copy_from ) || att . copy_from == ori . id || att . id == ori. copy_from
if att . id == @ ori. id || ( ! att . copy_from . nil? && ! @ ori. copy_from . nil? && att . copy_from == @ ori. copy_from ) || att . copy_from == @ori . id || att . id == @ ori. copy_from
att . created_on = Time . now
att . created_on = Time . now
att . save
att . save
@exist = true
@exist = true
@ -1582,18 +1711,21 @@ class UsersController < ApplicationController
end
end
end
end
next if @exist
next if @exist
attach_copied_obj = ori. copy
attach_copied_obj = @ ori. copy
attach_copied_obj . tag_list . add ( ori. tag_list ) # tag关联
attach_copied_obj . tag_list . add ( @ ori. tag_list ) # tag关联
attach_copied_obj . container = Course . find ( id )
attach_copied_obj . container = Course . find ( id )
attach_copied_obj . created_on = Time . now
attach_copied_obj . created_on = Time . now
attach_copied_obj . author_id = User . current . id
attach_copied_obj . author_id = User . current . id
attach_copied_obj . is_public = 0
attach_copied_obj . is_public = 0
attach_copied_obj . copy_from = ori . copy_from . nil? ? ori . id : ori. copy_from #发送要添加copy_from
attach_copied_obj . copy_from = @ori . copy_from . nil? ? @ori . id : @ ori. copy_from #发送要添加copy_from
if attach_copied_obj . attachtype == nil
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 4
attach_copied_obj . attachtype = 4
end
end
if attach_copied_obj . save
if attach_copied_obj . save
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
# 更新引用次数
quotes = @ori . quotes . to_i + 1
@ori . update_attribute ( :quotes , quotes ) unless @ori . nil?
@ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
end
end
@save_message = attach_copied_obj . errors . full_messages
@save_message = attach_copied_obj . errors . full_messages
end
end
@ -1605,10 +1737,11 @@ class UsersController < ApplicationController
@flag = false
@flag = false
end
end
send_ids . each do | send_id |
send_ids . each do | send_id |
quotes = 0
ori = Attachment . find_by_id ( send_id )
ori = Attachment . find_by_id ( send_id )
unless course_ids . nil?
unless course_ids . nil?
course_ids . each do | id |
course_ids . each do | id |
quotes = 0
next if ori . blank?
next if ori . blank?
@exist = false
@exist = false
Course . find ( id ) . attachments . each do | att | #如果课程中包含该资源
Course . find ( id ) . attachments . each do | att | #如果课程中包含该资源
@ -1631,6 +1764,9 @@ class UsersController < ApplicationController
attach_copied_obj . attachtype = 4
attach_copied_obj . attachtype = 4
end
end
if attach_copied_obj . save
if attach_copied_obj . save
# 更新引用次数
quotes = ori . quotes . to_i + 1
ori . update_attribute ( :quotes , quotes ) unless ori . nil?
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
end
end
@save_message = attach_copied_obj . errors . full_messages
@save_message = attach_copied_obj . errors . full_messages
@ -1691,6 +1827,9 @@ class UsersController < ApplicationController
attach_copied_obj . attachtype = 1
attach_copied_obj . attachtype = 1
end
end
if attach_copied_obj . save
if attach_copied_obj . save
# 更新引用次数
quotes = ori . quotes . to_i + 1
ori . update_attribute ( :quotes , quotes ) unless ori . nil?
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
end
end
unless Project . find ( project_id ) . project_score . nil?
unless Project . find ( project_id ) . project_score . nil?
@ -1698,6 +1837,7 @@ class UsersController < ApplicationController
Project . find ( project_id ) . project_score . attach_num + 1 )
Project . find ( project_id ) . project_score . attach_num + 1 )
end
end
end
end
@ori = ori
end
end
elsif params [ :send_ids ] . present?
elsif params [ :send_ids ] . present?
send_ids = params [ :send_ids ] . split ( " " )
send_ids = params [ :send_ids ] . split ( " " )
@ -1706,10 +1846,11 @@ class UsersController < ApplicationController
@flag = false
@flag = false
end
end
send_ids . each do | send_id |
send_ids . each do | send_id |
quotes = 0
ori = Attachment . find_by_id ( send_id )
ori = Attachment . find_by_id ( send_id )
unless project_ids . nil?
unless project_ids . nil?
project_ids . each do | project_id |
project_ids . each do | project_id |
quotes = 0
next if ori . blank?
next if ori . blank?
@exist = false
@exist = false
Project . find ( project_id ) . attachments . each do | att | #如果课程中包含该资源
Project . find ( project_id ) . attachments . each do | att | #如果课程中包含该资源
@ -1732,6 +1873,9 @@ class UsersController < ApplicationController
attach_copied_obj . attachtype = 1
attach_copied_obj . attachtype = 1
end
end
if attach_copied_obj . save
if attach_copied_obj . save
# 更新引用次数
quotes = ori . quotes . to_i + 1
ori . update_attribute ( :quotes , quotes ) unless ori . nil?
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
end
end
unless Project . find ( project_id ) . project_score . nil?
unless Project . find ( project_id ) . project_score . nil?
@ -1791,10 +1935,14 @@ class UsersController < ApplicationController
attach_copied_obj . attachtype = 1
attach_copied_obj . attachtype = 1
end
end
if attach_copied_obj . save
if attach_copied_obj . save
# 更新引用次数
quotes = ori . quotes . to_i + 1
ori . update_attribute ( :quotes , quotes ) unless ori . nil?
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
end
end
end
end
end
end
@ori = ori
elsif params [ :send_ids ] . present?
elsif params [ :send_ids ] . present?
send_ids = params [ :send_ids ] . split ( " " )
send_ids = params [ :send_ids ] . split ( " " )
subfield_id = params [ :subfield ]
subfield_id = params [ :subfield ]
@ -1802,7 +1950,7 @@ class UsersController < ApplicationController
@flag = false
@flag = false
end
end
send_ids . each do | send_id |
send_ids . each do | send_id |
quotes = 0
ori = Attachment . find_by_id ( send_id )
ori = Attachment . find_by_id ( send_id )
unless subfield_id . nil?
unless subfield_id . nil?
next if ori . blank?
next if ori . blank?
@ -1827,6 +1975,9 @@ class UsersController < ApplicationController
attach_copied_obj . attachtype = 1
attach_copied_obj . attachtype = 1
end
end
if attach_copied_obj . save
if attach_copied_obj . save
# 更新引用次数
quotes = ori . quotes . to_i + 1
ori . update_attribute ( :quotes , quotes ) unless ori . nil?
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
ori . forwards << Forward . new ( :to_type = > attach_copied_obj . class . name , :to_id = > attach_copied_obj . id , :created_at = > Time . now )
end
end
end
end
@ -2169,76 +2320,252 @@ class UsersController < ApplicationController
end
end
end
end
# 获取公共资源
def get_public_resources user_course_ids , user_project_ids
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 " )
end
# 获取我的资源
def get_my_resources author_id , user_course_ids , user_project_ids
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 " )
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 " )
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 " )
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 " )
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 " )
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 " )
end
# 获取公共资源中我上传的附件
def get_attch_resources_public
attchments = Attachment . where ( " container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') " ) . order ( " created_on desc " )
end
# 获取我的用户类型资源
def get_principal_resources author_id
attchments = Attachment . where ( " author_id = #{ author_id } and container_type = 'Principal' " ) . order ( " created_on desc " )
end
# 获取我的用户类型资源
def get_principal_resources_public
attchments = Attachment . where ( " container_type = 'Principal' " ) . order ( " created_on desc " )
end
# 资源库 分为全部 课程资源 项目资源 附件
# 资源库 分为全部 课程资源 项目资源 附件
def user_resource
def user_resource
#确定container_type
# @user = User.find(params[:id])
# 别人的资源库是没有权限去看的
# 别人的资源库是没有权限去看的
if User . current . id . to_i != params [ :id ] . to_i
if User . current . id . to_i != params [ :id ] . to_i
render_403
render_403
return
return
end
end
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
user_course_ids = User . current . courses . map { | c | c . id }
if User . current . id . to_i == params [ :id ] . to_i
user_project_ids = User . current . projects . map { | p | p . id }
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
# user_org_ids = User.current.organizations.map {|o| o.id}
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_publish = 1 and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
if ( params [ :type ] . blank? || params [ :type ] == " 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 " )
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
else
if params [ :status ] == " 2 "
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #Ta的资源库的话, 应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 and is_publish = 1 " +
elsif params [ :status ] == " 3 "
" and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } ) and is_publish = 1) " ) . order ( " created_on desc " )
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 )
end
end
elsif params [ :type ] == " 2 " # 课程资源
elsif params [ :type ] == " 2 " # 课程资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = get_course_resources ( params [ :id ] , user_course_ids )
elsif params [ :type ] == " 3 " # 项目资源
@attachments = get_project_resources ( params [ :id ] , user_project_ids )
elsif params [ :type ] == " 4 " #附件
@attachments = get_attch_resources params [ :id ]
elsif params [ :type ] == " 5 " #用户资源
@attachments = get_principal_resources params [ :id ]
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 )
end
end
@status = params [ :status ]
@type = params [ :type ]
@limit = 25
@is_remote = true
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments , 25
respond_to do | format |
format . js
format . html { render :layout = > 'new_base' }
end
end
# 导入资源
def import_resources
# 别人的资源库是没有权限去看的
if User . current . id . to_i != params [ :id ] . to_i
render_403
return
end
user_course_ids = User . current . courses . map { | c | c . id }
user_course_ids = User . current . courses . map { | c | c . id }
@attachments = Attachment . where ( " (author_id = #{ params [ :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 " )
user_project_ids = User . current . projects . map { | p | p . id }
else
# user_org_ids = User.current.organizations.map {|o| o.id}
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) # 我的资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Course' and is_publish = 1) " +
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
" or (container_type = 'Course' and is_public = 1 and is_publish = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
@attachments = get_my_resources ( params [ :id ] , user_course_ids , user_project_ids )
elsif params [ :type ] == " 6 " # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids )
end
end
elsif params [ :type ] == " 3 " #项目资源
@type = params [ :type ]
if User . current . id . to_i == params [ :id ] . to_i
@limit = 10
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' " ) . order ( " created_on desc " )
@is_remote = true
else
@atta_count = @attachments . count
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Project' " ) . order ( " created_on desc " )
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments , 10
respond_to do | format |
format . js
format . html { render :layout = > 'new_base' }
end
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','OrgSubfield','Principal') " ) . 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','OrgSubfield','Principal') " ) . order ( " created_on desc " )
end
end
elsif params [ :type ] == " 5 " #用户资源
if User . current . id . to_i == params [ :id ] . to_i
def import_resources_search
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' " ) . order ( " created_on desc " )
search = " % #{ params [ :search ] . strip . downcase } % "
else
# 别人的资源库是没有权限去看的
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Principal' " ) . order ( " created_on desc " )
if User . current . id . to_i != params [ :id ] . to_i
render_403
return
end
end
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 ] . blank? || params [ :type ] == " 1 " ) # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
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}
@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 " )
elsif params [ :type ] == " 6 " # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids )
end
end
@type = params [ :type ]
@type = params [ :type ]
@limit = 25
@limit = 10
@is_remote = true
@is_remote = true
@atta_count = @attachments . count
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
@offset || = @atta_pages . offset
#@curse_attachments_all = @all_attachments[@offset, @limit]
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments , 25
@attachments = paginateHelper @attachments , 10
respond_to do | format |
respond_to do | format |
format . js
format . js
format . html { render :layout = > 'new_base_user' }
format . html { render :layout = > 'new_base' }
end
end
# 内容导入到对象中
def import_into_container
send_ids = params [ :checkbox1 ]
# mul_id为当前课程id、项目id、组织id的多种形态
mul_id = params [ :mul_id ]
if params [ :mul_type ] == " Course "
mul_container = Course . find ( mul_id )
elsif params [ :mul_type ] == " Project "
mul_container = Project . find ( mul_id )
elsif params [ :mul_type ] == " SubfieldFile "
mul_container = OrgSubfield . find ( mul_id )
end
unless params [ :checkbox1 ] . blank?
send_ids . each do | send_id |
ori = Attachment . find_by_id ( send_id )
# 如果该附件已经存课程中,则只更新附件创建时间
mul_container . attachments . each do | att |
if att . id == ori . id || ( ! att . copy_from . nil? && ! ori . copy_from . nil? && att . copy_from == ori . copy_from ) || att . copy_from == ori . id || att . id == ori . copy_from
att . created_on = Time . now
att . save
@exist = true
break
end
end
next if @exist
attach_copied_obj = ori . copy
attach_copied_obj . tag_list . add ( ori . tag_list ) # tag关联
attach_copied_obj . container = mul_container
attach_copied_obj . created_on = Time . now
attach_copied_obj . author_id = User . current . id
attach_copied_obj . is_public = 0
attach_copied_obj . copy_from = ori . copy_from . nil? ? ori . id : ori . copy_from #发送要添加copy_from
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 4
end
attach_copied_obj . save
@save_message = attach_copied_obj . errors . full_messages
end
end
respond_to do | format |
format . html {
if params [ :mul_type ] == " Course "
redirect_to course_files_url ( mul_container ) unless mul_container . nil?
elsif params [ :mul_type ] == " Project "
redirect_to project_files_url ( mul_container ) unless mul_container . nil?
elsif params [ :mul_type ] == " SubfieldFile "
redirect_to org_subfield_files_url ( mul_container ) unless mul_container . nil?
end
}
end
end
end
end
# 根据资源关键字进行搜索
# 根据资源关键字进行搜索
def resource_search
def resource_search
search = " % #{ params [ :search ] . strip . downcase } % "
search = " % #{ params [ :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 ( params [ :type ] . nil? || params [ :type ] . blank? || params [ :type ] == " 1 " || params [ :type ] == 'all' ) #全部
if User . current . id . to_i == params [ :id ] . to_i
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','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@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 (filename like :p) " , :p = > search ) . order ( " created_on desc " )
" 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 " )
else
else
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
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 " +
@attachments = Attachment . where ( " ((author_id = #{ params [ :id ] } and is_public = 1 and container_type in " +
@ -2274,6 +2601,11 @@ class UsersController < ApplicationController
else
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 ( " created_on desc " )
end
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
end
@type = params [ :type ]
@type = params [ :type ]
@limit = 25
@limit = 25