diff --git a/backend/config/main.php b/backend/config/main.php index 4683bf1..e00864a 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -56,6 +56,9 @@ return [ 'interview' => [ 'class' => 'backend\modules\interview\Interview', ], + 'achievements' => [ + 'class' => 'backend\modules\achievements\Achievements', + ], ], 'components' => [ 'request' => [ diff --git a/backend/modules/achievements/Achievements.php b/backend/modules/achievements/Achievements.php new file mode 100755 index 0000000..fbb7d8e --- /dev/null +++ b/backend/modules/achievements/Achievements.php @@ -0,0 +1,24 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => ['admin'], + ], + ], + ], + ]; + } + + /** + * Renders the index view for the module + * @return string + */ + public function actionIndex() + { + $searchModel = new AchievementSearch(); + + $dataProvider = $searchModel->search(); + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ]); + } + + /** + * Creates a new note model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Achievement(); + + if ($model->load(\Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model + ]); + } + + /** + * Displays a single note model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + $additionalDataProvider = new ActiveDataProvider([ + 'query' => FieldsValueNew::find() + ->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_NOTE]) + ->orderBy('order'), + 'pagination' => [ + 'pageSize' => 200, + ], + ]); + + $changeDataProvider = new ActiveDataProvider([ + 'query' => \common\models\ChangeHistory::find()->where(['type_id' => $this->findModel($id)->id]), + 'pagination' => [ + 'pageSize' => 200, + ] + ]); + + return $this->render('view', [ + 'model' => Achievement::findOne($id), + 'additionalDataProvider' => $additionalDataProvider, + 'changeDataProvider' => $changeDataProvider, + ]); + } + + 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 Note 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 note model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Achievement the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Achievement::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/achievements/models/Achievement.php b/backend/modules/achievements/models/Achievement.php new file mode 100755 index 0000000..9d9262c --- /dev/null +++ b/backend/modules/achievements/models/Achievement.php @@ -0,0 +1,21 @@ + [ + 'class' => \common\behaviors\LogBehavior::class, + ] + ]; + } +} diff --git a/backend/modules/achievements/models/AchievementSearch.php b/backend/modules/achievements/models/AchievementSearch.php new file mode 100755 index 0000000..ca9761e --- /dev/null +++ b/backend/modules/achievements/models/AchievementSearch.php @@ -0,0 +1,58 @@ +request->queryParams; + $query = Achievement::find(); + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $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, + 'status' => $this->status + ]); + + $query->andFilterWhere(['like', 'slug', $this->slug]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'title', $this->title]); +// $query->orderBy('created_at DESC'); + + return $dataProvider; + } +} diff --git a/backend/modules/achievements/views/achievements/_form.php b/backend/modules/achievements/views/achievements/_form.php new file mode 100755 index 0000000..69e873c --- /dev/null +++ b/backend/modules/achievements/views/achievements/_form.php @@ -0,0 +1,50 @@ + + +
+ + + + field($model, 'title')->textInput(['maxlength' => true]) ?> + field($model, 'slug')->textInput(['maxlength' => true]) ?> + field($model, 'description')->textarea(['rows' => 6]) ?> + field($model, 'status')->dropDownList(\common\models\Achievement::getStatusLabel()) ?> +
+
+ 'ru', + 'controller' => 'elfinder', + // вставляем название контроллера, по умолчанию равен elfinder + 'filter' => 'image', + // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con.. + 'name' => 'Achievement[img]', + 'id' => 'achievement-img', + 'template' => '
{input}{button}
', + 'options' => ['class' => 'form-control itemImg', 'maxlength' => '255'], + 'buttonOptions' => ['class' => 'btn btn-primary'], + 'value' => $model->img, + 'buttonName' => 'Выбрать изображение', + ]); + ?> +
+ + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/achievements/views/achievements/create.php b/backend/modules/achievements/views/achievements/create.php new file mode 100755 index 0000000..c6bb6b7 --- /dev/null +++ b/backend/modules/achievements/views/achievements/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/backend/modules/achievements/views/achievements/index.php b/backend/modules/achievements/views/achievements/index.php new file mode 100755 index 0000000..5c99b31 --- /dev/null +++ b/backend/modules/achievements/views/achievements/index.php @@ -0,0 +1,49 @@ +title = 'Достижения'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

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

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], +// 'id', + 'title', + 'slug', + 'description', + [ + 'attribute' => 'status', + 'value' => function ($model) { + return \common\models\Achievement::getStatusLabel()[$model->status ?? 0]; + }, + 'filter' => kartik\select2\Select2::widget([ + 'model' => $searchModel, + 'attribute' => 'status', + 'data' => \common\models\Achievement::getStatusLabel(), + 'options' => ['placeholder' => 'Начните вводить...', 'class' => 'form-control'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ]), + ], +// 'created_at', +// 'updated_at', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/achievements/views/achievements/update.php b/backend/modules/achievements/views/achievements/update.php new file mode 100755 index 0000000..a1eacb9 --- /dev/null +++ b/backend/modules/achievements/views/achievements/update.php @@ -0,0 +1,17 @@ +title = 'Редактировать достижение: ' . $model->title; +$this->params['breadcrumbs'][] = ['label' => 'Заметки', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Редактировать'; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/achievements/views/achievements/view.php b/backend/modules/achievements/views/achievements/view.php new file mode 100755 index 0000000..e4475e8 --- /dev/null +++ b/backend/modules/achievements/views/achievements/view.php @@ -0,0 +1,60 @@ +title = $model->title; +$this->params['breadcrumbs'][] = ['label' => 'Достижения', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+

+ 'btn btn-primary']) ?> + $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', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'title', + 'slug', + 'description:ntext', + [ + 'attribute' => 'status', + 'value' => \common\models\Achievement::getStatusLabel()[$model->status ?? 0], + ], + [ + 'attribute' => 'img', + 'format' => 'raw', + 'value' => function ($model) { + return Html::tag('img', null, ['src' => $model->img, 'width' => '100px']); + } + ], + ], + ]) ?> + +

История изменений

+ $changeDataProvider, + 'columns' => [ + 'label', + 'old_value', + 'new_value', + 'created_at', + ], + ]); ?> + +
diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index d618438..4524d46 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -3,6 +3,7 @@ namespace backend\modules\card\controllers; use common\classes\Debug; +use common\models\AchievementUserCard; use common\models\AdditionalFields; use common\models\CardSkill; use common\Models\ChangeHistory; @@ -104,6 +105,12 @@ class UserCardController extends Controller ]); $skills = CardSkill::find()->where(['card_id' => $id])->with('skill')->all(); + $achievements = + AchievementUserCard::find()->where(['user_card_id' => $id]) + ->innerJoinWith(['achievement' => function($query) { + $query->andWhere(['status' => \common\models\Achievement::STATUS_ACTIVE]); + }]) + ->all(); $id_current_user = $this->findModel($id)->id_user; $changeDataProvider = new ActiveDataProvider([ @@ -117,6 +124,7 @@ class UserCardController extends Controller 'model' => $this->findModel($id), 'modelFieldValue' => $dataProvider, 'skills' => $skills, + 'achievements' => $achievements, 'userData' => User::findOne($id_current_user), 'changeDataProvider' => $changeDataProvider, ]); diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index fed5613..997a554 100755 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -2,7 +2,9 @@ namespace backend\modules\card\models; +use backend\modules\achievements\models\Achievement; use Common\Behaviors\LogBehavior; +use common\models\AchievementUserCard; use Yii; use backend\modules\settings\models\Skill; use common\classes\Debug; @@ -16,6 +18,7 @@ class UserCard extends \common\models\UserCard { public $fields; public $skill; + public $achievements; public function init() { @@ -63,6 +66,19 @@ class UserCard extends \common\models\UserCard if (!empty($skill)) { $this->skill = $skill; } + + $achievements = ArrayHelper::getColumn(AchievementUserCard::find() + ->where(['user_card_id' => \Yii::$app->request->get('id')]) + ->innerJoinWith(['achievement' => function($query) { + $query->andWhere(['status' => \common\models\Achievement::STATUS_ACTIVE]); + }]) + ->all(), + 'achievement_id' + ); + + if (!empty($achievements)) { + $this->achievements = $achievements; + } } public function behaviors() @@ -118,6 +134,19 @@ class UserCard extends \common\models\UserCard $skill->save(); } } + + if(is_array($post['achievements'])){ + AchievementUserCard::deleteAll(['user_card_id' => $this->id]); + + foreach ($post['achievements'] as $item) { + $achCard = new AchievementUserCard(); + $achCard->user_card_id = $this->id; + $achCard->achievement_id = $item; + + $achCard->save(); + } + } + parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub } } diff --git a/backend/modules/card/views/user-card/_form.php b/backend/modules/card/views/user-card/_form.php index 897bb98..5bbcecb 100755 --- a/backend/modules/card/views/user-card/_form.php +++ b/backend/modules/card/views/user-card/_form.php @@ -2,6 +2,7 @@ use asmoday74\ckeditor5\EditorClassic; use common\classes\Debug; +use common\models\Achievement; use kartik\select2\Select2; use mihaildev\elfinder\InputFile; use unclead\multipleinput\MultipleInput; @@ -175,6 +176,19 @@ use yii\widgets\ActiveForm; 'language' => 'ru', ] ]); ?> +
+
+ field($model, 'achievements')->widget(Select2::class, + [ + 'data' => \yii\helpers\ArrayHelper::map(Achievement::find()->where(['status' => Achievement::STATUS_ACTIVE])->all(),'id', 'title'), + 'options' => ['placeholder' => '...','class' => 'form-control', 'multiple' => true], + 'pluginOptions' => [ + 'allowClear' => true + ], + ] + ); ?> +
+
diff --git a/backend/modules/card/views/user-card/view.php b/backend/modules/card/views/user-card/view.php index 06d5385..fe5bf4f 100755 --- a/backend/modules/card/views/user-card/view.php +++ b/backend/modules/card/views/user-card/view.php @@ -8,7 +8,9 @@ use yii\widgets\DetailView; /* @var $model backend\modules\card\models\UserCard */ /* @var $userData common\models\User */ /* @var $skills \common\models\CardSkill */ +/* @var $achievements \common\models\AchievementUserCard */ /* @var $skill \common\models\Skill */ +/* @var $achievement \common\models\Achievement */ /* @var $modelFieldValue yii\data\ActiveDataProvider */ /* @var $changeDataProvider yii\data\ActiveDataProvider */ @@ -91,11 +93,22 @@ $this->params['breadcrumbs'][] = $this->title; ]) ?>

