diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb
index c8518e8a3..a77346d89 100644
--- a/app/controllers/boards_controller.rb
+++ b/app/controllers/boards_controller.rb
@@ -70,31 +70,16 @@ class BoardsController < ApplicationController
def show
# 讨论区消息状态更新(已读和未读)
if @project
- query_forge_messages = @board.messages
- query_forge_messages.each do |query_forge_message|
- query = query_forge_message.forge_messages
- query.each do |forge_message|
- if User.current.id == forge_message.user_id
- forge_message.update_attributes(:viewed => true)
- end
- end
- end
+ ForgeMessage.where("user_id =? and project_id =? and viewed =?", User.current.id, @project.id, 0).update_all(:viewed => true)
# 更新@消息为已读
- @project.boards.each do |board|
- board.messages.each do |m|
- User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!}
- end
- end
+ # 注释掉这句是因为和上面的方法代码重复,一个类型的消息,已经更新就不需要再更新
+ # @project.boards.each do |board|
+ # board.messages.each do |m|
+ # User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!}
+ # end
+ # end
elsif @course
- query_course_messages = @board.messages
- query_course_messages.each do |query_course_message|
- query = query_course_message.course_messages
- query.each do |course_message|
- if User.current.id == course_message.user_id
- course_message.update_attributes(:viewed => true)
- end
- end
- end
+ CourseMessage.where("user_id =? and course_id =? and viewed =?", User.current.id, @course.id, 0).update_all(:viewed => true)
end
sort_init 'updated_on', 'desc'
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index dfa30915e..515b94392 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -852,7 +852,7 @@ class CoursesController < ApplicationController
# return
# end
# 统计访问量
- @course.update_attribute(:visits, @course.visits.to_i + 1)
+ @course.update_column(:visits, @course.visits.to_i + 1)
#更新创建课程消息状态
create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0)
create_course_messages.update_all(:viewed => true)
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index 7ae1b85f8..69b356b5a 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -458,10 +458,16 @@ class FilesController < ApplicationController
if params[:in_project_toolbar]
@in_project_toolbar = params[:in_project_toolbar]
end
- # 发送邮件
attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type])
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
+ # 发送邮件
Mailer.run.attachments_added(attachments[:files])
+ # 生成动态
+ attachments[:files].each do |file|
+ ForgeActivity.create(:user_id => User.current.id, :project_id => @project.id, :forge_act_id => file.id, :forge_act_type => "Attachment")
+ end
+ # 更新资源总数, 根据上传的附件数累加
+ @project.project_score.update_attribute(:attach_num, @project.project_score.attach_num + attachments[:files].count) unless @project.project_score.nil?
end
# end
if params[:project_attachment_type] && params[:project_attachment_type].is_a?(Array)
@@ -485,11 +491,6 @@ class FilesController < ApplicationController
end
end
end
- # 更新资源总数, 根据上传的附件数累加
- unless @project.project_score.nil?
- @project.project_score.update_attribute(:attach_num, @project.project_score.attach_num + attachments[:files].count)
- end
- # end
# TODO: 临时用 nyan
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 17111b3f3..b1d16debb 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -37,16 +37,6 @@ class MessagesController < ApplicationController
# Show a topic and its replies
def show
-=begin
- if @course
- topic_id = params[:r]?params[:r]:params[:id]
- parent_id = params[:id]
- url = course_boards_path(@course,:topic_id => topic_id,:parent_id=>parent_id);
- redirect_to url
- return;
- end
-=end
-
@isReply = true
page = params[:page]
# Find the page of the requested reply
@@ -54,16 +44,7 @@ class MessagesController < ApplicationController
offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
page = 1 + offset / REPLIES_PER_PAGE
end
-
@reply_count = @topic.children.count
- # @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
- # @replies = @topic.children.
- # includes(:author, :attachments, {:board => :project}).
- # reorder("#{Message.table_name}.created_on DESC").
- # limit(@reply_pages.per_page).
- # offset(@reply_pages.offset).
- # all
-
@reply = Message.new(:subject => "RE: #{@message.subject}")
if @course
messages_replies = @topic.children.
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 2ced977be..113e37af3 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -295,34 +295,32 @@ class ProjectsController < ApplicationController
def show
# 更新消息为已读
update_message_status(User.current, @project)
+ # over
if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
return
end
# 统计访问量
- @project.update_attribute(:visits, @project.visits.to_i + 1)
+ @project.update_column(:visits, @project.visits + 1)
+ # over
@author = params[:user_id].blank? ? nil : User.active.find(params[:user_id])
@page = params[:page] ? params[:page].to_i + 1 : 0
# 根据私密性,取出符合条件的所有数据
if User.current.member_of?(@project) || User.current.admin?
case params[:type]
when nil
- @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo', 'Attachment')",@project).order("updated_at desc").limit(10).offset(@page * 10)
+ @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
when 'issue'
- @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'",@project).order("updated_at desc").limit(10).offset(@page * 10)
+ @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
when 'news'
- @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'",@project).order("updated_at desc").limit(10).offset(@page * 10)
+ @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
when 'message'
- @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'",@project).order("updated_at desc").limit(10).offset(@page * 10)
+ @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
when 'attachment'
- @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Attachment'",@project).order("updated_at desc").limit(10).offset(@page * 10)
+ @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Attachment'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
end
else
- @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public
- = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc")
- .page(params['page'|| 1]).per(10);
+ @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10);
end
- boards = @project.boards.includes(:last_message => :author).all
- @topic_count = @project.boards.count
# 根据对应的请求,返回对应的数据
respond_to do |format|
format.html
@@ -560,18 +558,9 @@ class ProjectsController < ApplicationController
end
def update_message_status(user, project)
- project_invite_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =?", user, project, "ProjectInvite")
- project_invite_messages.each do |project_invite_message|
- project_invite_message.update_attribute(:viewed, true)
- end
- #更新被加入项目消息的viewed字段
- join_project_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type=?", user, project, "JoinProject")
- join_project_messages.each do |join_project|
- join_project.update_attribute(:viewed, true)
- end
- #更新被移出项目消息的viewed字段
- remove_project_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type=?", user, project, "RemoveFromProject")
- remove_project_messages.update_all(:viewed => true)
+ # 更新加入项目消息
+ project__messages = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'JoinProject', 'RemoveFromProject') and user_id =? and project_id =? ", user, project)
+ project__messages.update_all(:viewed => true) unless project__messages.blank?
end
def message_invite(message_id, key)
diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb
index a698823e5..71b23fdcf 100644
--- a/app/controllers/student_work_controller.rb
+++ b/app/controllers/student_work_controller.rb
@@ -230,12 +230,12 @@ class StudentWorkController < ApplicationController
render_403
return
end
-
@student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name).count
end
@score = @b_sort == "desc" ? "asc" : "desc"
-
+ # 消息传过来的ID
+ @message_student_work_id = params[:student_work_id]
respond_to do |format|
format.js
format.html
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index d05867427..123f1fc96 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -119,49 +119,46 @@ class UsersController < ApplicationController
# @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count
case params[:type]
when nil
+ # 系统消息为管理员发送,我的消息中包含有系统消息
@message_alls = []
- messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user, "SystemMessage", "SystemMessage").order("created_at desc")
+ messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc")
messages.each do |message_all|
@message_alls << message_all.message
end
when 'unviewed'
@message_alls = []
- messages = MessageAll.where("user_id =?", @user).order("created_at desc")
+ messages = MessageAll.where("user_id =?", @user.id).includes(:message).order("created_at desc")
messages.each do |message_all|
# 在点击或者刷新消息列表后未读的消息存放在数组
if message_all.message_type != "SystemMessage"&& !message_all.message.nil? && message_all.message.viewed == 0
@message_alls << message_all.message
end
end
-
#课程相关消息
when 'homework'
- @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?", @user).order("created_at desc")
+ @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?", @user.id).order("created_at desc")
when 'course_message'
- @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc")
+ @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user.id).order("created_at desc")
when 'course_news'
# 课程通知包含发布的通知和回复的通知
- @message_alls = CourseMessage.where("course_message_type in (?, ? ,?)", "News", "Comment", "Course").where("user_id =?", @user).order("created_at desc")
+ @message_alls = CourseMessage.where("course_message_type in ('News', 'Comment') and user_id =?", @user.id).order("created_at desc")
when 'poll'
- @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc")
-
+ @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user.id).order("created_at desc")
#项目相关消息
when 'issue'
- @message_alls = ForgeMessage.where("forge_message_type =? or forge_message_type =?" , "Issue", "Journal").where("user_id=?", @user).order("created_at desc")
+ @message_alls = ForgeMessage.where("forge_message_type in ('Issue', 'Journal') and user_id =?" , @user.id).order("created_at desc")
when 'forge_message'
- @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user).order("created_at desc")
+ @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user.id).order("created_at desc")
when 'forge_news'
- @message_alls = ForgeMessage.where("forge_message_type in (?,?) and user_id =?", "News", "Comment", @user).order("created_at desc")
+ @message_alls = ForgeMessage.where("forge_message_type in (?,?) and user_id =?", "News", "Comment", @user.id).order("created_at desc")
when 'apply'
- @message_alls = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?", @user).order("created_at desc")
-
+ @message_alls = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?", @user.id).order("created_at desc")
#贴吧消息
when 'forum'
- @message_alls = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc")
-
+ @message_alls = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user.id).order("created_at desc")
#用户留言
when 'user_feedback'
- @message_alls = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "JournalsForMessage", @user).order("created_at desc")
+ @message_alls = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "JournalsForMessage", @user.id).order("created_at desc")
else
render_404
return
@@ -1209,9 +1206,7 @@ class UsersController < ApplicationController
def show
# 统计访问量
- unless User.current == @user
- @user.update_attribute(:visits, @user.visits.to_i + 1)
- end
+ @user.update_column(:visits, @user.visits.to_i + 1) unless User.current == @user
#更新用户申请成为课程老师或教辅消息的状态
if params[:course_id] != nil
join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?",
@@ -1253,7 +1248,12 @@ class UsersController < ApplicationController
end
else
# @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10)
- blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
+ # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
+ # 减少数据库交互
+ user_ids = "(" + @user.id.to_s + "," + User.watched_by(@user.id).map{|u| u.id }.join(',') + ")"
+ watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
+ blog_ids = "(" + watched_user_blog_ids + ")"
+
@user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 3a5cdb1a1..6432d83d8 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -764,7 +764,7 @@ module ApplicationHelper
# 判断版本库是否初始为gitlab
def rep_is_gitlab?(project)
- rep = Repository.where("project_id =? and type =?", project, "Repository::Gitlab")
+ rep = project.repositories.where("type =?", "Repository::Gitlab")
return rep.blank? ? true :false
end
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index 37c7deb4c..36eebe4f2 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -24,40 +24,20 @@ module CoursesHelper
def find_excelletn_course keywords, current_course
# 获取tag匹配结果ID
a_tags = []
- # kc = keywords.to_a
- Course.visible.where("is_excellent =? and is_public =?", 1, 1).each do |ec|
+ Course.where("is_excellent =? and is_public =?", 1, 1).includes(:tags).each do |ec|
if ec.tags.any?{|value| current_course.name.include?(value.to_s)}
a_tags << ec.id
end
end
- # sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and
- # ts.taggable_type = 'Course' and t.name like '%#{keywords}%'"
- # a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)}
- # 通过elastic结果获取精品课程
- a_courses = []
- #courses = Course.search(keywords)
- #courses.each do |c|
- # a_courses << c.id
- #end
- a_courses << a_tags unless a_tags.length == 0
# 课程本身不能搜索显示自己
- excellent_ids = a_courses.flatten.uniq.delete_if{|i| i == current_course.id}
- limit = 5 - excellent_ids.length.to_i
+ excellent_ids = a_tags.uniq.delete_if{|i| i == current_course.id}
sql = "SELECT distinct c.id FROM course_activities cs, courses c where cs.course_id = c.id
- and c.is_excellent =1 and c.is_public = 1 and c.id != #{current_course.id} order by cs.updated_at desc;"
- default_ecourse_ids = Course.find_by_sql(sql).flatten
- # REDO:时间紧,待优化
- default_ids =[]
- default_ecourse_ids.each do |de|
- default_ids << de.id
- end
- default_ids = default_ids - excellent_ids
- #default_ecourse = Course.where("id is not in (?)", ids).find_by_sql(sql).flatten.delete_if{|i| i == current_course.id}.flatten
- arr_result = excellent_ids << default_ids
- arr_result = arr_result.flatten.first(5)
- return arr_result
- # 过滤条件:精品课程、本身不在搜索范围
- #e_courses = Course.where("is_excellent =? and id in (?)",1, arr_result).where("id !=?", current_course.id)
+ and (c.is_excellent =1 or c.excellent_option =1) and c.is_public = 1 and c.id != #{current_course.id} order by cs.updated_at desc;"
+ default_ids = Course.find_by_sql(sql).flatten.map { |c| c.id }
+ excellent_ids << default_ids.flatten
+ arr_result = excellent_ids.flatten.uniq.first(5)
+ excellent_courses = Course.find(arr_result)
+ return excellent_courses
end
# 判断精品课程是否可见,非课程成员无法查看私有课程
@@ -258,7 +238,7 @@ module CoursesHelper
# 学生人数计算
# add by nwb
def studentCount course
- course ? course.student.count.to_s : 0#course.student.count
+ course ? course.student.count.to_i : 0#course.student.count
end
#课程成员数计算
@@ -293,12 +273,17 @@ module CoursesHelper
def searchTeacherAndAssistant project
#searchPeopleByRoles(project, TeacherRoles)
members = []
- project.members.each do |m|
+ project.members.includes(:user).each do |m|
members << m if m && m.user && m.user.allowed_to?(:as_teacher,project)
end
members
end
+ def TeacherAndAssistantCount course
+ students_count = course.student.count
+ number = course.members.count - students_count
+ end
+
def search_student_in_group(project, course_group_id)
#searchPeopleByRoles(project, StudentRoles)
members = []
@@ -766,7 +751,7 @@ module CoursesHelper
#加入课程、退出课程按钮
def join_in_course_header(course, user, options=[])
if user.logged?
- joined = course.members.map{|member| member.user_id}.include? user.id
+ joined = course.members.includes(:user).map{|member| member.user_id}.include? user.id
text = joined ? l(:label_course_exit_student) : l(:label_course_join_student)
url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id)
method = joined ? 'delete' : 'post'
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index 4ad3cb49d..1cd22558b 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -111,9 +111,9 @@ module IssuesHelper
def principals_options_for_isuue_list(project)
if User.current.member_of?(project)
- project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0])
+ project.members.includes(:user).order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0])
else
- project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["指派给", 0])
+ project.members.includes(:user).order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["指派给", 0])
end
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 714da9920..881621c3a 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -90,7 +90,7 @@ class Attachment < ActiveRecord::Base
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
before_save :files_to_final_location
- after_save :act_as_course_activity,:act_as_forge_activity
+ after_save :act_as_course_activity
after_create :office_conver, :be_user_score,: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, :down_course_score
diff --git a/app/models/project.rb b/app/models/project.rb
index 32677143d..184b3c7af 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -108,7 +108,8 @@ class Project < ActiveRecord::Base
has_many :tags, :through => :project_tags, :class_name => 'Tag'
has_many :project_tags, :class_name => 'ProjectTags'
# 动态级联删除
- has_many :forge_activities, :class_name => 'ForgeActivity', :dependent => :destroy
+ has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
+ #has_many :forge_activities, :class_name => 'ForgeActivity', :as =>:forge_act, :dependent => :destroy
# 关联虚拟表
has_many :forge_messages, :class_name =>'ForgeMessage', :as => :forge_message, :dependent => :destroy
@@ -1212,9 +1213,7 @@ class Project < ActiveRecord::Base
# Author lizanle
# Description 新建项目要在ForgeActivities中加一条数据。
def acts_as_forge_activities
- fa = ForgeActivity.new(:user_id => User.current.id,:project_id => self.id,
- :forge_act_id => self.id,:forge_act_type => "ProjectCreateInfo")
- fa.save!
+ self.forge_acts << ForgeActivity.new(:user_id => User.current.id, :project_id => self.id)
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 78d823ea7..2a9a13c73 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -339,13 +339,15 @@ class User < Principal
message_new_time.onclick_time = User.current.last_login_on.nil? ? Time.now : User.current.last_login_on
message_new_time.save
end
- course_count = CourseMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count
- forge_count = ForgeMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count
- user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count
- user_memo_count = MemoMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count
- system_messages_count = SystemMessage.where("created_at >?", User.current.onclick_time.onclick_time).count
- at_count = AtMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count
- org_count = OrgMessage.where("user_id=? and viewed =? and created_at >?", User.current.id,0, User.current.onclick_time.onclick_time).count
+ user = User.current
+ onclick_time = user.onclick_time.onclick_time
+ course_count = CourseMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
+ forge_count = ForgeMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
+ user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
+ user_memo_count = MemoMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
+ system_messages_count = SystemMessage.where("created_at >?", onclick_time).count
+ at_count = AtMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
+ org_count = OrgMessage.where("user_id=? and viewed =? and created_at >?", user.id,0, onclick_time).count
messages_count = course_count + forge_count + user_feedback_count + user_memo_count + system_messages_count + at_count + org_count
end
diff --git a/app/views/boards/_course_show_detail.html.erb b/app/views/boards/_course_show_detail.html.erb
index bc7b9667e..d465571c5 100644
--- a/app/views/boards/_course_show_detail.html.erb
+++ b/app/views/boards/_course_show_detail.html.erb
@@ -2,20 +2,7 @@
<%= import_ke(enable_at: false, prettify: false) %>
<%= javascript_include_tag "create_kindeditor" %>
<% end %>
-
-
-<% if topics%>
+<% if topics %>
<% topics.each do |topic| %>
<% if topic %>
- <%= render :partial => 'users/course_message', :locals => {:activity => topic, :user_activity_id => topic.id,:is_course=>1,:is_board=>1} %>
+ <%= render :partial => 'users/course_message', :locals => {:activity => topic, :user_activity_id => topic.id, :is_course => 1, :is_board=>1} %>
<% end %>
<% end %>
<% if topics.count == 10 %>
-
<%= link_to "点击展开更多",boards_topic_path(@board, :course_id => @board.course.id ,:page => page),:id => "show_more_course_topic",:remote => "true",:class => "loadMore mt10 f_grey"%>
<% end %>
<% end%>
-
diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb
index 9dd5c78ca..6cc755b61 100644
--- a/app/views/boards/show.html.erb
+++ b/app/views/boards/show.html.erb
@@ -192,6 +192,4 @@ function nh_init_board(params){
});
}
}
-
-
diff --git a/app/views/courses/_course_activity.html.erb b/app/views/courses/_course_activity.html.erb
index bdbcabff0..763748ad7 100644
--- a/app/views/courses/_course_activity.html.erb
+++ b/app/views/courses/_course_activity.html.erb
@@ -50,7 +50,7 @@
-<% course_activities.each do |activity| if course_activities %>
+<% course_activities.includes(:course_act).each do |activity| if course_activities %>
- <% if activity && activity.course_act%>
+ <% if activity && activity.course_act %>
<% act = activity.course_act %>
<% case activity.course_act_type.to_s %>
<% when 'HomeworkCommon' %>
diff --git a/app/views/courses/_course_activity_users.html.erb b/app/views/courses/_course_activity_users.html.erb
new file mode 100644
index 000000000..a0cac45f7
--- /dev/null
+++ b/app/views/courses/_course_activity_users.html.erb
@@ -0,0 +1,59 @@
+<% unless contributor_course_scor(course.id).count == 0 %>
+
+ 课程活跃度
+ 积分规则
+
+
+
+ 积分规则
+ 资源发布:资源数 x 5
+ 问答发布:发帖数 x 2
+ 通知发布:通知数 x 1
+ 问答回复:回复数 x 1
+ 作业留言:留言数 x 1
+ 通知留言:留言数 x 1
+ 课程留言:留言数 x 1
+ 总得分为以上得分之和
+
+ <% contributor_course_scor(course.id).each do |contributor_score| %>
+ <% 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.to_i * 1 + contributor_score.news_reply_num.to_i * 1 +
+ contributor_score.news_num.to_i * 1 %>
+ <% unless total_score ==0 %>
+ - <%=link_to image_tag(url_to_avatar(contributor_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(contributor_score.user) %>
+
<%=link_to contributor_score.user.show_name, user_path(contributor_score.user.id), :title => contributor_score.user.show_name %>
+
+
+ <%=total_score %>
+
+
积分计算
+ <%# unless contributor_score.resource_num.to_i == 0 %>
+
+ 资源发布数 x 5 = <%= contributor_score.resource_num.to_i %> x 5 = <%= contributor_score.resource_num.to_i * 5 %>
+ <%# end %>
+ <%# unless contributor_score.message_num.to_i == 0 %>
+ 问答发布数 x 2 = <%= contributor_score.message_num.to_i %> x 2 = <%= contributor_score.message_num.to_i * 2 %>
+ 通知发布数 x 1 = <%= contributor_score.news_num.to_i %> x 1 = <%= contributor_score.news_num.to_i %>
+ <%# end %>
+ <%# unless contributor_score.message_reply_num.to_i == 0 %>
+ 问答回帖数 x 1 = <%= contributor_score.message_reply_num.to_i %> x 1 = <%= contributor_score.message_reply_num.to_i %>
+ 作业留言数 x 1 = <%= contributor_score.homework_journal_num.to_i %> x 1 = <%= contributor_score.homework_journal_num.to_i %>
+ 通知留言数 x 1 = <%= contributor_score.news_reply_num.to_i %> x 1 = <%= contributor_score.news_reply_num.to_i %>
+ <%# end %>
+ <%# unless contributor_score.journal_num.to_i == 0 %>
+ 课程留言数 x 1 = <%= contributor_score.journal_num.to_i %> x 1 = <%= contributor_score.journal_num.to_i %>
+ <%# end %>
+ <%# unless contributor_score.homework_journal_num.to_i == 0 %>
+ <%# end %>
+ <%# unless contributor_score.news_reply_num.to_i == 0 %>
+ <%# end %>
+ 总得分:<%=total_score %>
+
+
+
+ <% end %>
+ <% end %>
+
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/courses/_course_heroes.html.erb b/app/views/courses/_course_heroes.html.erb
new file mode 100644
index 000000000..5e9851594
--- /dev/null
+++ b/app/views/courses/_course_heroes.html.erb
@@ -0,0 +1,21 @@
+<% hero_homework_scores = hero_homework_score(course, "desc") %>
+<% unless hero_homework_scores.map(&:score).detect{|s| s.to_i != 0}.nil? %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/courses/_recommendation.html.erb b/app/views/courses/_recommendation.html.erb
index a0c659493..63803a5b9 100644
--- a/app/views/courses/_recommendation.html.erb
+++ b/app/views/courses/_recommendation.html.erb
@@ -1,22 +1,21 @@
-<% unless excellent_course_recommend(course).length == 0 %>
+<% exc_course = excellent_course_recommend(course) %>
+<% unless exc_course.length == 0 %>
<%= l(:label_homework_recommendation) %>:
- <% excellent_course_recommend(course).each do |e_course| %>
- <% e_course = Course.find(e_course) %>
-
+ <% exc_course.each do |e_course| %>
- <%= image_tag(url_to_avatar(e_course), :width => "40", :height => "40", :class => "fl mr10 rankPortrait", :alt => "logo") %>
<%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %>
- <% if visable_attachemnts_incourse(e_course).count > 0 %>
- <%= l(:project_module_attachments) %>(<%= link_to visable_attachemnts_incourse(e_course).count, course_files_path(e_course), :class => "linkBlue2" %>)
+ <% if course_file_num > 0 %>
+ <%= l(:project_module_attachments) %>(<%= link_to course_file_num, course_files_path(e_course), :class => "linkBlue2" %>)
<% end %>
<% if e_course.homework_commons.where("publish_time <= '#{Date.today}'").count > 0 %>
<%= l(:label_homework_commont) %>(<%= link_to e_course.homework_commons.where("publish_time <= '#{Date.today}'").count, homework_common_index_path(:course=>e_course.id), :class => "linkBlue2" %>)
<% end %>
-
-
+
+
<% end %>
diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb
index 315b1d300..c04081128 100644
--- a/app/views/layouts/_logined_header.html.erb
+++ b/app/views/layouts/_logined_header.html.erb
@@ -24,19 +24,6 @@
+
@@ -44,8 +44,6 @@
-
- <%#= render :partial => 'layouts/new_header'%>
@@ -104,20 +102,6 @@
- <%# if User.current.member_of?(@project) %>
-
-
-
-
-
-
-
-
-
- <%# end %>
-
- <%#--project_new_type: 1为开发组;2为科研组;3为朋友圈子--%>
-
<% if @project.project_new_type == 1 || @project.project_new_type.nil? %>
<%= render :partial => 'projects/development_group', :locals => {:project => @project} %>
diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb
index c90c69f75..a613d8984 100644
--- a/app/views/layouts/new_base_user.html.erb
+++ b/app/views/layouts/new_base_user.html.erb
@@ -204,7 +204,13 @@
<% end%>
<% end%>
- <% courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %>
+ <% course_order_ids = "(" +
+ CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM
+ (SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ")
+ GROUP BY ca.course_id) AS c
+ ORDER BY c.updated_at DESC limit 5").map {|c| c.course_id}.join(",") + ")"%>
+ <% courses = Course.where("id in #{course_order_ids}")%>
+ <%# courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %>
- <% projects = @user.projects.visible.select("projects.*,(SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)%>
+ <% project_order_ids = "(" +
+ ForgeActivity.find_by_sql("SELECT p.project_id, p.created_at FROM
+ (SELECT fa.project_id, MAX(fa.created_at) AS created_at FROM forge_activities fa WHERE fa.project_id IN (" + @user.projects.visible.select('projects.id').map{|p| p.id}.join(',') + ")
+ GROUP BY fa.project_id) AS p
+ ORDER BY p.created_at DESC limit 5").map {|p| p.project_id}.join(",") + ")"%>
+ <%# project_order_ids = "(" + ForgeActivity.select("DISTINCT project_id, max(created_at) as max_created_at").where("project_id in #{"(" + @user.projects.visible.select("projects.id").map{|p| p.id}.join(",") + ")"}").order("max_created_at desc").map {|p| p.project_id}.join(",") + ")"%>
+ <% projects = Project.where("projects.id in #{project_order_ids}")%>
+ <%# projects = @user.projects.visible.select("projects.*, (SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)%>