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']); } }