diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3ebd3369..12f730e0 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -52,11 +52,40 @@ class CoursesController < ApplicationController end end + def handle_course courses,activities + course_activity_count_array=activities.values() + + course_array=[] + i=0; + courses.each do |course| + course_array[i]=course + i=i+1 + end + + courses=desc_sort_course_by_avtivity(course_activity_count_array,course_array) + + return courses + end + + def desc_sort_course_by_avtivity(activity_count,courses) + return courses if activity_count.size<2 + (activity_count.size-2).downto(0) do |i| + (0..i).each do |j| + if activity_count[j]?",date_from).count end - #time_entry_count - TimeEntry.where(course_id: @course_ids).where("updated_on>?",date_from).each do |timeentry| - activities[timeentry.course_id]+=1 - end - #feedbackc_count JournalsForMessage.where(jour_id: @course_ids, jour_type: Project).each do |jourformess| activities[jourformess.jour_id]+=1 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 6a348a1e..4c27af48 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -126,29 +126,25 @@ module CoursesHelper content = ''.html_safe case state when 0 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id))) when 1 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected") - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id))) when 2 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'), :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id))) #gcm when 3 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:course_sort_type => '0', :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:course_sort_type => '1', :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:course_sort_type => '2'))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id))) + content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected") end #gcmend diff --git a/app/models/course.rb b/app/models/course.rb index 0c5abd5c..0df09dd3 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -78,16 +78,15 @@ class Course < ActiveRecord::Base end def self.allowed_to_condition(user, permission, options={}) - perm = Redmine::AccessControl.permission(permission) + perm = Redmine::AccessControl.permission(permission) base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}") - if perm && perm.project_module - # If the permission belongs to a project module, make sure the module is enabled + if perm && perm.course_module base_statement << " AND #{Course.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}')" end - if options[:project] - project_statement = "#{Course.table_name}.id = #{options[:project].id}" - project_statement << " OR (#{Course.table_name}.lft > #{options[:project].lft} AND #{Course.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects] - base_statement = "(#{project_statement}) AND (#{base_statement})" + if options[:course] + course_statement = "#{Course.table_name}.id = #{options[:course].id}" + course_statement << " OR (#{Course.table_name}.lft > #{options[:course].lft} AND #{Course.table_name}.rgt < #{options[:course].rgt})" if options[:with_subcourses] + base_statement = "(#{course_statement}) AND (#{base_statement})" end if user.admin? @@ -101,9 +100,9 @@ class Course < ActiveRecord::Base end end if user.logged? - user.projects_by_role.each do |role, projects| - if role.allowed_to?(permission) && projects.any? - statement_by_role[role] = "#{Course.table_name}.id IN (#{projects.collect(&:id).join(',')})" + user.courses_by_role.each do |role, courses| + if role.allowed_to?(permission) && courses.any? + statement_by_role[role] = "#{Course.table_name}.id IN (#{courses.collect(&:id).join(',')})" end end end diff --git a/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb new file mode 100644 index 00000000..cefc3825 --- /dev/null +++ b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb @@ -0,0 +1,13 @@ +class AddCourseidToEnabledModules < ActiveRecord::Migration + def change + add_column :enabled_modules, :course_id, :int + + EnabledModule.all.each do |enablemodule| + project = Project.find_by_id(enablemodule.project_id) + if project && project.project_type == 1 + enablemodule.course_id = board.project_id + enablemodule.save + end + end + end +end diff --git a/lib/redmine.rb b/lib/redmine.rb index f5386029..7703b2b2 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -180,7 +180,8 @@ Redmine::AccessControl.map do |map| #课程权限模块 map.project_module :course do - map.permission :view_courses,{:projects => [:course]},:read => true + map.permission :view_course, {:courses => [:show], :activities => [:index]}, :public => true, :read => true + map.permission :view_courses,{:courses => [:course]},:read => true end #作业模块权限