diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index cab9c1ed19cc28c288087b2cd7841f55a370f5be..7c660fdbfe0ed457a2860e4725c2e46b654459f5 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -1,4 +1,4 @@ -# == Schema Information + # == Schema Information # # Table name: learning_objects # @@ -60,6 +60,8 @@ class LearningObject < ActiveRecord::Base default_scope { includes(:object_type, :attachment, :attachments).order(score: :desc) } scope :missing_thumbnail, ->() { where(thumbnail_file_name: nil) } + scope :this_week, -> { where('created_at >= ?', 1.week.ago) } + scope :this_month, -> { where('created_at >= ?', 1.month.ago) } searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author, :object_type], callbacks: :async @@ -136,4 +138,19 @@ class LearningObject < ActiveRecord::Base def user_category publisher.try('user_category') end + + #period is either :week or :month + def self.highlights(period, limit) + if period == :week + los = LearningObject.this_week + elsif period == :month + los = LearningObject.this_month + else + los = LearningObject.all + end + + los.order(score: :desc) + highlights = los.first(limit) + highlights + end end