From 1cc6e305ed723e3686ac9a3612eae560d488ea9f Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 27 Nov 2015 13:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=96=B0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=BC=80=E5=8F=91=EF=BC=9A=201=E3=80=81?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89=E6=88=90=E7=BB=A9=E5=88=99?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=202=E3=80=81=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=A1=86=E5=B1=95=E5=BC=80=E6=B2=A1=E6=9C=89=E5=88=99=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 17 ++++++++ app/helpers/courses_helper.rb | 3 -- app/models/attachment.rb | 17 +------- app/views/layouts/base_courses.html.erb | 55 ++++++++++++++----------- public/stylesheets/courses.css | 2 +- 5 files changed, 49 insertions(+), 45 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index a2902e3fc..b15be4896 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -374,6 +374,9 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end + # 更新课程英雄榜得分 + update_contributor_score(@course, attachments[:files].first) + # end if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) params[:course_attachment_type].each do |type| tag_name = get_tag_name_by_type_number type @@ -423,6 +426,20 @@ class FilesController < ApplicationController end end + def update_contributor_score(course, file ) + unless file.author.allowed_to?(:as_teacher, course) + course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5) + else + score = course_contributor_score.resource_num + 5 + total_score = course_contributor_score.total_score + 5 + course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score) + end + end + end + def get_tag_name_by_type_number type case type when "1" diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 1d82d035d..a1b119cb5 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -751,10 +751,7 @@ module CoursesHelper JOIN students_for_courses ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id WHERE members.course_id = #{course.id} ORDER BY score #{score_sort_by} limit 9" - sql = ActiveRecord::Base.connection() homework_scores = Member.find_by_sql(sql_select) - sql.close() - homework_scores end def contributor_course_scor(course_id) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 45d19e681..9c6bb9cb1 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -73,11 +73,10 @@ class Attachment < ActiveRecord::Base cattr_accessor :thumbnails_storage_path @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") - before_save :files_to_final_location,:act_as_course_activity, :act_as_student_score + before_save :files_to_final_location,:act_as_course_activity after_create :office_conver, :be_user_score,:act_as_forge_activity after_update :office_conver, :be_user_score after_destroy :delete_from_disk,:down_user_score - # after_save :act_as_student_score # add by nwb # 获取所有可公开的资源文件列表 @@ -562,18 +561,4 @@ class Attachment < ActiveRecord::Base end end - # 课程成员得分(英雄榜) - def act_as_student_score - unless self.author.allowed_to?(:as_teacher, self.container) - course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", self.container_id, self.author_id).first - if course_contributor_score.nil? - CourseContributorScore.create(:course_id => self.container_id, :user_id => self.author_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0) - else - score = course_contributor_score.news_reply_num + 5 - course_contributor_score.update_attributes(:resource_num => score) - end - end - end - end diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 00c56b7ee..603f7febb 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -196,59 +196,64 @@ <% end %> <%# 工具栏展开 %> - - + <% if @course.homework_commons.count == 0 || @course.news.count == 0 || course_file_num == 0 || course_poll_count == 0 || @course.exercises.count == 0 || + course_feedback_count == 0 || @course.exercises.count == 0 || (@course.boards.first ? @course.boards.first.topics.count : 0) == 0 %> + + + <% end %> <%# 课程贡献榜 %>
<% unless contributor_course_scor(@course.id).count == 0 %> -