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 @@
<%= l(:label_user_home) %> | -<%= l(:label_user_location) %> : | +<%= l(:label_user_location) %> : |
<%= form_tag(:controller => 'users', :action => 'search', :method => :get) do %>
@@ -143,7 +143,7 @@
<%= l(:label_technical_title) %>: | <%= @user.user_extensions.technical_title %> | <% end %>
<%= l(:label_bidding_user_studentcode)%>: | <%= @user.user_extensions.student_id %> |