@ -218,7 +218,7 @@ class UsersController < ApplicationController
end
# end
##added by fq
##added by fq
def watch_bids
# cond = 'bids.reward_type <> 1'
# @bids = Bid.watched_by(@user).where('reward_type = ?', 1) # added by huang
@ -342,6 +342,24 @@ class UsersController < ApplicationController
end
end
def new_user_commit_homework
@user = User . current
@homework = HomeworkCommon . find ( params [ :homework_id ] )
@student_work = @homework . student_works . where ( user_id : User . current . id ) . first
if @student_work . nil?
@student_work = StudentWork . new
end
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
end
end
def user_commit_homework
flash [ :notice ] = l ( :notice_successful_create )
redirect_to user_homeworks_user_path ( User . current )
end
def user_new_homework
if params [ :homework_common ]
homework = HomeworkCommon . new
@ -349,7 +367,7 @@ class UsersController < ApplicationController
homework . description = params [ :homework_common ] [ :description ]
homework . end_time = params [ :homework_common ] [ :end_time ] || Time . now
homework . publish_time = Time . now
homework . homework_type = 1
homework . homework_type = params [ :homework_type ] . to_i || 1
homework . late_penalty = 2
homework . user_id = User . current . id
homework . course_id = params [ :course_id ]
@ -358,6 +376,7 @@ class UsersController < ApplicationController
render_attachment_warning_if_needed ( homework )
#匿评作业相关属性
if homework . homework_type == 1
homework_detail_manual = HomeworkDetailManual . new
homework_detail_manual . ta_proportion = params [ :ta_proportion ] || 0 . 6
homework_detail_manual . comment_status = 1
@ -366,9 +385,27 @@ class UsersController < ApplicationController
homework_detail_manual . evaluation_num = params [ :evaluation_num ] || 3
homework_detail_manual . absence_penalty = 2
homework . homework_detail_manual = homework_detail_manual
else
homework_detail_programing = HomeworkDetailPrograming . new
homework . homework_detail_programing = homework_detail_programing
homework_detail_programing . ta_proportion = params [ :ta_proportion ] || 0 . 6
homework_detail_programing . language = params [ :program ] [ :language ] . to_i
inputs = params [ :program ] [ :input ]
if Array === inputs
inputs . each_with_index do | val , i |
homework . homework_tests << HomeworkTest . new (
input : val ,
output : params [ :program ] [ :output ] [ i ]
)
end
end
end
if homework . save
homework_detail_manual . save if homework_detail_manual
homework_detail_programing . save if homework_detail_programing
redirect_to user_homeworks_user_path ( User . current . id )
end
end
@ -376,9 +413,102 @@ class UsersController < ApplicationController
#用户从资源库导入资源到作业
def user_import_resource
@user = User . current
user_course_ids = @user . 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')) " +
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
@type = params [ :type ]
@homework_id = params [ :homework_id ]
@limit = 7
@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 , 7
respond_to do | format |
format . js
end
end
#引入资源列表根据类型过滤
def user_resource_type
if User . current . id . to_i != params [ :id ] . to_i
render_403
return
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')) " +
" 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 }
@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 " #项目资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' " ) . order ( " created_on desc " )
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 " )
elsif params [ :type ] == " 5 " #用户资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' " ) . order ( " created_on desc " )
end
@type = params [ :type ]
@limit = 7
@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 , 7
respond_to do | format |
format . js
end
end
#引入资源列表根据关键词过滤
def user_ref_resource_search
search = params [ :search ] . to_s . strip . downcase
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')) " +
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } ))) and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 2 " #课程资源
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 ( ',' ) } )) and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 3 " #项目资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
elsif params [ :type ] == " 4 " #附件
@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 " #用户资源
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
end
@type = params [ :type ]
@limit = 7
@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 , 7
respond_to do | format |
format . js
end
end
#将资源批量引入
def import_resources_to_homework
@attachments = [ ]
unless params [ :checkbox1 ] . nil? || params [ :checkbox1 ] . blank?
params [ :checkbox1 ] . each do | id |
atta = Attachment . find ( id )
att_copy = atta . copy
att_copy . container_id = nil
att_copy . container_type = nil
att_copy . copy_from = atta . id
att_copy . save
@attachments << att_copy
end
end
respond_to do | format |
format . js
end
@ -631,9 +761,7 @@ class UsersController < ApplicationController
end
def show
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
user_project_ids = @user . projects . visible . empty? ? " (-1) " : " ( " + @user . projects . visible . map { | project | project . id } . join ( " , " ) + " ) "
user_course_ids = @user . courses . visible . empty? ? " (-1) " : " ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
course_types = " ('Message','News','HomeworkCommon','poll') "
@ -978,7 +1106,7 @@ class UsersController < ApplicationController
#@user.save_attachments(params[:attachments],User.current)
# Container_type为Principal
Attachment . attach_filesex ( @user , params [ :attachments ] , params [ :attachment_type ] )
if ( params [ :type ] . nil? || 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 } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@ -1040,7 +1168,7 @@ class UsersController < ApplicationController
end
end
if ( params [ :type ] . nil ? || 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 } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
@ -1179,6 +1307,18 @@ class UsersController < ApplicationController
else
@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')) " +
" 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
@ -1235,7 +1375,18 @@ class UsersController < ApplicationController
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','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
@ -1450,7 +1601,7 @@ class UsersController < ApplicationController
render_403
return
end
if ( params [ :type ] . nil ? || 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 } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +