diff --git a/backend/modules/settings/controllers/SkillCategoryController.php b/backend/modules/settings/controllers/SkillCategoryController.php new file mode 100644 index 0000000..253aabc --- /dev/null +++ b/backend/modules/settings/controllers/SkillCategoryController.php @@ -0,0 +1,127 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all SkillCategory models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SkillCategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single SkillCategory 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 SkillCategory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new SkillCategory(); + + 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 SkillCategory 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 SkillCategory 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 SkillCategory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return SkillCategory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = SkillCategory::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/settings/models/SkillCategorySearch.php b/backend/modules/settings/models/SkillCategorySearch.php new file mode 100644 index 0000000..2a3708c --- /dev/null +++ b/backend/modules/settings/models/SkillCategorySearch.php @@ -0,0 +1,68 @@ + $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]); + + return $dataProvider; + } +} diff --git a/backend/modules/settings/views/skill-category/_form.php b/backend/modules/settings/views/skill-category/_form.php new file mode 100644 index 0000000..0cacfcf --- /dev/null +++ b/backend/modules/settings/views/skill-category/_form.php @@ -0,0 +1,23 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/settings/views/skill-category/_search.php b/backend/modules/settings/views/skill-category/_search.php new file mode 100644 index 0000000..22779d8 --- /dev/null +++ b/backend/modules/settings/views/skill-category/_search.php @@ -0,0 +1,29 @@ + + + diff --git a/backend/modules/settings/views/skill-category/create.php b/backend/modules/settings/views/skill-category/create.php new file mode 100644 index 0000000..6e1f2d7 --- /dev/null +++ b/backend/modules/settings/views/skill-category/create.php @@ -0,0 +1,18 @@ +title = 'Create Skill Category'; +$this->params['breadcrumbs'][] = ['label' => 'Skill Categories', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/settings/views/skill-category/index.php b/backend/modules/settings/views/skill-category/index.php new file mode 100644 index 0000000..e37ef13 --- /dev/null +++ b/backend/modules/settings/views/skill-category/index.php @@ -0,0 +1,34 @@ +title = 'Skill Categories'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_search', ['model' => $searchModel]); ?> + +

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

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/settings/views/skill-category/update.php b/backend/modules/settings/views/skill-category/update.php new file mode 100644 index 0000000..211ac68 --- /dev/null +++ b/backend/modules/settings/views/skill-category/update.php @@ -0,0 +1,19 @@ +title = 'Update Skill Category: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Skill Categories', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/settings/views/skill-category/view.php b/backend/modules/settings/views/skill-category/view.php new file mode 100644 index 0000000..8cab612 --- /dev/null +++ b/backend/modules/settings/views/skill-category/view.php @@ -0,0 +1,36 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Skill Categories', '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' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> + 'btn btn-primary']) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'name', + ], + ]) ?> + +
diff --git a/backend/modules/settings/views/skill/_form.php b/backend/modules/settings/views/skill/_form.php index b85532e..0d4aabc 100755 --- a/backend/modules/settings/views/skill/_form.php +++ b/backend/modules/settings/views/skill/_form.php @@ -13,6 +13,9 @@ use yii\widgets\ActiveForm; field($model, 'name')->textInput(['maxlength' => true]) ?> + field($model, 'category_id')->dropDownList( + \yii\helpers\ArrayHelper::map(\common\models\SkillCategory::getAll(), 'id', 'name') + ); ?>
'btn btn-success']) ?> diff --git a/backend/modules/settings/views/skill/index.php b/backend/modules/settings/views/skill/index.php index 90f50b2..9dc6ee9 100755 --- a/backend/modules/settings/views/skill/index.php +++ b/backend/modules/settings/views/skill/index.php @@ -16,6 +16,7 @@ $this->params['breadcrumbs'][] = $this->title;

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

params['breadcrumbs'][] = $this->title; 'id', 'name', + [ + 'attribute' => 'category_id', + 'value' => function ($model) { + return $model->category ? $model->category->name : '-'; + } + ], ['class' => 'yii\grid\ActionColumn'], ], diff --git a/common/models/Skill.php b/common/models/Skill.php index 90cbfb7..9ce0128 100755 --- a/common/models/Skill.php +++ b/common/models/Skill.php @@ -9,6 +9,7 @@ use Yii; * * @property int $id * @property string $name + * @property integer $category_id * * @property CardSkill[] $cardSkills */ @@ -29,6 +30,7 @@ class Skill extends \yii\db\ActiveRecord { return [ [['name'], 'required'], + [['category_id'], 'integer'], [['name'], 'string', 'max' => 100], ]; } @@ -51,4 +53,9 @@ class Skill extends \yii\db\ActiveRecord { return $this->hasMany(CardSkill::className(), ['skill_id' => 'id']); } + + public function getCategory() + { + return $this->hasOne(SkillCategory::class, ['id' => 'category_id']); + } } diff --git a/common/models/SkillCategory.php b/common/models/SkillCategory.php new file mode 100644 index 0000000..76360b3 --- /dev/null +++ b/common/models/SkillCategory.php @@ -0,0 +1,59 @@ + 255], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSkills() + { + return $this->hasMany(Skill::className(), ['category' => 'id']); + } + + public static function getAll() + { + return self::find()->all(); + } +} diff --git a/console/migrations/m210608_131432_create_skill_category_table.php b/console/migrations/m210608_131432_create_skill_category_table.php new file mode 100644 index 0000000..2293b06 --- /dev/null +++ b/console/migrations/m210608_131432_create_skill_category_table.php @@ -0,0 +1,57 @@ +createTable('{{%skill_category}}', [ + 'id' => $this->primaryKey(), + 'name' => $this->string(255)->notNull(), + ]); + + $this->addColumn('skill', 'category_id', $this->integer(11)); + + $this->createIndex( + 'idx-skill-category_id', + 'skill', + 'category_id' + ); + + $this->addForeignKey( + 'fk-skill-category_id', + 'skill', + 'category_id', + 'skill_category', + 'id', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey( + 'fk-skill-category_id', + 'skill' + ); + + $this->dropIndex( + 'idx-skill-category_id', + 'skill' + ); + + $this->dropColumn('skill', 'category_id'); + + $this->dropTable('{{%skill_category}}'); + } +}