1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\models\entity;
- use phpDocumentor\Reflection\Types\This;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "so_oilstat".
- *
- * @property int $id
- * @property string $cond
- * @property int $device_id
- * @property string $date [varchar(255)]
- * @property string $token [varchar(255)]
- * @property string $location [varchar(5)]
- * @property int $section_number [int(10)]
- * @property int $send_date [int(10)] Дата отправки данных timestamp
- * @property string $send_ip [varchar(255)] IP с которого запросили данные
- *
- * @property WheelPairs $wheelpairs
- */
- class Oilstat extends ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'so_oilstat';
- }
-
- public static function getDb()
- {
- return \Yii::$app->slave_db;
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['cond', 'date', 'device_id', 'token'], 'required'],
- [['device_id', 'send_date'], 'integer'],
- [['cond'], 'string', 'max' => 5],
- [['token','date'], 'unique', 'targetAttribute' => ['date', 'token']],
- [['date', 'token', 'send_ip'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'cond' => 'Состояние',
- 'device_id' => 'Номер устройства(масломер)',
- 'date' => 'Дата',
- 'token' => 'Метка (rfid)',
- 'location' => 'Расположение клёсной пары',
- 'section_number' => 'Номер секции',
- 'send_date' => 'Дата отправки показаний',
- 'send_ip' => 'IP с которого пришли показания'
- ];
- }
-
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getWheelpairs()
- {
- return $this->hasOne(WheelPairs::class, ['token' => 'token']);
- }
- public function getLocation()
- {
- if ($this->location) return $this->location;
- $location = explode('/', $this->token);
- return $location[1] ?? null;
- }
- }
|