add course activity

This commit is contained in:
kg 2014-04-24 09:13:06 +08:00
parent 271427d29e
commit 709629bcdf
2 changed files with 117 additions and 1 deletions

View File

@ -185,6 +185,109 @@ class ProjectsController < ApplicationController
@project_count = @projects_all.count
@project_pages = Paginator.new @project_count, per_page_option, params['page']
#gcm activity count
@project_activity_count=Hash.new
@projects_all.each do |project|
@project_activity_count[project.id]=1
end
project_ids=@project_activity_count.keys()
days = Setting.activity_days_default.to_i
date_to ||= Date.today + 1
date_from = date_to - days-1.years
#approach 1
=begin
@projects_all.each do |project|
#issue_count
issues=Issue.where("project_id=?",project.id)
issue_count=0
issues.each do |issue|
issue_count+=issue.journals.count
end
#repository_count
repositories=Repository.where("project_id=?",project.id)
repository_count=0
repositories.each do |repository|
repository_count+=repository.changesets.count
end
#news_count
news_count=News.where("project_id=?",project.id).count
#document_count
document_count=Document.where("project_id=?",project.id).count
#file_count
file_count=Attachment.where("container_type='Project' AND container_id=?",project.id).count
#message_count
boards=Board.where("project_id=?",project.id)
message_count=0
boards.each do |board|
message_count+=board.messages.count
end
#time_entry_count
time_entry_count=TimeEntry.where("project_id=?",project.id).count
#sum
@project_activity_count[project.id.to_s]=issue_count+repository_count+news_count+document_count+file_count+message_count+time_entry_count
end
=end
#gcm
#gcm approach 2
#issue_count
Issue.where(project_id: project_ids).where("updated_on>?",date_from).each do |issue|
# @project_activity_count[issue.project_id.to_s]+=1
@project_activity_count[issue.project_id]+=issue.journals.where("created_on>?",date_from).count
end
#repository_count
Repository.where(project_id: project_ids).each do |repository|
# @project_activity_count[repository.project_id.to_s]+=1
@project_activity_count[repository.project_id]+=repository.changesets.where("committed_on>?",date_from).count
end
#news_count
News.where(project_id: project_ids).where("created_on>?",date_from).each do |news|
@project_activity_count[news.project_id]+=1
end
#document_count
Document.where(project_id: project_ids).where("created_on>?",date_from).each do |document|
@project_activity_count[document.project_id]+=1
end
#file_count
Attachment.where(container_id: project_ids).where("container_type='Project' AND created_on>?",date_from).each do |attachment|
@project_activity_count[attachment.container_id]+=1
end
#message_count
Board.where(project_id: project_ids).take(1) do |board|
# @project_activity_count[board.project_id]+=1
@project_activity_count[board.project_id]+=board.messages.where("updated_on>?",date_from).count
end
#time_entry_count
TimeEntry.where(project_id: project_ids).where("updated_on>?",date_from).each do |timeentry|
@project_activity_count[timeentry.project_id]+=1
end
@project_activity_count_array=@project_activity_count.values()
max_ac=@project_activity_count_array.max
#gcm end
case params[:project_sort_type]
when '0'
@ -575,7 +678,7 @@ class ProjectsController < ApplicationController
"show_journals_for_messages" => true
}
@date_to ||= Date.today + 1
@date_from = @date_to - @days
@date_from = @date_to - @days-1.years
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
# 决定显示所用用户或单个用户活动
@ -880,4 +983,8 @@ class ProjectsController < ApplicationController
@users -= watched.watcher_users
end
end
def desc_sort_course_by_avtivity(projects,ids,activities)
end
end

View File

@ -45,6 +45,15 @@
<%= content_tag('span', link_to("#{@project.members.count}", member_project_path(@project)), :class => "info") %>
<%= content_tag('span', l(:label_x_member, :count => @project.members.count)) %>
</p>
<!--gcm-->
<p class="stats">
<%= content_tag('span', link_to("#{@project_activity_count[@project.id]}", member_project_path(@project)), :class => "info") %>
<%= content_tag('span', l(:label_x_activity, :count => @project_activity_count[@project.id])) %>
</p>
<!--gcm-->
<div class="buttons_for_course" style="margin-top:30px;margin-left:144px">
<span class="info"></span>
<% if @project.project_type==Project::ProjectType_course %>