From b703c650330cef4eace36aa5aadcec1b495c97a1 Mon Sep 17 00:00:00 2001 From: yanxd Date: Fri, 13 Dec 2013 20:01:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E6=B3=A8=E5=8F=96=E6=B6=88=E5=85=B3?= =?UTF-8?q?=E6=B3=A8=E4=BD=8D=E7=BD=AE=E6=BC=82=E7=A7=BB=20=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=BB=E9=A1=B5=E5=AD=A6=E5=8F=B7=E7=9A=84=E9=9A=90?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 35 +++++++++++++++--------- app/helpers/users_helper.rb | 20 ++++++++++++++ app/models/user_extensions.rb | 7 +++++ app/views/layouts/base_projects.html.erb | 4 +-- app/views/layouts/base_users.html.erb | 4 +-- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index a1ec84ad8..ac15bd9be 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -14,16 +14,16 @@ module CoursesHelper # 返回教师数量,即roles表中定义的Manager def teacherCount project - # searchCountByRoles project, TeacherRoles + searchCountByRoles project, TeacherRoles # or - searchTeacherAndAssistant(project).count + # searchTeacherAndAssistant(project).count end # 返回学生数量,即roles表中定义的Reporter def studentCount project - # searchCountByRoles project,StudentRoles + searchCountByRoles project,StudentRoles # or - searchStudent(project).count + # searchStudent(project).count end # ===================================================================================== @@ -38,29 +38,29 @@ module CoursesHelper # ===================================================================================== def searchCountByRoles project, roles_id - people = searchPeopleByRoles project, roles_id - people.count + members = searchPeopleByRoles project, roles_id + members.count end def searchPeopleByRoles project, roles_id - people = [] + members = [] begin - people = project.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => roles_id}) + members = project.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => roles_id}) rescue Exception => e logger.error "[CoursesHelper] ===> #{e}" end - people + members end #useless - def searchPeopleByRole project, role_id - people = [] + def searchMembersByRole project, role_id + members = [] begin - people = project.members.joins(:member_roles).where("member_roles.role_id = :role_id", {:role_id => role_id }) + members = project.members.joins(:member_roles).where("member_roles.role_id = :role_id", {:role_id => role_id }) rescue Exception => e logger.error "[CoursesHelper] ===> #{e}" end - people + members end def findCourseTime project @@ -78,4 +78,13 @@ module CoursesHelper end str end + + def members_to_user_ids members + people = [] + members.each { |member| + people << member.user_id + } + people + end + end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 8fd923234..647e76657 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -214,4 +214,24 @@ module UsersHelper person_gender = user.user_extensions.gender img_uri = (person_gender == 1) ? '/images/sidebar/female.png' : '/images/sidebar/male.png' end + + include CoursesHelper + def is_watching?(user) + login_user = User.current# 登录者 + + courses = user.projects.where('project_type=1') + return true if ((login_user == user) or login_user.admin?) + courses.each do |course| + return true if login_user.member_of?(course) + end + ## 下面的代码只判断是否是老师或者助教,上面是成员都可以看到 + # people_ids = [] + # user.projects.where('project_type=1').each do |project| + # tmp = searchTeacherAndAssistant(project) + # people_ids += (members_to_user_ids(tmp)) unless tmp.nil? + # end + # people_ids.include?(login_user.id) or (login_user == user) or login_user.admin? + + false + end end diff --git a/app/models/user_extensions.rb b/app/models/user_extensions.rb index aae6ada61..64229f517 100644 --- a/app/models/user_extensions.rb +++ b/app/models/user_extensions.rb @@ -1,3 +1,10 @@ +=begin + identity字段含义 + 0 教师教授 + 1 学生 + 2 企业 + 3 开发者 +=end class UserExtensions < ActiveRecord::Base belongs_to :user attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location,:occupation,:work_experience,:zip_code,:identity, :technical_title,:student_id diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 808bb2aba..403c74878 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -62,9 +62,9 @@
<%= @project.name %>
-
+
<% unless User.current.member_of? @project %> - <%= watcher_link(@project, User.current) %> + <%= watcher_link(@project, User.current) %> <% end %>
diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index 28a76d249..923c7bf0d 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -27,7 +27,7 @@ - + <% end %> - <% if @user.user_extensions.identity == 1 %> + <% if( (@user.user_extensions.identity == 1) && (is_watching?(@user) ) )%>
<%= l(:label_user_home) %><%= l(:label_user_location) %> : <%= l(:label_user_location) %> : <%= @user.user_extensions.technical_title %>
<%= l(:label_bidding_user_studentcode)%>:<%= @user.user_extensions.student_id %>