|
|
|
@ -347,15 +347,15 @@ class EcCoursesController < ApplicationController
|
|
|
|
|
def search_courses
|
|
|
|
|
user = User.where(:id => params[:user_id]).first
|
|
|
|
|
if user.try(:admin?) || user.try(:business?)
|
|
|
|
|
courses = Course.where(:is_delete => 0)
|
|
|
|
|
courses = Course.where(:is_delete => 0).limit(20)
|
|
|
|
|
else
|
|
|
|
|
course_ids = Member.where("user_id = #{user.try(:id)} and course_id != -1").pluck(:course_id)
|
|
|
|
|
courses = Course.where(:is_delete => 0, :id => course_ids)
|
|
|
|
|
courses = Course.where(:is_delete => 0, :id => course_ids).limit(20)
|
|
|
|
|
end
|
|
|
|
|
if params[:search] && params[:search].strip != ""
|
|
|
|
|
courses = courses.where("name like ?", "%#{params[:search].strip}%").reorder("created_at desc")
|
|
|
|
|
else
|
|
|
|
|
courses = courses.reorder("created_at desc")
|
|
|
|
|
courses = courses.reorder("created_at desc").limit(20)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|