diff --git a/app/controllers/cooperates_controller.rb b/app/controllers/cooperates_controller.rb index aecbb293..1f43fcaa 100644 --- a/app/controllers/cooperates_controller.rb +++ b/app/controllers/cooperates_controller.rb @@ -1,6 +1,20 @@ class CooperatesController < ApplicationController - def show + def partner_list + search = params[:search] + @schools = School.where(id: [179, 3181, 3216]).where("name like ?", "'%#{search}%'") + @all_count = @schools.size + unless search.blank? + @schools = @schools.where("name like ?", "'%#{search}%'") + end + @search_count = @schools.size + @schools = paginateHelper @schools, 15 + @schools = @schools.includes(:courses, users: :user_extensions) + + respond_to do |format| + format.js + format.html{render :layout => "base_edu"} + end end end diff --git a/app/models/school.rb b/app/models/school.rb index 2a33acac..2d69bf00 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -26,4 +26,36 @@ class School < ActiveRecord::Base def to_s self.name.to_s end + + def teacher_count + User.find_by_sql("SELECT COUNT(users.`id`) AS teacher_count FROM users LEFT JOIN user_extensions ON + users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{self.id} AND + user_extensions.`identity` = 0").first.try(:teacher_count) + end + + def student_count + User.find_by_sql("SELECT COUNT(users.`id`) AS student_count FROM users LEFT JOIN user_extensions ON + users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{self.id} AND + user_extensions.`identity` = 1").first.try(:student_count) + end + + def course_count + Course.find_by_sql("SELECT COUNT(courses.`id`) AS course_count FROM courses LEFT JOIN user_extensions ON + courses.tea_id=user_extensions.user_id WHERE user_extensions.`school_id` = #{self.id} AND + courses.id != 1309").first.try(:course_count) + end + + def shixun_count + Shixun.find_by_sql("select count(s.id) as shixun_count from users u right join shixuns s on u.id=s.user_id and + s.status in (2, 3) inner join user_extensions ue on u.id=ue.user_id and + ue.school_id=#{self.id}").first.try(:shixun_count) + end + + def shixun_report_count + StudentWork.find_by_sql("SELECT count(*) as sw_count FROM `student_works` where user_id in + (SELECT users.id FROM users RIGHT JOIN user_extensions ON users.id=user_extensions.user_id + WHERE user_extensions.`school_id`=#{self.id}) and work_status between 1 and 2 and + myshixun_id !=0").first.try(:sw_count) + end + end diff --git a/app/views/cooperates/partner_list.html.erb b/app/views/cooperates/partner_list.html.erb new file mode 100644 index 00000000..e69de29b