2014-12-08 15:19:10 +08:00
|
|
|
|
class CoursesService
|
|
|
|
|
include ApplicationHelper
|
2014-12-10 20:53:41 +08:00
|
|
|
|
include CoursesHelper
|
2014-12-08 15:19:10 +08:00
|
|
|
|
#参数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
|
|
|
|
|
|
2014-12-10 18:26:38 +08:00
|
|
|
|
#搜索课程
|
|
|
|
|
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
|
|
|
|
|
|
2014-12-10 20:53:41 +08:00
|
|
|
|
#课程老师或课程学生列表
|
|
|
|
|
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
|
|
|
|
|
|
2014-12-11 15:39:14 +08:00
|
|
|
|
#课程通知列表
|
|
|
|
|
def course_news_list params
|
|
|
|
|
if params[:course_id] && @course==nil
|
|
|
|
|
@course = Course.find(params[:course_id])
|
|
|
|
|
end
|
|
|
|
|
scope = @course ? @course.news.course_visible : News.course_visible
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show_course params
|
|
|
|
|
course = Course.find(params[:id])
|
|
|
|
|
course
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_course
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-08 15:19:10 +08:00
|
|
|
|
end
|