@ -522,7 +522,7 @@ class UsersController < ApplicationController
else
homework . publish_time = params [ :homework_common ] [ :publish_time ]
end
homework . anonymous_comment = params [ :homework_common ] [ :anonymous_comment ] ? params [ :homework_common ] [ :anonymous_comment ] : 1
homework . anonymous_comment = params [ :homework_common ] [ :anonymous_comment ] ? params [ :homework_common ] [ :anonymous_comment ] : 0
homework . homework_type = params [ :homework_type ] . to_i || 1
homework . late_penalty = 10
homework . teacher_priority = 1
@ -619,7 +619,7 @@ class UsersController < ApplicationController
end
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',' Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@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 " )
elsif params [ :type ] == " 2 " #课程资源
user_course_ids = User . current . courses . map { | c | c . id }
@ -1327,12 +1327,12 @@ class UsersController < ApplicationController
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 } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project',' Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@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',' Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
" 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 " #课程资源
@ -1389,12 +1389,12 @@ class UsersController < ApplicationController
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',' Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@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',' Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
" 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 " #课程资源
@ -1489,11 +1489,23 @@ class UsersController < ApplicationController
unless course_ids . nil?
course_ids . each do | id |
next if ori . blank?
@exist = false
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
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 = Course . find ( id )
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
@ -1513,11 +1525,23 @@ class UsersController < ApplicationController
unless course_ids . nil?
course_ids . each do | id |
next if ori . blank?
@exist = false
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
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 = Course . find ( id )
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
@ -1530,7 +1554,7 @@ class UsersController < ApplicationController
@flag = false
end
user_course_ids = User . current . 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')) " +
@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 " )
@type = params [ :type ]
@limit = 25
@ -1559,11 +1583,23 @@ class UsersController < ApplicationController
unless project_ids . nil?
project_ids . each do | project_id |
next if ori . blank?
@exist = false
Project . find ( project_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
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 = Project . find ( project_id )
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 = 1
end
@ -1582,11 +1618,23 @@ class UsersController < ApplicationController
unless project_ids . nil?
project_ids . each do | project_id |
next if ori . blank?
@exist = false
Project . find ( project_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
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 = Project . find ( project_id )
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 = 1
end
@ -1598,7 +1646,94 @@ class UsersController < ApplicationController
@flag = true
end
user_course_ids = User . current . 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')) " +
@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 " )
@type = params [ :type ]
@limit = 25
@user = User . current
@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
end
end
def add_exist_file_to_org
@flag = true
if params [ :send_id ] . present?
send_id = params [ :send_id ]
subfield_id = params [ :subfield ]
if subfield_id . nil?
@flag = false
end
ori = Attachment . find_by_id ( send_id )
unless subfield_id . nil?
attach_copied_obj = ori . copy
@exist = false
OrgSubfield . find ( subfield_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
att . created_on = Time . now
att . save
@exist = true
break
end
end
if @exist == false #如果不存在该资源
attach_copied_obj . tag_list . add ( ori . tag_list ) # tag关联
attach_copied_obj . container = OrgSubfield . find ( subfield_id )
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 = 1
end
attach_copied_obj . save
end
end
elsif params [ :send_ids ] . present?
send_ids = params [ :send_ids ] . split ( " " )
subfield_id = params [ :subfield ]
if subfield_id . nil?
@flag = false
end
send_ids . each do | send_id |
ori = Attachment . find_by_id ( send_id )
unless subfield_id . nil?
next if ori . blank?
@exist = false
OrgSubfield . find ( subfield_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
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 = OrgSubfield . find ( subfield_id )
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 = 1
end
attach_copied_obj . save
end
end
else
@flag = true
end
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 " )
@type = params [ :type ]
@limit = 25
@ -1614,6 +1749,10 @@ class UsersController < ApplicationController
end
end
def change_org_subfield
end
# 资源预览
def resource_preview
preview_id = params [ :resource_id ]
@ -1826,12 +1965,12 @@ class UsersController < ApplicationController
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 } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project',' Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@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',' Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
" 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 " #课程资源
@ -1882,7 +2021,7 @@ class UsersController < ApplicationController
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',' Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@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 ( ',' ) } ))) and (filename like :p) " , :p = > search ) . order ( " created_on desc " )
else
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
@ -1955,6 +2094,23 @@ class UsersController < ApplicationController
end
end
def search_user_org
@user = User . current
if ! params [ :search ] . nil? #发送到有栏目类型为资源的组织中
search = " % #{ params [ :search ] . to_s . strip . downcase } % "
@orgs = @user . organizations . where ( " name like ? " , search ) . select { | org | OrgSubfield . where ( " organization_id = #{ org . id } and field_type='Resource' " ) . count > 0 }
else
@orgs = @user . organizations . select { | org | OrgSubfield . where ( " organization_id = #{ org . id } and field_type='Resource' " ) . count > 0 }
end
@search = params [ :search ]
#这里仅仅是传递需要发送的资源id
@send_id = params [ :send_id ]
@send_ids = params [ :checkbox1 ] || params [ :send_ids ]
respond_to do | format |
format . js
end
end
private
def find_user