Source of file DBGeography.php
Size: 2,196 Bytes - Last Modified: 2021-12-23T10:37:40+00:00
/var/www/docs.ssmods.com/process/src/src/ORM/FieldType/DBGeography.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 | <?php namespace Smindel\GIS\ORM\FieldType; use SilverStripe\ORM\DB; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBComposite; use Smindel\GIS\Forms\MapField; use Smindel\GIS\GIS; class DBGeography extends DBComposite { /** * Add the field to the underlying database. */ public function requireField() { DB::require_field( $this->tableName, $this->name, [ 'type'=>'geography', ] ); } public function addToQuery(&$query) { $table = $this->getTable(); $column = $this->getName(); $identifier = $table ? sprintf('"%s"."%s"', $table, $column) : sprintf('"%s"', $column); $sqlFragment = DB::get_schema()->translateBasicSelectGeo(); $select = sprintf( $sqlFragment, $identifier, $identifier, $identifier, $column ); $query->selectField($select); } public function compositeDatabaseFields() { return ['' => 'Geography']; } public function prepValueForDB($value) { $value = GIS::create($value); if ($value->isNull()) { return null; } return ['ST_GeogFromText(?)' => [$value->reproject(4326)->wkt]]; } public function exists() { // reinstates parent::parent::exists() return DBField::exists(); } public function writeToManipulation(&$manipulation) { // reinstates parent::parent::writeToManipulation() DBField::writeToManipulation($manipulation); } public function saveInto($dataObject) { // reinstates parent::parent::saveInto() DBField::saveInto($dataObject); } public function setValue($value, $record = null, $markChanged = true) { // reinstates parent::parent::setValue() return DBField::setValue($value, $record, $markChanged); } public function scaffoldFormField($title = null, $params = null) { return MapField::create($this->name, $title); } public function getRAW() { return (string)$this; } } |