From d7c08ec60beaedc21a56ad712685a3b515458ee4 Mon Sep 17 00:00:00 2001 From: rocho Date: Sun, 29 Nov 2015 12:07:21 +0100 Subject: [PATCH] add key crud --- backend/components/AdminMenuStructure.php | 3 +- backend/controllers/KeyController.php | 122 +++++++++++++ backend/models/KeySearch.php | 70 ++++++++ backend/views/key/_form.php | 31 ++++ backend/views/key/_search.php | 37 ++++ backend/views/key/create.php | 21 +++ backend/views/key/index.php | 39 +++++ backend/views/key/update.php | 23 +++ backend/views/key/view.php | 40 +++++ common/models/Key.php | 54 ++++++ composer_kiement1.txt | 162 ++++++++++++++++++ .../m151129_101441_add_table_key.php | 44 +++++ tests/codeception/bin/yii | 0 13 files changed, 645 insertions(+), 1 deletion(-) create mode 100644 backend/controllers/KeyController.php create mode 100644 backend/models/KeySearch.php create mode 100644 backend/views/key/_form.php create mode 100644 backend/views/key/_search.php create mode 100644 backend/views/key/create.php create mode 100644 backend/views/key/index.php create mode 100644 backend/views/key/update.php create mode 100644 backend/views/key/view.php create mode 100644 common/models/Key.php create mode 100644 composer_kiement1.txt create mode 100644 console/migrations/m151129_101441_add_table_key.php mode change 100644 => 100755 tests/codeception/bin/yii diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 5976176..20e37cc 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -58,6 +58,7 @@ class AdminMenuStructure{ $items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ]; $items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ]; $items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ]; + $items[] = ['label' => 'Kulcsok', 'url' =>['/key/index']]; // $items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ]; $this->menuItems[] = ['label' => 'Törszadatok', 'url' =>$this->emptyUrl, 'items' => $items @@ -119,4 +120,4 @@ class AdminMenuStructure{ } -} \ No newline at end of file +} diff --git a/backend/controllers/KeyController.php b/backend/controllers/KeyController.php new file mode 100644 index 0000000..c07709c --- /dev/null +++ b/backend/controllers/KeyController.php @@ -0,0 +1,122 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Key models. + * @return mixed + */ + //http://localhost/fitness-web/backend/web/index.php?r=key/index erre ezt hívja meg elsőzör + public function actionIndex() + { + $searchModel = new KeySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + // backend/views/kex/index.php + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Key model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Key model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Key(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_key]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Key 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); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_key]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Key model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Key model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Key the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Key::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/KeySearch.php b/backend/models/KeySearch.php new file mode 100644 index 0000000..79eeb5b --- /dev/null +++ b/backend/models/KeySearch.php @@ -0,0 +1,70 @@ + $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([ + 'id_key' => $this->id_key, + 'status' => $this->status, + 'type' => $this->type, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'number', $this->number]); + + return $dataProvider; + } +} diff --git a/backend/views/key/_form.php b/backend/views/key/_form.php new file mode 100644 index 0000000..0f26488 --- /dev/null +++ b/backend/views/key/_form.php @@ -0,0 +1,31 @@ + + +
+ + + + field($model, 'number')->textInput(['maxlength' => true]) ?> + + field($model, 'status')->textInput() ?> + + field($model, 'type')->textInput() ?> + + field($model, 'created_at')->textInput() ?> + + field($model, 'updated_at')->textInput() ?> + +
+ isNewRecord ? Yii::t('backend/key', 'Create') : Yii::t('backend/key', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/key/_search.php b/backend/views/key/_search.php new file mode 100644 index 0000000..6610f21 --- /dev/null +++ b/backend/views/key/_search.php @@ -0,0 +1,37 @@ + + + diff --git a/backend/views/key/create.php b/backend/views/key/create.php new file mode 100644 index 0000000..19177f7 --- /dev/null +++ b/backend/views/key/create.php @@ -0,0 +1,21 @@ +title = Yii::t('backend/key', 'Create Key'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/key', 'Keys'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/key/index.php b/backend/views/key/index.php new file mode 100644 index 0000000..c8ab4cc --- /dev/null +++ b/backend/views/key/index.php @@ -0,0 +1,39 @@ +title = Yii::t('backend/key', 'Keys'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+asdf +

title) ?>

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

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

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id_key', + 'number', + 'status', + 'type', + 'created_at', + // 'updated_at', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + +
diff --git a/backend/views/key/update.php b/backend/views/key/update.php new file mode 100644 index 0000000..e3b223b --- /dev/null +++ b/backend/views/key/update.php @@ -0,0 +1,23 @@ +title = Yii::t('backend/key', 'Update {modelClass}: ', [ + 'modelClass' => 'Key', +]) . ' ' . $model->id_key; +$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/key', 'Keys'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id_key, 'url' => ['view', 'id' => $model->id_key]]; +$this->params['breadcrumbs'][] = Yii::t('backend/key', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/key/view.php b/backend/views/key/view.php new file mode 100644 index 0000000..48f5760 --- /dev/null +++ b/backend/views/key/view.php @@ -0,0 +1,40 @@ +title = $model->id_key; +$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/key', 'Keys'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id_key], ['class' => 'btn btn-primary']) ?> + $model->id_key], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('backend/key', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id_key', + 'number', + 'status', + 'type', + 'created_at', + 'updated_at', + ], + ]) ?> + +
diff --git a/common/models/Key.php b/common/models/Key.php new file mode 100644 index 0000000..985a764 --- /dev/null +++ b/common/models/Key.php @@ -0,0 +1,54 @@ + 255] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id_key' => Yii::t('common/key', 'Id Key'), + 'number' => Yii::t('common/key', 'Number'), + 'status' => Yii::t('common/key', 'Status'), + 'type' => Yii::t('common/key', 'Type'), + 'created_at' => Yii::t('common/key', 'Created At'), + 'updated_at' => Yii::t('common/key', 'Updated At'), + ]; + } +} diff --git a/composer_kiement1.txt b/composer_kiement1.txt new file mode 100644 index 0000000..6274c95 --- /dev/null +++ b/composer_kiement1.txt @@ -0,0 +1,162 @@ +sanya@sanyigep ~/public_html/fitness-web $ php composer.phar install +Loading composer repositories with package information +Installing dependencies (including require-dev) from lock file + - Installing yiisoft/yii2-composer (2.0.3) + Loading from cache + + - Installing bower-asset/accounting (v0.3.2) + Loading from cache + + - Installing bower-asset/jquery (2.1.4) + Loading from cache + + - Installing bower-asset/jquery.inputmask (3.1.63) + Loading from cache + + - Installing bower-asset/moment (2.10.6) + Loading from cache + + - Installing bower-asset/punycode (v1.3.2) + Loading from cache + + - Installing bower-asset/bootstrap (v3.3.5) + Loading from cache + + - Installing bower-asset/remarkable-bootstrap-notify (3.1.3) + Loading from cache + + - Installing bower-asset/yii2-pjax (v2.0.4) + Loading from cache + + - Installing cebe/markdown (1.1.0) + Loading from cache + + - Installing ezyang/htmlpurifier (v4.6.0) + Loading from cache + + - Installing yiisoft/yii2 (2.0.6) + Loading from cache + + - Installing yiisoft/yii2-bootstrap (2.0.5) + Loading from cache + + - Installing bower-asset/fontawesome (v4.4.0) + Loading from cache + + - Installing rmrevin/yii2-fontawesome (2.12.2) + Loading from cache + + - Installing cebe/yii2-gravatar (1.1) + Loading from cache + + - Installing almasaeed2010/adminlte (v2.3.2) + Loading from cache + + - Installing dmstr/yii2-adminlte-asset (2.2.4) + Loading from cache + + - Installing kartik-v/bootstrap-fileinput (v4.2.7) + Loading from cache + + - Installing kartik-v/bootstrap-star-rating (v3.5.4) + Loading from cache + + - Installing kartik-v/dependent-dropdown (v1.4.3) + Loading from cache + + - Installing kartik-v/yii2-krajee-base (v1.7.7) + Loading from cache + + - Installing kartik-v/yii2-widget-typeahead (v1.0.1) + Loading from cache + + - Installing kartik-v/yii2-widget-touchspin (v1.2.0) + Loading from cache + + - Installing kartik-v/yii2-widget-timepicker (v1.0.0) + Loading from cache + + - Installing kartik-v/yii2-widget-switchinput (v1.3.0) + Loading from cache + + - Installing kartik-v/yii2-widget-spinner (v1.0.0) + Loading from cache + + - Installing kartik-v/yii2-widget-sidenav (v1.0.0) + Loading from cache + + - Installing kartik-v/yii2-widget-select2 (v2.0.3) + Loading from cache + + - Installing kartik-v/yii2-widget-rating (v1.0.0) + Loading from cache + + - Installing kartik-v/yii2-widget-rangeinput (v1.0.0) + Loading from cache + + - Installing kartik-v/yii2-widget-growl (v1.1.1) + Loading from cache + + - Installing kartik-v/yii2-widget-fileinput (v1.0.3) + Loading from cache + + - Installing kartik-v/yii2-widget-depdrop (v1.0.2) + Loading from cache + + - Installing kartik-v/yii2-widget-datetimepicker (v1.4.0) + Loading from cache + + - Installing kartik-v/yii2-widget-datepicker (v1.3.3) + Loading from cache + + - Installing kartik-v/yii2-widget-colorinput (v1.0.0) + Loading from cache + + - Installing kartik-v/yii2-widget-alert (v1.1.0) + Loading from cache + + - Installing kartik-v/yii2-widget-affix (v1.0.0) + Loading from cache + + - Installing kartik-v/yii2-widget-activeform (v1.4.5) + Loading from cache + + - Installing kartik-v/yii2-widgets (v3.4.0) + Loading from cache + + - Installing bower-asset/jquery-ui (1.11.4) + Loading from cache + + - Installing yiisoft/yii2-jui (2.0.4) + Loading from cache + + - Installing swiftmailer/swiftmailer (v5.4.1) + Loading from cache + + - Installing yiisoft/yii2-swiftmailer (2.0.4) + Loading from cache + + - Installing yiisoft/yii2-codeception (2.0.4) + Loading from cache + + - Installing yiisoft/yii2-debug (2.0.5) + Loading from cache + + - Installing fzaninotto/faker (v1.5.0) + Loading from cache + + - Installing yiisoft/yii2-faker (2.0.3) + Loading from cache + + - Installing phpspec/php-diff (v1.0.2) + Loading from cache + + - Installing bower-asset/typeahead.js (v0.10.5) + Loading from cache + + - Installing yiisoft/yii2-gii (2.0.4) + Loading from cache + +fzaninotto/faker suggests installing ext-intl (*) +Generating autoload files + diff --git a/console/migrations/m151129_101441_add_table_key.php b/console/migrations/m151129_101441_add_table_key.php new file mode 100644 index 0000000..4df3a0b --- /dev/null +++ b/console/migrations/m151129_101441_add_table_key.php @@ -0,0 +1,44 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('{{%key}}', [ + 'id_key' => $this->primaryKey(), + 'number' => $this->string(255), + 'status' => $this->smallInteger(), + 'type' => $this->smallInteger(), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions); + + } + + public function down() + { + echo "m151129_101441_add_table_key cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/tests/codeception/bin/yii b/tests/codeception/bin/yii old mode 100644 new mode 100755