diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a65ed639c..046e0c5a0 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -83,34 +83,38 @@ module ApplicationHelper
when "JournalForMessage"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
- :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0)
+ :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0, :total_score => 1)
else
score = course_contributor_score.journal_num + 1
- course_contributor_score.update_attributes(:journal_num => score)
+ total_score = course_contributor_score.total_score + 1
+ course_contributor_score.update_attributes(:journal_num => score, :total_score => total_score)
end
when "Message"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 2, :message_reply_num => 0,
- :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
+ :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 2)
else
score = course_contributor_score.message_num + 2
- course_contributor_score.update_attributes(:message_num => score)
+ total_score = course_contributor_score.total_score + 2
+ course_contributor_score.update_attributes(:message_num => score, :total_score => total_score)
end
when "MessageReply"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1,
- :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
+ :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1)
else
score = course_contributor_score.message_reply_num + 1
- course_contributor_score.update_attributes(:message_reply_num => score)
+ total_score = course_contributor_score.total_score + 1
+ course_contributor_score.update_attributes(:message_reply_num => score, :total_score => total_score)
end
when "NewReply"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
- :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
+ :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1)
else
score = course_contributor_score.news_reply_num + 1
- course_contributor_score.update_attributes(:news_reply_num => score)
+ total_score = course_contributor_score.total_score + 1
+ course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score)
end
end
end
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index 022d86d9b..1d82d035d 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -758,7 +758,7 @@ module CoursesHelper
end
def contributor_course_scor(course_id)
- ccs = CourseContributorScore.where("course_id =?", course_id).limit(9)
+ ccs = CourseContributorScore.where("course_id =?", course_id).order("total_score desc") .limit(9)
end
end
diff --git a/app/models/course_contributor_score.rb b/app/models/course_contributor_score.rb
index 598b8e014..f2b05458f 100644
--- a/app/models/course_contributor_score.rb
+++ b/app/models/course_contributor_score.rb
@@ -1,5 +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
+ attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id, :total_score
belongs_to :course
belongs_to :user
end
diff --git a/app/views/courses/_tool_expand.html.erb b/app/views/courses/_tool_expand.html.erb
index cec5311c6..9a36b8efb 100644
--- a/app/views/courses/_tool_expand.html.erb
+++ b/app/views/courses/_tool_expand.html.erb
@@ -2,19 +2,19 @@
<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %>
<% if show_nav?(@course.homework_commons.count) %>
- <%= link_to l(:label_homework), homework_common_index_path(:course => @course.id), :class => "f14 c_blue02"%>
+ <%= link_to l(:label_homework), homework_common_index_path(:course => @course.id), :class => "f14 c_blue02 ml10"%>
<%= link_to( "", homework_common_index_path(:course => @course.id,:is_new => 1), :class => 'courseMenuSetting', :title =>"#{l(:label_course_homework_new)}") if is_teacher %>
<% end %>
<% if show_nav?(@course.news.count) %>
- <%= link_to l(:label_course_news), course_news_index_path(@course), :class => "f14 c_blue02" %>
+ <%= link_to l(:label_course_news), course_news_index_path(@course), :class => "f14 c_blue02 ml10" %>
<%= link_to( "", new_course_news_path(@course), :class => 'courseMenuSetting', :title =>"#{l(:label_course_news_new)}") if is_teacher %>
<% end %>
<% if show_nav?(course_file_num) %>
- <%= link_to l(:label_course_file), course_files_path(@course), :class => "f14 c_blue02" %>
+ <%= link_to l(:label_course_file), course_files_path(@course), :class => "f14 c_blue02 ml10" %>
<% if is_teacher || (@course.publish_resource == 1 && User.current.member_of_course?(@course)) %>
@@ -23,25 +23,25 @@
<% end %>
<% if show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %>
- <%= link_to l(:label_course_board), course_boards_path(@course), :class => "f14 c_blue02" %>
+ <%= link_to l(:label_course_board), course_boards_path(@course), :class => "f14 c_blue02 ml10" %>
<%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'courseMenuSetting', :title =>"#{l(:label_message_new)}") if User.current.member_of_course?(@course) && @course.boards.first %>
<% end %>
<% if show_nav?(course_feedback_count) %>
- <%= link_to l(:label_course_feedback), course_feedback_path(@course), :class => "f14 c_blue02" %>
+ <%= link_to l(:label_course_feedback), course_feedback_path(@course), :class => "f14 c_blue02 ml10" %>
<%= link_to "", course_feedback_path(@course), :class => 'courseMenuSetting', :title =>"#{l(:label_message_new)}", :id => "course_jour_count"%>
<% end %>
<% if show_nav?(course_poll_count) %>
- <%= link_to l(:label_poll), poll_index_path(:polls_type => "Course", :polls_group_id => @course.id), :class => " f14 c_blue02"%>
+ <%= link_to l(:label_poll), poll_index_path(:polls_type => "Course", :polls_group_id => @course.id), :class => " f14 c_blue02 ml10"%>
<%= link_to( "", new_poll_path(:polls_type => "Course",:polls_group_id => @course.id), :class => 'courseMenuSetting', :title =>"#{l(:label_new_poll)}") if is_teacher %>
<% end %>
<% if show_nav?(User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status=2").count) %>
- <%= link_to "在线测验", exercise_index_path(:course_id => @course.id), :class => " f14 c_blue02"%>
+ <%= link_to "在线测验", exercise_index_path(:course_id => @course.id), :class => " f14 c_blue02 ml10"%>
<%= link_to( "", new_exercise_path(:course_id => @course.id), :class => 'courseMenuSetting', :title =>"新建试卷") if is_teacher %>
<% 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 604bf2601..00c56b7ee 100644
--- a/app/views/layouts/base_courses.html.erb
+++ b/app/views/layouts/base_courses.html.erb
@@ -178,7 +178,7 @@
<%= link_to l(:label_course_feedback), course_feedback_path(@course), :class => "f14 c_blue02" %>
<%= link_to "(#{course_feedback_count})", course_feedback_path(@course), :class => "subnav_num c_orange", :id => "course_jour_count"%>
- <%= link_to "", course_feedback_path(@course), :class => 'courseMenuSetting', :title =>"#{l(:label_message_new)}", :id => "course_jour_count"%>
+ <%= link_to "", course_feedback_path(@course), :class => 'courseMenuSetting', :title =>"#{l(:label_course_feedback)}", :id => "course_jour_count"%>
<% end %>
<% unless show_nav?(course_poll_count) %>
@@ -203,41 +203,53 @@
<%# 课程贡献榜 %>
+ <% unless contributor_course_scor(@course.id).count == 0 %>
- 课程贡献榜
- <% contributor_course_scor(@course.id).each do |student_score| %>
- - <%=link_to image_tag(url_to_avatar(student_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(student_score.user) %>
-
<%=link_to student_score.user, user_path(student_score.user) %>
-
+ 课程贡献榜
+ <% contributor_course_scor(@course.id).each do |contributor_score| %>
+ - <%=link_to image_tag(url_to_avatar(contributor_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(contributor_score.user) %>
+
<%=link_to contributor_score.user, user_path(contributor_score.user), :title => contributor_score.user %>
+
<%#= link_to ma.course_message.title, {:controller => 'news', :action => 'show', :id => ma.course_message.id },
:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover =>"message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
- <%= student_score.total_score.to_i %>
-
- 资源:2
- 评论:98
- 留言:12
- 通知:8
-
-
-
-
+ <%= contributor_score.total_score.to_i %>
+
+ <% unless contributor_score.resource_num == 0 %>
+ 资源:<%= contributor_score.resource_num %>
+ <% end %>
+ <% unless contributor_score.message_num == 0 %>
+ 评论:<%= contributor_score.message_num %>
+ <% end %>
+ <% unless contributor_score.message_reply_num == 0 %>
+ 评论回复:<%= contributor_score.message_reply_num %>
+ <% end %>
+ <% unless contributor_score.journal_num == 0 %>
+ 留言:<%= contributor_score.journal_num %>
+ <% end %>
+ <% unless contributor_score.news_reply_num == 0 %>
+ 通知:<%= contributor_score.news_reply_num %>
+ <% end %>
+
+
<% end %>
+ <% end %>
- 课程英雄榜
+ 课程英雄榜
<% hero_homework_score(@course, "desc").each do |student_score| %>
- - <%=link_to image_tag(url_to_avatar(student_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(student_score.user) %>
-
<%=link_to student_score.user, user_path(student_score.user) %>
- <%= student_score.score.to_i %>
-
-
-
+ <% unless student_score.score.nil? %>
+ - <%=link_to image_tag(url_to_avatar(student_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(student_score.user) %>
+
<%=link_to student_score.user, user_path(student_score.user), :title => student_score.user %>
+ <%= student_score.score.to_i %>
+
+ <% end %>
<% end %>
+
<%= l(:label_course_brief_introduction)%>:
diff --git a/db/migrate/20151125072235_add_course_contributor_score.rb b/db/migrate/20151125072235_add_course_contributor_score.rb
deleted file mode 100644
index 99ef60cf0..000000000
--- a/db/migrate/20151125072235_add_course_contributor_score.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-class AddCourseContributorScore < ActiveRecord::Migration
- def up
- # course_count = Course.all.count / 30 + 1
- # transaction do
- # for i in 1 ... course_count do i
- Course.all.each do |course|
- if course.course_activities.count > 1
- course.student.each do |s|
- puts course.id
- puts course.name
- puts s.student_id
- # board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2
- board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.student_id} and me.parent_id is null;").count * 2
- message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.student_id} and me.parent_id is not null").count * 1
- common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.student_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1
- # attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5
- attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.student_id};").count * 5
- journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.student_id, course.id, "Course").count * 1
- # journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").count * 1
- # journal_reply_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and status =?", s.student_id, course.id, "Course",1).count * 1
- total = board_count + message_reply_count + common_reply_count + attachment_count + journal_count
- if total !=0
- CourseContributorScore.create(:course_id => course.id, :user_id => s.student_id, :message_num => board_count, :message_reply_num => message_reply_count,
- :news_reply_num => common_reply_count, :resource_num => attachment_count, :journal_num => journal_count, :journal_reply_num => 0, :total => total)
- end
-
- end
- end
- end
- # end
- # end
- end
-
- def down
- end
-end
\ No newline at end of file
diff --git a/db/migrate/20151127011351_add_course_contributor_total_score.rb b/db/migrate/20151127011351_add_course_contributor_total_score.rb
new file mode 100644
index 000000000..2606864d8
--- /dev/null
+++ b/db/migrate/20151127011351_add_course_contributor_total_score.rb
@@ -0,0 +1,36 @@
+class AddCourseContributorTotalScore < ActiveRecord::Migration
+ def up
+ # course_count = Course.all.count / 30 + 1
+ # transaction do
+ # for i in 1 ... course_count do i
+ Course.all.each do |course|
+ if course.course_activities.count > 1
+ course.student.each do |s|
+ puts course.id
+ puts course.name
+ puts s.student_id
+ # board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2
+ board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.student_id} and me.parent_id is null;").count * 2
+ message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.student_id} and me.parent_id is not null").count * 1
+ common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.student_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1
+ # attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5
+ attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.student_id};").count * 5
+ journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.student_id, course.id, "Course").count * 1
+ # journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").count * 1
+ # journal_reply_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and status =?", s.student_id, course.id, "Course",1).count * 1
+ total = board_count + message_reply_count + common_reply_count + attachment_count + journal_count
+ if total !=0
+ CourseContributorScore.create(:course_id => course.id, :user_id => s.student_id, :message_num => board_count, :message_reply_num => message_reply_count,
+ :news_reply_num => common_reply_count, :resource_num => attachment_count, :journal_num => journal_count, :journal_reply_num => 0, :total_score => total)
+ end
+
+ end
+ end
+ end
+ # end
+ # end
+ end
+
+ def down
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 8a0ec8605..8e2082b37 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 => 20151126160252) do
+ActiveRecord::Schema.define(:version => 20151127011351) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css
index 7d5d66103..bdcfbd08e 100644
--- a/public/stylesheets/courses.css
+++ b/public/stylesheets/courses.css
@@ -1172,7 +1172,7 @@ a:hover.testEdit{ background:url(images/icons.png) -21px -272px no-repeat;}
.courseMenuSetting {background:url(../images/homepage_icon2.png) -190px -365px no-repeat; width:15px; height:15px; margin-top:3px; float:right; margin-right:5px;}
.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 {width:73px; padding:8px 0px 0px 0px; text-align:center; float:left; position:relative;}
.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