HEX
Server: Apache
System: Linux server3230.server-vps.com 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64
User: lzgqnjwu (1002)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //proc/1122/cwd/common/models/BotTrackingEvent.php
<?php

namespace common\models;

use Yii;

/**
 * @property int $id
 * @property int $bot_id
 * @property string $chat_id
 * @property string|null $manager_name
 * @property string $event_type
 * @property float $latitude
 * @property float $longitude
 * @property string $maps_url
 * @property string $created_at
 */
class BotTrackingEvent extends \yii\db\ActiveRecord
{
    public const TYPE_START = 'start';
    public const TYPE_MEETING = 'meeting';
    public const TYPE_END = 'end';

    public static function tableName()
    {
        return '{{%bot_tracking_event}}';
    }

    public function rules()
    {
        return [
            [['bot_id', 'chat_id', 'event_type', 'latitude', 'longitude', 'maps_url', 'created_at'], 'required'],
            [['bot_id'], 'integer'],
            [['latitude', 'longitude'], 'number'],
            [['created_at'], 'safe'],
            [['chat_id'], 'string', 'max' => 32],
            [['manager_name'], 'string', 'max' => 255],
            [['event_type'], 'string', 'max' => 20],
            [['maps_url'], 'string', 'max' => 500],
            [['event_type'], 'in', 'range' => [self::TYPE_START, self::TYPE_MEETING, self::TYPE_END]],
        ];
    }

    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', 'ID'),
            'bot_id' => Yii::t('common', 'Bot ID'),
            'chat_id' => Yii::t('common', 'Contact'),
            'manager_name' => Yii::t('common', 'Name'),
            'event_type' => Yii::t('common', 'Tracking event type'),
            'latitude' => Yii::t('common', 'Latitude'),
            'longitude' => Yii::t('common', 'Longitude'),
            'maps_url' => Yii::t('common', 'Google Maps'),
            'created_at' => Yii::t('common', 'Created At'),
        ];
    }

    public function getEventTypeLabel(): string
    {
        $map = [
            self::TYPE_START => Yii::t('common', 'Tracking start'),
            self::TYPE_MEETING => Yii::t('common', 'Tracking meeting'),
            self::TYPE_END => Yii::t('common', 'Tracking end'),
        ];

        return $map[$this->event_type] ?? $this->event_type;
    }

    public static function buildMapsUrl(float $lat, float $lng): string
    {
        return 'https://maps.google.com/?q=' . rawurlencode(sprintf('%.7F,%.7F', $lat, $lng));
    }
}