diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index ca37e445c..e615de002 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -529,6 +529,7 @@ class FilesController < ApplicationController if attachment.publish_time > Date.today attachment.is_publish = 0 end + attachment.description = params[:description] attachment.save end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3114ef5e0..722522a76 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1658,6 +1658,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 4 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end @save_message = attach_copied_obj.errors.full_messages @@ -1670,10 +1673,11 @@ class UsersController < ApplicationController @flag = false end send_ids.each do |send_id| + quotes = 0 ori = Attachment.find_by_id(send_id) - unless course_ids.nil? course_ids.each do |id| + quotes = 0 next if ori.blank? @exist = false Course.find(id).attachments.each do |att| #如果课程中包含该资源 @@ -1696,6 +1700,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 4 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end @save_message = attach_copied_obj.errors.full_messages @@ -1756,6 +1763,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 1 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end unless Project.find(project_id).project_score.nil? @@ -1771,10 +1781,11 @@ class UsersController < ApplicationController @flag = false end send_ids.each do |send_id| - + quotes = 0 ori = Attachment.find_by_id(send_id) unless project_ids.nil? project_ids.each do |project_id| + quotes = 0 next if ori.blank? @exist = false Project.find(project_id).attachments.each do |att| #如果课程中包含该资源 @@ -1797,6 +1808,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 1 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end unless Project.find(project_id).project_score.nil? @@ -1856,6 +1870,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 1 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end end @@ -1867,7 +1884,7 @@ class UsersController < ApplicationController @flag = false end send_ids.each do |send_id| - + quotes = 0 ori = Attachment.find_by_id(send_id) unless subfield_id.nil? next if ori.blank? @@ -1892,6 +1909,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 1 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end end @@ -2253,9 +2273,19 @@ class UsersController < ApplicationController attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") end + # 获取公共资源课程 + def get_course_resources_public user_course_ids + attchments = Attachment.where("(container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + end + # 获取我的项目资源 def get_project_resources author_id, user_project_ids - attchments = Attachment.where("author_id = #{author_id} and container_type = 'Project'").order("created_on desc") + attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Project') or (container_type = 'Course' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + end + + # 获取公共资源的项目资源 + def get_project_resources_public user_project_ids + attchments = Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc") end # 获取我上传的附件 @@ -2263,11 +2293,21 @@ class UsersController < ApplicationController attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") end + # 获取公共资源中我上传的附件 + def get_attch_resources_public + attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") + end + # 获取我的用户类型资源 def get_principal_resources author_id attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc") end + # 获取我的用户类型资源 + def get_principal_resources_public + attchments = Attachment.where("container_type = 'Principal'").order("created_on desc") + end + # 资源库 分为全部 课程资源 项目资源 附件 def user_resource # 别人的资源库是没有权限去看的 @@ -2280,7 +2320,18 @@ class UsersController < ApplicationController # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + if params[:status] == 2 + @attachments = get_course_resources(params[:id], user_course_ids) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids) + elsif params[:status] == "4" + @attachments = get_attch_resources params[:id] + elsif params[:status] == "5" + @attachments = get_principal_resources params[:id] + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + end elsif params[:type] == "2" # 课程资源 @attachments = get_course_resources(params[:id], user_course_ids) elsif params[:type] == "3" # 项目资源 @@ -2290,9 +2341,20 @@ class UsersController < ApplicationController elsif params[:type] == "5" #用户资源 @attachments = get_principal_resources params[:id] elsif params[:type] == "6" # 公共资源 - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids) + elsif params[:status] == "4" + @attachments = get_attch_resources_public + elsif params[:status] == "5" + @attachments = get_principal_resources_public + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) + end end + @status = params[:status] @type = params[:type] @limit = 25 @is_remote = true @@ -2338,27 +2400,55 @@ class UsersController < ApplicationController end end + def import_resources_search + search = "%#{params[:search].strip.downcase}%" + # 别人的资源库是没有权限去看的 + if User.current.id.to_i != params[:id].to_i + render_403 + return + end + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} + @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null 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 is_publish = 1 and container_id is not null)" + + "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)) and (filename like :p)" ,:p => search).order("created_on desc") + elsif params[:type] == "6" # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) + end + @type = params[:type] + @limit = 10 + @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,10 + respond_to do |format| + format.js + format.html {render :layout => 'new_base'} + end + end + # 内容导入到对象中 def import_into_container - # attachments = Attachment.where("id in (#{params[:checkbox1].join(',')})") - # if params[:mul_type] == "Project" - # - # elsif params[:mul_type] == "Course" - # Attachment.create(:container_id => params[:mul_id], :container_type => "Course", :name => attachment.name) - # elsif params[:mul_type] == "SubfieldFile" - # end - + send_ids = params[:checkbox1] + # mul_id为当前课程id、项目id、组织id的多种形态 + mul_id = params[:mul_id] + if params[:mul_type] == "Course" + mul_container = Course.find(mul_id) + elsif params[:mul_type] == "Project" + mul_container = Project.find(mul_id) + elsif params[:mul_type] == "SubfieldFile" + mul_container = OrgSubfield.find(mul_id) + end unless params[:checkbox1].blank? - send_ids = params[:checkbox1] - # mul_id为当前课程id、项目id、组织id的多种形态 - mul_id = params[:mul_id] - if params[:mul_type] == "Course" - mul_container = Course.find(mul_id) - elsif params[:mul_type] == "Project" - mul_container = Project.find(mul_id) - elsif params[:mul_type] == "SubfieldFile" - mul_container = OrgSubfield.find(mul_id) - end send_ids.each do |send_id| ori = Attachment.find_by_id(send_id) # 如果该附件已经存课程中,则只更新附件创建时间 @@ -2388,11 +2478,11 @@ class UsersController < ApplicationController respond_to do |format| format.html { if params[:mul_type] == "Course" - redirect_to course_files_url(mul_container) + redirect_to course_files_url(mul_container) unless mul_container.nil? elsif params[:mul_type] == "Project" - redirect_to project_files_url(mul_container) + redirect_to project_files_url(mul_container) unless mul_container.nil? elsif params[:mul_type] == "SubfieldFile" - redirect_to org_subfield_files_url(mul_container) + redirect_to org_subfield_files_url(mul_container) unless mul_container.nil? end } end @@ -2401,11 +2491,15 @@ class UsersController < ApplicationController # 根据资源关键字进行搜索 def resource_search search = "%#{params[:search].strip.downcase}%" + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} 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','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") + + @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null 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 is_publish = 1 and container_id is not null)" + + "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)) 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的所有我可见的课程中 @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type in" + @@ -2443,8 +2537,9 @@ class UsersController < ApplicationController end elsif params[:type] == "6" #全部资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = Attachment.where("((is_public =1 and is_publish = 1 and container_id is not null)" + - "or (author_id = #{params[:id]} and is_publish = 0)) and (filename like :p) ", :p => search).order("created_on desc") + @attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+ + "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)" + + "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)) and (filename like :p)" ,:p => search).order("created_on desc") end @type = params[:type] @limit = 25 diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 044d30551..1c7a05cb1 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -288,7 +288,7 @@ class JournalsForMessage < ActiveRecord::Base if self.jour_type == "Course" course_member_score(self.jour_id, self.user_id, "JournalForMessage") elsif self.jour_type == "HomeworkCommon" - course_member_score(self.jour_id, self.user_id, "HomeworkCommon") + course_member_score(self.jour.course_id, self.user_id, "HomeworkCommon") end end diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 4a62c94aa..b548092cf 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -91,7 +91,7 @@ <%= form_tag( search_course_files_path(@course), method: 'get',:class => "re_search",:remote=>true) do %> <%= text_field_tag 'name', params[:name], name: "name", :class => 'researchBox fl',:style=>"padding: 0px"%> <%= submit_tag "课内搜索", :class => "blueBtn mr5 fl",:name => "incourse",:id => "incourse" %> - <%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %> + <%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %> <% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %> <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %> diff --git a/app/views/files/_resource_detail.html.erb b/app/views/files/_resource_detail.html.erb index 6342e91f6..bac00a68d 100644 --- a/app/views/files/_resource_detail.html.erb +++ b/app/views/files/_resource_detail.html.erb @@ -27,6 +27,10 @@
文件大小:<%= number_to_human_size(file.filesize) %>
下载<%= file.downloads%> | 引用<%= file.quotes.nil? ? 0:file.quotes %>
+ <% unless file.description.blank? %> + +