Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace common\models;
- use Yii;
- /**
- * This is the model class for table "places_gis".
- *
- * @property integer $id
- * @property integer $place_id
- * @property string $location
- * @property string $created_at
- * @property string $updated_at
- */
- class PlacesGis extends \common\models\_BaseModel {
- /**
- * @inheritdoc
- */
- public static function tableName() {
- return 'places_gis';
- }
- /**
- * @inheritdoc
- */
- public function rules() {
- return [
- [['place_id'], 'integer'],
- [['location', 'created_at', 'updated_at'], 'required'],
- [['location'], 'string'],
- [['created_at', 'updated_at'], 'safe']
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels() {
- return [
- 'id' => Yii::t('app', 'ID'),
- 'place_id' => Yii::t('app', 'Place ID'),
- 'location' => Yii::t('app', 'Location'),
- 'created_at' => Yii::t('app', 'Created At'),
- 'updated_at' => Yii::t('app', 'Updated At'),
- ];
- }
- /**
- * @inheritdoc
- * @return PlacesGisQuery the active query used by this AR class.
- */
- public static function find() {
- return new PlacesGisQuery(get_called_class());
- }
- /**
- * since yii2 does not support MYSQL GIS Out of the box
- * @param float $long x
- * @param float $lat y
- * @param integer $place_id
- * @return Boolean
- */
- public function saveRaw($long, $lat, $place_id) {
- $sql = "INSERT INTO `" . self::tableName() . "` ("
- . "`place_id`, "
- . "`location`, "
- . "`created_at`, "
- . "`updated_at`"
- . ") VALUES (:param_placeid, GeomFromText(:point), TIMESTAMP(NOW()), TIMESTAMP(NOW()));";
- $command = \yii::$app->db->createCommand($sql, [
- ':param_placeid' => $place_id,
- ':point' => sprintf('POINT(%f %f)', $long, $lat)
- ]);
- return $command->execute();
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getPlace() {
- return $this->hasOne(Places::className(), ['id' => 'place_id']);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement