Example #1
0
 public function beforeSave($insert)
 {
     $r = parent::beforeSave($insert);
     if ($r) {
         $scheme = static::getTableSchema();
         foreach ($scheme->columns as $column) {
             if (static::isSpatial($column)) {
                 $field = $column->name;
                 $attr = $this->getAttribute($field);
                 if ($attr) {
                     $this->_saved[$field] = $attr;
                     $feature = Json::decode($attr);
                     $wkt = SpatialHelper::featureToWkt($feature);
                     $this->setAttribute($field, new Expression("GeomFromText('{$wkt}')"));
                 }
             }
         }
     }
     return $r;
 }