From 061a1f602a2212891634d819623d4db8d06497bb Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 26 Nov 2015 21:17:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=88=E6=9E=9C=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 22 +++++--- app/models/attachment.rb | 18 +++--- app/views/courses/_tool_expand.html.erb | 27 +++------ app/views/layouts/base_courses.html.erb | 74 ++++++++++++------------- 4 files changed, 66 insertions(+), 75 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index d07001215..aa42d247e 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -737,11 +737,10 @@ module CoursesHelper end desc.html_safe end -end -# 学生按作业总分排序,取前8个 -def hero_homework_score(course, score_sort_by) - sql_select = "SELECT members.*,( + # 学生按作业总分排序,取前8个 + def hero_homework_score(course, score_sort_by) + sql_select = "SELECT members.*,( SELECT SUM(student_works.final_score) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id @@ -752,8 +751,15 @@ def hero_homework_score(course, score_sort_by) 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 + sql = ActiveRecord::Base.connection() + homework_scores = Member.find_by_sql(sql_select) + sql.close() + homework_scores + end + + def contributor_course_scor(course) + + end + end + diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 22be5a42f..45d19e681 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -73,10 +73,11 @@ 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 - after_create :office_conver, :be_user_score,:act_as_forge_activity, :act_as_student_score + before_save :files_to_final_location,:act_as_course_activity, :act_as_student_score + 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 # 获取所有可公开的资源文件列表 @@ -563,13 +564,14 @@ class Attachment < ActiveRecord::Base # 课程成员得分(英雄榜) def act_as_student_score - unless self.author.allowed_to?(:as_teacher, self.course) - if self.parent_id.nil? - # 发帖 - course_member_score(self.course.id, self.author_id, "Message") + 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 - # 回帖 - course_member_score(self.course.id, self.author_id, "MessageReply") + score = course_contributor_score.news_reply_num + 5 + course_contributor_score.update_attributes(:resource_num => score) end end end diff --git a/app/views/courses/_tool_expand.html.erb b/app/views/courses/_tool_expand.html.erb index 1f793de90..01454c8a8 100644 --- a/app/views/courses/_tool_expand.html.erb +++ b/app/views/courses/_tool_expand.html.erb @@ -1,60 +1,47 @@ <% course_file_num = visable_attachemnts_incourse(@course).count%> <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> -<% if show_nav?(@course.course_activities.count) %> - -<% end %> <% if show_nav?(@course.homework_commons.count) %> <% end %> <% if show_nav?(@course.news.count) %> <% end %> <% if show_nav?(course_file_num) %> <% end %> <% if show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %> <% end %> <% if show_nav?(course_feedback_count) %> <% end %> <% if show_nav?(course_poll_count) %> <% end %> <% if show_nav?(User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status=2").count) %> <% end %> \ No newline at end of file diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 4a7692405..c214145cc 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -147,14 +147,14 @@ <% end %> <% unless show_nav?(@course.news.count) %> <% end %> <% unless show_nav?(course_file_num) %> @@ -163,7 +163,7 @@ <%= link_to "(#{course_file_num})", course_files_path(@course), :class => "subnav_num c_orange",:id=>'courses_files_count_nav' %> <% if is_teacher || (@course.publish_resource == 1 && User.current.member_of_course?(@course)) %> - +上传资源 + <% end %> <% end %> @@ -171,27 +171,28 @@ <% end %> <% unless show_nav?(course_feedback_count) %> <% end %> <% unless show_nav?(course_poll_count) %> <% end %> <% unless show_nav?(User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status=2").count) %> <% end %> <%# 工具栏展开 %> @@ -204,40 +205,25 @@