@ -320,7 +320,7 @@ class UsersController < ApplicationController
case params [ :agree ]
when 'Y'
ar . update_column ( 'status' , 2 )
@msg . update_attributes ( :apply_result = > 1 , :viewed = > 1 )
@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 )
@ -539,28 +539,28 @@ class UsersController < ApplicationController
end
def student_homeworks
if User . current == @user
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
user_course_ids = @user . courses . empty? ? " (-1) " :" ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
#判断当前用户在当前课程的身份
visibleCourse = @user . courses . empty? ? [ ] : @user . courses . where ( " is_delete = 0 " ) . visible
homework_ids = [ ]
visibleCourse . each do | course |
homeworks = HomeworkCommon . where ( " course_id = #{ course . id } and publish_time <= ' #{ Date . today } ' " )
homework_ids << homeworks . pluck ( :id ) unless homeworks . empty?
end
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 )
@is_teacher = User . current . user_extensions && User . current . user_extensions . identity == 0 && User . current . allowed_to? ( :add_course , nil , :global = > true )
@is_in_course = params [ :is_in_course ] . to_i || 0
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
end
else
render_403
if User . current == @user
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
user_course_ids = @user . courses . empty? ? " (-1) " :" ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
#判断当前用户在当前课程的身份
visibleCourse = @user . courses . empty? ? [ ] : @user . courses . where ( " is_delete = 0 " ) . visible
homework_ids = [ ]
visibleCourse . each do | course |
homeworks = HomeworkCommon . where ( " course_id = #{ course . id } and publish_time <= ' #{ Date . today } ' " )
homework_ids << homeworks . pluck ( :id ) unless homeworks . empty?
end
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 )
@is_teacher = User . current . user_extensions && User . current . user_extensions . identity == 0 && User . current . allowed_to? ( :add_course , nil , :global = > true )
@is_in_course = params [ :is_in_course ] . to_i || 0
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
end
else
render_403
end
end
def choose_user_course
@ -2077,18 +2077,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
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 )
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
@type = params [ :type ]
@limit = 25
@ -2230,18 +2230,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
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 )
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
@status = params [ :status ]
@type = params [ :type ]
@ -2371,18 +2371,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
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 )
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
@type = params [ :type ]
@limit = 25
@ -2719,12 +2719,12 @@ class UsersController < ApplicationController
# 获取公共资源
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
# 获取公共资源搜索
def get_public_resources_search user_course_ids , user_project_ids , order , score , search
attachments = Attachment . where ( " is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" , :p = > search ) . 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') and (filename like :p)" , :p = > search ) . order ( " #{ order . nil? ? 'created_on' : order } #{ score } " )
end
# 获取我的资源
@ -2744,19 +2744,19 @@ class UsersController < ApplicationController
# 获取我的课程资源
def get_course_resources author_id , user_course_ids , order , score
attchments = Attachment . where ( " (author_id = #{ author_id } and is_publish = 1 and container_id is not null and container_type = 'Course') " +
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )
" 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 ) " ).order( " #{order.nil? ? 'created_on' : order} #{score}")
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_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
@ -2767,18 +2767,18 @@ class UsersController < ApplicationController
# 获取公共资源中课程资源
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
# 获取公共资源中课程资源搜索结果
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
# 获取我的项目资源
def get_project_resources author_id , user_project_ids , order , score
attchments = Attachment . where ( " (author_id = #{ author_id } and is_publish = 1 and container_id is not null and container_type = 'Project') " +
" or (container_type = 'Project' and container_id in ( #{ user_project_ids . empty? ? '0' : user_project_ids . join ( ',' ) } )
" 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( " #{order.nil? ? 'created_on' : order} #{score}")
end
@ -2791,12 +2791,12 @@ class UsersController < ApplicationController
# 获取公共资源的项目资源
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
# 获取公共资源的项目资源搜索
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
# 获取我上传的附件
@ -2814,13 +2814,13 @@ class UsersController < ApplicationController
# 获取公共资源中我上传的附件
def get_attch_resources_public order , score
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
# 获取公共资源中我上传的附件
def get_attch_resources_public_search order , score , search
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
# 获取我的用户类型资源
@ -2835,12 +2835,12 @@ class UsersController < ApplicationController
# 获取我的用户类型资源
def get_principal_resources_public order , score
attchments = Attachment . where ( " container_type = 'Principal' and is_public =1 and container_id is not null" ) . 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
# 获取我的用户类型资源
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
# 资源库 分为全部 课程资源 项目资源 附件
@ -2882,18 +2882,18 @@ class UsersController < ApplicationController
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources ( user_course_ids , user_project_ids , params [ :order ] , @score )
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 )
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
@status = params [ :status ]
@type = params [ :type ]
@ -3071,21 +3071,21 @@ class UsersController < ApplicationController
@attachments = get_principal_resources_public_search ( @order , @score , search )
else
# 公共资源库:所有公开资源或者我上传的私有资源
@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
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
# 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
@attachments = get_my_private_resources_search ( apply_ids , resource_type , @order , @score , search )
@attachments
end
@status = params [ :status ]
@type = params [ :type ]