Source of file SS_GeoLocation.php
Size: 3,726 Bytes - Last Modified: 2021-12-24T06:19:14+00:00
/var/www/docs.ssmods.com/process/src/code/Field/SS_GeoLocation.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 | <?php /** * Class SS_GeoLocation */ class SS_GeoLocation extends DBField { /** * @var */ protected $latitude; /** * @var */ protected $longitude; /** * @var */ protected $accuracy; /** * SS_GeoLocation constructor. * @param null $name */ public function __construct($name = null) { $this->defaultVal = ',,'; parent::__construct($name); } /** * */ public function requireField() { $parts = array( 'datatype' => 'varchar', 'precision' => 255, 'character set' => 'utf8', 'collate' => 'utf8_general_ci', 'arrayValue' => $this->arrayValue ); $values = array( 'type' => 'varchar', 'parts' => $parts ); // Add support for both SS DB API 3.2 and <3.2 if (method_exists('DB', 'require_field')) { DB::require_field($this->tableName, $this->name, $values); } else { DB::requireField($this->tableName, $this->name, $values); } } /** * @param null $title * @return GeoLocationField */ public function scaffoldFormField($title = null) { $field = new GeoLocationField($this->name, $title); return $field; } /** * @return null */ public function nullValue() { return null; } /** * @param $value * @return string */ protected function formatValue($value) { $val = $value; if ($val === null || $val === '' || $val === 0) { $val = $this->defaultVal; } return $val; } /** * @param mixed $value * @param null $record */ public function setValue($value, $record = null) { $this->value = $value; $values = explode(',', $value); $this->latitude = @$values[0]; $this->longitude = @$values[1]; $this->accuracy = @$values[2]; } /** * */ protected function syncValue() { $this->value = $this->latitude . ',' . $this->longitude . ',' . $this->accuracy; } /** * @param $value * @return mixed */ protected function extractLatitude($value) { $values = explode(',', $value); return $values[0]; } /** * @param $value * @return mixed */ protected function extractLongitude($value) { $values = explode(',', $value); return $values[1]; } /** * @param $value * @return mixed */ protected function extractAccuracy($value) { $values = explode(',', $value); return $values[2]; } /** * @param $latidude * @return $this */ public function setLatitude($latidude) { $this->latitude = $latidude; $this->syncValue(); return $this; } /** * @return mixed */ public function Latitude() { return $this->latitude; } /** * @param $longitude * @return $this */ public function setLongitude($longitude) { $this->longitude = $longitude; $this->syncValue(); return $this; } /** * @return mixed */ public function Longitude() { return $this->longitude; } /** * @param $accuracy * @return $this */ public function setAccuracy($accuracy) { $this->accuracy = $accuracy; $this->syncValue(); return $this; } /** * @return mixed */ public function Accuracy() { return $this->accuracy; } } |