added filter mechanism
This commit is contained in:
parent
4ebb7d4bf4
commit
4720bd7035
|
@ -1,8 +1,23 @@
|
||||||
class HpsLearningsController < ApplicationController
|
class HpsLearningsController < ApplicationController
|
||||||
def index
|
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)}}
|
table_fields = ["hps_learning.course_pic", "hps_learning.title", :category, "hps_learning.runtime", "hps_learning.lectures"].collect{|x| {"head" => t(x.to_sym)}}
|
||||||
classes = []
|
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
|
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
|
thumb = hpsclass.course_pic.thumb.url.nil? ? "http://www.placehold.it/150x150/EFEFEF/AAAAAA" : hpsclass.course_pic.thumb.url
|
||||||
classes << {
|
classes << {
|
||||||
|
|
Loading…
Reference in New Issue