123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace app\models\entity;
- use Yii;
- use app\models\WpLogs;
- /**
- * This is the model class for table "so_wheel_pairs".
- *
- * @property int $id
- * @property string $token
- * @property string $number_mnf
- * @property int $loco_id
- * @property string $location
- * @property int $dep_loco_number [int(10)]
- * @property int $dep_section_number [int(10)]
- * @property int $depo_id [smallint(5)]
- * @property int $account_id [int(5)]
- * @property int $section_id [int(5)]
- *
- * @property Section $section
- * @property LocomotiveSeries $loco
- */
- class WheelPairs extends \yii\db\ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'so_wheel_pairs';
- }
- public static function getDb()
- {
- return \Yii::$app->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++;
- }
- }
- }
|