diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index da29c713f..4cd22677d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -331,7 +331,80 @@ class CoursesController < ApplicationController end end + def show + # try to redirect to the requested menu item + if params[:jump] && redirect_to_course_menu_item(@course, params[:jump]) + return + end + @users_by_role = @course.users_by_role + if(User.find_by_id(CourseInfo.find_by_course_id(@course.id).try(:user_id))) + @user = User.find_by_id(CourseInfo.find_by_course_id(@course.id).user_id) + end + cond = @course.course_condition(Setting.display_subcourses_issues?) + @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker) + @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker) + + if User.current.allowed_to?(:view_time_entries, @course) + @total_hours = TimeEntry.visible.sum(:hours, :include => :course, :conditions => cond).to_f + end + + @key = User.current.rss_key + #新增内容 + @days = Setting.activity_days_default.to_i + + if params[:from] + begin; @date_to = params[:from].to_date + 1; rescue; end + end + + has = { + "show_files" => true, + "show_messages" => true, + "show_bids" => true, + "show_contests" => true, + "show_journals_for_messages" => true + } + @date_to ||= Date.today + 1 + @date_from = @date_to - @days-1.years + @with_subcourses = params[:with_subcourses].nil? ? Setting.display_subcourses_issues? : (params[:with_subcourses] == '1') + @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) + # 决定显示所用用户或单个用户活动 + @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, + :with_subcourses => @with_subcourses, + :author => @author) + @activity.scope_select {|t| !has["show_#{t}"].nil?} + # logger.debug "=========================================#{@activity.scope}" + # @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty? + #Added by young + events = @activity.events(@date_from, @date_to) + + @offset, @limit = api_offset_and_limit({:limit => 10}) + @events_count = events.count + @events_pages = Paginator.new @events_count, @limit, params['page'] + @offset ||= @events_pages.offset + events = events.slice(@offset,@limit) + #Ended by young + @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} + # documents + @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' + documents = @course.documents.includes(:attachments, :category).all + case @sort_by + when 'date' + @grouped = documents.group_by {|d| d.updated_on.to_date } + when 'title' + @grouped = documents.group_by {|d| d.title.first.upcase} + when 'author' + @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author} + else + @grouped = documents.group_by(&:category) + end + @document = @course.documents.build + # + respond_to do |format| + format.html{render :layout => 'base_courses'} + format.api + end + end private diff --git a/app/models/course.rb b/app/models/course.rb index bb80110a7..2252577c9 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -71,6 +71,16 @@ class Course < ActiveRecord::Base allowed_to_condition(user, :view_course, options) end + # 返回用户组可以访问的课程 + def users_by_role + members.includes(:user, :roles).all.inject({}) do |h, m| + m.roles.each do |r| + h[r] ||= [] + h[r] << m.user + end + h + end + end #自定义验证 def validate diff --git a/app/models/course_infos.rb b/app/models/course_infos.rb new file mode 100644 index 000000000..265cdccf6 --- /dev/null +++ b/app/models/course_infos.rb @@ -0,0 +1,3 @@ +class CourseInfos < ActiveRecord::Base + attr_accessible :typeId, :typeName +end diff --git a/db/migrate/20140605025300_create_course_infos.rb b/db/migrate/20140605025300_create_course_infos.rb new file mode 100644 index 000000000..b1947f3d3 --- /dev/null +++ b/db/migrate/20140605025300_create_course_infos.rb @@ -0,0 +1,25 @@ +class CreateCourseInfos < ActiveRecord::Migration + def change + create_table :course_infos do |t| + t.integer :course_id + t.integer :user_id + t.timestamps + end + + #迁移课程管理员数据 + Project.all.each do |project| + if project.project_type == 1 + course = Course.find_by_extra(project.identifier) + if course + projectinfos = ProjectInfo.find_all_by_project_id(project.id) + projectinfos.each do |projinfo| + courseinfo = CourseInfos.new + courseinfo.course_id = course.id + courseinfo.user_id = projinfo.user_id + courseinfo.save + end + end + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 49557a3bf..dae888700 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140604071624) do +ActiveRecord::Schema.define(:version => 20140605025300) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -218,6 +218,13 @@ ActiveRecord::Schema.define(:version => 20140604071624) do t.datetime "updated_on", :null => false end + create_table "course_infos", :force => true do |t| + t.integer "course_id" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "course_statuses", :force => true do |t| t.integer "changesets_count" t.integer "watchers_count" diff --git a/test/fixtures/course_infos.yml b/test/fixtures/course_infos.yml new file mode 100644 index 000000000..79b5cfde7 --- /dev/null +++ b/test/fixtures/course_infos.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + typeId: 1 + typeName: MyString + +two: + typeId: 1 + typeName: MyString diff --git a/test/unit/course_infos_test.rb b/test/unit/course_infos_test.rb new file mode 100644 index 000000000..f20a519db --- /dev/null +++ b/test/unit/course_infos_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CourseInfosTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end