added upload files in additional fields

This commit is contained in:
vladrigos 2020-08-04 11:14:55 +03:00
parent 38069c57d4
commit 8b3687cb81
9 changed files with 115 additions and 45 deletions

View File

@ -6,6 +6,7 @@ use yii\helpers\Html;
use yii\jui\DatePicker;
use yii\web\View;
use yii\widgets\ActiveForm;
use mihaildev\elfinder\InputFile;
/* @var $this yii\web\View */
/* @var $model backend\modules\company\models\Balance */
@ -35,7 +36,7 @@ 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',
@ -53,8 +54,16 @@ use yii\widgets\ActiveForm;
'name' => 'value',
'title' => 'Значение',
'enableError' => true,
'type' => InputFile::class,
'options' => [
'class' => 'input-priority'
'language' => 'ru',
'controller' => 'elfinder',
'name' => 'fields[value]',
'id' => 'fields-value',
'options' => ['class' => 'form-control itemImg', 'maxlength' => '255'],
'buttonOptions' => ['class' => 'btn btn-primary'],
'value' => $model->fields[0]['value'],
'buttonName' => 'Выбрать файл',
]
],
[

View File

@ -49,7 +49,11 @@ $this->params['breadcrumbs'][] = $this->title;
'field.name:text:Поле',
[
'attribute' => 'value',
'label' => 'Значение'
'format' => 'raw',
'label' => 'Значение',
'value' => function ($model) {
return $model->getValue();
}
],
],
]); ?>

View File

@ -4,6 +4,7 @@ namespace backend\modules\company\models;
use common\models\FieldsValue;
use common\models\FieldsValueNew;
use Yii;
class Company extends \common\models\Company
{
@ -27,6 +28,7 @@ class Company extends \common\models\Company
['field_id' => $item->field_id,
'value' => $item->value,
'order' => $item->order,
'type_file' => $item->type_file,
'field_name' => $item->field->name]);
}
$this->fields = $array;
@ -38,6 +40,7 @@ class Company extends \common\models\Company
'value' => null,
'order' => null,
'field_name' => null,
'type_file' => null,
],
];
}
@ -50,14 +53,19 @@ class Company extends \common\models\Company
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_COMPANY]);
foreach ( $post['fields'] as $item) {
$fildsValue = new FieldsValueNew();
$fildsValue->field_id = $item['field_id'];
$fildsValue->value = $item['value'];
$fildsValue->order = $item['order'];
$fildsValue->item_id = $this->id;
$fildsValue->item_type = FieldsValueNew::TYPE_COMPANY;
$fieldsValue = new FieldsValueNew();
$fieldsValue->field_id = $item['field_id'];
$fieldsValue->value = $item['value'];
$fieldsValue->order = $item['order'];
$fieldsValue->item_id = $this->id;
$fieldsValue->item_type = FieldsValueNew::TYPE_COMPANY;
if(is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])){
$fieldsValue->type_file = 'file';
}else{
$fieldsValue->type_file = 'text';
}
$fildsValue->save();
$fieldsValue->save();
}
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub

View File

@ -4,6 +4,7 @@ use backend\modules\settings\models\AdditionalFields;
use unclead\multipleinput\MultipleInput;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use mihaildev\elfinder\InputFile;
/* @var $this yii\web\View */
/* @var $model backend\modules\company\models\Company */
@ -31,8 +32,8 @@ use yii\widgets\ActiveForm;
<div class="row">
<div class="col-xs-12">
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [
<?= $form->field($model, 'fields')->widget(MultipleInput::class,[
'cloneButton' => true,
'columns' => [
[
'name' => 'field_id',
@ -50,9 +51,19 @@ use yii\widgets\ActiveForm;
'name' => 'value',
'title' => 'Значение',
'enableError' => true,
'type' => InputFile::class,
'options' => [
'class' => 'input-priority'
]
'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',
@ -61,7 +72,7 @@ use yii\widgets\ActiveForm;
'options' => [
'class' => 'input-priority'
]
]
],
]
])->label('Дополнительно');
?>

View File

@ -45,7 +45,11 @@ $this->params['breadcrumbs'][] = $this->title;
'field.name:text:Поле',
[
'attribute' => 'value',
'label' => 'Значение'
'format' => 'raw',
'label' => 'Значение',
'value' => function ($model) {
return $model->getValue();
}
],
],
]); ?>

View File

