From 6880eaa2badb1c54cd2482ea28582036ceb31ed6 Mon Sep 17 00:00:00 2001 From: akosse Date: Tue, 21 Jan 2020 17:33:07 +0300 Subject: [PATCH] accesses new --- .../accesses/models/AccessesSearch.php | 8 +- .../modules/accesses/views/accesses/_form.php | 49 ++++--- .../accesses/views/accesses/_search.php | 2 - .../modules/accesses/views/accesses/index.php | 23 ++-- .../modules/accesses/views/accesses/view.php | 34 ++--- .../modules/calendar/views/calendar/index.php | 42 +++--- backend/modules/card/models/UserCard.php | 2 +- common/models/Accesses.php | 16 ++- ...drop_access_column_from_accesses_table.php | 25 ++++ ...006_add_login_column_to_accesses_table.php | 25 ++++ ..._add_password_column_to_accesses_table.php | 31 +++++ .../access/controllers/AccessController.php | 124 ++++++++++++++++-- frontend/modules/access/models/Access.php | 29 ++++ .../modules/access/models/AccessSearch.php | 73 +++++++++++ .../modules/access/views/access/_form.php | 33 +++++ .../modules/access/views/access/_search.php | 39 ++++++ .../modules/access/views/access/create.php | 18 +++ .../modules/access/views/access/index.php | 41 ++++-- .../modules/access/views/access/update.php | 19 +++ frontend/modules/access/views/access/view.php | 40 ++++++ 20 files changed, 575 insertions(+), 98 deletions(-) create mode 100644 console/migrations/m200121_115737_drop_access_column_from_accesses_table.php create mode 100644 console/migrations/m200121_120006_add_login_column_to_accesses_table.php create mode 100644 console/migrations/m200121_120121_add_password_column_to_accesses_table.php mode change 100755 => 100644 frontend/modules/access/controllers/AccessController.php create mode 100644 frontend/modules/access/models/Access.php create mode 100644 frontend/modules/access/models/AccessSearch.php create mode 100644 frontend/modules/access/views/access/_form.php create mode 100644 frontend/modules/access/views/access/_search.php create mode 100644 frontend/modules/access/views/access/create.php mode change 100755 => 100644 frontend/modules/access/views/access/index.php create mode 100644 frontend/modules/access/views/access/update.php create mode 100644 frontend/modules/access/views/access/view.php diff --git a/backend/modules/accesses/models/AccessesSearch.php b/backend/modules/accesses/models/AccessesSearch.php index 709710a..4f375df 100755 --- a/backend/modules/accesses/models/AccessesSearch.php +++ b/backend/modules/accesses/models/AccessesSearch.php @@ -18,7 +18,7 @@ class AccessesSearch extends Accesses { return [ [['id'], 'integer'], - [['name', 'access'], 'safe'], + [['name', 'login', 'password', 'link', 'project', 'info'], 'safe'], ]; } @@ -62,7 +62,11 @@ class AccessesSearch extends Accesses ]); $query->andFilterWhere(['like', 'name', $this->name]) - ->andFilterWhere(['like', 'access', $this->access]); + ->andFilterWhere(['like', 'login', $this->login]) + ->andFilterWhere(['like', 'password', $this->password]) + ->andFilterWhere(['like', 'link', $this->link]) + ->andFilterWhere(['like', 'project', $this->project]) + ->andFilterWhere(['like', 'info', $this->info]); return $dataProvider; } diff --git a/backend/modules/accesses/views/accesses/_form.php b/backend/modules/accesses/views/accesses/_form.php index 0cd4345..0895c92 100755 --- a/backend/modules/accesses/views/accesses/_form.php +++ b/backend/modules/accesses/views/accesses/_form.php @@ -18,28 +18,38 @@ use kartik\select2\Select2; field($model, 'name')->textInput(['maxlength' => true]) ?> - field($model, 'access')->textarea(['maxlength' => true]) ?> + field($model, 'login')->textInput(['maxlength' => true]) ?> -
-
- $model, - 'attribute' => '_projects', - 'data' => \yii\helpers\ArrayHelper::map(\common\models\Project::find()->all(), 'id', 'name'), - 'options' => ['placeholder' => '...', 'class' => 'form-control', 'multiple' => true], - 'pluginOptions' => [ - 'allowClear' => true - ], - ] - ) ?> -
-
+ field($model, 'password')->textInput(['maxlength' => true]) ?> + + field($model, 'link')->textInput(['maxlength' => true]) ?> + + field($model, 'project')->textInput(['maxlength' => true]) ?> + + field($model, 'info')->textarea(['maxlength' => true]) ?> + + + + $model, +// 'attribute' => '_projects', +// 'data' => \yii\helpers\ArrayHelper::map(\common\models\Project::find()->all(), 'id', 'name'), +// 'options' => ['placeholder' => '...', 'class' => 'form-control', 'multiple' => true], +// 'pluginOptions' => [ +// 'allowClear' => true +// ], +// ] +// ) ?> + +
Пользователи - $model, 'attribute' => '_users', @@ -48,13 +58,12 @@ use kartik\select2\Select2; 'pluginOptions' => [ 'allowClear' => true ], - ] - ) ?> + ]); ?>
- 'btn btn-success']) ?> + ' . Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
diff --git a/backend/modules/accesses/views/accesses/_search.php b/backend/modules/accesses/views/accesses/_search.php index 40b1d85..cae9add 100755 --- a/backend/modules/accesses/views/accesses/_search.php +++ b/backend/modules/accesses/views/accesses/_search.php @@ -19,8 +19,6 @@ use yii\widgets\ActiveForm; field($model, 'name') ?> - field($model, 'access') ?> -
'btn btn-primary']) ?> 'btn btn-default']) ?> diff --git a/backend/modules/accesses/views/accesses/index.php b/backend/modules/accesses/views/accesses/index.php index 05d1c81..0507d75 100755 --- a/backend/modules/accesses/views/accesses/index.php +++ b/backend/modules/accesses/views/accesses/index.php @@ -24,10 +24,11 @@ $this->params['breadcrumbs'][] = $this->title; 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], - - 'name', - 'access', + 'login', + 'password', + 'link', + 'project', [ 'attribute' => 'userCard.fio', 'format' => 'raw', @@ -35,15 +36,13 @@ $this->params['breadcrumbs'][] = $this->title; return $model->getUserCardName(); }, ], - - [ - 'attribute' => 'projects.name', - 'format' => 'raw', - 'value' => function(\common\models\Accesses $model){ - return $model->getProjectName(); - }, - ], - +// [ +// 'attribute' => 'projects.name', +// 'format' => 'raw', +// 'value' => function(\common\models\Accesses $model){ +// return $model->getProjectName(); +// }, +// ], ['class' => 'yii\grid\ActionColumn'], ], ]); ?> diff --git a/backend/modules/accesses/views/accesses/view.php b/backend/modules/accesses/views/accesses/view.php index 7310ef2..bc75044 100755 --- a/backend/modules/accesses/views/accesses/view.php +++ b/backend/modules/accesses/views/accesses/view.php @@ -30,21 +30,25 @@ $this->params['breadcrumbs'][] = $this->title; 'model' => $model, 'attributes' => [ 'name', - 'access', - [ - 'attribute' => 'userCard.fio', - 'format' => 'raw', - 'value' => function(\common\models\Accesses $model){ - return $model->getUserCardName(); - }, - ], - [ - 'attribute' => 'projects.name', - 'format' => 'raw', - 'value' => function(\common\models\Accesses $model){ - return $model->getProjectName(); - }, - ], + 'login', + 'password', + 'link', + 'project', + 'info', +// [ +// 'attribute' => 'userCard.fio', +// 'format' => 'raw', +// 'value' => function(\common\models\Accesses $model){ +// return $model->getUserCardName(); +// }, +// ], +// [ +// 'attribute' => 'projects.name', +// 'format' => 'raw', +// 'value' => function(\common\models\Accesses $model){ +// return $model->getProjectName(); +// }, +// ], ], ]) ?> diff --git a/backend/modules/calendar/views/calendar/index.php b/backend/modules/calendar/views/calendar/index.php index ead41d5..148d8a5 100644 --- a/backend/modules/calendar/views/calendar/index.php +++ b/backend/modules/calendar/views/calendar/index.php @@ -1,24 +1,3 @@ -
- -

- -

- +

+ +

+ + 'reload']); echo GridView::widget([ 'dataProvider' => $dataProvider, diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index ebee681..8557172 100755 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -121,7 +121,7 @@ class UserCard extends \common\models\UserCard $user->save(); $log = "Логин: " . $email . " Пароль: " . $password . " | "; - //file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX); + file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX); return $user->id; } diff --git a/common/models/Accesses.php b/common/models/Accesses.php index 4d3c6c9..3d49c97 100755 --- a/common/models/Accesses.php +++ b/common/models/Accesses.php @@ -11,7 +11,11 @@ use yii\helpers\ArrayHelper; * * @property int $id * @property string $name - * @property string $access + * @property string $login + * @property string $password + * @property string $link + * @property string $project + * @property string $info */ class Accesses extends \yii\db\ActiveRecord { @@ -32,8 +36,8 @@ class Accesses extends \yii\db\ActiveRecord public function rules() { return [ - [['name'], 'string', 'max' => 255], - [['access'], 'string'], + [['name', 'login', 'password', 'link', 'project' ], 'string', 'max' => 255], + [['info'], 'string'], [['_projects'], 'safe'], [['_users'], 'safe'], ]; @@ -47,7 +51,11 @@ class Accesses extends \yii\db\ActiveRecord return [ 'id' => 'ID', 'name' => 'Название', - 'access' => 'Доступ', + 'login' => 'Логин', + 'password' => 'Пароль', + 'link' => 'Ссылка', + 'project' => 'Проект', + 'info' => 'Дополнительная информация', ]; } diff --git a/console/migrations/m200121_115737_drop_access_column_from_accesses_table.php b/console/migrations/m200121_115737_drop_access_column_from_accesses_table.php new file mode 100644 index 0000000..e7ca433 --- /dev/null +++ b/console/migrations/m200121_115737_drop_access_column_from_accesses_table.php @@ -0,0 +1,25 @@ +dropColumn('{{%accesses}}', 'access'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->addColumn('{{%accesses}}', 'access', $this->string()); + } +} diff --git a/console/migrations/m200121_120006_add_login_column_to_accesses_table.php b/console/migrations/m200121_120006_add_login_column_to_accesses_table.php new file mode 100644 index 0000000..4cbb9eb --- /dev/null +++ b/console/migrations/m200121_120006_add_login_column_to_accesses_table.php @@ -0,0 +1,25 @@ +addColumn('{{%accesses}}', 'login', $this->string()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('{{%accesses}}', 'login'); + } +} diff --git a/console/migrations/m200121_120121_add_password_column_to_accesses_table.php b/console/migrations/m200121_120121_add_password_column_to_accesses_table.php new file mode 100644 index 0000000..2e78572 --- /dev/null +++ b/console/migrations/m200121_120121_add_password_column_to_accesses_table.php @@ -0,0 +1,31 @@ +addColumn('{{%accesses}}', 'password', $this->string()); + $this->addColumn('{{%accesses}}', 'link', $this->string()); + $this->addColumn('{{%accesses}}', 'project', $this->string()); + $this->addColumn('{{%accesses}}', 'info', $this->text()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('{{%accesses}}', 'password'); + $this->dropColumn('{{%accesses}}', 'link'); + $this->dropColumn('{{%accesses}}', 'project'); + $this->dropColumn('{{%accesses}}', 'info'); + } +} diff --git a/frontend/modules/access/controllers/AccessController.php b/frontend/modules/access/controllers/AccessController.php old mode 100755 new mode 100644 index 8eb6c2c..d6e4c4a --- a/frontend/modules/access/controllers/AccessController.php +++ b/frontend/modules/access/controllers/AccessController.php @@ -3,28 +3,128 @@ namespace frontend\modules\access\controllers; use Yii; -use yii\web\Controller; -use yii\data\ActiveDataProvider; use common\models\Accesses; +use frontend\modules\access\models\AccessSearch; +use yii\data\ActiveDataProvider; +use yii\web\Controller; +use yii\web\NotFoundHttpException; +use yii\filters\VerbFilter; +/** + * AccessController implements the CRUD actions for Accesses model. + */ class AccessController extends Controller { /** + * {@inheritdoc} + */ + public function behaviors() + { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Accesses models. * @return mixed */ public function actionIndex() { - $id_user = Yii::$app->user->id; - $query = "SELECT accesses.name, accesses.access FROM `accesses`, `user_card`, `user_card_accesses` WHERE user_card.id_user =" . $id_user . " AND user_card_accesses.user_card_id = user_card.id AND accesses.id = user_card_accesses.accesses_id "; - $access = Accesses::findBySql($query); - - $dataProvider = new ActiveDataProvider([ - 'query' => $access, - 'pagination' => [ - 'pageSize' => 200, - ], + $dataProvider = new ActiveDataProvider(['query' => Accesses::find() + ->where(['user_card.id_user' => Yii::$app->user->identity->id]) + ->innerJoin('user_card_accesses', 'accesses.id = user_card_accesses.accesses_id') + ->innerJoin('user_card', 'user_card_accesses.user_card_id = user_card.id') ]); - return $this->render('index', compact('dataProvider', $dataProvider)); + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Accesses model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Accesses model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new \frontend\modules\access\models\Access(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Accesses model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Accesses model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Accesses model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Accesses the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Accesses::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); } } diff --git a/frontend/modules/access/models/Access.php b/frontend/modules/access/models/Access.php new file mode 100644 index 0000000..3ffeb0d --- /dev/null +++ b/frontend/modules/access/models/Access.php @@ -0,0 +1,29 @@ + Yii::$app->user->identity->id]); + $user_card_access = new UserCardAccesses(); + $user_card_access->user_card_id = $user_card->id; + $user_card_access->accesses_id = $this->id; + $user_card_access->save(); + } +} \ No newline at end of file diff --git a/frontend/modules/access/models/AccessSearch.php b/frontend/modules/access/models/AccessSearch.php new file mode 100644 index 0000000..9f173ba --- /dev/null +++ b/frontend/modules/access/models/AccessSearch.php @@ -0,0 +1,73 @@ + $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; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'login', $this->login]) + ->andFilterWhere(['like', 'password', $this->password]) + ->andFilterWhere(['like', 'link', $this->link]) + ->andFilterWhere(['like', 'project', $this->project]) + ->andFilterWhere(['like', 'info', $this->info]); + + return $dataProvider; + } +} diff --git a/frontend/modules/access/views/access/_form.php b/frontend/modules/access/views/access/_form.php new file mode 100644 index 0000000..4b979f7 --- /dev/null +++ b/frontend/modules/access/views/access/_form.php @@ -0,0 +1,33 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'login')->textInput(['maxlength' => true]) ?> + + field($model, 'password')->passwordInput(['maxlength' => true]) ?> + + field($model, 'link')->textInput(['maxlength' => true]) ?> + + field($model, 'project')->textInput(['maxlength' => true]) ?> + + field($model, 'info')->textarea(['rows' => 6]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/frontend/modules/access/views/access/_search.php b/frontend/modules/access/views/access/_search.php new file mode 100644 index 0000000..ab44ab4 --- /dev/null +++ b/frontend/modules/access/views/access/_search.php @@ -0,0 +1,39 @@ + + + diff --git a/frontend/modules/access/views/access/create.php b/frontend/modules/access/views/access/create.php new file mode 100644 index 0000000..09486ea --- /dev/null +++ b/frontend/modules/access/views/access/create.php @@ -0,0 +1,18 @@ +title = 'Добавить'; +$this->params['breadcrumbs'][] = ['label' => 'Accesses', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/frontend/modules/access/views/access/index.php b/frontend/modules/access/views/access/index.php old mode 100755 new mode 100644 index 4340a7c..415c7fc --- a/frontend/modules/access/views/access/index.php +++ b/frontend/modules/access/views/access/index.php @@ -1,14 +1,37 @@ title = 'Доступы'; +/* @var $this yii\web\View */ +/* @var $searchModel frontend\modules\access\models\AccessSearch */ +/* @var $dataProvider yii\data\ActiveDataProvider */ -echo GridView::widget([ - 'dataProvider' => $dataProvider, - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], - 'name', - 'access', - ], -]); +$this->title = 'Доступы'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_search', ['model' => $searchModel]); ?> + +

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

+ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'id', + 'name', + 'login', + 'password', + 'link', + 'project', + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{view} {update}', + ], + ], + ]); ?> +
diff --git a/frontend/modules/access/views/access/update.php b/frontend/modules/access/views/access/update.php new file mode 100644 index 0000000..0e59e05 --- /dev/null +++ b/frontend/modules/access/views/access/update.php @@ -0,0 +1,19 @@ +title = 'Изменить'; +$this->params['breadcrumbs'][] = ['label' => 'Доступы', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Изменить'; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/frontend/modules/access/views/access/view.php b/frontend/modules/access/views/access/view.php new file mode 100644 index 0000000..8a9c95e --- /dev/null +++ b/frontend/modules/access/views/access/view.php @@ -0,0 +1,40 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Accesses', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы уверенны, что хотите удалить эту запись?', + 'method' => 'post', + ], + ]) ?> + 'btn btn-primary']) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'name', + 'login', + 'password', + 'link', + 'project', + 'info:ntext', + ], + ]) ?> + +