Пример #1
0
 public function actionIndex()
 {
     $debug = '';
     $model = new DynamicModel(['vins', 'diller']);
     $model->addRule('vins', 'string')->addRule('diller', 'integer')->addRule(['diller', 'vins'], 'required');
     $list = ArrayHelper::map(Mod\cats\Diller::find()->all(), 'id', 'name');
     $prompt = Yii::t('app', 'Select diller');
     $arrError = [];
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         //			Yii::$app->session->setFlash('success', Yii::t('app', 'Done'));
         //			$debug = print_r(Yii::$app->request->post('DynamicModel'), true);
         $arrvin = explode("\n", $model->vins);
         foreach ($arrvin as $vin) {
             if ($car = Mod\Car::findOne(['vin' => trim($vin)])) {
                 $status = Mod\CarStatus::findOne(['car_id' => $car->id]);
                 $status->diller_id = $model->diller;
                 $status->save();
             } else {
                 $arrError[] = $vin . ' не найден VIN';
             }
         }
         $debug = implode('<br>', $arrError);
         return $this->render('finish', ['debug' => $debug]);
     }
     $arrVars = ['model' => $model, 'list' => $list, 'prompt' => $prompt, 'selLabel' => 'Диллер', 'title' => 'Пакетное присвоение'];
     return $this->render('index', $arrVars);
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDiller()
 {
     return $this->hasOne(cats\Diller::className(), ['id' => 'diller_id']);
 }