From 99610c4b69de42e68e09f659a11adf167f30890a Mon Sep 17 00:00:00 2001 From: Igor Borisov Date: Mon, 27 Jan 2020 12:10:11 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=9A=D0=BE=D1=81=D1=8F=D0=BA=20=D1=81=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/AddAdminController.php | 33 +++++++++++++++++++++++++++++++++ models/CreateUser.php | 1 + 2 files changed, 34 insertions(+) create mode 100644 commands/AddAdminController.php diff --git a/commands/AddAdminController.php b/commands/AddAdminController.php new file mode 100644 index 0000000..0c694cb --- /dev/null +++ b/commands/AddAdminController.php @@ -0,0 +1,33 @@ +email = 'admin@admin.ad'; + $user->username = 'admin'; + $user->setPassword('PMU8nrOr'); + if ($user->save()) { + echo 'admin created' . PHP_EOL; + } + $this->addRole($user->id); + } + + private function addRole($id) + { + $am = \Yii::$app->authManager; + $role = $am->getRole('admin'); + if($am->assign($role, $id)){ + echo 'role assigned' . PHP_EOL; + }; + } +} diff --git a/models/CreateUser.php b/models/CreateUser.php index 0736e3b..109ee3d 100644 --- a/models/CreateUser.php +++ b/models/CreateUser.php @@ -55,6 +55,7 @@ class CreateUser extends Model } $user = new Users(); $user->username = $this->username; + $user->isAdmin = $this->isAdmin; $user->email = $this->email; $user->object_id = $this->object_id; $user->setPassword($this->password); -- GitLab From 13a2063d3cfa79108f3e1e38cab31a44d08f5922 Mon Sep 17 00:00:00 2001 From: Igor Borisov Date: Thu, 30 Jan 2020 18:30:57 +0300 Subject: [PATCH 2/5] sdfsdf --- config/web.php | 1 + .../gii/templates/crud/simple/controller.php | 176 ++++++++++++++++++ .../gii/templates/crud/simple/search.php | 87 +++++++++ .../gii/templates/crud/simple/views/_form.php | 47 +++++ .../templates/crud/simple/views/_search.php | 49 +++++ .../templates/crud/simple/views/create.php | 29 +++ .../gii/templates/crud/simple/views/index.php | 78 ++++++++ .../templates/crud/simple/views/update.php | 31 +++ .../gii/templates/crud/simple/views/view.php | 55 ++++++ ...127_141526_create_transport_hubs_table.php | 28 +++ ...200130_150251_add_superadmin_user_role.php | 30 +++ .../m200130_151014_alter_users_table.php | 26 +++ models/CreateUser.php | 7 +- models/TransportHubs.php | 44 +++++ models/TransportHubsSearch.php | 70 +++++++ models/User.php | 1 + models/Users.php | 24 ++- .../controllers/TransportHubsController.php | 124 ++++++++++++ .../views/transport-hubs/_form.php | 27 +++ .../views/transport-hubs/_search.php | 29 +++ .../views/transport-hubs/create.php | 19 ++ .../views/transport-hubs/index.php | 31 +++ .../views/transport-hubs/update.php | 20 ++ .../views/transport-hubs/view.php | 34 ++++ views/layouts/left.php | 38 ++-- 25 files changed, 1084 insertions(+), 21 deletions(-) create mode 100644 generators/gii/templates/crud/simple/controller.php create mode 100644 generators/gii/templates/crud/simple/search.php create mode 100644 generators/gii/templates/crud/simple/views/_form.php create mode 100644 generators/gii/templates/crud/simple/views/_search.php create mode 100644 generators/gii/templates/crud/simple/views/create.php create mode 100644 generators/gii/templates/crud/simple/views/index.php create mode 100644 generators/gii/templates/crud/simple/views/update.php create mode 100644 generators/gii/templates/crud/simple/views/view.php create mode 100644 migrations/m200127_141526_create_transport_hubs_table.php create mode 100644 migrations/m200130_150251_add_superadmin_user_role.php create mode 100644 migrations/m200130_151014_alter_users_table.php create mode 100644 models/TransportHubs.php create mode 100644 models/TransportHubsSearch.php create mode 100644 modules/administrator/controllers/TransportHubsController.php create mode 100644 modules/administrator/views/transport-hubs/_form.php create mode 100644 modules/administrator/views/transport-hubs/_search.php create mode 100644 modules/administrator/views/transport-hubs/create.php create mode 100644 modules/administrator/views/transport-hubs/index.php create mode 100644 modules/administrator/views/transport-hubs/update.php create mode 100644 modules/administrator/views/transport-hubs/view.php diff --git a/config/web.php b/config/web.php index 7e69def..2f2b59b 100644 --- a/config/web.php +++ b/config/web.php @@ -109,6 +109,7 @@ if (YII_ENV_DEV) { 'class' => 'yii\gii\generators\crud\Generator', 'templates' => [ 'adminlte' => '@vendor/dmstr/yii2-adminlte-asset/gii/templates/crud/simple', + 'adminlteRus' => '@app/generators/gii/templates/crud/simple', ] ] ], diff --git a/generators/gii/templates/crud/simple/controller.php b/generators/gii/templates/crud/simple/controller.php new file mode 100644 index 0000000..cd5572b --- /dev/null +++ b/generators/gii/templates/crud/simple/controller.php @@ -0,0 +1,176 @@ +controllerClass); +$modelClass = StringHelper::basename($generator->modelClass); +$searchModelClass = StringHelper::basename($generator->searchModelClass); +if ($modelClass === $searchModelClass) { + $searchModelAlias = $searchModelClass . 'Search'; +} + +/* @var $class ActiveRecordInterface */ +$class = $generator->modelClass; +$pks = $class::primaryKey(); +$urlParams = $generator->generateUrlParams(); +$actionParams = $generator->generateActionParams(); +$actionParamComments = $generator->generateActionParamComments(); + +echo " + +namespace controllerClass, '\\')) ?>; + +use Yii; +use modelClass, '\\') ?>; +searchModelClass)): ?> +use searchModelClass, '\\') . (isset($searchModelAlias) ? " as $searchModelAlias" : "") ?>; + +use yii\data\ActiveDataProvider; + +use baseControllerClass, '\\') ?>; +use yii\web\NotFoundHttpException; +use yii\filters\VerbFilter; + +/** + * implements the CRUD actions for model. + */ +class extends baseControllerClass) . "\n" ?> +{ + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all models. + * @return mixed + */ + public function actionIndex() + { +searchModelClass)): ?> + $searchModel = new (); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + + $dataProvider = new ActiveDataProvider([ + 'query' => ::find(), + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + + } + + /** + * Displays a single model. + * + * @return mixed + */ + public function actionView() + { + return $this->render('view', [ + 'model' => $this->findModel(), + ]); + } + + /** + * Creates a new model. + * If creation is successful, the browser will be redirected to the 'index' page. + * @return mixed + */ + public function actionCreate() + { + $model = new (); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index']); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing model. + * If update is successful, the browser will be redirected to the 'index' page. + * + * @return mixed + */ + public function actionUpdate() + { + $model = $this->findModel(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index']); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @return mixed + */ + public function actionDelete() + { + $this->findModel()->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @return the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel() + { + \$$pk"; + } + $condition = '[' . implode(', ', $condition) . ']'; +} +?> + if (($model = ::findOne()) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/generators/gii/templates/crud/simple/search.php b/generators/gii/templates/crud/simple/search.php new file mode 100644 index 0000000..248a9d6 --- /dev/null +++ b/generators/gii/templates/crud/simple/search.php @@ -0,0 +1,87 @@ +modelClass); +$searchModelClass = StringHelper::basename($generator->searchModelClass); +if ($modelClass === $searchModelClass) { + $modelAlias = $modelClass . 'Model'; +} +$rules = $generator->generateSearchRules(); +$labels = $generator->generateSearchLabels(); +$searchAttributes = $generator->getSearchAttributes(); +$searchConditions = $generator->generateSearchConditions(); + +echo " + +namespace searchModelClass, '\\')) ?>; + +use Yii; +use yii\base\Model; +use yii\data\ActiveDataProvider; +use modelClass, '\\') . (isset($modelAlias) ? " as $modelAlias" : "") ?>; + +/** + * represents the model behind the search form of `modelClass ?>`. + */ +class extends + +{ + /** + * @inheritdoc + */ + public function rules() + { + return [ + , + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = ::find(); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, ['defaultOrder' => ['id' => SORT_DESC]]\n" : '' ?> + ]); + + $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 + + + return $dataProvider; + } +} diff --git a/generators/gii/templates/crud/simple/views/_form.php b/generators/gii/templates/crud/simple/views/_form.php new file mode 100644 index 0000000..a92e3d4 --- /dev/null +++ b/generators/gii/templates/crud/simple/views/_form.php @@ -0,0 +1,47 @@ +modelClass(); +$safeAttributes = $model->safeAttributes(); +if (empty($safeAttributes)) { + $safeAttributes = $model->attributes(); +} + +echo " + +use yii\helpers\Html; +use yii\widgets\ActiveForm; + +/* @var $this yii\web\View */ +/* @var $model modelClass, '\\') ?> */ +/* @var $form yii\widgets\ActiveForm */ +?> + +
+ $form = ActiveForm::begin(); ?> +
+ +getColumnNames() as $attribute) { + if (in_array($attribute, $safeAttributes)) { + echo " generateActiveField($attribute) . " ?>\n\n"; + } +} ?> +
+ + ActiveForm::end(); ?> +
diff --git a/generators/gii/templates/crud/simple/views/_search.php b/generators/gii/templates/crud/simple/views/_search.php new file mode 100644 index 0000000..d393baf --- /dev/null +++ b/generators/gii/templates/crud/simple/views/_search.php @@ -0,0 +1,49 @@ + + +use yii\helpers\Html; +use yii\widgets\ActiveForm; + +/* @var $this yii\web\View */ +/* @var $model searchModelClass, '\\') ?> */ +/* @var $form yii\widgets\ActiveForm */ +?> + + diff --git a/generators/gii/templates/crud/simple/views/create.php b/generators/gii/templates/crud/simple/views/create.php new file mode 100644 index 0000000..6930827 --- /dev/null +++ b/generators/gii/templates/crud/simple/views/create.php @@ -0,0 +1,29 @@ + + +use yii\helpers\Html; + + +/* @var $this yii\web\View */ +/* @var $model modelClass, '\\') ?> */ + +$this->title = generateString('Создание ' . Inflector::camel2words(StringHelper::basename + ($generator->modelClass))) ?>; +$this->params['breadcrumbs'][] = ['label' => generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>, 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + $this->render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/generators/gii/templates/crud/simple/views/index.php b/generators/gii/templates/crud/simple/views/index.php new file mode 100644 index 0000000..895121f --- /dev/null +++ b/generators/gii/templates/crud/simple/views/index.php @@ -0,0 +1,78 @@ +generateUrlParams(); +$nameAttribute = $generator->getNameAttribute(); + +echo " + +use yii\helpers\Html; +use indexWidgetType === 'grid' ? "yii\\grid\\GridView" : "yii\\widgets\\ListView" ?>; +enablePjax ? 'use yii\widgets\Pjax;' : '' ?> + +/* @var $this yii\web\View */ +searchModelClass) ? "/* @var \$searchModel " . ltrim($generator->searchModelClass, '\\') . " */\n" : '' ?> +/* @var $dataProvider yii\data\ActiveDataProvider */ + +$this->title = generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>; +$this->params['breadcrumbs'][] = $this->title; +?> +
+enablePjax ? " \n" : '' +?>
+ Html::a(generateString('Добавить ' . Inflector::camel2words(StringHelper::basename + ($generator->modelClass))) ?>, ['create'], ['class' => 'btn btn-success btn-flat']) ?> +
+
+searchModelClass)): ?> +indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?> +indexWidgetType === 'grid'): + echo " GridView::widget([ + 'dataProvider' => $dataProvider, + searchModelClass) ? "'filterModel' => \$searchModel,\n 'layout' => \"{items}\\n{summary}\\n{pager}\",\n 'columns' => [\n" : "'layout' => \"{items}\\n{summary}\\n{pager}\",\n 'columns' => [\n"; ?> + +getTableSchema()) === false) { + foreach ($generator->getColumnNames() as $name) { + if (++$count < 6) { + echo " '" . $name . "',\n"; + } else { + echo " // '" . $name . "',\n"; + } + } +} else { + foreach ($tableSchema->columns as $column) { + $format = $generator->generateColumnFormat($column); + if (++$count < 6) { + echo " '" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n"; + } else { + echo " // '" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n"; + } + } +} +?> + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + + ListView::widget([ + 'dataProvider' => $dataProvider, + 'itemOptions' => ['class' => 'item'], + 'itemView' => function ($model, $key, $index, $widget) { + return Html::a(Html::encode($model->), ['view', ]); + }, + ]) ?> + +
+enablePjax ? " \n" : '' ?> +
diff --git a/generators/gii/templates/crud/simple/views/update.php b/generators/gii/templates/crud/simple/views/update.php new file mode 100644 index 0000000..fae6237 --- /dev/null +++ b/generators/gii/templates/crud/simple/views/update.php @@ -0,0 +1,31 @@ +generateUrlParams(); + +echo " + +use yii\helpers\Html; + +/* @var $this yii\web\View */ +/* @var $model modelClass, '\\') ?> */ + +$this->title = generateString('Редактирование {modelClass}: ', ['modelClass' => Inflector::camel2words +(StringHelper::basename($generator->modelClass))]) ?> . $model->getNameAttribute() ?>; +$this->params['breadcrumbs'][] = ['label' => generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>, 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->getNameAttribute() ?>, 'url' => ['view', ]]; +$this->params['breadcrumbs'][] = generateString('редактирование') ?>; +?> +
+ + $this->render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/generators/gii/templates/crud/simple/views/view.php b/generators/gii/templates/crud/simple/views/view.php new file mode 100644 index 0000000..6d42baf --- /dev/null +++ b/generators/gii/templates/crud/simple/views/view.php @@ -0,0 +1,55 @@ +generateUrlParams(); + +echo " + +use yii\helpers\Html; +use yii\widgets\DetailView; + +/* @var $this yii\web\View */ +/* @var $model modelClass, '\\') ?> */ + +$this->title = $model->getNameAttribute() ?>; +$this->params['breadcrumbs'][] = ['label' => generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>, 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ Html::a(generateString('Редактировать') ?>, ['update', ], ['class' + => 'btn btn-primary btn-flat']) ?> + Html::a(generateString('Удалить') ?>, ['delete', ], [ + 'class' => 'btn btn-danger btn-flat', + 'data' => [ + 'confirm' => generateString('Вы действительно хотите удалить?') ?>, + 'method' => 'post', + ], + ]) ?> +
+
+ DetailView::widget([ + 'model' => $model, + 'attributes' => [ +getTableSchema()) === false) { + foreach ($generator->getColumnNames() as $name) { + echo " '" . $name . "',\n"; + } +} else { + foreach ($generator->getTableSchema()->columns as $column) { + $format = stripos($column->name, 'created_at') !== false || stripos($column->name, 'updated_at') !== false ? 'datetime' : $generator->generateColumnFormat($column); + echo " '" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n"; + } +} +?> + ], + ]) ?> +
+
diff --git a/migrations/m200127_141526_create_transport_hubs_table.php b/migrations/m200127_141526_create_transport_hubs_table.php new file mode 100644 index 0000000..c101b15 --- /dev/null +++ b/migrations/m200127_141526_create_transport_hubs_table.php @@ -0,0 +1,28 @@ +createTable('{{%transport_hubs}}', [ + 'id' => $this->primaryKey(), + 'name' => $this->string(32)->notNull() + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('{{%transport_hubs}}'); + } +} diff --git a/migrations/m200130_150251_add_superadmin_user_role.php b/migrations/m200130_150251_add_superadmin_user_role.php new file mode 100644 index 0000000..37cf865 --- /dev/null +++ b/migrations/m200130_150251_add_superadmin_user_role.php @@ -0,0 +1,30 @@ +authManager; + $superAdmin = $am->createRole('superadmin'); + $am->add($superAdmin); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m200130_150251_add_superadmin_user_role cannot be reverted.\n"; + + return false; + } + +} diff --git a/migrations/m200130_151014_alter_users_table.php b/migrations/m200130_151014_alter_users_table.php new file mode 100644 index 0000000..d0277f6 --- /dev/null +++ b/migrations/m200130_151014_alter_users_table.php @@ -0,0 +1,26 @@ +addColumn('users', 'hub_id', 'integer default null'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('users', 'hub_id'); + } + +} diff --git a/models/CreateUser.php b/models/CreateUser.php index 109ee3d..c6d58c5 100644 --- a/models/CreateUser.php +++ b/models/CreateUser.php @@ -13,6 +13,7 @@ class CreateUser extends Model public $password; public $isAdmin = false; public $object_id = false; + public $hub_id = false; /** * {@inheritdoc} @@ -25,10 +26,12 @@ class CreateUser extends Model ['password', 'string', 'min' => 6], ['email', 'email'], ['email', 'unique', 'targetClass' => Users::className()], - [['object_id'], 'integer'], + [['object_id', 'hub'], 'integer'], [['isAdmin'], 'boolean'], [['username', 'password', 'email'], 'string', 'max' => 255], [['object_id'], 'exist', 'skipOnError' => true, 'targetClass' => Objects::className(), 'targetAttribute' => ['object_id' => 'id']], + [['hub_id'], 'exist', 'skipOnError' => true, 'targetClass' => TransportHubs::className(), 'targetAttribute' => + ['hub_id' => 'id']], ]; } @@ -43,6 +46,7 @@ class CreateUser extends Model 'password' => 'Пароль', 'email' => 'Email', 'object_id' => 'Объект', + 'hub_id' => 'ТУ', 'objectName' => 'Объект', 'isAdmin' => 'Администратор?', ]; @@ -58,6 +62,7 @@ class CreateUser extends Model $user->isAdmin = $this->isAdmin; $user->email = $this->email; $user->object_id = $this->object_id; + $user->hub_id = $this->hub_id; $user->setPassword($this->password); return $user->save(); } diff --git a/models/TransportHubs.php b/models/TransportHubs.php new file mode 100644 index 0000000..3f9a8fc --- /dev/null +++ b/models/TransportHubs.php @@ -0,0 +1,44 @@ + 32], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Наименование', + ]; + } +} diff --git a/models/TransportHubsSearch.php b/models/TransportHubsSearch.php new file mode 100644 index 0000000..29e600c --- /dev/null +++ b/models/TransportHubsSearch.php @@ -0,0 +1,70 @@ + $query, + 'sort' => ['defaultOrder' => ['id' => SORT_DESC]] + ]); + + $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]); + + return $dataProvider; + } +} diff --git a/models/User.php b/models/User.php index 3c9b632..6aff24d 100644 --- a/models/User.php +++ b/models/User.php @@ -8,6 +8,7 @@ class User extends \yii\base\BaseObject implements \yii\web\IdentityInterface public $username; public $email; public $object_id; + public $hub_id; public $password_hash; public $authKey; public $accessToken; diff --git a/models/Users.php b/models/Users.php index 3cfc371..2046402 100644 --- a/models/Users.php +++ b/models/Users.php @@ -12,6 +12,7 @@ use Yii; * @property string $password_hash * @property string $email * @property int|null $object_id + * @property int|null $hub_id * @property boolean $isAdmin * * @property Objects $object @@ -35,13 +36,15 @@ class Users extends \yii\db\ActiveRecord { return [ [['username', 'password_hash', 'email'], 'required'], - [['object_id'], 'integer'], + [['object_id', 'hub_id'], 'integer'], [['isAdmin'], 'boolean'], [['username', 'password_hash', 'email'], 'string', 'max' => 255], [['username'], 'unique'], [['email'], 'unique'], ['email', 'email'], [['object_id'], 'exist', 'skipOnError' => true, 'targetClass' => Objects::className(), 'targetAttribute' => ['object_id' => 'id']], + [['hub_id'], 'exist', 'skipOnError' => true, 'targetClass' => TransportHubs::className(), 'targetAttribute' => + ['hub_id' => 'id']], ]; } @@ -57,6 +60,7 @@ class Users extends \yii\db\ActiveRecord 'password' => 'Пароль', 'email' => 'Email', 'object_id' => 'Объект', + 'hub_id' => 'ТУ', 'objectName' => 'Объект', 'isAdmin' => 'Администратор?', ]; @@ -70,6 +74,14 @@ class Users extends \yii\db\ActiveRecord return $this->hasOne(Objects::className(), ['id' => 'object_id']); } + /** + * @return \yii\db\ActiveQuery + */ + public function getHub() + { + return $this->hasOne(TransportHubs::className(), ['id' => 'hub_id']); + } + /** * @return string|null */ @@ -78,6 +90,14 @@ class Users extends \yii\db\ActiveRecord if (!empty($this->object)) return $this->object->name; } + /** + * @return string|null + */ + public function getHubName() + { + if (!empty($this->hub)) + return $this->hub->name; + } /** * @inheritdoc @@ -124,7 +144,7 @@ class Users extends \yii\db\ActiveRecord { if ($insert) { $am = Yii::$app->authManager; - $role = $this->isAdmin ? $am->getRole('admin') : $am->getRole('manager'); + $role = $this->isAdmin == 1 ? $am->getRole('admin') : $am->getRole('manager'); $am->assign($role, $this->id); } } diff --git a/modules/administrator/controllers/TransportHubsController.php b/modules/administrator/controllers/TransportHubsController.php new file mode 100644 index 0000000..805129f --- /dev/null +++ b/modules/administrator/controllers/TransportHubsController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all TransportHubs models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new TransportHubsSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single TransportHubs model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new TransportHubs model. + * If creation is successful, the browser will be redirected to the 'index' page. + * @return mixed + */ + public function actionCreate() + { + $model = new TransportHubs(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index']); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing TransportHubs model. + * If update is successful, the browser will be redirected to the 'index' 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(['index']); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing TransportHubs 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 TransportHubs model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return TransportHubs the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = TransportHubs::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/modules/administrator/views/transport-hubs/_form.php b/modules/administrator/views/transport-hubs/_form.php new file mode 100644 index 0000000..4057e0e --- /dev/null +++ b/modules/administrator/views/transport-hubs/_form.php @@ -0,0 +1,27 @@ + + +
+ +
+ + field($model, 'name')->textInput(['maxlength' => true]) ?> + +
+ + +
diff --git a/modules/administrator/views/transport-hubs/_search.php b/modules/administrator/views/transport-hubs/_search.php new file mode 100644 index 0000000..7268aaf --- /dev/null +++ b/modules/administrator/views/transport-hubs/_search.php @@ -0,0 +1,29 @@ + + + diff --git a/modules/administrator/views/transport-hubs/create.php b/modules/administrator/views/transport-hubs/create.php new file mode 100644 index 0000000..5bb95cc --- /dev/null +++ b/modules/administrator/views/transport-hubs/create.php @@ -0,0 +1,19 @@ +title = 'Создание ТУ'; +$this->params['breadcrumbs'][] = ['label' => 'Транспортные узлы', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/modules/administrator/views/transport-hubs/index.php b/modules/administrator/views/transport-hubs/index.php new file mode 100644 index 0000000..37b1c45 --- /dev/null +++ b/modules/administrator/views/transport-hubs/index.php @@ -0,0 +1,31 @@ +title = 'Транспортные узлы'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ 'btn btn-success btn-flat']) ?> +
+
+ render('_search', ['model' => $searchModel]); ?> + $dataProvider, + 'filterModel' => $searchModel, + 'layout' => "{items}\n{summary}\n{pager}", + 'columns' => [ + + 'name', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
+
diff --git a/modules/administrator/views/transport-hubs/update.php b/modules/administrator/views/transport-hubs/update.php new file mode 100644 index 0000000..5ce753e --- /dev/null +++ b/modules/administrator/views/transport-hubs/update.php @@ -0,0 +1,20 @@ +title = 'Редактирование ТУ: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Транспортные узлы', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'редактирование'; +Html::a('dsf') +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/modules/administrator/views/transport-hubs/view.php b/modules/administrator/views/transport-hubs/view.php new file mode 100644 index 0000000..4425bea --- /dev/null +++ b/modules/administrator/views/transport-hubs/view.php @@ -0,0 +1,34 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Транспортные узлы', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ $model->id], ['class' + => 'btn btn-primary btn-flat']) ?> + $model->id], [ + 'class' => 'btn btn-danger btn-flat', + 'data' => [ + 'confirm' => 'Вы действительно хотите удалить?', + 'method' => 'post', + ], + ]) ?> +
+
+ $model, + 'attributes' => [ + 'id', + 'name', + ], + ]) ?> +
+
diff --git a/views/layouts/left.php b/views/layouts/left.php index d8aedbf..ed702c6 100644 --- a/views/layouts/left.php +++ b/views/layouts/left.php @@ -1,21 +1,23 @@