讨论区新建帖子代码优化
This commit is contained in:
parent
41aa81f966
commit
8064fe6c46
|
@ -120,59 +120,52 @@ module ApplicationHelper
|
|||
case type
|
||||
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)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1)
|
||||
else
|
||||
score = course_contributor_score.homework_journal_num + 1
|
||||
score = course_contributor_score.homework_journal_num.to_i + 1
|
||||
course_contributor_score.update_attributes(:homework_journal_num => score)
|
||||
end
|
||||
# 课程留言
|
||||
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)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1)
|
||||
else
|
||||
score = course_contributor_score.journal_num + 1
|
||||
score = course_contributor_score.journal_num.to_i + 1
|
||||
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 => 1, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1)
|
||||
else
|
||||
score = course_contributor_score.message_num + 1
|
||||
score = course_contributor_score.message_num.to_i + 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)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1)
|
||||
else
|
||||
score = course_contributor_score.message_reply_num + 1
|
||||
score = course_contributor_score.message_reply_num.to_i + 1
|
||||
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)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1)
|
||||
else
|
||||
score = course_contributor_score.news_reply_num + 1
|
||||
score = course_contributor_score.news_reply_num.to_i + 1
|
||||
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)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1)
|
||||
else
|
||||
score = course_contributor_score.news_num + 1
|
||||
score = course_contributor_score.news_num.to_i + 1
|
||||
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)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1)
|
||||
else
|
||||
score = course_contributor_score.resource_num + 1
|
||||
score = course_contributor_score.resource_num.to_i + 1
|
||||
course_contributor_score.update_attributes(:resource_num => score)
|
||||
end
|
||||
end
|
||||
|
@ -184,38 +177,38 @@ module ApplicationHelper
|
|||
case type
|
||||
when "HomeworkCommon"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.homework_journal_num - 1
|
||||
score = course_contributor_score.homework_journal_num.to_i - 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
|
||||
score = course_contributor_score.journal_num.to_i - 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
|
||||
score = course_contributor_score.message_num.to_i - 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
|
||||
score = course_contributor_score.message_reply_num.to_i - 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
|
||||
score = course_contributor_score.news_reply_num.to_i - 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
|
||||
score = course_contributor_score.news_num.to_i - 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
|
||||
score = course_contributor_score.resource_num.to_i - 1
|
||||
course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -77,12 +77,10 @@ class Message < ActiveRecord::Base
|
|||
validates_length_of :subject, :maximum => 255
|
||||
validate :cannot_reply_to_locked_topic, :on => :create
|
||||
|
||||
after_create :add_author_as_watcher, :reset_counters!, :add_boards_count
|
||||
# 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, :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(:content, :author_id)
|
||||
after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count
|
||||
#before_save :be_user_score
|
||||
|
||||
scope :visible, lambda {|*args|
|
||||
|
@ -134,11 +132,11 @@ class Message < ActiveRecord::Base
|
|||
if self.project && !project.project_score.nil?
|
||||
# 讨论区
|
||||
if self.parent_id.nil?
|
||||
count = self.project.project_score.board_num + 1
|
||||
self.project.project_score.update_attribute(:board_num, count)
|
||||
count = self.project.project_score.board_num.to_i + 1
|
||||
self.project.project_score.update_column(:board_num, count)
|
||||
else # 回复
|
||||
count = self.project.project_score.board_message_num + 1
|
||||
self.project.project_score.update_attribute(:board_message_num, count)
|
||||
count = self.project.project_score.board_message_num.to_i + 1
|
||||
self.project.project_score.update_column(:board_message_num, count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue