aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/access_link_pair.rb45
-rw-r--r--app/models/referential.rb35
2 files changed, 80 insertions, 0 deletions
diff --git a/app/models/access_link_pair.rb b/app/models/access_link_pair.rb
new file mode 100644
index 000000000..16df48fd5
--- /dev/null
+++ b/app/models/access_link_pair.rb
@@ -0,0 +1,45 @@
+class AccessLinkPair
+ include ActiveModel::Validations
+ include ActiveModel::Conversion
+ extend ActiveModel::Naming
+
+
+ attr_accessor :from_access_point, :to_access_point
+
+ validates_presence_of :from_access_point, :to_access_point
+
+ def initialize(attributes = {})
+ attributes.each do |name, value|
+ send("#{name}=", value)
+ end
+ end
+
+ def persisted?
+ false
+ end
+
+ def access_point
+ return nil if from_access_point.nil?
+ from_access_point.access_point
+ end
+
+ def stop_area
+ return nil if from_access_point.nil?
+ from_access_point.stop_area
+ end
+
+ def in_valid?
+ access_point.access_point_type != "out"
+ end
+
+ def out_valid?
+ access_point.access_point_type != "in"
+ end
+
+ def in_exists?
+ !from_access_point.id.nil?
+ end
+ def out_exists?
+ !to_access_point.id.nil?
+ end
+end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index b4601caee..70035a32b 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -59,6 +59,14 @@ class Referential < ActiveRecord::Base
Chouette::StopArea.scoped
end
+ def access_points
+ Chouette::AccessPoint.scoped
+ end
+
+ def access_links
+ Chouette::AccessLink.scoped
+ end
+
def time_tables
Chouette::TimeTable.scoped
end
@@ -210,4 +218,31 @@ Rails.application.config.after_initialize do
end
end
end
+
+ Chouette::AccessPoint
+
+ class Chouette::AccessPoint
+
+ # add projection_type set on pre-insert and pre_update action
+ before_validation :set_projections
+ def set_projections
+ if ! self.latitude.nil? && ! self.longitude.nil?
+ self.long_lat_type = 'WGS84'
+ else
+ self.long_lat_type = nil
+ end
+ if ! self.referential.projection_type.nil? && !self.referential.projection_type.empty?
+ if ! self.x.nil? && ! self.y.nil?
+ self.projection_type = referential.projection_type_label
+ else
+ self.projection_type = nil
+ end
+ else
+ self.projection_type = nil
+ self.x = nil
+ self.y = nil
+ end
+ end
+ end
+
end