Class: SpreeCmCommissioner::OrganizerProfileEventQuery
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::OrganizerProfileEventQuery
- Defined in:
- app/queries/spree_cm_commissioner/organizer_profile_event_query.rb
Instance Attribute Summary collapse
-
#section ⇒ Object
readonly
Returns the value of attribute section.
-
#start_from_date ⇒ Object
readonly
Returns the value of attribute start_from_date.
-
#vendor_id ⇒ Object
readonly
Returns the value of attribute vendor_id.
Instance Method Summary collapse
- #events ⇒ Object
-
#initialize(vendor_id:, section:, start_from_date: nil) ⇒ OrganizerProfileEventQuery
constructor
user_id: user ID, vendor_id: vendor ID, section: ‘upcoming’, ‘previous’ or ‘all’.
Constructor Details
#initialize(vendor_id:, section:, start_from_date: nil) ⇒ OrganizerProfileEventQuery
user_id: user ID, vendor_id: vendor ID, section: ‘upcoming’, ‘previous’ or ‘all’
6 7 8 9 10 |
# File 'app/queries/spree_cm_commissioner/organizer_profile_event_query.rb', line 6 def initialize(vendor_id:, section:, start_from_date: nil) @vendor_id = vendor_id @section = section @start_from_date = start_from_date || Time.zone.now end |
Instance Attribute Details
#section ⇒ Object (readonly)
Returns the value of attribute section.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/organizer_profile_event_query.rb', line 3 def section @section end |
#start_from_date ⇒ Object (readonly)
Returns the value of attribute start_from_date.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/organizer_profile_event_query.rb', line 3 def start_from_date @start_from_date end |
#vendor_id ⇒ Object (readonly)
Returns the value of attribute vendor_id.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/organizer_profile_event_query.rb', line 3 def vendor_id @vendor_id end |
Instance Method Details
#events ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/queries/spree_cm_commissioner/organizer_profile_event_query.rb', line 12 def events taxons = Spree::Taxon.includes(:vendor).where(vendor_id: vendor_id, depth: 1) case section when 'upcoming' taxons.where('to_date >= ?', start_from_date) .order(from_date: :asc) when 'previous' taxons.where('to_date < ?', start_from_date) .order(to_date: :desc) else taxons.order(from_date: :asc) end end |