From 5ebdc16a8af4c30610d4590159406256fc490a84 Mon Sep 17 00:00:00 2001 From: Leorne Date: Thu, 5 Dec 2019 17:03:00 +0300 Subject: [PATCH] note files data --- backend/modules/notes/Notes.php | 0 backend/modules/notes/models/Note.php | 43 ++++++++++++++++++++ backend/modules/notes/models/NoteSearch.php | 0 backend/modules/notes/views/notes/_form.php | 18 ++++++-- backend/modules/notes/views/notes/index.php | 0 backend/modules/notes/views/notes/update.php | 0 backend/modules/notes/views/notes/view.php | 8 +++- common/models/Note.php | 0 8 files changed, 64 insertions(+), 5 deletions(-) mode change 100644 => 100755 backend/modules/notes/Notes.php mode change 100644 => 100755 backend/modules/notes/models/Note.php mode change 100644 => 100755 backend/modules/notes/models/NoteSearch.php mode change 100644 => 100755 backend/modules/notes/views/notes/index.php mode change 100644 => 100755 backend/modules/notes/views/notes/update.php mode change 100644 => 100755 backend/modules/notes/views/notes/view.php mode change 100644 => 100755 common/models/Note.php 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