diff --git a/app/controllers/hps_learnings_controller.rb b/app/controllers/hps_learnings_controller.rb index d4520f4..acca9b0 100644 --- a/app/controllers/hps_learnings_controller.rb +++ b/app/controllers/hps_learnings_controller.rb @@ -1,8 +1,23 @@ class HpsLearningsController < ApplicationController def index + params = OrbitHelper.params table_fields = ["hps_learning.course_pic", "hps_learning.title", :category, "hps_learning.runtime", "hps_learning.lectures"].collect{|x| {"head" => t(x.to_sym)}} classes = [] - HpsClass.filter_by_categories.desc(:created_at).each do |hpsclass| + tags = !params['tags'].blank? ? params[:tags] : OrbitHelper.page_tags + + onlineclassess = HpsClass.filter_by_categories.filter_by_tags(tags) + + if params[:keywords].present? + key_string = params[:keywords] + key_string = key_string.strip.nil? ? key_string : key_string.strip + keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) + regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")}) + onlineclassess = onlineclassess.any_of({:title => regex}) + end + + onlineclassess = onlineclassess.desc(:created_at) + + onlineclassess.each do |hpsclass| if hpsclass.hps_lectures.count > 0 thumb = hpsclass.course_pic.thumb.url.nil? ? "http://www.placehold.it/150x150/EFEFEF/AAAAAA" : hpsclass.course_pic.thumb.url classes << {