add portfolio projects

This commit is contained in:
iIronside 2022-12-27 11:45:28 +03:00
parent 24e3dce192
commit 74214f090e
10 changed files with 407 additions and 11 deletions

View File

@ -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
]);
}

View File

@ -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]);

View File

@ -223,6 +223,60 @@ use yii\widgets\ActiveForm;
</div>
</div>
<div class="row">
<div class="col-xs-12">
<?= $form->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('Проекты в портфолио');
?>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [

View File

@ -1,7 +1,6 @@
<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;
use yii\widgets\DetailView;
@ -14,6 +13,7 @@ use yii\widgets\DetailView;
/* @var $achievement \common\models\Achievement */
/* @var $modelFieldValue yii\data\ActiveDataProvider */
/* @var $changeDataProvider yii\data\ActiveDataProvider */
/* @var $portfolioProjects yii\data\ActiveDataProvider */
$this->title = $model->fio;
$this->params['breadcrumbs'][] = ['label' => 'Профили', 'url' => ['index']];
@ -127,6 +127,22 @@ $this->params['breadcrumbs'][] = $this->title;
</a>
<?php endforeach; ?>
<h2>Проекты в портфолио</h2>
<?= GridView::widget([
'dataProvider' => $portfolioProjects,
'layout' => "{items}",
'columns' => [
'title',
'description',
[
'attribute' => 'main_stack',
'value' => 'skill.name'
],
'additional_stack',
'link:url',
],
]); ?>
<h2>Дополнительные сведения</h2>
<?= GridView::widget([

View File

@ -271,6 +271,11 @@ class UserCard extends \yii\db\ActiveRecord
return $this->hasMany(ManagerEmployee::class, ['user_card_id' => 'id']);
}
public function getUserCardPortfolioProjects()
{
return $this->hasMany(UserCardPortfolioProjects::className(), ['card_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/

View File

@ -0,0 +1,79 @@
<?php
namespace common\models;
/**
* This is the model class for table "user_card_portfolio_projects".
*
* @property int $id
* @property int $card_id
* @property string $title
* @property string $description
* @property int $main_stack
* @property string $additional_stack
* @property string $link
*
* @property Skill $mainStack
* @property UserCard $card
*/
class UserCardPortfolioProjects extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'user_card_portfolio_projects';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['card_id', 'title', 'main_stack', 'link'], 'required'],
[['card_id', 'main_stack'], 'integer'],
[['title', 'description', 'additional_stack', 'link'], 'string', 'max' => 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']);
}
}

View File

@ -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
*/

View File

@ -0,0 +1,37 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{{%user_card_portfolio_projects}}`.
*/
class m221226_114011_create_user_card_portfolio_projects_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->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}}');
}
}

View File

@ -41,6 +41,14 @@
Получить получить основные данные профиля
</td>
</tr>
<tr>
<td>
profile/portfolio-projects
</td>
<td>
Массив проектов в портфолио(для страницы мой код)
</td>
</tr>
</table>
### Список
@ -347,3 +355,116 @@
</tr>
</table>
## Массив проектов в портфолио(для страницы мой код)
`https://guild.craft-group.xyz/api/profile/profile/portfolio-projects?card_id=9`
<p>
Требуемые параметры:
</p>
<table>
<tr>
<th>
Параметры
</th>
<th>
Значение
</th>
</tr>
<tr>
<td>
card_id
</td>
<td>
Id профиля пользователя
</td>
</tr>
</table>
<p>
Возвращает массив объектов <b>Проект в портфолио</b>. <br>
Ответ имеет следующий вид:
</p>
```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"
}
]
```
<p>
Возвращаемые параметры:
</p>
<table>
<tr>
<th>
Параметры
</th>
<th>
Значение
</th>
</tr>
<tr>
<td>
id
</td>
<td>
Id
</td>
</tr>
<tr>
<td>
title
</td>
<td>
название
</td>
</tr>
<tr>
<td>
description
</td>
<td>
описание
</td>
</tr>
<tr>
<td>
main_stack
</td>
<td>
основной язык проекта
</td>
</tr>
<tr>
<td>
additional_stack
</td>
<td>
используемые технологии
</td>
</tr>
<tr>
<td>
link
</td>
<td>
ссылка на репозиторий
</td>
</tr>
</table>

View File

@ -49,4 +49,9 @@ class ProfileController extends ApiController
{
return ProfileService::getMainData($user_id);
}
public function actionPortfolioProjects($card_id): array
{
return ProfileService::getPortfolioProjects($card_id);
}
}