From bc4cb3b54c02f4863e0f27a443244b7e93d8d2a0 Mon Sep 17 00:00:00 2001 From: iIronside Date: Wed, 8 Nov 2023 12:06:22 +0300 Subject: [PATCH] update resume method --- common/models/User.php | 2 +- .../api/models/UserCardPortfolioProjects.php | 74 +++++++++++++++++++ frontend/modules/api/models/resume/Resume.php | 39 +++++++++- frontend/modules/card/models/UserCard.php | 10 +++ 4 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 frontend/modules/api/models/UserCardPortfolioProjects.php diff --git a/common/models/User.php b/common/models/User.php index 43fe046..96c96b8 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -231,6 +231,6 @@ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface public function getProjectUser() { - return $this->hasMany(ProjectUser::className(), ['user_id' => 'id']); + return $this->hasMany(ProjectUser::class, ['user_id' => 'id']); } } diff --git a/frontend/modules/api/models/UserCardPortfolioProjects.php b/frontend/modules/api/models/UserCardPortfolioProjects.php new file mode 100644 index 0000000..9c4ac8d --- /dev/null +++ b/frontend/modules/api/models/UserCardPortfolioProjects.php @@ -0,0 +1,74 @@ + function () { + return $this->mainStack->name; + }, + 'additional_stack', + 'link', + ]; + } + + /** + * @return string[] + */ + public function extraFields(): array + { + return []; + } + + public function getMainStack() + { + return $this->hasOne(Skill::class, ['id' => 'main_stack']); + } +} diff --git a/frontend/modules/api/models/resume/Resume.php b/frontend/modules/api/models/resume/Resume.php index 4af8a90..89eb669 100644 --- a/frontend/modules/api/models/resume/Resume.php +++ b/frontend/modules/api/models/resume/Resume.php @@ -2,12 +2,26 @@ namespace frontend\modules\api\models\resume; -use yii\helpers\ArrayHelper; +use frontend\modules\card\models\UserCard; /** * * @OA\Schema( * schema="Resume", + * type="array", + * @OA\Items( + * @OA\Property( + * property="fio", + * type="string", + * example="ФИО", + * description="ФИО" + * ), + * @OA\Property( + * property="position", + * type="string", + * example="position", + * description="Специализация" + * ), * @OA\Property( * property="stack", * type="array", @@ -23,6 +37,11 @@ use yii\helpers\ArrayHelper; * example="Резюме", * description="Тело резюме в HTML разметке" * ), + * @OA\Property( + * property="projects", + * ref="#/components/schemas/UserCardPortfolioProjectsExample", + * ), + * ), *) * * @OA\Schema( @@ -32,23 +51,37 @@ use yii\helpers\ArrayHelper; * ref="#/components/schemas/Resume", * ), *) + * @property UserCard $userCard */ class Resume extends \common\models\User { - /** * @return string[] */ public function fields(): array { return [ - 'stack' => function() { + 'fio' => function () { + return $this->userCard->fio; + }, + 'position' => function () { + return $this->userCard->position->name; + }, + 'stack' => function () { return $this->userCard->getSkillsName(); }, 'resume' => function () { return $this->userCard->vc_text; }, + 'projects' => function () { + return $this->userCard->userCardPortfolioProjects; + }, ]; } + + public function getUserCard() + { + return $this->hasOne(UserCard::class, ['id_user' => 'id']); + } } \ No newline at end of file diff --git a/frontend/modules/card/models/UserCard.php b/frontend/modules/card/models/UserCard.php index 923904e..fd7390e 100755 --- a/frontend/modules/card/models/UserCard.php +++ b/frontend/modules/card/models/UserCard.php @@ -3,9 +3,14 @@ namespace frontend\modules\card\models; use common\models\CardSkill; +use frontend\modules\api\models\UserCardPortfolioProjects; use Yii; +use yii\db\ActiveQuery; use yii\helpers\ArrayHelper; +/** + * @property UserCardPortfolioProjects[] $userCardPortfolioProjects + */ class UserCard extends \common\models\UserCard { public $fields; @@ -48,4 +53,9 @@ class UserCard extends \common\models\UserCard { return self::findOne(['id_user' => $userId]); } + + public function getUserCardPortfolioProjects(): ActiveQuery + { + return $this->hasMany(UserCardPortfolioProjects::class, ['card_id' => 'id']); + } }