@ -7,6 +7,7 @@ use common\models\FieldsValue;
use common\models\FieldsValueNew;
use common\models\ProjectUser;
use yii\helpers\ArrayHelper;
use Yii;
class Project extends \common\models\Project
{
@ -31,6 +32,7 @@ class Project extends \common\models\Project
'field_id' => $item->field_id,
'value' => $item->value,
'order' => $item->order,
'type_file' => $item->type_file,
'field_name' => $item->field->name]);
}
$this->fields = $array;
@ -40,6 +42,7 @@ class Project extends \common\models\Project
'field_id' => null,
'value' => null,
'order' => null,
'type_file' => null,
'field_name' => null,
],
];
@ -61,14 +64,20 @@ class Project extends \common\models\Project
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROJECT]);
foreach ($post['fields'] as $item) {
$fildsValue = new FieldsValueNew();
$fildsValue->field_id = $item['field_id'];
$fildsValue->value = $item['value'];
$fildsValue->order = $item['order'];
$fildsValue->item_id = $this->id;
$fildsValue->item_type = FieldsValueNew::TYPE_PROJECT;
$fieldsValue = new FieldsValueNew();
$fieldsValue->field_id = $item['field_id'];
$fieldsValue->value = $item['value'];
$fieldsValue->order = $item['order'];
$fieldsValue->item_id = $this->id;
$fieldsValue->item_type = FieldsValueNew::TYPE_PROJECT;
$fildsValue->save();
if(is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])){
$fieldsValue->type_file = 'file';
}else{
$fieldsValue->type_file = 'text';
}
$fieldsValue->save();
}
ProjectUser::deleteAll(['project_id' => $this->id]);

View File

@ -4,6 +4,7 @@ use kartik\select2\Select2;
use unclead\multipleinput\MultipleInput;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use mihaildev\elfinder\InputFile;
/* @var $this yii\web\View */
/* @var $model backend\modules\project\models\Project */
@ -53,7 +54,7 @@ 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',
@ -71,8 +72,16 @@ use yii\widgets\ActiveForm;
'name' => 'value',
'title' => 'Значение',
'enableError' => true,
'type' => InputFile::class,
'options' => [
'class' => 'input-priority'
'language' => 'ru',
'controller' => 'elfinder',
'name' => 'fields[value]',
'id' => 'fields-value',
'options' => ['class' => 'form-control itemImg', 'maxlength' => '255'],
'buttonOptions' => ['class' => 'btn btn-primary'],
'value' => $model->fields[0]['value'],
'buttonName' => 'Выбрать файл',
]
],
[

View File

@ -47,7 +47,14 @@ $this->params['breadcrumbs'][] = $this->title;
'layout' => "{items}",
'columns' => [
'field.name:text:Поле',
'value',
[
'attribute' => 'value',
'format' => 'raw',
'label' => 'Значение',
'value' => function ($model) {
return $model->getValue();
}
],
],
]); ?>

View File

@ -7,6 +7,7 @@ use common\classes\Debug;
use PHPUnit\Framework\MockObject\Matcher\DeferredError;
use yii\db\Query;
use yii\helpers\ArrayHelper;
use yii;
/**
* This is the model class for table "company".
@ -42,6 +43,7 @@ class Balance extends \yii\db\ActiveRecord
['field_id' => $item->field_id,
'value' => $item->value,
'order' => $item->order,
'type_file' => $item->type_file,
'field_name' => $item->field->name]);
}
$this->fields = $array;
@ -51,6 +53,7 @@ class Balance extends \yii\db\ActiveRecord
'field_id' => null,
'value' => null,
'order' => null,
'type_file' => null,
'field_name' => null,
],
];
@ -131,14 +134,20 @@ class Balance extends \yii\db\ActiveRecord
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_BALANCE]);
foreach ($post['fields'] as $item) {
$fildsValue = new FieldsValueNew();
$fildsValue->field_id = $item['field_id'];
$fildsValue->value = $item['value'];
$fildsValue->order = $item['order'];
$fildsValue->item_id = $this->id;
$fildsValue->item_type = FieldsValueNew::TYPE_BALANCE;
$fieldsValue = new FieldsValueNew();
$fieldsValue->field_id = $item['field_id'];
$fieldsValue->value = $item['value'];
$fieldsValue->order = $item['order'];
$fieldsValue->item_id = $this->id;
$fieldsValue->item_type = FieldsValueNew::TYPE_BALANCE;
$fildsValue->save();
if(is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])){
$fieldsValue->type_file = 'file';
}else{
$fieldsValue->type_file = 'text';
}
$fieldsValue->save();
}
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub