diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index e974f26b4..9853b4dc1 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -103,6 +103,9 @@ class AttachmentsController < ApplicationController direct_download_history end else + # 记录用户行为 + record_user_actions(params[:id]) + # 直接下载历史版本 direct_download_history end end @@ -113,6 +116,14 @@ class AttachmentsController < ApplicationController redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html" end + def record_user_actions id + if params[:action] == "download_history" + UserActions.create(:action_id => id, :action_type => "AttachmentHistory", :user_id => User.current.id) unless id.nil? + elsif params[:action] == "download" + UserActions.create(:action_id => id, :action_type => "Attachment", :user_id => User.current.id) unless id.nil? + end + end + def download # modify by nwb # 下载添加权限设置 @@ -135,6 +146,8 @@ class AttachmentsController < ApplicationController direct_download end else + # 记录用户行为 + record_user_actions(params[:id]) direct_download end end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index b6ac99f11..7ae1b85f8 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -207,8 +207,7 @@ class FilesController < ApplicationController sort = "created_on DESC" end if keywords != "%%" - resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%"). - reorder(sort) + resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort) else resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' "). reorder(sort) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7b59d8916..63155e25a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2533,6 +2533,8 @@ class UsersController < ApplicationController render_403 return end + @resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id] + @resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project" @user = User.find(params[:id]) @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @score = @b_sort == "desc" ? "asc" : "desc" @@ -2561,6 +2563,8 @@ class UsersController < ApplicationController end def import_resources_search + @resource_id = params[:mul_id] + @resource_type = params[:mul_type] @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @score = @b_sort == "desc" ? "asc" : "desc" @user = User.current @@ -2571,6 +2575,7 @@ class UsersController < ApplicationController render_403 return end + @resource_id = params[:mul_id] if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 user_course_ids = User.current.courses.map { |c| c.id} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 42911cc33..3a5cdb1a1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -370,7 +370,7 @@ module ApplicationHelper def link_to_short_attachment(attachment, options={}) length = options[:length] ? options[:length]:23 text = h(truncate(options.delete(:text) || attachment.filename, length: length, omission: '...')) - route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path + route_method = options.delete(:download) ? :download_named_attachment_url_without_domain : :named_attachment_url_without_domain html_options = options.slice!(:only_path) url = send(route_method, attachment, attachment.filename, options) link_to text, url, html_options @@ -841,7 +841,7 @@ module ApplicationHelper def project_member_check_box_tags_ex name, principals s = '' principals.each do |principal| - s << "
  • #{ check_box_tag name, principal.id, false, :id => nil } #{h link_to principal.userInfo, user_path( principal.id)}
  • \n" + s << "
  • #{ check_box_tag name, principal.id, false, :id => nil } #{h link_to principal.userInfo, user_url_in_org( principal.id)}
  • \n" end s.html_safe end @@ -2582,9 +2582,9 @@ module ApplicationHelper elsif homework.student_works.count >= 2 && homework.homework_detail_manual#作业份数大于2 case homework.homework_detail_manual.comment_status when 1 - link = link_to '启动匿评', alert_anonymous_comment_homework_common_path(homework,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity), id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'postOptionLink' + link = link_to '启动匿评', Setting.protocol + "://" + Setting.host_name + "/homework_common/" + homework.id.to_s + "/alert_anonymous_comment?is_in_course=" + is_in_course.to_s + "&user_activity_id=" + user_activity_id.to_s + "&course_activity=" + course_activity.to_s, id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'postOptionLink' when 2 - link = link_to '关闭匿评', alert_anonymous_comment_homework_common_path(homework,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity), id: "#{homework.id}_stop_anonymous_comment", remote: true,:class => 'postOptionLink' + link = link_to '关闭匿评', Setting.protocol + "://" + Setting.host_name + "/homework_common/" + homework.id.to_s + "/alert_anonymous_comment?is_in_course=" + is_in_course.to_s + "&user_activity_id=" + user_activity_id.to_s + "&course_activity=" + course_activity.to_s, id: "#{homework.id}_stop_anonymous_comment", remote: true,:class => 'postOptionLink' when 3 # link = link_to "匿评结束","javascript:void(0)", :class => "postOptionLink", :title => "匿评结束" end @@ -2631,7 +2631,7 @@ module ApplicationHelper def user_for_homework_common homework,is_teacher if User.current.member_of_course?(homework.course) if is_teacher #老师显示作品数量 - link_to "作品(#{homework.student_works.count})",student_work_index_path(:homework => homework.id),:class => "c_blue" + link_to "作品(#{homework.student_works.count})", student_work_index_url_in_org(homework.id), :class => "c_blue" else #学生显示提交作品、修改作品等按钮 work = cur_user_works_for_homework homework project = cur_user_projects_for_homework homework @@ -2639,30 +2639,30 @@ module ApplicationHelper if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 link_to "提交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品' else - link_to "提交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue' + link_to "提交作品(#{homework.student_works.count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue' end elsif work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1 link_to "补交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品' else - link_to "补交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_red' + link_to "补交作品(#{homework.student_works.count})", new_student_work_url_without_domain(homework.id),:class => 'c_red' end else if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 #匿评作业,且作业状态不是在开启匿评之前 - link_to "作品匿评", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品" + link_to "作品匿评", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品" elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 - link_to "查看作品(#{homework.student_works.count})", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "匿评已结束" + link_to "查看作品(#{homework.student_works.count})",student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "匿评已结束" elsif homework.homework_type == 2 && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")#编程作业不能修改作品 - link_to "修改作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue' + link_to "修改作品(#{homework.student_works.count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue' elsif Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") && work.user_id == User.current.id - link_to "修改作品(#{homework.student_works.count})", edit_student_work_path(work.id),:class => 'c_blue' + link_to "修改作品(#{homework.student_works.count})", edit_student_work_url_without_domain(work.id),:class => 'c_blue' else - link_to "查看作品(#{homework.student_works.count})", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品" + link_to "查看作品(#{homework.student_works.count})", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品" end end end else - link_to "作品(#{homework.student_works.count})",student_work_index_path(:homework => homework.id),:class => "c_blue" + link_to "作品(#{homework.student_works.count})",student_work_index_url_in_org(homework.id),:class => "c_blue" end end @@ -3021,6 +3021,24 @@ end def register_url_without_domain Setting.protocol + "://" + Setting.host_name + "/login?login=false" end + +def new_student_work_url_without_domain(homework_id) + Setting.protocol + "://" + Setting.host_name + "/student_work/new?homework=" + homework_id.to_s +end + +def edit_student_work_url_without_domain(homework_id) + Setting.protocol + "://" + Setting.host_name + "/student_work/" + homework_id.to_s + "/edit" +end + +def download_named_attachment_url_without_domain(id, filename, option={}) + attachment_id = (Attachment === id ? id.id : id) + Setting.protocol + "://" + Setting.host_name + "/attachments/download/" + attachment_id.to_s + "/" + filename +end + +def named_attachment_url_without_domain(id, filename, option={}) + attachment_id = (Attachment === id ? id.id : id) + Setting.protocol + "://" + Setting.host_name + "/attachments/" + attachment_id.to_s + "/" + filename +end #判断是否为默认的组织栏目 def is_default_field? field (field.name == 'activity' || field.name == 'course' || field.name == 'project') && field.field_type == 'default' diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index d98de27f6..37c7deb4c 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -865,7 +865,7 @@ module CoursesHelper # 学生按作业总分排序,取前8个 def hero_homework_score(course, score_sort_by) sql_select = "SELECT members.*,( - SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty)) + SELECT SUM(IF(student_works.final_score is null,null,IF(student_works.final_score = 0, 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty))) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{course.id} diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index bdd34d80d..44b919121 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -62,7 +62,7 @@ module UsersHelper when 'Course' result = current_time_and_term_resource content when 'Project' - result = content.name + "(" + content.id.to_s + ")" + result = content.name when 'Issue' result = content.subject when 'Message' diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index a02eb750c..96ec6e355 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -66,8 +66,8 @@ class CourseActivity < ActiveRecord::Base # 发布新课导语 # 导语要放置在课程创建信息之后 - # 导语 def add_course_lead + # 避免空数据迁移报错问题 if self.course_act_type == "Course" and Message.where("id=12440").any? lead_message = Message.find(12440) name = lead_message.subject @@ -75,7 +75,7 @@ class CourseActivity < ActiveRecord::Base # message的status状态为0为正常,为1表示创建课程时发送的message # author_id 默认为课程使者创建 message = Message.create(:subject => name, :content => content, :board_id => self.course.boards.first.id, :author_id => 1 , :sticky => true, :status => true ) - # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一直 + # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一致 message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) if message.course_acts.first end end diff --git a/app/models/user_actions.rb b/app/models/user_actions.rb new file mode 100644 index 000000000..de2388911 --- /dev/null +++ b/app/models/user_actions.rb @@ -0,0 +1,4 @@ +class UserActions < ActiveRecord::Base + attr_accessible :action_id, :action_type, :user_id + has_many :users +end diff --git a/app/views/courses/_course_activity.html.erb b/app/views/courses/_course_activity.html.erb index d65c0b3ab..bdbcabff0 100644 --- a/app/views/courses/_course_activity.html.erb +++ b/app/views/courses/_course_activity.html.erb @@ -2,6 +2,8 @@ <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> <% end %>