@ -311,6 +311,28 @@ class UsersController < ApplicationController
end
end
end
end
# 处理资源引用请求
# status
def deal_with_apply_resource
@msg = CourseMessage . find ( params [ :msg_id ] )
ar = ApplyResource . where ( " id = ? " , @msg . course_message_id ) . first
unless ar . nil?
case params [ :agree ]
when 'Y'
ar . update_column ( 'status' , 2 )
@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 )
@msg . update_attributes ( :apply_result = > 2 , :viewed = > 1 )
ar . course_messages << CourseMessage . new ( :user_id = > ar . user_id , :course_id = > - 1 , :viewed = > false , :apply_result = > 3 , :status = > 1 )
end
end
respond_to do | format |
format . js
end
end
#处理引用作业的请求
#处理引用作业的请求
#status 1 同意 2 拒绝
#status 1 同意 2 拒绝
def dealwith_apply_homework
def dealwith_apply_homework
@ -419,6 +441,19 @@ class UsersController < ApplicationController
end
end
# end
# end
# 资源分享请求弹框
def apply_resource
if User . current . logged?
@attachment = Attachment . find params [ :attachment_id ]
@state = 2
else
@state = 1
end
respond_to do | format |
format . js
end
end
#引用作业请求弹框
#引用作业请求弹框
def apply_homework
def apply_homework
if User . current . logged?
if User . current . logged?
@ -432,6 +467,27 @@ class UsersController < ApplicationController
end
end
end
end
# 申请引用资源
def apply_for_resource
if User . current . logged?
@attachment = Attachment . where ( " id =? " , params [ :attachment_id ] . to_i ) . first
unless @attachment . nil?
ar = ApplyResource . where ( " user_id = ? and attachment_id = ? " , User . current . id , params [ :attacment_id ] . to_i )
if ar . empty?
ApplyResource . create ( :user_id = > params [ :id ] . to_i , :attachment_id = > params [ :attachment_id ] . to_i , :status = > true , :container_id = > @attachment . container_id , :container_type = > @attachment . container_type , :content = > params [ :content ] , :apply_user_id = > @attachment . author_id )
@state = 2
else
@state = 3
end
end
else
@state = 1
end
respond_to do | format |
format . js
end
end
#申请引用非公开作业
#申请引用非公开作业
def apply_for_homework
def apply_for_homework
if User . current . logged?
if User . current . logged?
@ -1933,14 +1989,14 @@ class UsersController < ApplicationController
end
end
send_ids . each do | send_id |
send_ids . each do | send_id |
quotes = 0
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
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 | #如果课程中包含该资源
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
@ -1948,21 +2004,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
# 更新引用次数
# 更新引用次数
quotes = ori. quotes . to_i + 1
quotes = @ ori. quotes . to_i + 1
ori. update_attribute ( :quotes , quotes ) unless ori. nil?
@ 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
end
end
@ -2002,6 +2058,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
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 )
end
end
@type = params [ :type ]
@type = params [ :type ]
@limit = 25
@limit = 25
@ -2143,6 +2211,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
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 )
end
end
@status = params [ :status ]
@status = params [ :status ]
@type = params [ :type ]
@type = params [ :type ]
@ -2272,6 +2352,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
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 )
end
end
@type = params [ :type ]
@type = params [ :type ]
@limit = 25
@limit = 25
@ -2608,7 +2700,7 @@ class UsersController < ApplicationController
# 获取公共资源
# 获取公共资源
def get_public_resources user_course_ids , user_project_ids , order , score
def get_public_resources user_course_ids , user_project_ids , order , score
attachments = Attachment . where ( " (is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) " ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
attachments = Attachment . where ( " (is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) " ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
end
# 获取公共资源搜索
# 获取公共资源搜索
@ -2637,6 +2729,16 @@ class UsersController < ApplicationController
and is_publish = 1 and container_id is not null ) " ).order( " #{order.nil? ? 'created_on' : order} #{score}")
and is_publish = 1 and container_id is not null ) " ).order( " #{order.nil? ? 'created_on' : order} #{score}")
end
end
# 获取我的私有资源分享结果
def get_my_private_resources apply_ids , resource_type , order , score
attachments = Attachment . where ( " id in ( #{ apply_ids . empty? ? '0' : apply_ids . join ( ',' ) } ) and container_type in( #{ resource_type } ) " ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
# 获取我的私有资源分享搜索结果
def get_my_private_resources_search apply_ids , resource_type , order , score , search
attachments = Attachment . where ( " id in ( #{ apply_ids . empty? ? '0' : apply_ids . join ( ',' ) } ) and container_type in( #{ resource_type } ) and (filename like :p) " , :p = > search ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
# 获取我的课程资源中搜索结果
# 获取我的课程资源中搜索结果
def get_course_resources_search author_id , user_course_ids , order , score , search
def get_course_resources_search author_id , user_course_ids , order , score , search
attchments = Attachment . where ( " ((author_id = #{ author_id } and is_publish = 1 and container_id is not null and container_type = 'Course') " +
attchments = Attachment . where ( " ((author_id = #{ author_id } and is_publish = 1 and container_id is not null and container_type = 'Course') " +
@ -2646,12 +2748,12 @@ class UsersController < ApplicationController
# 获取公共资源中课程资源
# 获取公共资源中课程资源
def get_course_resources_public user_course_ids , order , score
def get_course_resources_public user_course_ids , order , score
attchments = Attachment . where ( " (container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1 )" ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
attchments = Attachment . where ( " (container_type = 'Course'and container_id is not null and is_publish = 1 )" ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
end
# 获取公共资源中课程资源搜索结果
# 获取公共资源中课程资源搜索结果
def get_course_resources_public_search user_course_ids , order , score , search
def get_course_resources_public_search user_course_ids , order , score , search
attchments = Attachment . where ( " (container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1 ) and (filename like :p)" , :p = > search ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
attchments = Attachment . where ( " (container_type = 'Course'and container_id is not null and is_publish = 1 ) and (filename like :p)" , :p = > search ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
end
# 获取我的项目资源
# 获取我的项目资源
@ -2670,12 +2772,12 @@ class UsersController < ApplicationController
# 获取公共资源的项目资源
# 获取公共资源的项目资源
def get_project_resources_public user_project_ids , order , score
def get_project_resources_public user_project_ids , order , score
attchments = Attachment . where ( " container_type = 'Project' and container_id is not null and is_public =1 " ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
attchments = Attachment . where ( " container_type = 'Project' and container_id is not null " ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
end
# 获取公共资源的项目资源搜索
# 获取公共资源的项目资源搜索
def get_project_resources_public_search user_project_ids , order , score , search
def get_project_resources_public_search user_project_ids , order , score , search
attchments = Attachment . where ( " (container_type = 'Project' and container_id is not null and is_public =1 ) and (filename like :p)" , :p = > search ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
attchments = Attachment . where ( " (container_type = 'Project' and container_id is not null ) and (filename like :p)" , :p = > search ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
end
# 获取我上传的附件
# 获取我上传的附件
@ -2693,13 +2795,13 @@ class UsersController < ApplicationController
# 获取公共资源中我上传的附件
# 获取公共资源中我上传的附件
def get_attch_resources_public order , score
def get_attch_resources_public order , score
attchments = Attachment . where ( " container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
attchments = Attachment . where ( " container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
and container_id is not null and is_public = 1 " ).order( " #{order.nil? ? 'created_on' : order} #{score}")
and container_id is not null " ).order( " #{order.nil? ? 'created_on' : order} #{score}")
end
end
# 获取公共资源中我上传的附件
# 获取公共资源中我上传的附件
def get_attch_resources_public_search order , score , search
def get_attch_resources_public_search order , score , search
attchments = Attachment . where ( " (container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
attchments = Attachment . where ( " (container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
and container_id is not null and is_public = 1 ) and ( filename like :p ) " , :p => search).order( " #{order.nil? ? 'created_on' : order} #{score}")
and container_id is not null ) and ( filename like :p ) " , :p => search).order( " #{order.nil? ? 'created_on' : order} #{score}")
end
end
# 获取我的用户类型资源
# 获取我的用户类型资源
@ -2714,12 +2816,12 @@ class UsersController < ApplicationController
# 获取我的用户类型资源
# 获取我的用户类型资源
def get_principal_resources_public order , score
def get_principal_resources_public order , score
attchments = Attachment . where ( " container_type = 'Principal'and container_id is not null and is_public =1 " ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
attchments = Attachment . where ( " container_type = 'Principal'and container_id is not null " ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
end
# 获取我的用户类型资源
# 获取我的用户类型资源
def get_principal_resources_public_search order , score , search
def get_principal_resources_public_search order , score , search
attchments = Attachment . where ( " (container_type = 'Principal'and container_id is not null and is_public =1 ) and (filename like :p)" , :p = > search ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
attchments = Attachment . where ( " (container_type = 'Principal'and container_id is not null ) and (filename like :p)" , :p = > search ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
end
# 资源库 分为全部 课程资源 项目资源 附件
# 资源库 分为全部 课程资源 项目资源 附件
@ -2734,7 +2836,7 @@ class UsersController < ApplicationController
user_course_ids = User . current . courses . map { | c | c . is_delete == 0 && c . id }
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_project_ids = User . current . projects . map { | p | p . status != 9 && 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 ] . blank? || params [ :type ] == " 1 " ) # 我的资源
if ( params [ :type ] == " 1 " ) # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params [ :status ] == " 2 "
if params [ :status ] == " 2 "
@attachments = get_course_resources ( params [ :id ] , user_course_ids , @order , @score )
@attachments = get_course_resources ( params [ :id ] , user_course_ids , @order , @score )
@ -2748,7 +2850,7 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources ( params [ :id ] , user_course_ids , user_project_ids , @order , @score )
@attachments = get_my_resources ( params [ :id ] , user_course_ids , user_project_ids , @order , @score )
end
end
elsif params [ :type ] == " 6 " # 公共资源
elsif ( params [ :type ] . blank? || params [ :type ] == " 6 " ) # 公共资源
if params [ :status ] == " 2 "
if params [ :status ] == " 2 "
@attachments = get_course_resources_public ( user_course_ids , @order , @score )
@attachments = get_course_resources_public ( user_course_ids , @order , @score )
elsif params [ :status ] == " 3 "
elsif params [ :status ] == " 3 "
@ -2761,6 +2863,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
end
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 )
end
end
@status = params [ :status ]
@status = params [ :status ]
@type = params [ :type ]
@type = params [ :type ]
@ -2780,8 +2894,7 @@ class UsersController < ApplicationController
# 导入资源
# 导入资源
def import_resources
def import_resources
# 别人的资源库是没有权限去看的
# 别人的资源库是没有权限去看的
@user = User . find_by_login ( params [ :id ] )
if User . current . id != params [ :id ] . to_i
if User . current != @user
render_403
render_403
return
return
end
end
@ -2941,6 +3054,19 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources_search ( user_course_ids , user_project_ids , @order , @score , search )
@attachments = get_public_resources_search ( user_course_ids , user_project_ids , @order , @score , search )
end
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
end
@status = params [ :status ]
@status = params [ :status ]
@type = params [ :type ]
@type = params [ :type ]