From 74214f090e23720f26eb30e553cb448ae18c40f0 Mon Sep 17 00:00:00 2001 From: iIronside Date: Tue, 27 Dec 2022 11:45:28 +0300 Subject: [PATCH] add portfolio projects --- .../card/controllers/UserCardController.php | 10 +- backend/modules/card/models/UserCard.php | 60 ++++++++- .../modules/card/views/user-card/_form.php | 54 ++++++++ backend/modules/card/views/user-card/view.php | 18 ++- common/models/UserCard.php | 5 + common/models/UserCardPortfolioProjects.php | 79 ++++++++++++ common/services/ProfileService.php | 29 ++++- ...ate_user_card_portfolio_projects_table.php | 37 ++++++ docs/api/profile.md | 121 ++++++++++++++++++ .../api/controllers/ProfileController.php | 5 + 10 files changed, 407 insertions(+), 11 deletions(-) create mode 100644 common/models/UserCardPortfolioProjects.php create mode 100644 console/migrations/m221226_114011_create_user_card_portfolio_projects_table.php diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 10da2a8..4c861c1 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -6,11 +6,11 @@ use backend\modules\card\models\ResumeTemplate; use backend\modules\card\models\UserCard; use backend\modules\card\models\UserCardSearch; use backend\modules\settings\models\Skill; -use common\classes\Debug; use common\models\AchievementUserCard; use common\models\CardSkill; use common\models\FieldsValueNew; use common\models\User; +use common\models\UserCardPortfolioProjects; use kartik\mpdf\Pdf; use Yii; use yii\data\ActiveDataProvider; @@ -118,6 +118,13 @@ class UserCardController extends Controller ] ]); + $portfolioProjects = new ActiveDataProvider([ + 'query' => UserCardPortfolioProjects::find()->where(['card_id' => $id]), + 'pagination' => [ + 'pageSize' => 200, + ] + ]); + return $this->render('view', [ 'model' => $this->findModel($id), 'modelFieldValue' => $dataProvider, @@ -125,6 +132,7 @@ class UserCardController extends Controller 'achievements' => $achievements, 'userData' => User::findOne($id_current_user), 'changeDataProvider' => $changeDataProvider, + 'portfolioProjects' => $portfolioProjects ]); } diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index 9d032f8..c25b8bb 100755 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -2,16 +2,11 @@ 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; use common\models\CardSkill; -use common\models\User; -use common\models\FieldsValue; use common\models\FieldsValueNew; +use common\models\UserCardPortfolioProjects; +use Yii; use yii\helpers\ArrayHelper; class UserCard extends \common\models\UserCard @@ -19,6 +14,7 @@ class UserCard extends \common\models\UserCard public $fields; public $skill; public $achievements; + public $portfolioProjects; public function init() { @@ -79,6 +75,40 @@ class UserCard extends \common\models\UserCard if (!empty($achievements)) { $this->achievements = $achievements; } + + /** @var UserCardPortfolioProjects[] $portfolioProjects */ + $portfolioProjects = UserCardPortfolioProjects::find() + ->where(['card_id' => \Yii::$app->request->get('id')]) + ->all(); + + $array = []; + if (!empty($portfolioProjects)) { + foreach ($portfolioProjects as $item) { + array_push( + $array, + [ + 'id' => $item->id, + 'title' => $item->title, + 'description' => $item->description, + 'main_stack' => $item->main_stack, + 'additional_stack' => $item->additional_stack, + 'link' => $item->link + ] + ); + } + $this->portfolioProjects = $array; + } else { + $this->portfolioProjects = [ + [ + 'id' => null, + 'title' => null, + 'description' => null, + 'main_stack' => null, + 'additional_stack' => null, + 'link' => null + ] + ]; + } } public function behaviors() @@ -135,6 +165,22 @@ class UserCard extends \common\models\UserCard } } + if(array_key_exists('portfolioProjects', $post) && is_array($post['portfolioProjects'])){ + UserCardPortfolioProjects::deleteAll(['card_id' => $this->id]); + + foreach ($post['portfolioProjects'] as $item) { + $portfolioProject = new UserCardPortfolioProjects(); + $portfolioProject->card_id = $this->id; + $portfolioProject->title = $item['title']; + $portfolioProject->description = $item['description']; + $portfolioProject->main_stack = $item['main_stack']; + $portfolioProject->additional_stack = $item['additional_stack']; + $portfolioProject->link = $item['link']; + + $portfolioProject->save(); + } + } + if(array_key_exists('achievements', $post) && is_array($post['achievements'])){ AchievementUserCard::deleteAll(['user_card_id' => $this->id]); diff --git a/backend/modules/card/views/user-card/_form.php b/backend/modules/card/views/user-card/_form.php index 109b359..70d8658 100755 --- a/backend/modules/card/views/user-card/_form.php +++ b/backend/modules/card/views/user-card/_form.php @@ -223,6 +223,60 @@ use yii\widgets\ActiveForm; +
+
+ field($model, 'portfolioProjects')->widget(MultipleInput::class, [ + 'cloneButton' => true, + 'columns' => [ + [ + 'name' => 'title', + 'type' => 'textInput', + 'title' => 'Название', + 'defaultValue' => null, + 'options' => ['prompt' => 'Заполните'] + ], + [ + 'name' => 'description', + 'type' => 'textarea', + 'title' => 'Описание', + 'defaultValue' => null, + 'options' => [ + 'prompt' => 'Заполните', + 'rows' => '3' + ] + ], + [ + 'name' => 'main_stack', + 'type' => 'dropDownList', + 'title' => 'Основная технология', + 'defaultValue' => null, + 'items' => \yii\helpers\ArrayHelper::map( + \backend\modules\settings\models\Skill::find()->all(), + 'id', + 'name' + ), + 'options' => ['prompt' => 'Выберите'] + ], + [ + 'name' => 'additional_stack', + 'type' => 'textInput', + 'title' => 'Используемые технологии', + 'defaultValue' => null, + 'options' => ['prompt' => 'Заполните'] + ], + [ + 'name' => 'link', + 'type' => 'textInput', + 'title' => 'Ссылка', + 'defaultValue' => null, + 'options' => ['prompt' => 'Заполните'] + ], + ], + ])->label('Проекты в портфолио'); + ?> +
+
+
field($model, 'fields')->widget(MultipleInput::class, [ diff --git a/backend/modules/card/views/user-card/view.php b/backend/modules/card/views/user-card/view.php index 29af3d7..807dbaf 100755 --- a/backend/modules/card/views/user-card/view.php +++ b/backend/modules/card/views/user-card/view.php @@ -1,7 +1,6 @@ title = $model->fio; $this->params['breadcrumbs'][] = ['label' => 'Профили', 'url' => ['index']]; @@ -127,6 +127,22 @@ $this->params['breadcrumbs'][] = $this->title; +

Проекты в портфолио

+ $portfolioProjects, + 'layout' => "{items}", + 'columns' => [ + 'title', + 'description', + [ + 'attribute' => 'main_stack', + 'value' => 'skill.name' + ], + 'additional_stack', + 'link:url', + ], + ]); ?> +

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

hasMany(ManagerEmployee::class, ['user_card_id' => 'id']); } + public function getUserCardPortfolioProjects() + { + return $this->hasMany(UserCardPortfolioProjects::className(), ['card_id' => 'id']); + } + /** * @return \yii\db\ActiveQuery */ diff --git a/common/models/UserCardPortfolioProjects.php b/common/models/UserCardPortfolioProjects.php new file mode 100644 index 0000000..5d0d044 --- /dev/null +++ b/common/models/UserCardPortfolioProjects.php @@ -0,0 +1,79 @@ + 255], + [['main_stack'], 'exist', 'skipOnError' => true, 'targetClass' => Skill::className(), 'targetAttribute' => ['main_stack' => 'id']], + [['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'card_id' => 'Card ID', + 'title' => 'Название', + 'description' => 'Описание', + 'main_stack' => 'Основная технология', + 'additional_stack' => 'Используемые технологии', + 'link' => 'Ссылка', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getMainStack() + { + return $this->hasOne(Skill::className(), ['id' => 'main_stack']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCard() + { + return $this->hasOne(UserCard::className(), ['id' => 'card_id']); + } + + public function getSkill() + { + return $this->hasOne(Skill::className(), ['id' => 'main_stack']); + } +} diff --git a/common/services/ProfileService.php b/common/services/ProfileService.php index 909e07f..96a21d5 100644 --- a/common/services/ProfileService.php +++ b/common/services/ProfileService.php @@ -2,17 +2,42 @@ namespace common\services; -use common\classes\Debug; use common\models\Manager; use common\models\ManagerEmployee; use common\models\UserCard; +use common\models\UserCardPortfolioProjects; use frontend\modules\api\models\ProfileSearchForm; use Yii; -use yii\web\BadRequestHttpException; use yii\web\ServerErrorHttpException; class ProfileService { + public static function getPortfolioProjects($card_id) + { + /** @var UserCardPortfolioProjects[] $portfolioProjects */ + $portfolioProjects = UserCardPortfolioProjects::find() + ->where(['card_id' => $card_id]) + ->all(); + + $array = []; + if (!empty($portfolioProjects)) { + foreach ($portfolioProjects as $project) { + array_push( + $array, + [ + 'id' => $project->id, + 'title' => $project->title, + 'description' => $project->description, + 'main_stack' => $project->skill->name, + 'additional_stack' => $project->additional_stack, + 'link' => $project->link + ] + ); + } + } + return $array; + } + /** * @throws ServerErrorHttpException */ diff --git a/console/migrations/m221226_114011_create_user_card_portfolio_projects_table.php b/console/migrations/m221226_114011_create_user_card_portfolio_projects_table.php new file mode 100644 index 0000000..115d5d3 --- /dev/null +++ b/console/migrations/m221226_114011_create_user_card_portfolio_projects_table.php @@ -0,0 +1,37 @@ +createTable('{{%user_card_portfolio_projects}}', [ + 'id' => $this->primaryKey(), + 'card_id' => $this->integer(), + 'title' => $this->string(), + 'description' => $this->string(), + 'main_stack' => $this->integer(), + 'additional_stack' => $this->string(), + 'link' => $this->string(), + ]); + $this->addForeignKey('user_card_user_card_portfolio_projects', 'user_card_portfolio_projects', 'card_id', 'user_card', 'id'); + $this->addForeignKey('skill_user_card_portfolio_projects', 'user_card_portfolio_projects', 'main_stack', 'skill', 'id'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('user_card_user_card_portfolio_projects', 'user_card_portfolio_projects'); + $this->dropForeignKey('skill_user_card_portfolio_projects', 'user_card_portfolio_projects'); + $this->dropTable('{{%user_card_portfolio_projects}}'); + } +} diff --git a/docs/api/profile.md b/docs/api/profile.md index 85dae18..1b9124e 100644 --- a/docs/api/profile.md +++ b/docs/api/profile.md @@ -41,6 +41,14 @@ Получить получить основные данные профиля + + + profile/portfolio-projects + + + Массив проектов в портфолио(для страницы мой код) + + ### Список @@ -347,3 +355,116 @@ +## Массив проектов в портфолио(для страницы мой код) + +`https://guild.craft-group.xyz/api/profile/profile/portfolio-projects?card_id=9` +

+ Требуемые параметры: +

+ + + + + + + + + +
+ Параметры + + Значение +
+ card_id + + Id профиля пользователя +
+ +

+ Возвращает массив объектов Проект в портфолио.
+ Ответ имеет следующий вид: +

+ +```json5 +[ + { + "id": 11, + "title": "yguyyyyy", + "description": "пппппппппппп", + "main_stack": "JS", + "additional_stack": "jnvbklfbmklfdv", + "link": "11111" + }, + { + "id": 12, + "title": "smclksdmk", + "description": "ссссссссссс", + "main_stack": "JS", + "additional_stack": "ksdlkcmskl", + "link": "kwemfdkflefmkl" + } +] +``` + +

+ Возвращаемые параметры: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ id + + Id +
+ title + + название +
+ description + + описание +
+ main_stack + + основной язык проекта +
+ additional_stack + + используемые технологии +
+ link + + ссылка на репозиторий +
+ diff --git a/frontend/modules/api/controllers/ProfileController.php b/frontend/modules/api/controllers/ProfileController.php index 0369ecc..f8fa565 100755 --- a/frontend/modules/api/controllers/ProfileController.php +++ b/frontend/modules/api/controllers/ProfileController.php @@ -49,4 +49,9 @@ class ProfileController extends ApiController { return ProfileService::getMainData($user_id); } + + public function actionPortfolioProjects($card_id): array + { + return ProfileService::getPortfolioProjects($card_id); + } } \ No newline at end of file