159 lines
3.4 KiB
PHP
Executable File
159 lines
3.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace common\models;
|
|
|
|
use Yii;
|
|
|
|
/**
|
|
* This is the model class for table "gis_geo_features".
|
|
*
|
|
* @property int $id
|
|
* @property int $gis_base_id
|
|
* @property string $name
|
|
* @property string $geometry
|
|
* @property string $type
|
|
* @property int|null $created_at
|
|
* @property int|null $updated_at
|
|
* @property int|null $created_by
|
|
* @property int|null $updated_by
|
|
*/
|
|
class GisGeoFeatures extends \yii\db\ActiveRecord
|
|
{
|
|
|
|
/**
|
|
* ENUM field values
|
|
*/
|
|
const TYPE_POINT = 'Point';
|
|
const TYPE_LINESTRING = 'LineString';
|
|
const TYPE_POLYGON = 'Polygon';
|
|
const TYPE_OTHER = 'Other';
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public static function tableName()
|
|
{
|
|
return 'gis_geo_features';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['created_at', 'updated_at', 'created_by', 'updated_by'], 'default', 'value' => null],
|
|
[['gis_base_id', 'name', 'geometry', 'type'], 'required'],
|
|
[['gis_base_id', 'created_at', 'updated_at', 'created_by', 'updated_by'], 'integer'],
|
|
[['geometry', 'type'], 'string'],
|
|
[['name'], 'string', 'max' => 255],
|
|
['type', 'in', 'range' => array_keys(self::optsType())],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id' => 'ID',
|
|
'gis_base_id' => 'ชั้นข้อมูล',
|
|
'name' => 'ชื่อ',
|
|
'geometry' => 'Geometry',
|
|
'type' => 'Type',
|
|
'created_at' => 'Created At',
|
|
'updated_at' => 'Updated At',
|
|
'created_by' => 'Created By',
|
|
'updated_by' => 'Updated By',
|
|
];
|
|
}
|
|
|
|
|
|
/**
|
|
* column type ENUM value labels
|
|
* @return string[]
|
|
*/
|
|
public static function optsType()
|
|
{
|
|
return [
|
|
self::TYPE_POINT => 'Point',
|
|
self::TYPE_LINESTRING => 'LineString',
|
|
self::TYPE_POLYGON => 'Polygon',
|
|
self::TYPE_OTHER => 'Other',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function displayType()
|
|
{
|
|
return self::optsType()[$this->type];
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isTypePoint()
|
|
{
|
|
return $this->type === self::TYPE_POINT;
|
|
}
|
|
|
|
public function setTypeToPoint()
|
|
{
|
|
$this->type = self::TYPE_POINT;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isTypeLinestring()
|
|
{
|
|
return $this->type === self::TYPE_LINESTRING;
|
|
}
|
|
|
|
public function setTypeToLinestring()
|
|
{
|
|
$this->type = self::TYPE_LINESTRING;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isTypePolygon()
|
|
{
|
|
return $this->type === self::TYPE_POLYGON;
|
|
}
|
|
|
|
public function setTypeToPolygon()
|
|
{
|
|
$this->type = self::TYPE_POLYGON;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isTypeOther()
|
|
{
|
|
return $this->type === self::TYPE_OTHER;
|
|
}
|
|
|
|
public function setTypeToOther()
|
|
{
|
|
$this->type = self::TYPE_OTHER;
|
|
}
|
|
|
|
public function getGeoJson()
|
|
{
|
|
return \Yii::$app->db->createCommand('SELECT ST_AsGeoJSON(geometry) FROM geo_features WHERE id = :id')
|
|
->bindValue(':id', $this->id)
|
|
->queryScalar();
|
|
}
|
|
|
|
public function getGisBase()
|
|
{
|
|
return $this->hasOne(GisBase::class, ['id' => 'gis_base_id']);
|
|
}
|
|
}
|