From b427543e93b4f42705b7808d939916e8585d2ca5 Mon Sep 17 00:00:00 2001 From: andryeyev Date: Thu, 5 Nov 2015 11:27:13 +0200 Subject: [PATCH] Итерация 2 (рекурсия): Вставка терминов --- .htaccess | 7 +------ backend/config/main.php | 9 +-------- backend/controllers/Termin_langController.php | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/models/TerminLangSearch.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/page/index.php | 10 +++++++--- backend/views/termin_lang/_form.php | 23 +++++++++++++++++++++++ backend/views/termin_lang/_search.php | 31 +++++++++++++++++++++++++++++++ backend/views/termin_lang/create.php | 22 ++++++++++++++++++++++ backend/views/termin_lang/index.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ backend/views/termin_lang/update.php | 21 +++++++++++++++++++++ backend/views/termin_lang/view.php | 37 +++++++++++++++++++++++++++++++++++++ common/config/.gitignore | 2 -- common/config/main-local.php | 20 ++++++++++++++++++++ common/config/params-local.php | 3 +++ common/models/Termin.php | 9 +-------- common/models/TerminLang.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ common/models/TerminOption.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php | 2 +- vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php | 1 + 19 files changed, 536 insertions(+), 28 deletions(-) create mode 100644 backend/controllers/Termin_langController.php create mode 100644 backend/models/TerminLangSearch.php create mode 100644 backend/views/termin_lang/_form.php create mode 100644 backend/views/termin_lang/_search.php create mode 100644 backend/views/termin_lang/create.php create mode 100644 backend/views/termin_lang/index.php create mode 100644 backend/views/termin_lang/update.php create mode 100644 backend/views/termin_lang/view.php delete mode 100644 common/config/.gitignore create mode 100644 common/config/main-local.php create mode 100644 common/config/params-local.php create mode 100644 common/models/TerminLang.php create mode 100644 common/models/TerminOption.php diff --git a/.htaccess b/.htaccess index 3751198..d37f705 100644 --- a/.htaccess +++ b/.htaccess @@ -17,12 +17,7 @@ # the main rewrite rule for the frontend application RewriteCond %{REQUEST_URI} !^/(backend/web|admin) RewriteRule !^frontend/web /frontend/web%{REQUEST_URI} [L] - - RewriteRule ^admin$ /admin/$1 [R=301,L] - - RewriteCond %{REQUEST_URI} ^/admin/ - RewriteRule ^admin(.*) /backend/web/$1 [L,QSA] - + RewriteCond %{REQUEST_URI} ^/frontend/web RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d diff --git a/backend/config/main.php b/backend/config/main.php index add0a7e..8b43499 100644 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -26,14 +26,7 @@ return [ ], 'urlManager' => [ 'enablePrettyUrl' => true, - 'showScriptName' => false, - 'rules' => [ - '/' => '/view', - '//' => '/', - '//' => '/', - // get. - '//' => '/', - ] + 'showScriptName' => false, ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, diff --git a/backend/controllers/Termin_langController.php b/backend/controllers/Termin_langController.php new file mode 100644 index 0000000..cb90553 --- /dev/null +++ b/backend/controllers/Termin_langController.php @@ -0,0 +1,163 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all TerminLang models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new TerminLangSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single TerminLang model. + * @param integer $termin_id + * @param integer $lang_id + * @return mixed + */ + public function actionView($termin_id) + { + return $this->render('view', [ + 'model' => $this->findModel($termin_id, $lang_id), + ]); + } + + /** + * Creates a new TerminLang model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $termin = new Termin(); + $termin_lang = new TerminLang(); + + if ($termin_lang->load(Yii::$app->request->post())) { + + $termin->termin_id = ''; + $termin->save(); + $termin_lang->termin_id = $termin->termin_id; + $termin_lang->save(); + + return $this->redirect(['index']); + } else { + return $this->render('create', [ + 'termin_lang' => $termin_lang, + 'termin' => $termin, + ]); + } + } + + public function actionCreate_parent($termin_id) + { + $termin = new Termin(); + $termin_lang = new TerminLang(); + $termin_option = new TerminOption(); + + if ($termin_lang->load(Yii::$app->request->post())) { + + $termin->termin_id = ''; + $termin->save(); + // var_dump($termin->termin_id);die(); + $termin_lang->termin_id = $termin->termin_id; + $termin_lang->save(); + + $termin_option->termin_id = $termin->termin_id; + $termin_option->termin_pid = $termin_id; + $termin_option->save(); + + + return $this->redirect(['index']); + } else { + return $this->render('create', [ + 'termin_lang' => $termin_lang, + 'termin' => $termin, + ]); + } + } + + /** + * Updates an existing TerminLang model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $termin_id + * @param integer $lang_id + * @return mixed + */ + public function actionUpdate($termin_id, $lang_id) + { + $model = $this->findModel($termin_id, $lang_id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'termin_id' => $model->termin_id, 'lang_id' => $model->lang_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing TerminLang model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $termin_id + * @param integer $lang_id + * @return mixed + */ + public function actionDelete($termin_id, $lang_id) + { + $this->findModel($termin_id, $lang_id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the TerminLang model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $termin_id + * @param integer $lang_id + * @return TerminLang the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($termin_id, $lang_id) + { + if (($model = TerminLang::findOne(['termin_id' => $termin_id, 'lang_id' => $lang_id])) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/TerminLangSearch.php b/backend/models/TerminLangSearch.php new file mode 100644 index 0000000..84d4582 --- /dev/null +++ b/backend/models/TerminLangSearch.php @@ -0,0 +1,67 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'termin_id' => $this->termin_id, + 'lang_id' => $this->lang_id, + ]); + + $query->andFilterWhere(['like', 'termin_title', $this->termin_title]); + + return $dataProvider; + } +} diff --git a/backend/views/page/index.php b/backend/views/page/index.php index 816f582..ee0b1aa 100644 --- a/backend/views/page/index.php +++ b/backend/views/page/index.php @@ -20,13 +20,17 @@ $this->params['breadcrumbs'][] = $this->title; $dataProvider, - 'filterModel' => ['title' => 1], + 'filterModel' => $searchModel, + //'filterModel' => ['title' => 1], 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], + + ['class' => 'yii\grid\SerialColumn'], + 'page_id' , 'date_add', - 'title', + //'title', 'show', + ['class' => 'yii\grid\ActionColumn'], ], ]); ?> diff --git a/backend/views/termin_lang/_form.php b/backend/views/termin_lang/_form.php new file mode 100644 index 0000000..e3736aa --- /dev/null +++ b/backend/views/termin_lang/_form.php @@ -0,0 +1,23 @@ + + +
+ + + + field($termin_lang, 'termin_title')->textInput(['maxlength' => true]) ?> + +
+ isNewRecord ? 'Create' : 'Update', ['class' => $termin_lang->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/termin_lang/_search.php b/backend/views/termin_lang/_search.php new file mode 100644 index 0000000..3ba1e0c --- /dev/null +++ b/backend/views/termin_lang/_search.php @@ -0,0 +1,31 @@ + + + diff --git a/backend/views/termin_lang/create.php b/backend/views/termin_lang/create.php new file mode 100644 index 0000000..5929357 --- /dev/null +++ b/backend/views/termin_lang/create.php @@ -0,0 +1,22 @@ +title = 'Create Termin Lang'; +$this->params['breadcrumbs'][] = ['label' => 'Termin Langs', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'termin_lang' => $termin_lang, + 'termin' => $termin, + ]) ?> + +
diff --git a/backend/views/termin_lang/index.php b/backend/views/termin_lang/index.php new file mode 100644 index 0000000..e64c82e --- /dev/null +++ b/backend/views/termin_lang/index.php @@ -0,0 +1,44 @@ +title = 'Termin Langs'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'termin_id', + 'termin_title', + 'lang_id', + + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{create} {view} {update} {delete} {create_parent}', + 'buttons' => [ + 'create_parent' => function ($url, $model, $key) { + return Html::a('', $url); + } + ], + ], + ], + ]); ?> + +
diff --git a/backend/views/termin_lang/update.php b/backend/views/termin_lang/update.php new file mode 100644 index 0000000..c061a32 --- /dev/null +++ b/backend/views/termin_lang/update.php @@ -0,0 +1,21 @@ +title = 'Update Termin Lang: ' . ' ' . $model->termin_id; +$this->params['breadcrumbs'][] = ['label' => 'Termin Langs', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->termin_id, 'url' => ['view', 'termin_id' => $model->termin_id, 'lang_id' => $model->lang_id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/termin_lang/view.php b/backend/views/termin_lang/view.php new file mode 100644 index 0000000..09bef92 --- /dev/null +++ b/backend/views/termin_lang/view.php @@ -0,0 +1,37 @@ +title = $model->termin_id; +$this->params['breadcrumbs'][] = ['label' => 'Termin Langs', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->termin_id, 'lang_id' => $model->lang_id], ['class' => 'btn btn-primary']) ?> + $model->termin_id, 'lang_id' => $model->lang_id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'termin_id', + 'termin_title', + 'lang_id', + ], + ]) ?> + +
diff --git a/common/config/.gitignore b/common/config/.gitignore deleted file mode 100644 index 97c0f01..0000000 --- a/common/config/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -main-local.php -params-local.php diff --git a/common/config/main-local.php b/common/config/main-local.php new file mode 100644 index 0000000..c5c1a2b --- /dev/null +++ b/common/config/main-local.php @@ -0,0 +1,20 @@ + [ + 'db' => [ + 'class' => 'yii\db\Connection', + 'dsn' => 'mysql:host=localhost;dbname=artbox_db', + 'username' => 'root', + 'password' => '', + 'charset' => 'utf8', + ], + 'mailer' => [ + 'class' => 'yii\swiftmailer\Mailer', + 'viewPath' => '@common/mail', + // send all mails to a file by default. You have to set + // 'useFileTransport' to false and configure a transport + // for the mailer to send real emails. + 'useFileTransport' => true, + ], + ], +]; diff --git a/common/config/params-local.php b/common/config/params-local.php new file mode 100644 index 0000000..d0b9c34 --- /dev/null +++ b/common/config/params-local.php @@ -0,0 +1,3 @@ + 'Termin ID', - 'termin_pid' => 'Termin Pid', - 'lfr' => 'Lfr', - 'rgt' => 'Rgt', 'termin_type_id' => 'Termin Type ID', 'page_id' => 'Page ID', ]; diff --git a/common/models/TerminLang.php b/common/models/TerminLang.php new file mode 100644 index 0000000..720e96b --- /dev/null +++ b/common/models/TerminLang.php @@ -0,0 +1,47 @@ + 256] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'termin_id' => 'Termin ID', + 'termin_title' => 'Termin Title', + 'lang_id' => 'Lang ID', + ]; + } +} diff --git a/common/models/TerminOption.php b/common/models/TerminOption.php new file mode 100644 index 0000000..717f4df --- /dev/null +++ b/common/models/TerminOption.php @@ -0,0 +1,46 @@ + 'Termin ID', + 'termin_pid' => 'Termin Pid', + 'sortorder' => 'Sortorder', + ]; + } +} diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php index 824b085..9149654 100644 --- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php +++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php @@ -264,7 +264,7 @@ $username = Yii::$app->user->identity->firstname.' '.Yii::$app->user->identity->