添加课程列表接口
This commit is contained in:
parent
db9eebbac7
commit
5676770100
|
@ -0,0 +1,29 @@
|
|||
class CoursesService
|
||||
include ApplicationHelper
|
||||
#参数school_id为0或不传时返回所有课程,否则返回对应学校的课程
|
||||
#参数per_page_count分页功能,每页显示的课程数
|
||||
#参数page分页功能,当前页码
|
||||
def course_list params
|
||||
@school_id = params[:school_id]
|
||||
per_page_option = params[:per_page_count] || 10
|
||||
page_no = params[:page] || 1
|
||||
if @school_id == "0" || @school_id.nil?
|
||||
@courses_all = Course.active.visible.
|
||||
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
||||
else
|
||||
@courses_all = Course.active.visible.
|
||||
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
||||
where("#{Course.table_name}.school_id = ?", @school_id)
|
||||
end
|
||||
@course_count = @courses_all.count
|
||||
@course_pages = Redmine::Pagination::Paginator.new @course_count, per_page_option,page_no
|
||||
@courses = @courses_all.order("created_at desc")
|
||||
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||
course_list = []
|
||||
@courses.each do |course|
|
||||
course_list << {:course => course,:img_url => url_to_avatar(course)}
|
||||
end
|
||||
course_list
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue