diff --git a/backend/modules/notes/Notes.php b/backend/modules/notes/Notes.php old mode 100644 new mode 100755 diff --git a/backend/modules/notes/models/Note.php b/backend/modules/notes/models/Note.php old mode 100644 new mode 100755 index 6ebedbf..e1d320c --- a/backend/modules/notes/models/Note.php +++ b/backend/modules/notes/models/Note.php @@ -2,11 +2,48 @@ namespace backend\modules\notes\models; +use Yii; use common\models\FieldsValueNew; class Note extends \common\models\Note { + public $fields; + + public function init() + { + parent::init(); + + $fieldValue = FieldsValueNew::find() + ->where( + [ + 'item_id' => \Yii::$app->request->get('id'), + 'item_type' => FieldsValueNew::TYPE_NOTE, + ]) + ->all(); + $array = []; + if(!empty($fieldValue)){ + foreach ($fieldValue as $item){ + array_push($array, + ['field_id' => $item->field_id, + 'value' => $item->value, + 'order' => $item->order, + 'field_name' => $item->field->name]); + } + $this->fields = $array; + } + else{ + $this->fields = [ + [ + 'field_id' => null, + 'value' => null, + 'order' => null, + 'field_name' => null, + ], + ]; + } + } + public function afterSave($insert, $changedAttributes) { $post = \Yii::$app->request->post('Note'); @@ -21,6 +58,12 @@ class Note extends \common\models\Note $fieldsValue->order = $item['order']; $fieldsValue->value = $item['value']; + if(is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])){ + $fieldsValue->type_file = 'file'; + }else{ + $fieldsValue->type_file = 'text'; + } + $fieldsValue->save(); } diff --git a/backend/modules/notes/models/NoteSearch.php b/backend/modules/notes/models/NoteSearch.php old mode 100644 new mode 100755 diff --git a/backend/modules/notes/views/notes/_form.php b/backend/modules/notes/views/notes/_form.php index ef68ef5..e339fd2 100755 --- a/backend/modules/notes/views/notes/_form.php +++ b/backend/modules/notes/views/notes/_form.php @@ -1,6 +1,7 @@ ['prompt' => 'Выберите'] ], [ - 'name' => 'value', + 'name' => 'value', 'title' => 'Значение', - 'enableError' => true, + 'type' => InputFile::className(), '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', diff --git a/backend/modules/notes/views/notes/index.php b/backend/modules/notes/views/notes/index.php old mode 100644 new mode 100755 diff --git a/backend/modules/notes/views/notes/update.php b/backend/modules/notes/views/notes/update.php old mode 100644 new mode 100755 diff --git a/backend/modules/notes/views/notes/view.php b/backend/modules/notes/views/notes/view.php old mode 100644 new mode 100755 index f236d2c..20388d7 --- a/backend/modules/notes/views/notes/view.php +++ b/backend/modules/notes/views/notes/view.php @@ -44,7 +44,13 @@ $this->params['breadcrumbs'][] = $this->title; 'field.name:text:Поле', [ 'attribute' => 'value', - 'label' => 'Значение' + 'format' => 'raw', + 'value' => function ($model) { + if ($model->type_file == 'file') { + return $model->value . ' (' . Html::a('Скачать', $model->value, ['target' => '_blank', 'download' => 'download']) . ')'; + } + return $model->value; + } ], ], ]); ?> diff --git a/common/models/Note.php b/common/models/Note.php old mode 100644 new mode 100755