数据迁移
This commit is contained in:
parent
38fca02193
commit
f381784a3c
|
@ -629,7 +629,6 @@ class FilesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_contributor_score(course, file )
|
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
|
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first
|
||||||
if course_contributor_score.nil?
|
if course_contributor_score.nil?
|
||||||
CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0,
|
CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0,
|
||||||
|
@ -640,7 +639,6 @@ class FilesController < ApplicationController
|
||||||
course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score)
|
course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def get_project_tag_name_by_type_nmuber type
|
def get_project_tag_name_by_type_nmuber type
|
||||||
case type
|
case type
|
||||||
|
|
|
@ -110,8 +110,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 更新课程英雄榜得分
|
# 更新课程活跃度得分
|
||||||
# user传过来必须是学生
|
|
||||||
def course_member_score(course_id,user_id,type)
|
def course_member_score(course_id,user_id,type)
|
||||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first
|
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first
|
||||||
case type
|
case type
|
||||||
|
@ -160,6 +159,15 @@ module ApplicationHelper
|
||||||
total_score = course_contributor_score.total_score + 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, :total_score => total_score)
|
||||||
end
|
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 => news_num)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,10 @@ class Comment < ActiveRecord::Base
|
||||||
# 课程成员得分(英雄榜)
|
# 课程成员得分(英雄榜)
|
||||||
def act_as_student_score
|
def act_as_student_score
|
||||||
if self.commented.course
|
if self.commented.course
|
||||||
unless self.author.allowed_to?(:as_teacher, 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
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class CourseContributorScore < ActiveRecord::Base
|
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
|
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 :course
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -283,7 +283,7 @@ class JournalsForMessage < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 课程成员得分(英雄榜)
|
# 课程成员得分(活跃度)
|
||||||
def act_as_student_score
|
def act_as_student_score
|
||||||
if self.jour_type == "Course"
|
if self.jour_type == "Course"
|
||||||
course_member_score(self.jour_id, self.user_id, "JournalForMessage")
|
course_member_score(self.jour_id, self.user_id, "JournalForMessage")
|
||||||
|
|
|
@ -341,10 +341,9 @@ class Message < ActiveRecord::Base
|
||||||
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE
|
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE
|
||||||
end
|
end
|
||||||
|
|
||||||
# 课程成员得分(英雄榜)
|
# 课程成员得分(活跃度)
|
||||||
def act_as_student_score
|
def act_as_student_score
|
||||||
if self.course
|
if self.course
|
||||||
unless self.author.allowed_to?(:as_teacher, self.course)
|
|
||||||
if self.parent_id.nil?
|
if self.parent_id.nil?
|
||||||
# 发帖
|
# 发帖
|
||||||
course_member_score(self.course.id, self.author_id, "Message")
|
course_member_score(self.course.id, self.author_id, "Message")
|
||||||
|
@ -354,7 +353,6 @@ class Message < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def delete_org_activities
|
def delete_org_activities
|
||||||
OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all
|
OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddNewsNumToCourseContributorScores < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :course_contributor_scores, :news_num, :integer , :default => 0
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,43 @@
|
||||||
|
class UpdateContributorForCourse < 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 * 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.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
|
||||||
|
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
|
||||||
|
end
|
||||||
|
# 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
|
||||||
|
# 课程留言数
|
||||||
|
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
|
||||||
|
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, :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)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue