From cd10dd54335e7d540ab5a918c0d877f5ba80b5a1 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 3 Jun 2014 16:21:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=9D=83=E9=99=90=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E5=8F=98=E6=9B=B4=EF=BC=8C=E4=BB=8E=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 39 +++++++++++++++---- app/helpers/courses_helper.rb | 28 ++++++------- app/models/course.rb | 19 +++++---- ...3081801_add_courseid_to_enabled_modules.rb | 13 +++++++ lib/redmine.rb | 3 +- 5 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 db/migrate/20140603081801_add_courseid_to_enabled_modules.rb 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 #作业模块权限