课堂首页的调整

dev_forum
cxt 6 years ago
parent d1511241b2
commit 86726005bb

@ -62,15 +62,12 @@ class CoursesController < ApplicationController
if @order == "mine"
@courses = Course.joins(:course_members)
.where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id)
.order("courses.id = 1309 DESC, courses.#{order_str} DESC")
elsif @order == "created_at"
# REDO:Extension
@courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0)
.order("courses.id = 1309 DESC, courses.#{order_str} DESC")
else
# REDO:Extension
@courses = Course.where(is_delete: 0, is_hidden: 0)
.order("courses.id = 1309 DESC, courses.#{order_str} DESC")
end
# 根据搜索关键字进一步筛选
@ -89,14 +86,15 @@ class CoursesController < ApplicationController
@courses = @courses.joins(:school, course_members: :user)
.where("#{sql}", keyword: "%#{params[:search]}%").distinct
end
@courses_count = @courses.size
@courses_count = @courses.count("courses.id")
@courses = @courses.order("courses.id = 1309 DESC, courses.#{order_str} DESC")
# 分页
page = params[:page] || 1
limit = params[:limit] || 16
@courses = @courses.page(page).per(limit)
@courses = @courses.preload(:school, teacher: :user_extension)
@courses = @courses.preload(:school, :none_hidden_course_modules, teacher: :user_extension)
end
def visits_plus_one

@ -10,6 +10,7 @@ class Course < ApplicationRecord
has_many :course_infos, dependent: :destroy
# 课堂左侧导航栏的模块
has_many :course_modules, dependent: :destroy
has_many :none_hidden_course_modules, -> { not_hidden }, class_name: "CourseModule"
has_many :board_course_modules, -> { board_module }, class_name: "CourseModule"
has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule"
has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule"

@ -11,5 +11,6 @@ json.courses @courses do |course|
json.is_public course.is_public
json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL
json.is_end course.is_end
json.first_category_url module_url(course.none_hidden_course_modules.first, course)
end
json.courses_count @courses_count

Loading…
Cancel
Save