diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0058e6e4c..a88068be7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -381,14 +381,107 @@ class UsersController < ApplicationController #用户从资源库导入资源到作业 def user_import_resource - user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 + @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].nil? || 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].nil? || 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 + end + include CoursesHelper def user_courses diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index b41b9f28f..387b38936 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -1,5 +1,8 @@ <% if attachments.nil? || attachments.empty? %> +

+ <%= l(:label_no_data) %> +

<% else %> <% attachments.each do |attach| %>