@ -192,11 +192,13 @@ class UsersController < ApplicationController
forge_querys = ForgeMessage . where ( " user_id =? and viewed =? " , user , 0 )
user_querys = UserFeedbackMessage . where ( " user_id =? and viewed =? " , user , 0 )
forum_querys = MemoMessage . where ( " user_id =? and viewed =? " , user , 0 )
org_querys = OrgMessage . where ( " user_id=? and viewed=0 " , user )
if User . current . id == @user . id
course_querys . update_all ( :viewed = > true )
forge_querys . update_all ( :viewed = > true )
user_querys . update_all ( :viewed = > true )
forum_querys . update_all ( :viewed = > true )
org_querys . update_all ( :viewed = > true )
end
end
@ -403,8 +405,47 @@ class UsersController < ApplicationController
#导入作业
def user_import_homeworks
@user = User . current
@select_course = params [ :select_course ] ? 1 : 0
@user_homeworks = HomeworkCommon . where ( :user_id = > @user . id ) . order ( " created_at desc " )
#@user_homeworks = HomeworkCommon.where(:user_id => @user.id).order("created_at desc")
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 " )
@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
end
end
def user_homework_type
@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
end
end
def show_homework_detail
@homework = HomeworkCommon . find params [ :homework ] . to_i
respond_to do | format |
format . js
end
@ -412,7 +453,22 @@ class UsersController < ApplicationController
#用户主页过滤作业
def user_search_homeworks
@user_homeworks = HomeworkCommon . where ( " user_id = ' #{ @user . id } ' and lower(name) like '% #{ params [ :name ] . to_s . downcase } %' " ) . order ( " created_at desc " )
@user = User . current
search = params [ :name ] . to_s . strip . downcase
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 } ' and (name like '% #{ search } %') " ) . order ( " created_at desc " )
elsif params [ :type ] == " 2 " #课程资源
@homeworks = HomeworkCommon . where ( " user_id = #{ @user . id } and publish_time <= ' #{ Date . today } ' and (name like '% #{ search } %') " ) . 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
end
@ -426,6 +482,7 @@ class UsersController < ApplicationController
@homework = HomeworkCommon . new
@select_course = params [ :select_course ] || 0
if homework
@ref_homework = homework
@homework . name = homework . name
@homework . description = homework . description
@homework . end_time = homework . end_time
@ -583,13 +640,15 @@ class UsersController < ApplicationController
homework_detail_manual . save if homework_detail_manual
homework_detail_programing . save if homework_detail_programing
homework_detail_group . save if homework_detail_group
if params [ :quotes ] && ! params [ :quotes ] . blank?
homework = HomeworkCommon . find params [ :quotes ] . to_i
homework . update_attribute ( :quotes , homework . quotes + 1 )
end
if params [ :is_in_course ] == " 1 "
redirect_to homework_common_index_path ( :course = > homework . course_id )
else
redirect_to user_homeworks_user_path ( User . current . id )
end
end
end
else
@ -755,23 +814,17 @@ class UsersController < ApplicationController
if params [ :type ] . present?
case params [ :type ]
when " public "
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL and private = 0' ) . order ( 'created_on DESC' )
@jour_count = jours . count
@jour = jours . limit ( 10 ) . offset ( @page * 10 )
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL and private = 0' ) . order ( 'updated_on DESC' )
when " private "
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL and private = 1' ) . order ( 'created_on DESC' )
@jour_count = jours . count
@jour = jours . limit ( 10 ) . offset ( @page * 10 )
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL and private = 1' ) . order ( 'updated_on DESC' )
else
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL' ) . order ( 'created_on DESC' )
@jour_count = jours . count
@jour = jours . limit ( 10 ) . offset ( @page * 10 )
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL' ) . order ( 'updated_on DESC' )
end
else
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL' ) . order ( 'created_on DESC' )
@jour_count = jours . count
@jour = jours . limit ( 10 ) . offset ( @page * 10 )
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL' ) . order ( 'updated_on DESC' )
end
@jour_count = jours . count
@jour = jours . limit ( 10 ) . offset ( @page * 10 )
@type = params [ :type ]
if User . current == @user
jours . update_all ( :is_readed = > true , :status = > false )
@ -1633,6 +1686,10 @@ class UsersController < ApplicationController
attach_copied_obj . attachtype = 1
end
attach_copied_obj . save
unless Project . find ( project_id ) . project_score . nil?
Project . find ( project_id ) . project_score . update_attribute ( :attach_num ,
Project . find ( project_id ) . project_score . attach_num + 1 )
end
end
end
elsif params [ :send_ids ] . present?
@ -1668,6 +1725,9 @@ class UsersController < ApplicationController
attach_copied_obj . attachtype = 1
end
attach_copied_obj . save
unless Project . find ( project_id ) . project_score . nil?
Project . find ( project_id ) . project_score . update_attribute ( :attach_num , Project . find ( project_id ) . project_score . attach_num + 1 )
end
end
end
end
@ -1797,12 +1857,13 @@ class UsersController < ApplicationController
news = News . find ( params [ :send_id ] )
project_ids = params [ :project_ids ]
project_ids . each do | project_id |
if Project . find ( project_id ) . news . map ( & :id ) . exclude? ( news . id )
project_news = News . create ( :project_id = > project_id . to_i , :title = > news . title , :summary = > news . summary , :description = > news . description , :author_id = > User . current . id , :created_on = > Time . now )
project = Project . find ( project_id )
if project . news . map ( & :id ) . exclude? ( news . id )
message = Message . create ( :board_id = > project . boards . first . id , :subject = > news . title , :content = > news . description , :author_id = > User . current . id )
news . attachments . each do | attach |
project_news . attachments << Attachment . new ( :filename = > attach . filename , :disk_filename = > attach . disk_filename , :filesize = > attach . filesize , :content_type = > attach . content_type , :digest = > attach . digest ,
:downloads = > 0 , :author_id = > User . current . id , :created_on = > Time . now , :description = > attach . description , :disk_directory = > attach . disk_directory , :attachtype = > attach . attachtype ,
:is_public = > attach . is_public , :quotes = > 0 )
message . attachments << Attachment . new ( :filename = > attach . filename , :disk_filename = > attach . disk_filename , :filesize = > attach . filesize , :content_type = > attach . content_type , :digest = > attach . digest ,
:downloads = > 0 , :author_id = > User . current . id , :created_on = > Time . now , :description = > attach . description , :disk_directory = > attach . disk_directory , :attachtype = > attach . attachtype ,
:is_public = > attach . is_public , :quotes = > 0 )
end
end
end
@ -1820,6 +1881,53 @@ class UsersController < ApplicationController
OrgActivity . create ( :container_type = > 'OrgSubfield' , :container_id = > field_id . to_i , :org_act_type = > 'News' , :org_act_id = > org_news . id , :user_id = > User . current . id )
end
def share_message_to_course
@message = Message . find ( params [ :send_id ] )
course_ids = params [ :course_ids ]
course_ids . each do | course_id |
course = Course . find ( course_id )
if course . news . map ( & :id ) . exclude? ( @message . id )
message = Message . create ( :board_id = > course . boards . first . id , :subject = > @message . subject , :content = > @message . content , :author_id = > User . current . id )
@message . attachments . each do | attach |
message . attachments << Attachment . new ( :filename = > attach . filename , :disk_filename = > attach . disk_filename , :filesize = > attach . filesize , :content_type = > attach . content_type , :digest = > attach . digest ,
:downloads = > 0 , :author_id = > User . current . id , :created_on = > Time . now , :description = > attach . description , :disk_directory = > attach . disk_directory , :attachtype = > attach . attachtype ,
:is_public = > attach . is_public , :quotes = > 0 )
end
end
end
end
def share_message_to_project
@message = Message . find ( params [ :send_id ] )
project_ids = params [ :project_ids ]
project_ids . each do | project_id |
project = Project . find ( project_id )
if project . news . map ( & :id ) . exclude? ( @message . id )
message = Message . create ( :board_id = > project . boards . first . id , :subject = > @message . subject , :content = > @message . content , :author_id = > User . current . id )
@message . attachments . each do | attach |
message . attachments << Attachment . new ( :filename = > attach . filename , :disk_filename = > attach . disk_filename , :filesize = > attach . filesize , :content_type = > attach . content_type , :digest = > attach . digest ,
:downloads = > 0 , :author_id = > User . current . id , :created_on = > Time . now , :description = > attach . description , :disk_directory = > attach . disk_directory , :attachtype = > attach . attachtype ,
:is_public = > attach . is_public , :quotes = > 0 )
end
end
end
end
def share_message_to_org
field_id = params [ :subfield ]
@message = Message . find ( params [ :send_id ] )
@message . quotes = @message . quotes . nil? ? 1 : ( @message . quotes + 1 )
@message . save
board = OrgSubfield . find ( field_id ) . boards . first
mes = Message . create ( :board_id = > board . id , :subject = > @message . subject , :content = > @message . content , :author_id = > User . current . id )
@message . attachments . each do | attach |
mes . attachments << Attachment . new ( :filename = > attach . filename , :disk_filename = > attach . disk_filename , :filesize = > attach . filesize , :content_type = > attach . content_type , :digest = > attach . digest ,
:downloads = > 0 , :author_id = > User . current . id , :created_on = > Time . now , :description = > attach . description , :disk_directory = > attach . disk_directory , :attachtype = > attach . attachtype ,
:is_public = > attach . is_public , :quotes = > 0 )
end
OrgActivity . create ( :container_type = > 'OrgSubfield' , :container_id = > field_id . to_i , :org_act_type = > 'Message' , :org_act_id = > mes . id , :user_id = > User . current . id )
end
def change_org_subfield
end
@ -2061,9 +2169,9 @@ class UsersController < ApplicationController
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' )" ) . order ( " created_on desc " )
@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' )" ) . order ( " created_on desc " )
@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
elsif params [ :type ] == " 5 " #用户资源
if User . current . id . to_i == params [ :id ] . to_i
@ -2169,7 +2277,7 @@ class UsersController < ApplicationController
@user = User . current
if ! params [ :search ] . nil? #发送到有栏目类型为资源的组织中
search = " % #{ params [ :search ] . to_s . strip . downcase } % "
if params [ :send_type ] . present? and params [ :send_type ] == 'news'
if params [ :send_type ] . present? and ( params [ :send_type ] == 'news' or params [ :send_type ] == 'message' )
@orgs = @user . organizations . where ( " name like ? " , search ) . select { | org | OrgSubfield . where ( " organization_id = #{ org . id } and field_type='Post' " ) . count > 0 }
else
@orgs = @user . organizations . where ( " name like ? " , search ) . select { | org | OrgSubfield . where ( " organization_id = #{ org . id } and field_type='Resource' " ) . count > 0 }