- Achievement input at user card form.

- Achievement at user view with img
This commit is contained in:
Korzinkayablok 2021-09-09 13:12:37 +03:00
parent 0dbb05ee8e
commit b7ed0dab99
6 changed files with 75 additions and 2 deletions

View File

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

View File

@ -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
}
}

View File

@ -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',
]
]); ?>
<div class="row">
<div class="col-xs-12">
<?= $form->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
],
]
); ?>
</div>
</div>
<div class="row">
<div class="col-xs-12">

View File

@ -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;
]) ?>
<h2>Навыки</h2>
<?php foreach ($skills as $skill) : ?>
<span class="btn btn-default btn-sm"><?= $skill['skill']->name; ?></span>
<?php endforeach; ?>
<h2>Достижения</h2>
<?php foreach ($achievements as $achievement) : ?>
<a target="_blank"
href="<? echo \yii\helpers\Url::to(['/achievements/achievements/view', 'id' => $achievement['achievement']->id]);?>"
class="btn btn-default btn-sm">
<?= Html::tag('img', null,
['src' => $achievement['achievement']->img, 'height' => '50px', 'alt'=> $achievement['achievement']->title]
) ?>
<?= $achievement['achievement']->title; ?>
</a>
<?php endforeach; ?>
<h2>Дополнительные сведения</h2>
<?= GridView::widget([

View File

@ -9,7 +9,7 @@ use Yii;
*
* @property int $id
* @property int $user_card_id
* @property int $achievement
* @property int $achievement_id
*
* @property Accesses $accesses
* @property UserCard $userCard

View File

@ -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 [