Merge pull request #44 from apuc/upload_files_for_all_entitys
Upload files for all entitys
This commit is contained in:
commit
4af80790c3
@ -6,6 +6,7 @@ use yii\helpers\Html;
|
|||||||
use yii\jui\DatePicker;
|
use yii\jui\DatePicker;
|
||||||
use yii\web\View;
|
use yii\web\View;
|
||||||
use yii\widgets\ActiveForm;
|
use yii\widgets\ActiveForm;
|
||||||
|
use mihaildev\elfinder\InputFile;
|
||||||
|
|
||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $model backend\modules\company\models\Balance */
|
/* @var $model backend\modules\company\models\Balance */
|
||||||
@ -35,7 +36,7 @@ use yii\widgets\ActiveForm;
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [
|
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [
|
||||||
|
'cloneButton' => true,
|
||||||
'columns' => [
|
'columns' => [
|
||||||
[
|
[
|
||||||
'name' => 'field_id',
|
'name' => 'field_id',
|
||||||
@ -53,8 +54,16 @@ use yii\widgets\ActiveForm;
|
|||||||
'name' => 'value',
|
'name' => 'value',
|
||||||
'title' => 'Значение',
|
'title' => 'Значение',
|
||||||
'enableError' => true,
|
'enableError' => true,
|
||||||
|
'type' => InputFile::class,
|
||||||
'options' => [
|
'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' => 'Выбрать файл',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -49,7 +49,11 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'field.name:text:Поле',
|
'field.name:text:Поле',
|
||||||
[
|
[
|
||||||
'attribute' => 'value',
|
'attribute' => 'value',
|
||||||
'label' => 'Значение'
|
'format' => 'raw',
|
||||||
|
'label' => 'Значение',
|
||||||
|
'value' => function ($model) {
|
||||||
|
return $model->getValue();
|
||||||
|
}
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]); ?>
|
]); ?>
|
||||||
|
@ -4,6 +4,7 @@ namespace backend\modules\company\models;
|
|||||||
|
|
||||||
use common\models\FieldsValue;
|
use common\models\FieldsValue;
|
||||||
use common\models\FieldsValueNew;
|
use common\models\FieldsValueNew;
|
||||||
|
use Yii;
|
||||||
|
|
||||||
class Company extends \common\models\Company
|
class Company extends \common\models\Company
|
||||||
{
|
{
|
||||||
@ -15,10 +16,10 @@ class Company extends \common\models\Company
|
|||||||
|
|
||||||
$fieldValue = FieldsValueNew::find()
|
$fieldValue = FieldsValueNew::find()
|
||||||
->where(
|
->where(
|
||||||
[
|
[
|
||||||
'item_id' => \Yii::$app->request->get('id'),
|
'item_id' => \Yii::$app->request->get('id'),
|
||||||
'item_type' => FieldsValueNew::TYPE_COMPANY,
|
'item_type' => FieldsValueNew::TYPE_COMPANY,
|
||||||
])
|
])
|
||||||
->all();
|
->all();
|
||||||
$array = [];
|
$array = [];
|
||||||
if(!empty($fieldValue)){
|
if(!empty($fieldValue)){
|
||||||
@ -27,6 +28,7 @@ class Company extends \common\models\Company
|
|||||||
['field_id' => $item->field_id,
|
['field_id' => $item->field_id,
|
||||||
'value' => $item->value,
|
'value' => $item->value,
|
||||||
'order' => $item->order,
|
'order' => $item->order,
|
||||||
|
'type_file' => $item->type_file,
|
||||||
'field_name' => $item->field->name]);
|
'field_name' => $item->field->name]);
|
||||||
}
|
}
|
||||||
$this->fields = $array;
|
$this->fields = $array;
|
||||||
@ -38,6 +40,7 @@ class Company extends \common\models\Company
|
|||||||
'value' => null,
|
'value' => null,
|
||||||
'order' => null,
|
'order' => null,
|
||||||
'field_name' => null,
|
'field_name' => null,
|
||||||
|
'type_file' => null,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -59,14 +62,19 @@ class Company extends \common\models\Company
|
|||||||
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_COMPANY]);
|
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_COMPANY]);
|
||||||
|
|
||||||
foreach ( $post['fields'] as $item) {
|
foreach ( $post['fields'] as $item) {
|
||||||
$fildsValue = new FieldsValueNew();
|
$fieldsValue = new FieldsValueNew();
|
||||||
$fildsValue->field_id = $item['field_id'];
|
$fieldsValue->field_id = $item['field_id'];
|
||||||
$fildsValue->value = $item['value'];
|
$fieldsValue->value = $item['value'];
|
||||||
$fildsValue->order = $item['order'];
|
$fieldsValue->order = $item['order'];
|
||||||
$fildsValue->item_id = $this->id;
|
$fieldsValue->item_id = $this->id;
|
||||||
$fildsValue->item_type = FieldsValueNew::TYPE_COMPANY;
|
$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
|
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
|
||||||
|
@ -4,6 +4,7 @@ use backend\modules\settings\models\AdditionalFields;
|
|||||||
use unclead\multipleinput\MultipleInput;
|
use unclead\multipleinput\MultipleInput;
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
use yii\widgets\ActiveForm;
|
use yii\widgets\ActiveForm;
|
||||||
|
use mihaildev\elfinder\InputFile;
|
||||||
|
|
||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $model backend\modules\company\models\Company */
|
/* @var $model backend\modules\company\models\Company */
|
||||||
@ -31,12 +32,12 @@ use yii\widgets\ActiveForm;
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [
|
<?= $form->field($model, 'fields')->widget(MultipleInput::class,[
|
||||||
|
'cloneButton' => true,
|
||||||
'columns' => [
|
'columns' => [
|
||||||
[
|
[
|
||||||
'name' => 'field_id',
|
'name' => 'field_id',
|
||||||
'type' => 'dropDownList',
|
'type' => 'dropDownList',
|
||||||
'title' => 'Поле',
|
'title' => 'Поле',
|
||||||
'defaultValue' => null,
|
'defaultValue' => null,
|
||||||
'items' => \yii\helpers\ArrayHelper::map(AdditionalFields::find()
|
'items' => \yii\helpers\ArrayHelper::map(AdditionalFields::find()
|
||||||
@ -47,21 +48,31 @@ use yii\widgets\ActiveForm;
|
|||||||
'options' => ['prompt' => 'Выберите']
|
'options' => ['prompt' => 'Выберите']
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'value',
|
'name' => 'value',
|
||||||
'title' => 'Значение',
|
'title' => 'Значение',
|
||||||
'enableError' => true,
|
'enableError' => true,
|
||||||
|
'type' => InputFile::class,
|
||||||
'options' => [
|
'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',
|
'name' => 'order',
|
||||||
'title' => 'Приоритет',
|
'title' => 'Приоритет',
|
||||||
'enableError' => true,
|
'enableError' => true,
|
||||||
'options' => [
|
'options' => [
|
||||||
'class' => 'input-priority'
|
'class' => 'input-priority'
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
]
|
]
|
||||||
])->label('Дополнительно');
|
])->label('Дополнительно');
|
||||||
?>
|
?>
|
||||||
|
@ -45,7 +45,11 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'field.name:text:Поле',
|
'field.name:text:Поле',
|
||||||
[
|
[
|
||||||
'attribute' => 'value',
|
'attribute' => 'value',
|
||||||
'label' => 'Значение'
|
'format' => 'raw',
|
||||||
|
'label' => 'Значение',
|
||||||
|
'value' => function ($model) {
|
||||||
|
return $model->getValue();
|
||||||
|
}
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]); ?>
|
]); ?>
|
||||||
|
@ -7,6 +7,7 @@ use common\models\FieldsValue;
|
|||||||
use common\models\FieldsValueNew;
|
use common\models\FieldsValueNew;
|
||||||
use common\models\ProjectUser;
|
use common\models\ProjectUser;
|
||||||
use yii\helpers\ArrayHelper;
|
use yii\helpers\ArrayHelper;
|
||||||
|
use Yii;
|
||||||
|
|
||||||
class Project extends \common\models\Project
|
class Project extends \common\models\Project
|
||||||
{
|
{
|
||||||
@ -31,15 +32,17 @@ class Project extends \common\models\Project
|
|||||||
'field_id' => $item->field_id,
|
'field_id' => $item->field_id,
|
||||||
'value' => $item->value,
|
'value' => $item->value,
|
||||||
'order' => $item->order,
|
'order' => $item->order,
|
||||||
|
'type_file' => $item->type_file,
|
||||||
'field_name' => $item->field->name]);
|
'field_name' => $item->field->name]);
|
||||||
}
|
}
|
||||||
$this->fields = $array;
|
$this->fields = $array;
|
||||||
} else {
|
} else {
|
||||||
$this->fields = [
|
$this->fields = [
|
||||||
[
|
[
|
||||||
'field_id' => null,
|
'field_id' => null,
|
||||||
'value' => null,
|
'value' => null,
|
||||||
'order' => null,
|
'order' => null,
|
||||||
|
'type_file' => null,
|
||||||
'field_name' => null,
|
'field_name' => null,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -70,14 +73,20 @@ class Project extends \common\models\Project
|
|||||||
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROJECT]);
|
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROJECT]);
|
||||||
|
|
||||||
foreach ($post['fields'] as $item) {
|
foreach ($post['fields'] as $item) {
|
||||||
$fildsValue = new FieldsValueNew();
|
$fieldsValue = new FieldsValueNew();
|
||||||
$fildsValue->field_id = $item['field_id'];
|
$fieldsValue->field_id = $item['field_id'];
|
||||||
$fildsValue->value = $item['value'];
|
$fieldsValue->value = $item['value'];
|
||||||
$fildsValue->order = $item['order'];
|
$fieldsValue->order = $item['order'];
|
||||||
$fildsValue->item_id = $this->id;
|
$fieldsValue->item_id = $this->id;
|
||||||
$fildsValue->item_type = FieldsValueNew::TYPE_PROJECT;
|
$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]);
|
ProjectUser::deleteAll(['project_id' => $this->id]);
|
||||||
|
@ -4,6 +4,7 @@ use kartik\select2\Select2;
|
|||||||
use unclead\multipleinput\MultipleInput;
|
use unclead\multipleinput\MultipleInput;
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
use yii\widgets\ActiveForm;
|
use yii\widgets\ActiveForm;
|
||||||
|
use mihaildev\elfinder\InputFile;
|
||||||
|
|
||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $model backend\modules\project\models\Project */
|
/* @var $model backend\modules\project\models\Project */
|
||||||
@ -53,7 +54,7 @@ use yii\widgets\ActiveForm;
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [
|
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [
|
||||||
|
'cloneButton' => true,
|
||||||
'columns' => [
|
'columns' => [
|
||||||
[
|
[
|
||||||
'name' => 'field_id',
|
'name' => 'field_id',
|
||||||
@ -71,8 +72,16 @@ use yii\widgets\ActiveForm;
|
|||||||
'name' => 'value',
|
'name' => 'value',
|
||||||
'title' => 'Значение',
|
'title' => 'Значение',
|
||||||
'enableError' => true,
|
'enableError' => true,
|
||||||
|
'type' => InputFile::class,
|
||||||
'options' => [
|
'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' => 'Выбрать файл',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -47,7 +47,14 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'layout' => "{items}",
|
'layout' => "{items}",
|
||||||
'columns' => [
|
'columns' => [
|
||||||
'field.name:text:Поле',
|
'field.name:text:Поле',
|
||||||
'value',
|
[
|
||||||
|
'attribute' => 'value',
|
||||||
|
'format' => 'raw',
|
||||||
|
'label' => 'Значение',
|
||||||
|
'value' => function ($model) {
|
||||||
|
return $model->getValue();
|
||||||
|
}
|
||||||
|
],
|
||||||
],
|
],
|
||||||
]); ?>
|
]); ?>
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ use common\classes\Debug;
|
|||||||
use PHPUnit\Framework\MockObject\Matcher\DeferredError;
|
use PHPUnit\Framework\MockObject\Matcher\DeferredError;
|
||||||
use yii\db\Query;
|
use yii\db\Query;
|
||||||
use yii\helpers\ArrayHelper;
|
use yii\helpers\ArrayHelper;
|
||||||
|
use yii;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the model class for table "company".
|
* This is the model class for table "company".
|
||||||
@ -42,6 +43,7 @@ class Balance extends \yii\db\ActiveRecord
|
|||||||
['field_id' => $item->field_id,
|
['field_id' => $item->field_id,
|
||||||
'value' => $item->value,
|
'value' => $item->value,
|
||||||
'order' => $item->order,
|
'order' => $item->order,
|
||||||
|
'type_file' => $item->type_file,
|
||||||
'field_name' => $item->field->name]);
|
'field_name' => $item->field->name]);
|
||||||
}
|
}
|
||||||
$this->fields = $array;
|
$this->fields = $array;
|
||||||
@ -51,6 +53,7 @@ class Balance extends \yii\db\ActiveRecord
|
|||||||
'field_id' => null,
|
'field_id' => null,
|
||||||
'value' => null,
|
'value' => null,
|
||||||
'order' => null,
|
'order' => null,
|
||||||
|
'type_file' => null,
|
||||||
'field_name' => null,
|
'field_name' => null,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -82,8 +85,8 @@ class Balance extends \yii\db\ActiveRecord
|
|||||||
|
|
||||||
return ArrayHelper::map(
|
return ArrayHelper::map(
|
||||||
AdditionalFields::find()
|
AdditionalFields::find()
|
||||||
->leftJoin('use_field', 'additional_fields.id=use_field.field_id')
|
->leftJoin('use_field', 'additional_fields.id=use_field.field_id')
|
||||||
->where(['use_field.use' => $type])->all(), 'id', 'name'
|
->where(['use_field.use' => $type])->all(), 'id', 'name'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,14 +134,20 @@ class Balance extends \yii\db\ActiveRecord
|
|||||||
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_BALANCE]);
|
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_BALANCE]);
|
||||||
|
|
||||||
foreach ($post['fields'] as $item) {
|
foreach ($post['fields'] as $item) {
|
||||||
$fildsValue = new FieldsValueNew();
|
$fieldsValue = new FieldsValueNew();
|
||||||
$fildsValue->field_id = $item['field_id'];
|
$fieldsValue->field_id = $item['field_id'];
|
||||||
$fildsValue->value = $item['value'];
|
$fieldsValue->value = $item['value'];
|
||||||
$fildsValue->order = $item['order'];
|
$fieldsValue->order = $item['order'];
|
||||||
$fildsValue->item_id = $this->id;
|
$fieldsValue->item_id = $this->id;
|
||||||
$fildsValue->item_type = FieldsValueNew::TYPE_BALANCE;
|
$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
|
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
|
||||||
|
@ -52,7 +52,7 @@ class Project extends \yii\db\ActiveRecord
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['name'], 'required'],
|
[['name', 'status'], 'required'],
|
||||||
[['description'], 'string'],
|
[['description'], 'string'],
|
||||||
[['created_at', 'updated_at'], 'safe'],
|
[['created_at', 'updated_at'], 'safe'],
|
||||||
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
|
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class m200803_135837_add_table_options_to_company_table
|
||||||
|
*/
|
||||||
|
class m200803_135837_add_table_options_to_company_table extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
if ($this->db->driverName === 'mysql') {
|
||||||
|
$this->execute('ALTER TABLE company DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function safeDown()
|
||||||
|
{
|
||||||
|
if ($this->db->driverName === 'mysql') {
|
||||||
|
$this->execute('ALTER TABLE company DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ENGINE=InnoDB');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user