课程模块/通知、作业、留言、发帖,删除的时候统计数字递减
This commit is contained in:
parent
f022950408
commit
f469e51202
|
@ -555,7 +555,8 @@ class FilesController < ApplicationController
|
|||
end
|
||||
end
|
||||
# 更新课程英雄榜得分
|
||||
update_contributor_score(@course, attachments[:files].first)
|
||||
course_member_score(@course.id, attachments[:files].first.author_id, "Attachment")
|
||||
# end
|
||||
# end
|
||||
# TODO: 临时用 nyan
|
||||
sort_init 'created_on', 'desc'
|
||||
|
@ -628,18 +629,6 @@ class FilesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_contributor_score(course, file )
|
||||
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
|
||||
|
||||
def get_project_tag_name_by_type_nmuber type
|
||||
case type
|
||||
when "1"
|
||||
|
|
|
@ -117,56 +117,102 @@ module ApplicationHelper
|
|||
when "HomeworkCommon"
|
||||
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 => 0, :journal_reply_num => 0, :homework_journal_num => 1 , :total_score => 1)
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1)
|
||||
else
|
||||
score = course_contributor_score.homework_journal_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:homework_journal_num => score, :total_score => total_score)
|
||||
course_contributor_score.update_attributes(:homework_journal_num => score)
|
||||
end
|
||||
when "JournalForMessage"
|
||||
# 课程留言
|
||||
when "Course"
|
||||
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, :total_score => 1)
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0)
|
||||
else
|
||||
score = course_contributor_score.journal_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:journal_num => score, :total_score => total_score)
|
||||
course_contributor_score.update_attributes(:journal_num => 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, :total_score => 2)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
else
|
||||
score = course_contributor_score.message_num + 2
|
||||
total_score = course_contributor_score.total_score + 2
|
||||
course_contributor_score.update_attributes(:message_num => score, :total_score => total_score)
|
||||
score = course_contributor_score.message_num + 1
|
||||
course_contributor_score.update_attributes(:message_num => 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, :total_score => 1)
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
else
|
||||
score = course_contributor_score.message_reply_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:message_reply_num => score, :total_score => total_score)
|
||||
course_contributor_score.update_attributes(:message_reply_num => 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, :total_score => 1)
|
||||
:news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
else
|
||||
score = course_contributor_score.news_reply_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score)
|
||||
course_contributor_score.update_attributes(:news_reply_num => 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)
|
||||
:news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
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)
|
||||
course_contributor_score.update_attributes(:news_num => score)
|
||||
end
|
||||
when "Attachment"
|
||||
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 => 0, :resource_num => 1, :journal_num => 0, :journal_reply_num => 0)
|
||||
else
|
||||
score = course_contributor_score.resource_num + 1
|
||||
course_contributor_score.update_attributes(:resource_num => score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 删除某条记录相应减少课程统计数
|
||||
def down_course_score_num (course_id,user_id,type)
|
||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first
|
||||
case type
|
||||
when "HomeworkCommon"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.homework_journal_num - 1
|
||||
course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score)
|
||||
end
|
||||
# 课程留言
|
||||
when "Course"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.journal_num - 1
|
||||
course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "Message"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.message_num - 1
|
||||
course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "MessageReply"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.message_reply_num - 1
|
||||
course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "NewReply"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.news_reply_num - 1
|
||||
course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "News"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.news_num - 1
|
||||
course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "Attachment"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.resource_num - 1
|
||||
course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,6 +43,7 @@ class Attachment < ActiveRecord::Base
|
|||
|
||||
#elasticsearch
|
||||
include Elasticsearch::Model
|
||||
include ApplicationHelper
|
||||
#elasticsearch kaminari init
|
||||
Kaminari::Hooks.init
|
||||
Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari
|
||||
|
@ -92,7 +93,7 @@ class Attachment < ActiveRecord::Base
|
|||
after_save :act_as_course_activity
|
||||
after_create :office_conver, :be_user_score,:act_as_forge_activity,:create_attachment_ealasticsearch_index
|
||||
after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index
|
||||
after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count
|
||||
after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count, :down_course_score
|
||||
|
||||
# add by nwb
|
||||
# 获取所有可公开的资源文件列表
|
||||
|
@ -655,6 +656,12 @@ class Attachment < ActiveRecord::Base
|
|||
self.container.project_score.update_attribute(:attach_num, attach_count < 0 ? 0 : attach_count)
|
||||
end
|
||||
end
|
||||
|
||||
def down_course_score
|
||||
if self.container_type == "Course"
|
||||
down_course_score_num(self.container_id, self.author_id, "Attachment")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Delete the previous articles index in Elasticsearch
|
||||
|
|
|
@ -36,6 +36,7 @@ class Comment < ActiveRecord::Base
|
|||
validates_presence_of :commented, :author, :comments
|
||||
safe_attributes 'comments'
|
||||
after_create :send_mail, :act_as_system_message, :act_as_student_score
|
||||
after_destroy :down_course_score
|
||||
|
||||
def act_as_system_message
|
||||
if self.commented.course
|
||||
|
@ -86,4 +87,11 @@ class Comment < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# 课程新闻数减少
|
||||
def down_course_score
|
||||
if self.commented.course
|
||||
down_course_score_num(self.commented.course.id, self.author_id, "NewReply")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -73,7 +73,7 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
#after_update :update_activity
|
||||
after_destroy :reset_counters!
|
||||
after_save :be_user_score
|
||||
after_destroy :down_user_score
|
||||
after_destroy :down_user_score, :down_course_score
|
||||
|
||||
# default_scope { where('m_parent_id IS NULL') }
|
||||
|
||||
|
@ -184,6 +184,7 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 更新用户分数 -by zjc
|
||||
def down_user_score
|
||||
#删除了留言回复
|
||||
|
@ -286,10 +287,19 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
# 课程成员得分(活跃度)
|
||||
def act_as_student_score
|
||||
if self.jour_type == "Course"
|
||||
course_member_score(self.jour_id, self.user_id, "JournalForMessage")
|
||||
course_member_score(self.jour_id, self.user_id, "Course")
|
||||
elsif self.jour_type == "HomeworkCommon"
|
||||
course_member_score(self.jour.course_id, self.user_id, "HomeworkCommon")
|
||||
end
|
||||
end
|
||||
|
||||
# 删除操作的时候相应扣掉回复数
|
||||
def down_course_score
|
||||
if self.jour_type == "Course"
|
||||
down_course_score_num(self.jour_id, self.user_id, "Course")
|
||||
elsif self.jour_type == "HomeworkCommon"
|
||||
down_course_score_num(self.jour.course_id, self.user_id, "HomeworkCommon")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -79,7 +79,7 @@ class Message < ActiveRecord::Base
|
|||
|
||||
after_create :add_author_as_watcher, :reset_counters!, :add_boards_count
|
||||
after_update :update_messages_board, :update_activity
|
||||
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count
|
||||
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score
|
||||
|
||||
after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score, :act_as_at_message
|
||||
#before_save :be_user_score
|
||||
|
@ -354,6 +354,18 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# 删除帖子的时候更新课程帖子总数, 删除回复的时候减少总数
|
||||
def down_course_score
|
||||
if self.course
|
||||
if self.parent_id.nil? # 发帖
|
||||
down_course_score_num(self.course.id, self.author_id, "Message")
|
||||
else
|
||||
# 回帖
|
||||
down_course_score_num(self.course.id, self.author_id, "MessageReply")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete_org_activities
|
||||
OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all
|
||||
end
|
||||
|
|
|
@ -61,7 +61,7 @@ class News < ActiveRecord::Base
|
|||
|
||||
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
|
||||
after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score
|
||||
|
||||
scope :visible, lambda {|*args|
|
||||
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
|
||||
|
@ -195,10 +195,18 @@ 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
|
||||
|
||||
# 删除新闻统计数减少
|
||||
def down_course_score
|
||||
if self.course
|
||||
down_course_score_num(self.course.id, self.author_id, "News")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -163,8 +163,8 @@
|
|||
+ contributor_score.homework_journal_num.to_i * 1 + contributor_score.news_reply_num.to_i * 1 +
|
||||
contributor_score.news_num.to_i * 1 %>
|
||||
<% unless total_score ==0 %>
|
||||
<li> <a href="javascript:void:(0);"><%=link_to image_tag(url_to_avatar(contributor_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(contributor_score.user) %></a>
|
||||
<p><a href="javascript:void:(0);"><%=link_to contributor_score.user.show_name, user_path(contributor_score.user), :title => contributor_score.user.show_name %></a></p>
|
||||
<li><%=link_to image_tag(url_to_avatar(contributor_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(contributor_score.user) %>
|
||||
<p><%=link_to contributor_score.user.show_name, user_path(contributor_score.user.id), :title => contributor_score.user.show_name %></p>
|
||||
<p><span class="c_green" style="cursor:pointer">
|
||||
<a onmouseover ="message_titile_show($(this),event)" onmouseout ="message_titile_hide($(this))" class="c_green">
|
||||
<%=total_score %></a></span></p>
|
||||
|
|
|
@ -1387,7 +1387,6 @@ ActiveRecord::Schema.define(:version => 20160304234903) 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
|
||||
|
|
Loading…
Reference in New Issue