From c8b1cae947121ac5d6546551c89509cbcb4367a2 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 25 Nov 2015 15:16:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E8=B4=A1=E7=8C=AE=E6=A6=9C?= =?UTF-8?q?=E8=A1=A8=E5=8F=8A=E7=9B=B8=E5=85=B3=E5=85=B3=E8=81=94=20?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2=20=E6=8C=89=E6=80=BB?= =?UTF-8?q?=E5=88=86=E6=8E=92=E5=BA=8F=EF=BC=88=E8=8B=B1=E9=9B=84=E6=A6=9C?= =?UTF-8?q?=EF=BC=89=20=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2=EF=BC=88?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 19 ++++++ app/models/course.rb | 4 +- app/models/course_contributor_score.rb | 5 ++ app/models/user.rb | 2 + app/views/layouts/base_courses.html.erb | 51 ++++++++++++++ ...064914_create_course_contributor_scores.rb | 16 +++++ db/schema.rb | 67 ++++++++++++++++++- public/stylesheets/courses.css | 2 +- spec/factories/course_contributor_scores.rb | 13 ++++ spec/models/course_contributor_score_spec.rb | 5 ++ 10 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 app/models/course_contributor_score.rb create mode 100644 db/migrate/20151125064914_create_course_contributor_scores.rb create mode 100644 spec/factories/course_contributor_scores.rb create mode 100644 spec/models/course_contributor_score_spec.rb diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 7c1831d56..d07001215 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -738,3 +738,22 @@ module CoursesHelper desc.html_safe end end + +# 学生按作业总分排序,取前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 + AND homework_commons.course_id = #{course.id} + AND student_works.user_id = members.user_id + ) AS score + FROM members + 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 diff --git a/app/models/course.rb b/app/models/course.rb index 1350b8cf7..ec1afd611 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -40,8 +40,10 @@ class Course < ActiveRecord::Base has_many :course_activities # 课程消息 - has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :exercises, :dependent => :destroy + # 课程贡献榜 + has_many :course_contributor_scores, :dependent => :destroy acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy diff --git a/app/models/course_contributor_score.rb b/app/models/course_contributor_score.rb new file mode 100644 index 000000000..598b8e014 --- /dev/null +++ b/app/models/course_contributor_score.rb @@ -0,0 +1,5 @@ +class CourseContributorScore < ActiveRecord::Base + attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id + belongs_to :course + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 3e7bc2ddb..cd8b96d47 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -153,6 +153,8 @@ class User < Principal # 邮件邀请状态 has_many :invite_lists, :dependent => :destroy # end + # 课程贡献榜 + has_many :course_contributor_scores, :dependent => :destroy ######added by nie has_many :project_infos, :dependent => :destroy diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 8b15e67ea..4a7692405 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -200,7 +200,58 @@ <%= render 'courses/tool_expand', :locals => {:is_teacher => is_teacher, :course_file_num => course_file_num} %> + <%# 课程贡献榜 %>
+ +

<%= l(:label_course_brief_introduction)%>:

diff --git a/db/migrate/20151125064914_create_course_contributor_scores.rb b/db/migrate/20151125064914_create_course_contributor_scores.rb new file mode 100644 index 000000000..0d16ac68b --- /dev/null +++ b/db/migrate/20151125064914_create_course_contributor_scores.rb @@ -0,0 +1,16 @@ +class CreateCourseContributorScores < ActiveRecord::Migration + def change + create_table :course_contributor_scores do |t| + t.integer :course_id + t.integer :user_id + t.integer :message_num + t.integer :message_reply_num + t.integer :news_reply_num + t.integer :resource_num + t.integer :journal_num + t.integer :journal_reply_num + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 95f79b84b..64f94cc29 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151120134208) do +ActiveRecord::Schema.define(:version => 20151125064914) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -241,6 +241,58 @@ ActiveRecord::Schema.define(:version => 20151120134208) do add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true + create_table "code_review_assignments", :force => true do |t| + t.integer "issue_id" + t.integer "change_id" + t.integer "attachment_id" + t.string "file_path" + t.string "rev" + t.string "rev_to" + t.string "action_type" + t.integer "changeset_id" + end + + create_table "code_review_project_settings", :force => true do |t| + t.integer "project_id" + t.integer "tracker_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "updated_by" + t.boolean "hide_code_review_tab", :default => false + t.integer "auto_relation", :default => 1 + t.integer "assignment_tracker_id" + t.text "auto_assign" + t.integer "lock_version", :default => 0, :null => false + t.boolean "tracker_in_review_dialog", :default => false + end + + create_table "code_review_user_settings", :force => true do |t| + t.integer "user_id", :default => 0, :null => false + t.integer "mail_notification", :default => 0, :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "code_reviews", :force => true do |t| + t.integer "project_id" + t.integer "change_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "line" + t.integer "updated_by_id" + t.integer "lock_version", :default => 0, :null => false + t.integer "status_changed_from" + t.integer "status_changed_to" + t.integer "issue_id" + t.string "action_type" + t.string "file_path" + t.string "rev" + t.string "rev_to" + t.integer "attachment_id" + t.integer "file_count", :default => 0, :null => false + t.boolean "diff_all" + end + create_table "comments", :force => true do |t| t.string "commented_type", :limit => 30, :default => "", :null => false t.integer "commented_id", :default => 0, :null => false @@ -330,6 +382,19 @@ ActiveRecord::Schema.define(:version => 20151120134208) do t.integer "container_id", :default => 0 end + create_table "course_contributor_scores", :force => true do |t| + t.integer "course_id" + t.integer "user_id" + t.integer "message_num" + t.integer "message_reply_num" + t.integer "news_reply_num" + t.integer "resource_num" + t.integer "journal_num" + t.integer "journal_reply_num" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "course_groups", :force => true do |t| t.string "name" t.integer "course_id" diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index e71eb975c..7d5d66103 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -1173,6 +1173,6 @@ a:hover.testEdit{ background:url(images/icons.png) -21px -272px no-repeat;} .courseMenuSetting:hover {background:url(../images/homepage_icon2.png) -190px -407px no-repeat;} .rankList {width:220px; padding:10px; background-color:#ffffff; margin-top:10px;} .rankList li {width:73px; padding:5px 0px; text-align:center; float:left; position:relative;} -.rankList li p {width:100%; overflow:hidden; white-space:normal; text-overflow:ellipsis; color:#585858;} +.rankList li p {width:100%; overflow:hidden; white-space:normal; text-overflow:ellipsis; color:#585858;word-wrap: normal; word-break: normal;} .rankPortrait {border-radius:50%; width:35px; height:35px;} .numIntro {position:absolute; text-align:left; z-index:999; box-shadow:0px 2px 8px rgba(146, 153, 169, 0.5); border:1px solid #eaeaea; background-color:#ffffff; padding:3px 5px; left:15px; width:65px; color:#585858;} \ No newline at end of file diff --git a/spec/factories/course_contributor_scores.rb b/spec/factories/course_contributor_scores.rb new file mode 100644 index 000000000..2226a60d2 --- /dev/null +++ b/spec/factories/course_contributor_scores.rb @@ -0,0 +1,13 @@ +FactoryGirl.define do + factory :course_contributor_score do + course_id 1 +user_id 1 +message_num 1 +message_reply_num 1 +news_reply_num 1 +resource_num 1 +journal_num 1 +journal_reply_num 1 + end + +end diff --git a/spec/models/course_contributor_score_spec.rb b/spec/models/course_contributor_score_spec.rb new file mode 100644 index 000000000..bc3b3cb52 --- /dev/null +++ b/spec/models/course_contributor_score_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseContributorScore, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end