diff options
| author | Alban Peignier | 2018-02-20 14:27:22 +0100 | 
|---|---|---|
| committer | GitHub | 2018-02-20 14:27:22 +0100 | 
| commit | 338a4df2491bebe0acd30c384665dd420899910c (patch) | |
| tree | 23be5c137acab77020c5d3c340b1028db1c660a5 /app/models | |
| parent | 6599a8d6a10e338fed38119115d12a3acb507e1b (diff) | |
| parent | 30916d0303fb80d896c125f7531dac573bf97f11 (diff) | |
| download | chouette-core-338a4df2491bebe0acd30c384665dd420899910c.tar.bz2 | |
Merge pull request #308 from af83/5911-stops-filter-on-referential-journeys-index
Better stops filters on ReferentialVJs#index. Refs #5911 
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/chouette/vehicle_journey.rb | 38 | 
1 files changed, 38 insertions, 0 deletions
| diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index 1a79db823..6209993de 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -52,6 +52,44 @@ module Chouette        end      } +    scope :with_stop_area_id, ->(id){ +      if id.present? +        joins(journey_pattern: :stop_points).where('stop_points.stop_area_id = ?', id) +      else +        all +      end +    } + +    scope :with_ordered_stop_area_ids, ->(first, second){ +      if first.present? && second.present? +        joins(journey_pattern: :stop_points). +          joins('INNER JOIN "journey_patterns" ON "journey_patterns"."id" = "vehicle_journeys"."journey_pattern_id" INNER JOIN "journey_patterns_stop_points" ON "journey_patterns_stop_points"."journey_pattern_id" = "journey_patterns"."id" INNER JOIN "stop_points" as "second_stop_points" ON "stop_points"."id" = "journey_patterns_stop_points"."stop_point_id"'). +          where('stop_points.stop_area_id = ?', first). +          where('second_stop_points.stop_area_id = ? and stop_points.position < second_stop_points.position', second) +      else +        all +      end +    } + +    scope :starting_with, ->(id){ +      if id.present? +        joins(journey_pattern: :stop_points).where('stop_points.position = 0 AND stop_points.stop_area_id = ?', id) +      else +        all +      end +    } + +    scope :ending_with, ->(id){ +      if id.present? +        pattern_ids = all.select(:journey_pattern_id).uniq.map(&:journey_pattern_id) +        pattern_ids = Chouette::JourneyPattern.where(id: pattern_ids).to_a.select{|jp| p "ici: #{jp.stop_points.order(:position).last.stop_area_id}" ; jp.stop_points.order(:position).last.stop_area_id == id.to_i}.map &:id +        where(journey_pattern_id: pattern_ids) +      else +        all +      end +    } + +      scope :in_purchase_window, ->(range){        purchase_windows = Chouette::PurchaseWindow.overlap_dates(range)        sql = purchase_windows.joins(:vehicle_journeys).select('vehicle_journeys.id').uniq.to_sql | 
