创建课程数、加入课程数、创建项目数、加入项目数统计问题

This commit is contained in:
sw 2015-08-01 14:58:41 +08:00
parent 1cd50693b5
commit 793f477f1c
1 changed files with 20 additions and 8 deletions

View File

@ -332,33 +332,45 @@ module UsersHelper
end end
def get_create_course_count(user) def get_create_course_count(user)
if user == User.current user.courses.visible.where("tea_id = ?",user.id).count
user.courses.count
else
user.courses.where("is_public = 1").count
end
end end
#获取加入课程数
def get_join_course_count(user) def get_join_course_count(user)
user.coursememberships.count - get_create_course_count(user) user.courses.visible.count - get_create_course_count(user)
end end
#发布作业数
def get_homework_commons_count(user) def get_homework_commons_count(user)
HomeworkCommon.where("user_id = ?",user.id).count HomeworkCommon.where("user_id = ?",user.id).count
end end
#资源数
def get_projectandcourse_attachment_count(user) def get_projectandcourse_attachment_count(user)
Attachment.where("author_id = ? and container_type in ('Project','Course')",user.id).count Attachment.where("author_id = ? and container_type in ('Project','Course')",user.id).count
end end
#创建项目数
def get_create_project_count(user) def get_create_project_count(user)
Project.where("user_id = ? and project_type = ?",user.id,Project::ProjectType_project).count user.projects.visible.where("projects.user_id=#{user.id}").count
end end
#加入项目数
def get_join_project_count(user) def get_join_project_count(user)
user.memberships.count(conditions: "projects.project_type = #{Project::ProjectType_project}") - get_create_project_count(user) user.projects.visible.count - get_create_project_count(user)
end end
#创建缺陷数
def get_create_issue_count(user) def get_create_issue_count(user)
Issue.where("author_id = ?",user.id).count Issue.where("author_id = ?",user.id).count
end end
#解决缺陷数
def get_resolve_issue_count(user) def get_resolve_issue_count(user)
Issue.where("assigned_to_id = ? and status_id=3",user.id).count Issue.where("assigned_to_id = ? and status_id=3",user.id).count
end end
#参与匿评数
def get_anonymous_evaluation_count(user) def get_anonymous_evaluation_count(user)
StudentWorksScore.where("user_id = ? and reviewer_role=3",user.id).count StudentWorksScore.where("user_id = ? and reviewer_role=3",user.id).count
end end