Навыки

- name; ?> +

Достижения

+ + + $achievement['achievement']->img, 'height' => '50px', 'width' => '50px'] + ) ?> + title; ?> + + +

Дополнительные сведения

'Баланс', 'icon' => 'dollar', 'url' => ['/balan ce/balance'], 'active' => \Yii::$app->controller->id == 'balance', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday', 'visible' => Yii::$app->user->can('confidential_information')], + ['label' => 'Достижения', 'icon' => 'trophy', 'url' => ['/achievements/achievements'], 'active' => \Yii::$app->controller->id == 'achievements', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Доступы', 'icon' => 'key', 'url' => ['/accesses/accesses'], 'active' => \Yii::$app->controller->id == 'accesses', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Заметки', 'icon' => 'sticky-note', 'url' => ['/notes/notes'], 'active' => \Yii::$app->controller->id == 'notes', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Календарь ДР', 'icon' => 'calendar', 'url' => ['/calendar/calendar'], 'active' => \Yii::$app->controller->id == 'calendar', 'visible' => Yii::$app->user->can('confidential_information')], diff --git a/common/models/Achievement.php b/common/models/Achievement.php new file mode 100644 index 0000000..4e80d66 --- /dev/null +++ b/common/models/Achievement.php @@ -0,0 +1,65 @@ + 'Активна', + self::STATUS_DISABLE => 'Не активна' + ]; + } + /** + * {@inheritdoc} + */ + public static function tableName() + { + return 'achievement'; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return [ + [['title', 'slug'], 'required'], + [['status'], 'integer'], + [['slug', 'title'], 'string', 'max' => 255], + [['description', 'img'], 'string'], + [['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'title' => 'Название', + 'slug' => 'Slug', + 'description' => 'Описание', + 'status' => 'Статус', + 'img' => 'Изображение', + ]; + } +} diff --git a/common/models/AchievementUserCard.php b/common/models/AchievementUserCard.php new file mode 100644 index 0000000..6ce74f6 --- /dev/null +++ b/common/models/AchievementUserCard.php @@ -0,0 +1,66 @@ + true, 'targetClass' => Achievement::className(), 'targetAttribute' => ['achievement_id' => 'id']], + [['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'achievement_id' => 'Achievement ID', + 'user_card_id' => 'User Card ID', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getAchievement() + { + return $this->hasOne(Achievement::className(), ['id' => 'achievement_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUserCard() + { + return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']); + } +} diff --git a/common/models/UserCard.php b/common/models/UserCard.php index 6802b2b..6fc5bb4 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -38,6 +38,7 @@ use yii\helpers\ArrayHelper; * @property ProjectUser[] $projectUsers * @property Position $position * @property Status $status0 + * @property Achievement[] $achievements */ class UserCard extends \yii\db\ActiveRecord { @@ -171,6 +172,14 @@ class UserCard extends \yii\db\ActiveRecord return $this->hasOne(Status::class, ['id' => 'status']); } + /** + * @return \yii\db\ActiveQuery + */ + public function getAchievements(): \yii\db\ActiveQuery + { + return $this->hasMany(AchievementUserCard::class, ['user_card_id' => 'id'])->with('achievement'); + } + public function getGenders() { return [ diff --git a/console/migrations/m210908_110644_create_achievement_table_and_link_table_to_user_card.php b/console/migrations/m210908_110644_create_achievement_table_and_link_table_to_user_card.php new file mode 100644 index 0000000..4952548 --- /dev/null +++ b/console/migrations/m210908_110644_create_achievement_table_and_link_table_to_user_card.php @@ -0,0 +1,66 @@ +createTable('{{%achievement}}', [ + 'id' => $this->primaryKey(), + 'slug' => $this->string(255), + 'title' => $this->string(255), + 'img' => $this->text(), + 'description' => $this->text(), + 'status' => $this->integer()->defaultValue(1), + ]); + $this->createTable('{{%achievement_user_card}}', [ + 'id' => $this->primaryKey(), + 'user_card_id' => $this->integer(), + 'achievement_id' => $this->integer() + ]); + $this->addForeignKey( + 'fk-achievement_user_card-user_id', + 'achievement_user_card', + 'user_card_id', + 'user_card', + 'id', + 'CASCADE' + ); + $this->addForeignKey( + 'fk-achievement_user_card-achievement_id', + 'achievement_user_card', + 'achievement_id', + 'achievement', + 'id', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey( + 'fk-achievement_user_card-user_id', + 'achievement_user_card' + ); + + $this->dropForeignKey( + 'fk-achievement_user_card-achievement_id', + 'achievement_user_card' + ); + + $this->dropTable('{{%achievement_user_card}}'); + + $this->dropTable('{{%achievement}}'); + + } +} diff --git a/frontend/modules/card/controllers/UserCardController.php b/frontend/modules/card/controllers/UserCardController.php index 40dfa43..f9f7d54 100755 --- a/frontend/modules/card/controllers/UserCardController.php +++ b/frontend/modules/card/controllers/UserCardController.php @@ -4,6 +4,7 @@ namespace frontend\modules\card\controllers; use common\classes\Debug; +use common\models\AchievementUserCard; use common\models\CardSkill; use common\models\FieldsValueNew; use common\models\User; @@ -60,10 +61,18 @@ class UserCardController extends Controller ]); $skills = CardSkill::find()->where(['card_id' => $id])->with('skill')->all(); + $achievements = AchievementUserCard::find() + ->where(['user_card_id' => $id]) + ->innerJoinWith(['achievement' => function($query) { + $query->andWhere(['status' => \common\models\Achievement::STATUS_ACTIVE]); + }]) + ->all(); + return $this->render('view', [ 'model' => $this->findModel($id), 'modelFildValue' => $dataProvider, 'skills' => $skills, + 'achievements' => $achievements, ]); } else return $this->render('index', ['info' => '

Ваши личные данные не заненсены в базу.

']); diff --git a/frontend/modules/card/views/user-card/view.php b/frontend/modules/card/views/user-card/view.php index d9c0437..9cfc7e7 100755 --- a/frontend/modules/card/views/user-card/view.php +++ b/frontend/modules/card/views/user-card/view.php @@ -7,6 +7,7 @@ use yii\widgets\DetailView; /* @var $this yii\web\View */ /* @var $skills \common\models\CardSkill */ /* @var $skill \common\models\Skill */ +/* @var $achievements \common\models\Achievement */ /* @var $modelFildValue yii\data\ActiveDataProvider */ /* @var $model */ @@ -31,13 +32,24 @@ $this->title = 'Профиль'; ], ]); ?> -

Навыки

name; ?> +

Достижения

+ + + $achievement['achievement']->img, 'height' => '50px','width' => '50px'] + ) ?> + title; ?> + + +

Дополнительные сведения