Example #1
0
 public function getContent($lang_id = null)
 {
     $lang_id = $lang_id === null ? Lang::getCurrent()->id : $lang_id;
     return $this->hasOne(SaleLang::className(), ['id' => 'id'])->where('lang_id = :lang_id', [':lang_id' => $lang_id]);
 }
Example #2
0
 function actionSaleUpdate($id)
 {
     $model = Sale::findOne(['id' => $id, 'user_id' => Yii::$app->user->identity->getId()]);
     if (empty($model)) {
         return $this->redirect(['/personal']);
     }
     for ($i = 1; $i <= Lang::find()->count(); $i++) {
         $model_content[$i] = SaleLang::findOne(['id' => $id, 'lang_id' => $i]);
     }
     if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content) && $model->save()) {
         foreach ($model_content as $key => $content) {
             $content->save(false);
         }
         return $this->redirect(['/personal']);
     } else {
         return $this->render('sale/update', ['model' => $model, 'model_content' => $model_content]);
     }
 }
Example #3
0
 /**
  * Updates an existing Sale model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     for ($i = 1; $i <= Lang::find()->count(); $i++) {
         $model_content[$i] = SaleLang::findOne(['id' => $id, 'lang_id' => $i]);
     }
     if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content) && $model->save()) {
         foreach ($model_content as $key => $content) {
             $content->save(false);
         }
         return $this->redirect(['/sale']);
     } else {
         return $this->render('update', ['model' => $model, 'model_content' => $model_content]);
     }
 }
Example #4
0
 public function actionSend()
 {
     $data = Yii::$app->request->post();
     if (!empty($data['Parse']['id'])) {
         $parse = Parse::findOne($data['Parse']['id']);
     } else {
         return false;
     }
     if (!empty($data['Sale']['id'])) {
         $sale = Sale::findOne($data['Sale']['id']);
         $content = $sale->content;
     }
     if (empty($sale)) {
         $sale = new Sale();
         $sale->user_id = @$data['Sale']['user_id'];
     }
     if (empty($content)) {
         $content = new SaleLang();
         $content->lang_id = Lang::getCurrent()->id;
         $content->id = 0;
     }
     if ($sale->load($data) && $content->load($data) && $sale->validate() && $content->validate()) {
         $sale->save(false);
         if (!$content->id) {
             for ($i = 1; $i <= Lang::find()->count(); $i++) {
                 $model_content[$i] = new SaleLang();
                 $model_content[$i]['lang_id'] = $i;
                 $model_content[$i]['id'] = $sale->id;
                 $model_content[$i]['description'] = $content->description;
                 $model_content[$i]['name'] = $content->name;
                 $model_content[$i]->save(false);
             }
             $parse->sale_id = $sale->id;
             $parse->save();
         } else {
             $content->save(false);
         }
         return true;
     } else {
         Yii::trace(print_r($sale->errors, true));
         Yii::trace(print_r($content->errors, true));
         return false;
     }
 }