区分新闻和新闻回复得分

hjq_dianming_api
huang 10 years ago
parent 6ceb4f4549
commit d54609075b

@ -166,7 +166,7 @@ module ApplicationHelper
else else
score = course_contributor_score.news_num + 1 score = course_contributor_score.news_num + 1
total_score = course_contributor_score.total_score + 1 total_score = course_contributor_score.total_score + 1
course_contributor_score.update_attributes(:news_num => score, :total_score => news_num) course_contributor_score.update_attributes(:news_num => score, :total_score => total_score)
end end
end end
end end

@ -82,11 +82,7 @@ class Comment < ActiveRecord::Base
# 课程成员得分(英雄榜) # 课程成员得分(英雄榜)
def act_as_student_score def act_as_student_score
if self.commented.course if self.commented.course
if self.author.allowed_to?(:as_teacher, self.commented.course)
course_member_score(self.commented.course.id, self.author_id, "NewReply") course_member_score(self.commented.course.id, self.author_id, "NewReply")
else
course_member_score(self.commented.course.id, self.author_id, "News")
end
end end
end end

@ -59,7 +59,7 @@ class News < ActiveRecord::Base
:author_key => :author_id :author_key => :author_id
acts_as_watchable 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_update :update_activity
after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities 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 OrgActivity.where("container_type='OrgSubfield' and org_act_type='News' and org_act_id=?", self.id).destroy_all
end end
def act_as_student_score
if self.course
course_member_score(self.course.id, self.author_id, "News")
end
end
end end

@ -148,9 +148,10 @@
资源得分:资源数 x 5 </br> 资源得分:资源数 x 5 </br>
发帖得分:发帖数 x 2 </br> 发帖得分:发帖数 x 2 </br>
回帖得分:回复数 x 1 </br> 回帖得分:回复数 x 1 </br>
通知得分:通知数 x 1 </br>
课程留言得分:留言数 x 1 </br> 课程留言得分:留言数 x 1 </br>
作业留言得分:留言数 x 1 </br> 作业留言得分:留言数 x 1 </br>
通知得分:通知数 x 1 </br> 通知回复得分:回复数 x 1 </br>
总得分为以上得分之和 总得分为以上得分之和
</div> </div>
@ -162,7 +163,8 @@
<a onmouseover ="message_titile_show($(this),event)" onmouseout ="message_titile_hide($(this))" class="c_green"> <a onmouseover ="message_titile_show($(this),event)" onmouseout ="message_titile_hide($(this))" class="c_green">
<%=total_score = contributor_score.resource_num.to_i * 5 + contributor_score.message_num.to_i * 2 + <%=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.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 %></a></span></p> + contributor_score.homework_journal_num.to_i * 1 + contributor_score.news_reply_num.to_i * 1 +
contributor_score.news_num.to_i * 1 %></a></span></p>
<div style="display: none" class="numIntro"> <div style="display: none" class="numIntro">
<!--<div style="display: none" class="message_title_red system_message_style">--> <!--<div style="display: none" class="message_title_red system_message_style">-->
<!--<p><strong>评论对象:</strong><%#= ma.course_message.commented.title %></p>--> <!--<p><strong>评论对象:</strong><%#= ma.course_message.commented.title %></p>-->
@ -188,7 +190,8 @@
作业留言:留言数 x 1 = <%= contributor_score.homework_journal_num.to_i %> x 1 = <%= contributor_score.homework_journal_num.to_i %></br> 作业留言:留言数 x 1 = <%= contributor_score.homework_journal_num.to_i %> x 1 = <%= contributor_score.homework_journal_num.to_i %></br>
<%# end %> <%# end %>
<%# unless contributor_score.news_reply_num.to_i == 0 %> <%# unless contributor_score.news_reply_num.to_i == 0 %>
课程通知:通知数 x 1 = <%= contributor_score.news_reply_num.to_i %> x 1 = <%= contributor_score.news_reply_num.to_i %></br> 发布通知:通知数 x 1 = <%= contributor_score.news_num.to_i %> x 1 = <%= contributor_score.news_num.to_i %></br>
通知回复:通知数 x 1 = <%= contributor_score.news_reply_num.to_i %> x 1 = <%= contributor_score.news_reply_num.to_i %></br>
<%# end %> <%# end %>
总得分:<%=total_score %> 总得分:<%=total_score %>
</div> </div>

@ -12,11 +12,9 @@ class UpdateContributorForCourse < ActiveRecord::Migration
# 回帖数 # 回帖数
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 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
# 新闻回复 # 新闻回复
if s.user.allowed_to?(:as_teacher, course)
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_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
else # 通知
common_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 = New.find_by_sql("select n.* from news n where n.author_id = #{s.user_id} and n.course_id = #{course.id} ").count * 1
end
# attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5 # 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 * 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 * 5
@ -27,10 +25,20 @@ class UpdateContributorForCourse < ActiveRecord::Migration
# journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").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 # 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 total = board_count + message_reply_count + common_reply_count + attachment_count + journal_count
if total !=0 course_contributor = CourseContributorScore.where("course_id =? and user_id =?", course.id, s.user_id).first
CourseContributorScore.create(:course_id => course.id, :user_id => s.student_id, :message_num => board_count, :message_reply_num => message_reply_count, 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, :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) :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

@ -99,6 +99,8 @@ ActiveRecord::Schema.define(:version => 20160304154643) do
t.integer "quotes" t.integer "quotes"
t.integer "version" t.integer "version"
t.integer "attachment_id" t.integer "attachment_id"
t.integer "is_publish", :default => 1
t.date "publish_time"
end end
create_table "attachments", :force => true do |t| create_table "attachments", :force => true do |t|
@ -1278,7 +1280,6 @@ ActiveRecord::Schema.define(:version => 20160304154643) do
t.text "description" t.text "description"
t.integer "creator_id" t.integer "creator_id"
t.integer "home_id" t.integer "home_id"
t.string "domain"
t.boolean "is_public" t.boolean "is_public"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
@ -1386,7 +1387,6 @@ ActiveRecord::Schema.define(:version => 20160304154643) do
t.integer "changeset_num", :default => 0 t.integer "changeset_num", :default => 0
t.integer "board_message_num", :default => 0 t.integer "board_message_num", :default => 0
t.integer "board_num", :default => 0 t.integer "board_num", :default => 0
t.integer "act_num", :default => 0
t.integer "attach_num", :default => 0 t.integer "attach_num", :default => 0
t.datetime "commit_time" t.datetime "commit_time"
end end

Loading…
Cancel
Save