diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index e615de002..a40b24fe2 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -629,16 +629,14 @@ class FilesController < ApplicationController 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 + 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c37d3ad55..22890fd9a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -110,8 +110,7 @@ module ApplicationHelper end end - # 更新课程英雄榜得分 - # user传过来必须是学生 + # 更新课程活跃度得分 def course_member_score(course_id,user_id,type) course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first case type @@ -160,6 +159,15 @@ module ApplicationHelper total_score = course_contributor_score.total_score + 1 course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score) end + when "News" + 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, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + else + score = course_contributor_score.news_num + 1 + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:news_num => score, :total_score => total_score) + end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 69753d81c..4d7af1d73 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -82,9 +82,7 @@ class Comment < ActiveRecord::Base # 课程成员得分(英雄榜) def act_as_student_score if self.commented.course - unless self.author.allowed_to?(:as_teacher, self.commented.course) - course_member_score(self.commented.course.id, self.author_id, "NewReply") - end + course_member_score(self.commented.course.id, self.author_id, "NewReply") end end diff --git a/app/models/course_contributor_score.rb b/app/models/course_contributor_score.rb index 0b1ccf5d9..4f3b3e187 100644 --- a/app/models/course_contributor_score.rb +++ b/app/models/course_contributor_score.rb @@ -1,5 +1,6 @@ -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, :total_score, :homework_journal_num - belongs_to :course - belongs_to :user -end +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, :total_score, :homework_journal_num, :news_num + belongs_to :course + belongs_to :user +end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 1c7a05cb1..7990979e4 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -283,7 +283,7 @@ class JournalsForMessage < ActiveRecord::Base end end - # 课程成员得分(英雄榜) + # 课程成员得分(活跃度) def act_as_student_score if self.jour_type == "Course" course_member_score(self.jour_id, self.user_id, "JournalForMessage") diff --git a/app/models/message.rb b/app/models/message.rb index 24bda5610..44f2d2c80 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -341,17 +341,15 @@ class Message < ActiveRecord::Base delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE end - # 课程成员得分(英雄榜) + # 课程成员得分(活跃度) def act_as_student_score if self.course - unless self.author.allowed_to?(:as_teacher, self.course) - if self.parent_id.nil? - # 发帖 - course_member_score(self.course.id, self.author_id, "Message") - else - # 回帖 - course_member_score(self.course.id, self.author_id, "MessageReply") - end + if self.parent_id.nil? + # 发帖 + course_member_score(self.course.id, self.author_id, "Message") + else + # 回帖 + course_member_score(self.course.id, self.author_id, "MessageReply") end end end diff --git a/app/models/news.rb b/app/models/news.rb index f31c6bcef..028b6d737 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -59,7 +59,7 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count + after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score after_update :update_activity after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities @@ -195,4 +195,10 @@ class News < ActiveRecord::Base OrgActivity.where("container_type='OrgSubfield' and org_act_type='News' and org_act_id=?", self.id).destroy_all end + def act_as_student_score + if self.course + course_member_score(self.course.id, self.author_id, "News") + end + end + 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 4940b60d6..ceb526f44 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -148,9 +148,10 @@ 资源得分:资源数 x 5
发帖得分:发帖数 x 2
回帖得分:回复数 x 1
+ 通知得分:通知数 x 1
课程留言得分:留言数 x 1
作业留言得分:留言数 x 1
- 通知得分:通知数 x 1
+ 通知回复得分:回复数 x 1
总得分为以上得分之和 @@ -162,7 +163,8 @@ <%=total_score = contributor_score.resource_num.to_i * 5 + contributor_score.message_num.to_i * 2 + contributor_score.message_reply_num.to_i * 1 + contributor_score.journal_num.to_i * 1 + - + contributor_score.homework_journal_num * 1 + contributor_score.news_reply_num.to_i * 1 %>

+ + contributor_score.homework_journal_num.to_i * 1 + contributor_score.news_reply_num.to_i * 1 + + contributor_score.news_num.to_i * 1 %>

diff --git a/db/migrate/20160304154005_add_news_num_to_course_contributor_scores.rb b/db/migrate/20160304154005_add_news_num_to_course_contributor_scores.rb new file mode 100644 index 000000000..4cb1679f5 --- /dev/null +++ b/db/migrate/20160304154005_add_news_num_to_course_contributor_scores.rb @@ -0,0 +1,5 @@ +class AddNewsNumToCourseContributorScores < ActiveRecord::Migration + def change + add_column :course_contributor_scores, :news_num, :integer , :default => 0 + end +end diff --git a/db/migrate/20160304200639_update_contributor.rb b/db/migrate/20160304200639_update_contributor.rb new file mode 100644 index 000000000..d90699b91 --- /dev/null +++ b/db/migrate/20160304200639_update_contributor.rb @@ -0,0 +1,51 @@ +class UpdateContributor < ActiveRecord::Migration + def up + Course.all.each do |course| + if course.course_activities.count > 1 + course.members.each do |s| + puts course.id + puts course.name + puts s.user_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.user_id} and me.parent_id is null;").count + # 回帖数 + 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.user_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.user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1 + # 通知 + common_count = News.find_by_sql("select n.* from news n where n.author_id = #{s.user_id} and n.course_id = #{course.id} ").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.user_id} and container_type ='Course'").count + # 课程留言数 + journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.user_id, course.id, "Course").count * 1 + # 作业留言 + journal_homework_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.user_id, course.id, "HomeworkCommon").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 + course_contributor = CourseContributorScore.where("course_id =? and user_id =?", course.id, s.user_id).first + if course_contributor.nil? + CourseContributorScore.create(:course_id => course.id, :user_id => s.user_id, :message_num => board_count, :message_reply_num => message_reply_count, + :news_reply_num => common_reply_count, :news_num => common_count, :resource_num => attachment_count, :journal_num => journal_count, + :homework_journal_num => journal_homework_count, :journal_reply_num => 0, :total_score => total) + else + course_contributor.message_num = board_count + course_contributor.message_reply_num = message_reply_count + course_contributor.news_reply_num = common_reply_count + course_contributor.news_num = common_count + course_contributor.resource_num = attachment_count + course_contributor.journal_num = journal_count + course_contributor.homework_journal_num = journal_homework_count + course_contributor.save + end + + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 9b2b6e942..c21580c90 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 => 20160303103231) do +ActiveRecord::Schema.define(:version => 20160304154643) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -99,6 +99,8 @@ ActiveRecord::Schema.define(:version => 20160303103231) do t.integer "quotes" t.integer "version" t.integer "attachment_id" + t.integer "is_publish", :default => 1 + t.date "publish_time" end create_table "attachments", :force => true do |t| @@ -434,6 +436,7 @@ ActiveRecord::Schema.define(:version => 20160303103231) do t.datetime "updated_at", :null => false t.integer "total_score" t.integer "homework_journal_num", :default => 0 + t.integer "news_num", :default => 0 end create_table "course_groups", :force => true do |t| @@ -1277,7 +1280,6 @@ ActiveRecord::Schema.define(:version => 20160303103231) do t.text "description" t.integer "creator_id" t.integer "home_id" - t.string "domain" t.boolean "is_public" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false @@ -1385,7 +1387,6 @@ ActiveRecord::Schema.define(:version => 20160303103231) do t.integer "changeset_num", :default => 0 t.integer "board_message_num", :default => 0 t.integer "board_num", :default => 0 - t.integer "act_num", :default => 0 t.integer "attach_num", :default => 0 t.datetime "commit_time" end