Редактирование skills
This commit is contained in:
parent
6037c69b85
commit
028cce3bef
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use yii\grid\GridView;
|
use yii\grid\GridView;
|
||||||
|
|
||||||
|
$this->title = 'Доступы';
|
||||||
|
|
||||||
echo GridView::widget([
|
echo GridView::widget([
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
'columns' => [
|
'columns' => [
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
|
|
||||||
namespace frontend\modules\card\controllers;
|
namespace frontend\modules\card\controllers;
|
||||||
|
|
||||||
use common\classes\Debug;
|
|
||||||
use common\models\CardSkill;
|
use common\models\CardSkill;
|
||||||
use common\models\FieldsValueNew;
|
use common\models\FieldsValueNew;
|
||||||
use Yii;
|
use Yii;
|
||||||
use common\models\UserCard;
|
use frontend\modules\card\models\UserCard;
|
||||||
use yii\data\ActiveDataProvider;
|
use yii\data\ActiveDataProvider;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
@ -49,6 +48,25 @@ class UserCardController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing UserCard model.
|
||||||
|
* If update is successful, the browser will be redirected to the 'view' page.
|
||||||
|
* @param integer $id
|
||||||
|
* @return mixed
|
||||||
|
* @throws NotFoundHttpException if the model cannot be found
|
||||||
|
*/
|
||||||
|
public function actionUpdate($id)
|
||||||
|
{
|
||||||
|
$model = $this->findModel($id);
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||||
|
return $this->redirect(['index', 'id' => $model->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('update', [
|
||||||
|
'model' => $model,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the Product model based on its primary key value.
|
* Finds the Product model based on its primary key value.
|
||||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||||
|
45
frontend/modules/card/models/UserCard.php
Normal file
45
frontend/modules/card/models/UserCard.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace frontend\modules\card\models;
|
||||||
|
|
||||||
|
use common\models\CardSkill;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
|
class UserCard extends \common\models\UserCard
|
||||||
|
{
|
||||||
|
public $fields;
|
||||||
|
public $skill;
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
$skill = ArrayHelper::getColumn(
|
||||||
|
CardSkill::find()->where(['card_id' => \Yii::$app->request->get('id')])->all(),
|
||||||
|
'skill_id'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!empty($skill)) {
|
||||||
|
$this->skill = $skill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterSave($insert, $changedAttributes)
|
||||||
|
{
|
||||||
|
$post = \Yii::$app->request->post('UserCard');
|
||||||
|
|
||||||
|
if ($post['skill']) {
|
||||||
|
CardSkill::deleteAll(['card_id' => $this->id]);
|
||||||
|
|
||||||
|
foreach ($post['skill'] as $item) {
|
||||||
|
$skill = new CardSkill();
|
||||||
|
$skill->skill_id = $item;
|
||||||
|
$skill->card_id = $this->id;
|
||||||
|
|
||||||
|
$skill->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
|
||||||
|
}
|
||||||
|
}
|
39
frontend/modules/card/views/user-card/_form.php
Normal file
39
frontend/modules/card/views/user-card/_form.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use kartik\select2\Select2;
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
use common\models\Skill;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model frontend\modules\card\models\UserCard */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="user-card-form">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<?= $form->field($model, 'skill')->widget(
|
||||||
|
Select2::class,
|
||||||
|
[
|
||||||
|
'data' => ArrayHelper::map(Skill::find()->all(), 'id', 'name'),
|
||||||
|
'options' => ['placeholder' => '...', 'class' => 'form-control', 'multiple' => true],
|
||||||
|
'pluginOptions' => [
|
||||||
|
'allowClear' => true
|
||||||
|
],
|
||||||
|
]
|
||||||
|
)->label('Навыки'); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
@ -1 +1,7 @@
|
|||||||
<?= $info ?>
|
<?php
|
||||||
|
|
||||||
|
/* @var $info */
|
||||||
|
|
||||||
|
$this->title = 'Профиль';
|
||||||
|
|
||||||
|
echo $info;
|
||||||
|
14
frontend/modules/card/views/user-card/update.php
Normal file
14
frontend/modules/card/views/user-card/update.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model backend\modules\card\models\UserCard */
|
||||||
|
|
||||||
|
$this->title = "Редактировать профиль";
|
||||||
|
?>
|
||||||
|
<div class="user-card-update">
|
||||||
|
|
||||||
|
<?= $this->render('_form', [
|
||||||
|
'model' => $model,
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
@ -9,7 +9,7 @@ use yii\widgets\DetailView;
|
|||||||
/* @var $skill \common\models\Skill */
|
/* @var $skill \common\models\Skill */
|
||||||
/* @var $modelFildValue yii\data\ActiveDataProvider */
|
/* @var $modelFildValue yii\data\ActiveDataProvider */
|
||||||
|
|
||||||
|
$this->title = 'Профиль';
|
||||||
?>
|
?>
|
||||||
<div class="user-card-view">
|
<div class="user-card-view">
|
||||||
|
|
||||||
@ -48,7 +48,6 @@ use yii\widgets\DetailView;
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
['label' => 'Добвлен', 'attribute' => 'created_at',],
|
['label' => 'Добвлен', 'attribute' => 'created_at',],
|
||||||
['label' => 'Изменен', 'attribute' => 'updated_at',],
|
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
?>
|
?>
|
||||||
@ -58,6 +57,9 @@ use yii\widgets\DetailView;
|
|||||||
<?php foreach ($skills as $skill) : ?>
|
<?php foreach ($skills as $skill) : ?>
|
||||||
<span class="btn btn-default btn-sm"><?= $skill['skill']->name; ?></span>
|
<span class="btn btn-default btn-sm"><?= $skill['skill']->name; ?></span>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<?= Html::a('Добавить', ['/card/user-card/update', 'id' => $model->id], ['class' => 'btn btn-success']); ?>
|
||||||
|
|
||||||
<h2>Дополнительные сведения</h2>
|
<h2>Дополнительные сведения</h2>
|
||||||
|
|
||||||
<?= GridView::widget([
|
<?= GridView::widget([
|
||||||
|
Loading…
Reference in New Issue
Block a user