diff --git a/app/api/mobile/apis/auth.rb b/app/api/mobile/apis/auth.rb index 05b0a793b..320497e50 100644 --- a/app/api/mobile/apis/auth.rb +++ b/app/api/mobile/apis/auth.rb @@ -1,3 +1,5 @@ +#coding=utf-8 + module Mobile module Entities diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 9aeea5176..515ebce77 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -1,3 +1,4 @@ +#coding=utf-8 module Mobile module Apis class Courses < Grape::API diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 61859904f..6e2952290 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -1,3 +1,4 @@ +#coding=utf-8 module Mobile module Apis class Users < Grape::API diff --git a/app/api/mobile/apis/watches.rb b/app/api/mobile/apis/watches.rb index 0ee454c25..4e8510d89 100644 --- a/app/api/mobile/apis/watches.rb +++ b/app/api/mobile/apis/watches.rb @@ -1,3 +1,4 @@ +#coding=utf-8 module Mobile module Apis class Watches < Grape::API diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index bd389ff68..26b96eaf3 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -126,18 +126,21 @@ class CoursesController < ApplicationController # 课程搜索 # add by nwb def search - courses_all = Course.all_course - name = params[:name] - (redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank? - @courses = courses_all.visible - if params[:name].present? - @courses_all = @courses.like(params[:name]) - else - @courses_all = @courses; - end + #courses_all = Course.all_course + #name = params[:name] + #(redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank? + #@courses = courses_all.visible + #if params[:name].present? + # @courses_all = @courses.like(params[:name]) + #else + # @courses_all = @courses; + #end + cs = CoursesService.new + @courses_all = cs.search_course params @course_count = @courses_all.count @course_pages = Paginator.new @course_count, per_page_option, params['page'] + # 课程的动态数 @course_activity_count=Hash.new @courses_all.each do |course| @@ -194,24 +197,31 @@ class CoursesController < ApplicationController render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") } end + + rescue Exception => e + if e.message == 'sumbit empty' + (redirect_to courses_url, :notice => l(:label_sumbit_empty);return) + end end def member ## 有角色参数的才是课程,没有的就是项目 @render_file = 'member_list' - @teachers= searchTeacherAndAssistant(@course) + #@teachers= searchTeacherAndAssistant(@course) @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' case params[:role] when '1' @subPage_title = l :label_teacher_list - @members = searchTeacherAndAssistant(@course) + #@members = searchTeacherAndAssistant(@course) when '2' @subPage_title = l :label_student_list - @members = searchStudent(@course) + #@members = searchStudent(@course) else @subPage_title = '' - @members = @course.member_principals.includes(:roles, :principal).all.sort + #@members = @course.member_principals.includes(:roles, :principal).all.sort end + cs = CoursesService.new + @members = cs.course_teacher_or_student_list(params,@course) @members = paginateHelper @members render :layout => 'base_courses' end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4049c2ae8..084e720d8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -364,33 +364,35 @@ class UsersController < ApplicationController sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) (redirect_to user_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? - case params[:format] - when 'xml', 'json' - @offset, @limit = api_offset_and_limit({:limit => 15}) + case params[:format] + when 'xml', 'json' + @offset, @limit = api_offset_and_limit({:limit => 15}) + else + @limit = 15#per_page_option + end + # + #@status = params[:status] || 1 + #has = { + # "show_changesets" => true + #} + # scope = User.logged.status(@status) + # @search_by = params[:search_by] ? params[:search_by][:id] : 0 + # scope = scope.like(params[:name],@search_by) if params[:name].present? + us = UsersService.new + scope = us.search_user params + @user_count = scope.count + @user_pages = Paginator.new @user_count, @limit, params['page'] + @user_base_tag = params[:id] ? 'base_users':'users_base' + @offset ||= @user_pages.reverse_offset + unless @offset == 0 + @users = scope.offset(@offset).limit(@limit).all.reverse else - @limit = 15#per_page_option + limit = @user_count % @limit + if limit == 0 + limit = @limit + end + @users = scope.offset(@offset).limit(limit).all.reverse end - - @status = params[:status] || 1 - has = { - "show_changesets" => true - } - scope = User.logged.status(@status) - @search_by = params[:search_by] ? params[:search_by][:id] : 0 - scope = scope.like(params[:name],@search_by) if params[:name].present? - @user_count = scope.count - @user_pages = Paginator.new @user_count, @limit, params['page'] - @user_base_tag = params[:id] ? 'base_users':'users_base' - @offset ||= @user_pages.reverse_offset - unless @offset == 0 - @users = scope.offset(@offset).limit(@limit).all.reverse - else - limit = @user_count % @limit - if limit == 0 - limit = @limit - end - @users = scope.offset(@offset).limit(limit).all.reverse - end respond_to do |format| format.html { diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 0a1fa553d..0468de367 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -1,5 +1,6 @@ class CoursesService include ApplicationHelper + include CoursesHelper #参数school_id为0或不传时返回所有课程,否则返回对应学校的课程 #参数per_page_count分页功能,每页显示的课程数 #参数page分页功能,当前页码 @@ -26,4 +27,43 @@ class CoursesService course_list end + #搜索课程 + def search_course params + courses_all = Course.all_course + name = params[:name] + if name.blank? + raise 'sumbit empty' + end + @courses = courses_all.visible + if params[:name].present? + @courses_all = @courses.like(params[:name]) + else + @courses_all = @courses; + end + @courses_all + end + + #获取头像 + def get_img obj + url_to_avatar(obj) + end + + #课程老师或课程学生列表 + def course_teacher_or_student_list params,course + @teachers= searchTeacherAndAssistant(course) + #@canShowCode = isCourseTeacher(User.current.id,course) && params[:role] != '1' + case params[:role] + when '1' + #@subPage_title = l :label_teacher_list + @members = searchTeacherAndAssistant(course) + when '2' + #@subPage_title = l :label_student_list + @members = searchStudent(course) + else + #@subPage_title = '' + @members = @course.member_principals.includes(:roles, :principal).all.sort + end + @members + end + end \ No newline at end of file diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 9587427b5..d281edb19 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -126,4 +126,16 @@ class UsersService @current_user end + #搜索用户 + def search_user params + @status = params[:status] || 1 + has = { + "show_changesets" => true + } + scope = User.logged.status(@status) + @search_by = params[:search_by] ? params[:search_by][:id] : 0 + scope = scope.like(params[:name],@search_by) if params[:name].present? + scope + end + end