diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b93bdd1e..30f28a88 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -86,6 +86,35 @@ class CoursesController < ApplicationController end end + def member + ## 有角色参数的才是课程,没有的就是项目 + @render_file = 'member_list' + @teachers= searchTeacherAndAssistant(@course) + @canShowCode = isCourseTeacher(User.current.id) + case params[:role] + when '1' + @subPage_title = l :label_teacher_list + @members = searchTeacherAndAssistant(@course) + when '2' + @subPage_title = l :label_student_list + @members = searchStudent(@course) + else + @subPage_title = '' + @members = @course.member_principals.includes(:roles, :principal).all.sort + end + @members = paginateHelper @members + render :layout => 'base_courses' + end + + #判断指定用户是否为课程教师 + def isCourseTeacher(id) + result = false + if @teachers.find_by_user_id(id) != nil + result = true + end + result + end + def handle_course courses, activities course_activity_count_array=activities.values() diff --git a/app/models/principal.rb b/app/models/principal.rb index 6681855b..efe24f03 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -28,6 +28,8 @@ class Principal < ActiveRecord::Base has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status<>#{Project::STATUS_ARCHIVED}", :order => "#{Project.table_name}.name" has_many :coursememberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :course, :roles ], :conditions => "#{Course.table_name}.status<>#{Course::STATUS_ARCHIVED}", :order => "#{Course.table_name}.name" has_many :projects, :through => :memberships + #add by nwb + has_many :courses, :through => :coursememberships has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify # Groups and active users diff --git a/app/models/user.rb b/app/models/user.rb index 735a9e19..fd4508ce 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -100,7 +100,7 @@ class User < Principal has_many :journal_replies, :dependent => :destroy has_many :activities, :dependent => :destroy has_many :students_for_courses - has_many :courses, :through => :students_for_courses, :source => :project + #has_many :courses, :through => :students_for_courses, :source => :project has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Project' or container_type = 'Version'" #### @@ -690,6 +690,10 @@ class User < Principal projects.to_a.include?(project) end + def member_of_course?(course) + courses.to_a.include?(course) + end + # Returns a hash of user's projects grouped by roles def projects_by_role return @projects_by_role if @projects_by_role diff --git a/app/views/courses/_member_list.html.erb b/app/views/courses/_member_list.html.erb new file mode 100644 index 00000000..e356c22e --- /dev/null +++ b/app/views/courses/_member_list.html.erb @@ -0,0 +1,31 @@ +<% if members.any? %> + <% members.each do |member| %> +
+
++ <%= l(:label_no_data) %> +
+<% end %> \ No newline at end of file diff --git a/app/views/courses/member.html.erb b/app/views/courses/member.html.erb new file mode 100644 index 00000000..3d3076bc --- /dev/null +++ b/app/views/courses/member.html.erb @@ -0,0 +1,10 @@ ++ <%= @subPage_title %> +
+