diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 31463d691..25bb31cbb 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -25,6 +25,7 @@ class AttachmentsController < ApplicationController #before_filter :login_without_softapplication, only: [:download] accept_api_auth :show, :download, :upload require 'iconv' + include AttachmentsHelper def show @@ -346,8 +347,18 @@ class AttachmentsController < ApplicationController def add_exist_file_to_courses file = Attachment.find(params[:file_id]) courses = params[:courses][:course] + @message = "" courses.each do |course| c = Course.find(course); + if course_contains_attachment?(c,file) + if @message && @message == "" + @message += l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + else + @message += "
" + l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + end + end attach_copied_obj = file.copy attach_copied_obj.tag_list.add(file.tag_list) # tag关联 attach_copied_obj.container = c diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 251496e30..aa1c158e0 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -28,6 +28,7 @@ class FilesController < ApplicationController include SortHelper include FilesHelper helper :project_score + include CoursesHelper def show_attachments obj @attachments = [] diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 3c882d393..52002b028 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -67,6 +67,15 @@ module AttachmentsHelper end end + def course_contains_attachment? course,attachment + course.attachments.each do |att| + if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from + return true + end + end + false + end + private def deletable? container, user=User.current diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 73e7daa26..d06bf7d38 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -486,6 +486,20 @@ module CoursesHelper term end + def course_in_current_or_next_term course + is_current_term = false + is_next_term = false + if course.time == Time.now.year && course.term == cur_course_term + is_current_term = true + end + if cur_course_term == "秋季学期" && course.time == (Time.now.year + 1) && course.term == "春季学期" + is_next_term = true + elsif cur_course_term == "春季学期" && course.time == Time.now.year && course.term == "秋季学期" + is_next_term = true + end + is_current_term || is_next_term + end + #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 399b7be1d..c3a6a7b3e 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -47,18 +47,18 @@ module FilesHelper def courses_check_box_tags(name,courses,current_course,attachment) s = '' courses.each do |course| - if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) - s << "
" + if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course) + s << " [#{get_course_term course}]
" end end s.html_safe end - #判断用户是否拥有课程,需用户在该课程中角色为教师 + #判断用户是否拥有课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 def has_course? user result = false user.courses.each do |course| - if is_course_teacher(user,course) + if is_course_teacher(User.current,course) && course_in_current_or_next_term(course) return true end end @@ -86,7 +86,7 @@ module FilesHelper def visable_attachemnts attachments result = [] attachments.each do |attachment| - if attachment.is_public? || attachment.author_id == User.current.id + if attachment.is_public? || (attachment.container_type == "Course" && attachment.author.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id result << attachment end end @@ -94,9 +94,15 @@ module FilesHelper end def get_qute_number attachment - if attachment.copy_from.nil? - return 0 + if attachment.copy_from + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") + else + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") + end + if result.nil? || result.count <= 0 + return 0 + else + return result[0].number end - count = Attachment.find_by_sql("select count(*) from attachments where copy_from = #{attachment.copy_from}") end end \ No newline at end of file diff --git a/app/views/attachments/add_exist_file_to_courses.js.erb b/app/views/attachments/add_exist_file_to_courses.js.erb index 23761647f..eec1e255a 100644 --- a/app/views/attachments/add_exist_file_to_courses.js.erb +++ b/app/views/attachments/add_exist_file_to_courses.js.erb @@ -1,5 +1,7 @@ -<% if !@save_flag%> +<% if !@save_flag && @save_message %> $("#error_show").html("<%= @save_message.join(', ') %>"); +<% elsif @message && @message != "" %> + $("#error_show").html("<%= @message.html_safe %>"); <% else %> closeModal(); <% end %> diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 6e434ed14..93e39f73f 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -41,7 +41,7 @@

文件大小:<%= number_to_human_size(file.filesize) %>

<%= link_to( l(:button_delete), attachment_path(file), :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if delete_allowed && file.container_id == @course.id && file.container_type == "Course"%> -

<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>  |  下载<%= file.downloads %>  

+

<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>  |  下载<%= file.downloads %>  |  引用<%= get_qute_number file %>

diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 7d6cc85b2..0ec623217 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2205,3 +2205,7 @@ zh: label_my_score: 我的评分 field_open_anonymous_evaluation: 是否使用匿评 label_course_empty_select: 尚未选择课程! + label_course_prompt: 课程: + label_contain_resource: 已包含资源: + label_quote_resource_failed: ",此资源引用失败! " +