модуль генерации пользователей
This commit is contained in:
@ -5,6 +5,7 @@ namespace backend\modules\card\controllers;
|
||||
use common\classes\Debug;
|
||||
use common\models\AdditionalFields;
|
||||
use common\models\CardSkill;
|
||||
use common\models\User;
|
||||
use common\models\FieldsValue;
|
||||
use common\models\FieldsValueNew;
|
||||
use common\models\Status;
|
||||
@ -71,10 +72,14 @@ class UserCardController extends Controller
|
||||
|
||||
$skills = CardSkill::find()->where(['card_id' => $id])->with('skill')->all();
|
||||
|
||||
$id_current_user = $this->findModel($id)->id_user;
|
||||
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
'modelFildValue' => $dataProvider,
|
||||
'skills' => $skills,
|
||||
// 'userData' => $userData,
|
||||
'userData' => User::findOne($id_current_user),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -88,6 +93,8 @@ class UserCardController extends Controller
|
||||
$model = new UserCard();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
UserCard::generateUserForUserCard($model->id);
|
||||
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
@ -134,6 +141,17 @@ class UserCardController extends Controller
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all UserCard models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionGenerate()
|
||||
{
|
||||
$massage = UserCard::generateUserForUserCard();
|
||||
return $this->render('generate', ['massage' => $massage]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds the UserCard model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
|
@ -2,9 +2,11 @@
|
||||
|
||||
namespace backend\modules\card\models;
|
||||
|
||||
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 yii\helpers\ArrayHelper;
|
||||
@ -22,21 +24,25 @@ class UserCard extends \common\models\UserCard
|
||||
[
|
||||
'item_id' => \Yii::$app->request->get('id'),
|
||||
'item_type' => FieldsValueNew::TYPE_PROFILE,
|
||||
])
|
||||
]
|
||||
)
|
||||
->all();
|
||||
$array = [];
|
||||
if(!empty($fieldValue)){
|
||||
foreach ($fieldValue as $item){
|
||||
array_push($array,
|
||||
['field_id' => $item->field_id,
|
||||
if (!empty($fieldValue)) {
|
||||
foreach ($fieldValue as $item) {
|
||||
array_push(
|
||||
$array,
|
||||
[
|
||||
'field_id' => $item->field_id,
|
||||
'value' => $item->value,
|
||||
'order' => $item->order,
|
||||
'type_file' => $item->type_file,
|
||||
'field_name' => $item->field->name]);
|
||||
'field_name' => $item->field->name
|
||||
]
|
||||
);
|
||||
}
|
||||
$this->fields = $array;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$this->fields = [
|
||||
[
|
||||
'field_id' => null,
|
||||
@ -48,28 +54,28 @@ class UserCard extends \common\models\UserCard
|
||||
];
|
||||
}
|
||||
|
||||
$skill = ArrayHelper::getColumn(CardSkill::find()->where(['card_id' => \Yii::$app->request->get('id')])->all(),
|
||||
'skill_id');
|
||||
$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['fields']){
|
||||
if ($post['fields']) {
|
||||
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROFILE]);
|
||||
foreach ( $post['fields'] as $item) {
|
||||
foreach ($post['fields'] as $item) {
|
||||
$fildsValue = new FieldsValueNew();
|
||||
$fildsValue->field_id = $item['field_id'];
|
||||
$fildsValue->value = $item['value'];
|
||||
$fildsValue->type_file = 'text';
|
||||
if(substr($item['value'],0,1) == '/'){
|
||||
if (substr($item['value'], 0, 1) == '/') {
|
||||
$fildsValue->type_file = 'file';
|
||||
}
|
||||
$fildsValue->order = $item['order'];
|
||||
@ -80,10 +86,10 @@ class UserCard extends \common\models\UserCard
|
||||
}
|
||||
}
|
||||
|
||||
if($post['skill']){
|
||||
if ($post['skill']) {
|
||||
CardSkill::deleteAll(['card_id' => $this->id]);
|
||||
|
||||
foreach ( $post['skill'] as $item) {
|
||||
foreach ($post['skill'] as $item) {
|
||||
$skill = new CardSkill();
|
||||
$skill->skill_id = $item;
|
||||
$skill->card_id = $this->id;
|
||||
@ -95,4 +101,59 @@ class UserCard extends \common\models\UserCard
|
||||
|
||||
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
||||
|
||||
public function generateUser($email, $status)
|
||||
{
|
||||
$user = new User();
|
||||
$auth_key = Yii::$app->security->generateRandomString();
|
||||
$password = Yii::$app->security->generateRandomString(12);
|
||||
$password_hash = Yii::$app->security->generatePasswordHash($password);
|
||||
|
||||
$user->username = $email;
|
||||
$user->auth_key = $auth_key;
|
||||
$user->password_hash = $password_hash;
|
||||
$user->email = $email;
|
||||
if ($status == 1) $user->status = 10;
|
||||
|
||||
$user->save();
|
||||
|
||||
$log = "Логин: " . $email . " Пароль: " . $password . " | ";
|
||||
file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX);
|
||||
|
||||
return $user->id;
|
||||
}
|
||||
|
||||
public function genereateLinlkOnUser($user_card, $user_id)
|
||||
{
|
||||
$user_card->id_user = $user_id;
|
||||
$user_card->save();
|
||||
}
|
||||
|
||||
public function generateUserForUserCard($card_id = null)
|
||||
{
|
||||
$userCardQuery = UserCard::find();
|
||||
$card_id ? $userCardQuery->where(['id' => $card_id]) : $userCardQuery->where(['id_user' => NULL]);
|
||||
$user_card_array = $userCardQuery->all();
|
||||
$user_array = User::find()->select(['id', 'email'])->all();
|
||||
|
||||
foreach ($user_card_array as $user_card_value) {
|
||||
|
||||
foreach ($user_array as $user_value)
|
||||
if ($user_card_value->email == $user_value->email) {
|
||||
$user_id = $user_value->id;
|
||||
break;
|
||||
} else $user_id = NULL;
|
||||
|
||||
if ($user_id) {
|
||||
UserCard::genereateLinlkOnUser($user_card_value, $user_id);
|
||||
} else {
|
||||
|
||||
$user_id = UserCard::generateUser($user_card_value->email, $user_card_value->status);
|
||||
UserCard::genereateLinlkOnUser($user_card_value, $user_id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user_card_array) return "Данные успешно сгенерированы";
|
||||
else return "Нет данных для генерации";
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<div class="row" style="padding-bottom: 15px">
|
||||
<div class="imgUpload col-xs-6">
|
||||
<div class="media__upload_img"><img src="<?= $model->photo; ?>" width="100px"/></div>
|
||||
<div class="media__upload_img"><img src="<?= $model->photo; ?>" width="100px" /></div>
|
||||
<?php
|
||||
echo InputFile::widget([
|
||||
'language' => 'ru',
|
||||
@ -47,13 +47,13 @@ use yii\widgets\ActiveForm;
|
||||
?>
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
<!--<div class="media__upload_img"><img src="<?/*= $model->photo; */?>" width="100px"/></div>-->
|
||||
<!--<div class="media__upload_img"><img src="<?/*= $model->photo; */ ?>" width="100px"/></div>-->
|
||||
<?php
|
||||
echo InputFile::widget([
|
||||
'language' => 'ru',
|
||||
'controller' => 'elfinder',
|
||||
// вставляем название контроллера, по умолчанию равен elfinder
|
||||
'filter' => ['image','application/zip','application/pdf','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
||||
'filter' => ['image', 'application/zip', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
||||
// фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con..
|
||||
'name' => 'UserCard[resume]',
|
||||
'id' => 'usercard-resume',
|
||||
@ -73,31 +73,36 @@ use yii\widgets\ActiveForm;
|
||||
</div>
|
||||
|
||||
<div class="col-xs-6">
|
||||
<?= $form->field($model, 'gender')->dropDownList($model->genders,
|
||||
[
|
||||
'prompt' => 'Выберите'
|
||||
]) ?>
|
||||
<?= $form->field($model, 'gender')->dropDownList(
|
||||
$model->genders,
|
||||
[
|
||||
'prompt' => 'Выберите'
|
||||
]
|
||||
) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<?= $form->field($model, 'dob')->input('date',
|
||||
[
|
||||
'placeholder' => 'Zadejte svůj Datum narození',
|
||||
'language' => 'en',
|
||||
"data-format" => "DD MMMM YYYY",
|
||||
|
||||
]) ?>
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
<?= $form->field($model, 'status')
|
||||
->dropDownList(\common\models\Status::getStatusesArray(\common\models\UseStatus::USE_PROFILE),
|
||||
<?= $form->field($model, 'dob')->input(
|
||||
'date',
|
||||
[
|
||||
'prompt' => 'Выберите'
|
||||
'placeholder' => 'Zadejte svůj Datum narození',
|
||||
'language' => 'en',
|
||||
"data-format" => "DD MMMM YYYY",
|
||||
|
||||
]
|
||||
) ?>
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
<?= $form->field($model, 'status')
|
||||
->dropDownList(
|
||||
\common\models\Status::getStatusesArray(\common\models\UseStatus::USE_PROFILE),
|
||||
[
|
||||
'prompt' => 'Выберите'
|
||||
]
|
||||
) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@ -116,10 +121,11 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<?= $form->field($model, 'skill')->widget(Select2::class,
|
||||
<?= $form->field($model, 'skill')->widget(
|
||||
Select2::class,
|
||||
[
|
||||
'data' => \yii\helpers\ArrayHelper::map(\common\models\Skill::find()->all(),'id', 'name'),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control', 'multiple' => true],
|
||||
'data' => \yii\helpers\ArrayHelper::map(\common\models\Skill::find()->all(), 'id', 'name'),
|
||||
'options' => ['placeholder' => '...', 'class' => 'form-control', 'multiple' => true],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
@ -130,49 +136,52 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [
|
||||
'cloneButton' => true,
|
||||
'columns' => [
|
||||
[
|
||||
'name' => 'field_id',
|
||||
'type' => 'dropDownList',
|
||||
'title' => 'Поле',
|
||||
'defaultValue' => null,
|
||||
'items' => \yii\helpers\ArrayHelper::map(\backend\modules\settings\models\AdditionalFields::find()
|
||||
->joinWith('useFields')
|
||||
->where(['`use_field`.`use`' => \common\models\UseStatus::USE_PROFILE])
|
||||
->all(),
|
||||
'id', 'name'),
|
||||
'options' => ['prompt' => 'Выберите']
|
||||
],
|
||||
[
|
||||
'name' => 'value',
|
||||
'title' => 'Значение',
|
||||
'type' => InputFile::className(),
|
||||
'options' => [
|
||||
'language' => 'ru',
|
||||
'controller' => 'elfinder',
|
||||
// вставляем название контроллера, по умолчанию равен elfinder
|
||||
// фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con..
|
||||
'name' => 'fields[value]',
|
||||
'id' => 'fields-value',
|
||||
'options' => ['class' => 'form-control itemImg', 'maxlength' => '255'],
|
||||
'buttonOptions' => ['class' => 'btn btn-primary'],
|
||||
'value' => $model->fields[0]['value'],
|
||||
'buttonName' => 'Выбрать файл',
|
||||
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [
|
||||
'cloneButton' => true,
|
||||
'columns' => [
|
||||
[
|
||||
'name' => 'field_id',
|
||||
'type' => 'dropDownList',
|
||||
'title' => 'Поле',
|
||||
'defaultValue' => null,
|
||||
'items' => \yii\helpers\ArrayHelper::map(
|
||||
\backend\modules\settings\models\AdditionalFields::find()
|
||||
->joinWith('useFields')
|
||||
->where(['`use_field`.`use`' => \common\models\UseStatus::USE_PROFILE])
|
||||
->all(),
|
||||
'id',
|
||||
'name'
|
||||
),
|
||||
'options' => ['prompt' => 'Выберите']
|
||||
],
|
||||
[
|
||||
'name' => 'value',
|
||||
'title' => 'Значение',
|
||||
'type' => InputFile::className(),
|
||||
'options' => [
|
||||
'language' => 'ru',
|
||||
'controller' => 'elfinder',
|
||||
// вставляем название контроллера, по умолчанию равен elfinder
|
||||
// фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con..
|
||||
'name' => 'fields[value]',
|
||||
'id' => 'fields-value',
|
||||
'options' => ['class' => 'form-control itemImg', 'maxlength' => '255'],
|
||||
'buttonOptions' => ['class' => 'btn btn-primary'],
|
||||
'value' => $model->fields[0]['value'],
|
||||
'buttonName' => 'Выбрать файл',
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'order',
|
||||
'title' => 'Приоритет',
|
||||
'enableError' => true,
|
||||
'options' => [
|
||||
'class' => 'input-priority'
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'order',
|
||||
'title' => 'Приоритет',
|
||||
'enableError' => true,
|
||||
'options' => [
|
||||
'class' => 'input-priority'
|
||||
]
|
||||
],
|
||||
],
|
||||
])->label('Дополнительно');
|
||||
?>
|
||||
])->label('Дополнительно');
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -182,4 +191,4 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
</div>
|
@ -13,4 +13,4 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
</div>
|
3
backend/modules/card/views/user-card/generate.php
Normal file
3
backend/modules/card/views/user-card/generate.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
echo $massage;
|
@ -16,6 +16,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<p>
|
||||
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
<?= Html::a('Сгенерировать пользователей', ['generate'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
@ -28,8 +29,8 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
[
|
||||
'label' => 'photo',
|
||||
'format' => 'raw',
|
||||
'value' => function($model){
|
||||
return Html::img(Url::to($model->photo),[
|
||||
'value' => function ($model) {
|
||||
return Html::img(Url::to($model->photo), [
|
||||
'style' => 'width:100px;'
|
||||
]);
|
||||
},
|
||||
@ -42,14 +43,14 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
//'dob',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'value' => function($model){
|
||||
'value' => function ($model) {
|
||||
return $model->status0->name;
|
||||
},
|
||||
'filter' => kartik\select2\Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'status',
|
||||
'data' => \common\models\Status::getStatusesArray(\common\models\UseStatus::USE_PROFILE),
|
||||
'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'],
|
||||
'options' => ['placeholder' => 'Начните вводить...', 'class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
@ -58,22 +59,21 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
//'created_at',
|
||||
//'updated_at',
|
||||
[
|
||||
'label' => 'Навыки',
|
||||
'format' => 'raw',
|
||||
'value' => function($model){
|
||||
$str = '';
|
||||
foreach ($model->skillValues as $item)
|
||||
{
|
||||
$str .= $item->skill->name . ', ';
|
||||
}
|
||||
$str = substr( $str, 0, -2);
|
||||
return $str;
|
||||
},
|
||||
'label' => 'Навыки',
|
||||
'format' => 'raw',
|
||||
'value' => function ($model) {
|
||||
$str = '';
|
||||
foreach ($model->skillValues as $item) {
|
||||
$str .= $item->skill->name . ', ';
|
||||
}
|
||||
$str = substr($str, 0, -2);
|
||||
return $str;
|
||||
},
|
||||
'filter' => kartik\select2\Select2::widget([
|
||||
'attribute' => 'skills',
|
||||
'attribute' => 'skills',
|
||||
'model' => $searchModel,
|
||||
'data' => \common\models\UserCard::getNameSkills(),
|
||||
'options' => ['multiple' => true,'placeholder' => 'Выбрать параметр','class' => 'form-control'],
|
||||
'options' => ['multiple' => true, 'placeholder' => 'Выбрать параметр', 'class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
@ -83,4 +83,4 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
@ -6,6 +6,7 @@ use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\card\models\UserCard */
|
||||
/* @var $userData common\models\User */
|
||||
/* @var $skills \common\models\CardSkill */
|
||||
/* @var $skill \common\models\Skill */
|
||||
|
||||
@ -27,14 +28,14 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
[
|
||||
'attribute' => 'Photo',
|
||||
'format' => 'raw',
|
||||
'value' => function($model){
|
||||
'value' => function ($model) {
|
||||
return Html::tag('img', null, ['src' => $model->photo, 'width' => '100px']);
|
||||
}
|
||||
],
|
||||
[
|
||||
'attribute' => 'Resume',
|
||||
'format' => 'raw',
|
||||
'value' => function($model){
|
||||
'value' => function ($model) {
|
||||
return Html::a('Скачать', $model->resume, ['target' => '_blank']);
|
||||
}
|
||||
],
|
||||
@ -62,21 +63,21 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<h2>Навыки</h2>
|
||||
|
||||
<?php foreach ($skills as $skill): ?>
|
||||
<?php foreach ($skills as $skill) : ?>
|
||||
<span class="btn btn-default btn-sm"><?= $skill['skill']->name; ?></span>
|
||||
<?php endforeach; ?>
|
||||
<h2>Дополнительные сведения</h2>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $modelFildValue,
|
||||
'layout'=>"{items}",
|
||||
'layout' => "{items}",
|
||||
'columns' => [
|
||||
'field.name:text:Поле',
|
||||
[
|
||||
'attribute' => 'value',
|
||||
'format' => 'raw',
|
||||
'value' => function($model){
|
||||
if ($model->type_file == 'file'){
|
||||
'value' => function ($model) {
|
||||
if ($model->type_file == 'file') {
|
||||
return $model->value . ' (' . Html::a('Скачать', $model->value, ['target' => '_blank', 'download' => 'download']) . ')';
|
||||
}
|
||||
return $model->value;
|
||||
@ -84,4 +85,5 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
||||
|
||||
</div>
|
Reference in New Issue
Block a user