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| %> +
+ <% next if member.new_record? %> + <% unless member.created_on.nil? %> + <%= content_tag "p", "#{format_date(member.created_on)}#{l(:label_member_since)}", :class => "float_right member_since" %> + <% end %> + <%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :class => 'avatar')) %> + <%= content_tag "div", link_to(member.user.name, user_path(member.user)), :class => "nomargin avatar_name" %> + + + <% unless member.user.user_extensions.identity ==0 %> + + <%if @canShowCode%> + <%= content_tag "p", "#{l(:label_bidding_user_studentcode)}#{' : '}#{member.user.user_extensions.student_id}", :class => "nomargin avatar_name" %> + <% end %> + <% end %> +
  +

+

+
+ + <%= call_hook(:view_projects_settings_members_table_row, { :course => @course, :member => member}) %> +
+ <% end; reset_cycle %> + +<% else %> +

+ <%= 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 %> +

+
+
+ <%= error_messages_for 'member' %> + <%= render :partial => @render_file, :locals => {:members => @members} %> +
+ diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 8e32e219..a180b2a6 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -77,7 +77,7 @@ <%= join_in_course(@course, User.current) %> <% end %> - <% unless User.current.member_of?(@course) %> + <% unless User.current.member_of_course?(@course) %> <% end %> <% end %> @@ -99,14 +99,14 @@ - <% if User.current.member_of?(@course) %> + <% if User.current.member_of_course?(@course) %> <%= link_to "#{teacherCount(@course)}", course_member_path(@course, :role => 1), :course => '1' %> <% else %> <%= teacherCount(@course)%> <% end%> - <% if User.current.member_of?(@course) %> + <% if User.current.member_of_course?(@course) %> <%= link_to "#{studentCount(@course)}", course_member_path(@course, :role => 2), :course => '1' %> <% else %> <%= studentCount(@course)%> diff --git a/config/routes.rb b/config/routes.rb index bf356b6d..709175a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -551,9 +551,11 @@ RedmineApp::Application.routes.draw do get 'homework', :action => 'homework', :as => 'homework' get 'new_homework', :action => 'new_homework', :as => 'new_homework' get 'file', :action => 'file', :as => 'file' + get 'member', :controller => 'courses', :action => 'member', :as => 'member' post 'finishcourse' post 'restartcourse' end + match '/member', :controller => 'courses', :action => 'member', :as => 'member', :via => :get resources :boards resources :files, :only => [:index, :new, :create] do collection do