diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index c37edf2e4..b4f5b0468 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -27,6 +27,11 @@ class SchoolController < ApplicationController def upload_logo end + + #获取制定学校开设的课程数 + def course_count school_id + School.find(school_id).courses.count + end def index diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index d474b5587..35a907ecc 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -108,5 +108,7 @@ module CoursesHelper now > cTime end - + def find_by_extra_from_project extra + Course.find_by_extra(try(extra)) + end end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 53869b9ed..ed435fe6d 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -105,7 +105,31 @@ module WelcomeHelper # c2 = c2 - c1 # (c1.take(max)+c2).take(sum) end - + + #查找所有学校按每个学校开设课程数量降序排序 + #page 分页查询开始条数的编号,从0开始 + #limit 分页查询的数量 + def find_maxmin_course_school page,limit + School.find_by_sql("SELECT *,(SELECT COUNT(*) FROM courses WHERE school_id = schools.id) AS a + FROM schools + ORDER BY a DESC LIMIT #{page},#{limit}") + #School.where(" id IN (SELECT school_id FROM courses GROUP BY school_id)").limit limit; + #School.order("#{School.course_count}").limit(limit).all + #@school = School.all.sort + #@school.each do |s| + # s.courses.count + #end + #result = [] + #@school = School.all.to_ary + #i = 1 + #for i in i < School.count + # j = i - 1 + # for j in j > 0 + # if @school[j].courses.count > + # end + #end + end + def find_miracle_project(sum, max_rate) max = sum*(max_rate.to_f/10) c1 = find_new_project(sum).to_a.dup diff --git a/app/models/course.rb b/app/models/course.rb index 9f0c42c6f..0420b1744 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -47,5 +47,4 @@ class Course < ActiveRecord::Base return time end end - end diff --git a/app/views/bids/show_course.html.erb b/app/views/bids/show_course.html.erb index 0d1bdee57..574bd117c 100644 --- a/app/views/bids/show_course.html.erb +++ b/app/views/bids/show_course.html.erb @@ -12,7 +12,8 @@ <%= l(:label_homework) %> (<%= link_to (course.homeworks.count), {:controller => 'projects', :action => 'homework', :id => course.identifier} %>)     <%= l(:label_course_news)%> (<%= link_to (course.news.count), {:controller => 'news', :action => 'index', :project_id => course.identifier} %>) - + + diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index 14277afed..286ff60d3 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -1,6 +1,7 @@ <%= stylesheet_link_tag 'welcome' %> <%= javascript_include_tag 'welcome' %> -