slave_db; } /** * {@inheritdoc} */ public function rules() { return [ [[ 'location'], 'required'], [[ 'location'], 'safe'], //['token', 'default', 'value' => 'Отсутствует'], ['number_mnf', 'default', 'value' => 'Отсутствует'], //[['loco_id'], 'integer'], [['token'], 'string', 'max' => 255], [['number_mnf'], 'string', 'max' => 55], [['location'], 'string', 'max' => 5], //['token', 'unique'], [['token','section_id'], 'unique', 'targetAttribute' => ['token', 'section_id']], [['location','section_id'], 'unique', 'targetAttribute' => ['location', 'section_id']], //[['loco_id'], 'exist', 'skipOnError' => true, 'targetClass' => Locomotive::className(), 'targetAttribute' => ['loco_id' => 'id']], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'token' => 'Номер метки', 'number_mnf' => 'Number Mnf', 'loco_id' => 'Loco ID', 'location' => 'Location', ]; } /** * @return \yii\db\ActiveQuery */ public function getLoco() { return $this->hasOne(LocomotiveSeries::class, ['id' => 'loco_id']); } /** * @return \yii\db\ActiveQuery */ public function getOilstat() { return $this->hasMany(Oilstat::class, ['token' => 'token'])->orderBy(['date' => SORT_DESC]); } /** * @return \yii\db\ActiveQuery */ public function getSection() { return $this->hasOne(Section::class, ['id' => 'section_id']); } /** * @param WheelPairs[] $wheelPairs * @param Oilstat[] $oilstat */ public function updateWheelPair(array $wheelPairs, array $oilstat, $id = null ) { $count = 0; $oilstat = array_reverse($oilstat); foreach ($wheelPairs as $pair) { $WpLogs = new WpLogs(); $WpLogs->id_session = $id; $WpLogs->old_val = 'token => ' . $pair->token . ' loco_id => ' . $pair->loco_id . ' location => ' . $pair->location . ' section_id => ' . $pair->section_id; $pair->property = ''; if (in_array($oilstat[$count]->token, Yii::$app->params['materials'])) { $pair->property = $oilstat[$count]->token; $pair->token = 'null/'.$pair->location .'/'. $pair->section_id; } else { $pair->token = $oilstat[$count]->token; } $WpLogs->new_val = 'token => ' . $pair->token . ' loco_id => ' . $pair->loco_id . ' location => ' . $pair->location . ' section_id => ' . $pair->section_id; $WpLogs->save(); //var_dump('prop - ' . $pair->property,'token - '.$pair->token, 'time - '. $oilstat[$count]->date,'location - '. $pair->location); $pair->save(); //var_dump($pair->errors); $count++; } } }