Пример #1
0
 static function getLangByUrl($url = null)
 {
     if ($url === null) {
         return null;
     } else {
         $language = Lang::find()->where('url = :url', [':url' => $url])->one();
         if ($language === null) {
             return null;
         } else {
             return $language;
         }
     }
 }
Пример #2
0
 public static function getLangByUrl($code = null)
 {
     if ($code === null) {
         return null;
     } else {
         $language = Lang::find()->where('code = :code', [':code' => $code])->one();
         if ($language === null) {
             return null;
         } else {
             return $language;
         }
     }
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Lang::find()->notDeleted();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'default' => $this->default, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by, 'deleted' => $this->deleted]);
     $query->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'local', $this->local])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Пример #4
0
 /**
  * Updates an existing View 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] = ViewLang::findOne(['id' => $id, 'lang_id' => $i]);
     }
     if (Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content)) {
         foreach ($model_content as $key => $content) {
             $content->save(false);
         }
         return $this->redirect(['/view']);
     } else {
         return $this->render('update', ['model' => $model, 'model_content' => $model_content]);
     }
 }
Пример #5
0
 /**
  * Updates an existing SourceMessage 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);
     $lang = Lang::find()->all();
     foreach ($lang as $i) {
         $model_content[$i->code] = Message::findOne(['id' => $id, 'language' => $i->code]);
     }
     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(['/message']);
     } else {
         return $this->render('update', ['model' => $model, 'model_content' => $model_content]);
     }
 }
Пример #6
0
 function actionSaleCreate()
 {
     $model = new Sale();
     for ($i = 1; $i <= Lang::find()->count(); $i++) {
         $model_content[$i] = new SaleLang();
         $model_content[$i]['lang_id'] = $i;
         $model_content[$i]['id'] = 0;
     }
     $model->status = Sale::STATUS_AWAITING;
     $model->sold = 1;
     $model->code = rand(100000000, 999999999);
     if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content) && $model->validate() && $model->district_id > 0) {
         $model->save();
         foreach ($model_content as $key => $content) {
             $content->id = $model->id;
             $content->lang_id = $key;
             $content->save(false);
         }
         return $this->redirect(['sale-update', 'id' => $model->id]);
     } else {
         return $this->render('sale/create', ['model' => $model, 'model_content' => $model_content]);
     }
 }
Пример #7
0
 /**
  * Lists all Lang models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Lang::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Пример #8
0
 public function run()
 {
     return $this->render('lang/view', ['current' => Lang::getCurrent(), 'langs' => Lang::find()->where('id != :current_id', [':current_id' => Lang::getCurrent()->id])->all()]);
 }
Пример #9
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;
     }
 }