public function search($params) { $query = Agreement::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'default_flag' => $this->default_flag]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'body', $this->body]); return $dataProvider; }
/** * Updates an existing Product 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); foreach ((array) $model->attributes as $field => $v) { if (substr($field, -5, 5) == '_file' || substr($field, -6, 6) == '_image') { $model->{$field} = file_exists($_SERVER['DOCUMENT_ROOT'] . $model->{$field}) ? $model->{$field} : null; } } if (!is_numeric($model['agreement_id'])) { $agreement = Agreement::find()->where(["default_flag" => 1])->asArray()->one(); $model['agreement_id'] = $agreement['id']; } if ($model->load(Yii::$app->request->post()) && $model->save()) { $redirect = yii::$app->request->post('goto') == 'list' ? ['index'] : ['update', 'id' => $model->id]; return $this->redirect($redirect); } return $this->render('update', ['model' => $model]); }
/** * Страница продукта */ public function actionProductBuy($id) { $item = Product::find()->with('organization', 'type')->with('agreement')->where(['id' => $id])->asArray()->one(); $item['price_format'] = Product::priceFormat($item['price']); $item['price_discount_format'] = Product::priceFormat($item['price_discount']); if (!count($item['agreement'])) { $agreement = Agreement::find()->where(["default_flag" => 1])->asArray()->one(); $item['agreement'] = $agreement; } // Загружаем в форму данные пользователя $user = Yii::$app->user->getIdentity(); $model_signup = array(); $page = $user ? 'product_buy' : 'buy_forbidden'; if ($page == 'buy_forbidden') { $model_signup = new ProfileForm(); $model_signup->setScenario('signup'); if ($model_signup->load(Yii::$app->request->post())) { if ($user = $model_signup->signup()) { if (Yii::$app->getUser()->login($user)) { return $this->redirect(Yii::$app->request->referrer); //return $this->goHome(); } } } } else { if (Yii::$app->request->post() && $user) { // Устанавливаем сценарий валидации $form = new OrderForm(); if ($form->saveOrder($user, $item, Yii::$app->request->post())) { die('true'); } else { die('false'); } } } return $this->render($page, ['item' => $item, 'user' => $user, 'model_signup' => $model_signup]); }