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\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' => 'Выбрать файл',
|
||||
]
|
||||
],
|
||||
[
|
||||
|
@ -49,7 +49,11 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'field.name:text:Поле',
|
||||
[
|
||||
'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\FieldsValueNew;
|
||||
use Yii;
|
||||
|
||||
class Company extends \common\models\Company
|
||||
{
|
||||
@ -15,10 +16,10 @@ class Company extends \common\models\Company
|
||||
|
||||
$fieldValue = FieldsValueNew::find()
|
||||
->where(
|
||||
[
|
||||
'item_id' => \Yii::$app->request->get('id'),
|
||||
'item_type' => FieldsValueNew::TYPE_COMPANY,
|
||||
])
|
||||
[
|
||||
'item_id' => \Yii::$app->request->get('id'),
|
||||
'item_type' => FieldsValueNew::TYPE_COMPANY,
|
||||
])
|
||||
->all();
|
||||
$array = [];
|
||||
if(!empty($fieldValue)){
|
||||
@ -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,
|
||||
],
|
||||
];
|
||||
}
|
||||
@ -59,14 +62,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
|
||||
|
@ -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,12 +32,12 @@ 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',
|
||||
'type' => 'dropDownList',
|
||||
'name' => 'field_id',
|
||||
'type' => 'dropDownList',
|
||||
'title' => 'Поле',
|
||||
'defaultValue' => null,
|
||||
'items' => \yii\helpers\ArrayHelper::map(AdditionalFields::find()
|
||||
@ -47,21 +48,31 @@ use yii\widgets\ActiveForm;
|
||||
'options' => ['prompt' => 'Выберите']
|
||||
],
|
||||
[
|
||||
'name' => 'value',
|
||||
'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',
|
||||
'name' => 'order',
|
||||
'title' => 'Приоритет',
|
||||
'enableError' => true,
|
||||
'options' => [
|
||||
'class' => 'input-priority'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
])->label('Дополнительно');
|
||||
?>
|
||||
|
@ -45,7 +45,11 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'field.name:text:Поле',
|
||||
[
|
||||
'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\ProjectUser;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use Yii;
|
||||
|
||||
class Project extends \common\models\Project
|
||||
{
|
||||
@ -31,15 +32,17 @@ 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;
|
||||
} else {
|
||||
$this->fields = [
|
||||
[
|
||||
'field_id' => null,
|
||||
'value' => null,
|
||||
'field_id' => null,
|
||||
'value' => null,
|
||||
'order' => null,
|
||||
'type_file' => 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]);
|
||||
|
||||
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]);
|
||||
|
@ -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' => 'Выбрать файл',
|
||||
]
|
||||
],
|
||||
[
|
||||
|
@ -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();
|
||||
}
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
@ -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,
|
||||
],
|
||||
];
|
||||
@ -82,8 +85,8 @@ class Balance extends \yii\db\ActiveRecord
|
||||
|
||||
return ArrayHelper::map(
|
||||
AdditionalFields::find()
|
||||
->leftJoin('use_field', 'additional_fields.id=use_field.field_id')
|
||||
->where(['use_field.use' => $type])->all(), 'id', 'name'
|
||||
->leftJoin('use_field', 'additional_fields.id=use_field.field_id')
|
||||
->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]);
|
||||
|
||||
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
|
||||
|
@ -52,7 +52,7 @@ class Project extends \yii\db\ActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name'], 'required'],
|
||||
[['name', 'status'], 'required'],
|
||||
[['description'], 'string'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['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