diff --git a/backend/modules/company/controllers/CompanyController.php b/backend/modules/company/controllers/CompanyController.php index 3235f73..2ee9ff7 100755 --- a/backend/modules/company/controllers/CompanyController.php +++ b/backend/modules/company/controllers/CompanyController.php @@ -2,9 +2,11 @@ namespace backend\modules\company\controllers; +use common\models\FieldsValueNew; use Yii; use backend\modules\company\models\Company; use backend\modules\company\models\CompanySearch; +use yii\data\ActiveDataProvider; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -52,8 +54,17 @@ class CompanyController extends Controller */ public function actionView($id) { + $dataProviderF = new ActiveDataProvider([ + 'query' => FieldsValueNew::find() + ->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_COMPANY]) + ->orderBy('order'), + 'pagination' => [ + 'pageSize' => 200, + ], + ]); return $this->render('view', [ 'model' => $this->findModel($id), + 'dataProviderF' => $dataProviderF ]); } diff --git a/backend/modules/company/models/Company.php b/backend/modules/company/models/Company.php index b023103..fe44a2a 100755 --- a/backend/modules/company/models/Company.php +++ b/backend/modules/company/models/Company.php @@ -3,6 +3,7 @@ namespace backend\modules\company\models; use common\models\FieldsValue; +use common\models\FieldsValueNew; class Company extends \common\models\Company { @@ -12,17 +13,21 @@ class Company extends \common\models\Company { parent::init(); - $fieldValue = FieldsValue::find()->where( + $fieldValue = FieldsValueNew::find() + ->where( [ - 'company_id' => \Yii::$app->request->get('id'), - 'project_id' => null, - 'card_id' => null, + 'item_id' => \Yii::$app->request->get('id'), + 'item_type' => FieldsValueNew::TYPE_COMPANY, ]) ->all(); $array = []; if(!empty($fieldValue)){ foreach ($fieldValue as $item){ - array_push($array, ['field_id' => $item->field_id, 'value' => $item->value, 'order' => $item->order]); + array_push($array, + ['field_id' => $item->field_id, + 'value' => $item->value, + 'order' => $item->order, + 'field_name' => $item->field->name]); } $this->fields = $array; } @@ -32,6 +37,7 @@ class Company extends \common\models\Company 'field_id' => null, 'value' => null, 'order' => null, + 'field_name' => null, ], ]; } @@ -44,11 +50,12 @@ class Company extends \common\models\Company FieldsValue::deleteAll(['company_id' => $this->id]); foreach ( $post['fields'] as $item) { - $fildsValue = new FieldsValue(); + $fildsValue = new FieldsValueNew(); $fildsValue->field_id = $item['field_id']; $fildsValue->value = $item['value']; $fildsValue->order = $item['order']; - $fildsValue->company_id = $this->id; + $fildsValue->item_id = $this->id; + $fildsValue->item_type = FieldsValueNew::TYPE_COMPANY; $fildsValue->save(); } diff --git a/backend/modules/company/views/company/view.php b/backend/modules/company/views/company/view.php index 942c8d0..4ddd155 100755 --- a/backend/modules/company/views/company/view.php +++ b/backend/modules/company/views/company/view.php @@ -1,9 +1,11 @@ title = $model->name; @@ -12,6 +14,7 @@ $this->params['breadcrumbs'][] = $this->title; ?>

+ 'btn btn-primary']) ?> $model->id], ['class' => 'btn btn-primary']) ?> $model->id], [ 'class' => 'btn btn-danger', @@ -34,4 +37,17 @@ $this->params['breadcrumbs'][] = $this->title; ], ]) ?> +

Дополнительные сведения

+ $dataProviderF, + 'layout' => "{items}", + 'columns' => [ + 'field.name:text:Поле', + [ + 'attribute' => 'value', + 'label' => 'Значение' + ], + ], + ]); ?> +
diff --git a/backend/modules/settings/models/AdditionalFieldsSearch.php b/backend/modules/settings/models/AdditionalFieldsSearch.php index aa1ae40..7a08973 100755 --- a/backend/modules/settings/models/AdditionalFieldsSearch.php +++ b/backend/modules/settings/models/AdditionalFieldsSearch.php @@ -2,6 +2,7 @@ namespace backend\modules\settings\models; +use common\classes\Debug; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; @@ -62,7 +63,7 @@ class AdditionalFieldsSearch extends AdditionalFields ]); $query->andFilterWhere(['like', 'name', $this->name]); - +// Debug::dd($query->createCommand()->rawSql); return $dataProvider; } } diff --git a/backend/modules/settings/views/additional-fields/_additional.php b/backend/modules/settings/views/additional-fields/_additional.php new file mode 100644 index 0000000..c38e605 --- /dev/null +++ b/backend/modules/settings/views/additional-fields/_additional.php @@ -0,0 +1,6 @@ +use); \ No newline at end of file diff --git a/backend/modules/settings/views/additional-fields/index.php b/backend/modules/settings/views/additional-fields/index.php index 2443c2d..85fac4c 100755 --- a/backend/modules/settings/views/additional-fields/index.php +++ b/backend/modules/settings/views/additional-fields/index.php @@ -1,7 +1,9 @@ params['breadcrumbs'][] = $this->title; 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], - - 'id', 'name', + [ + 'label' => 'Доп. информация', + 'format' => 'raw', + 'value' => function ($model) { + $dataProvider = new ActiveDataProvider([ + 'query' => $model->getUseFields(), + ]); + return ListView::widget([ + 'dataProvider' => $dataProvider, + 'itemView' => '_additional', + 'layout' => "{items}", + ]); + }, + 'headerOptions' => ['width' => '300'], + ], ['class' => 'yii\grid\ActionColumn'], ], ]); ?> diff --git a/common/models/AdditionalFields.php b/common/models/AdditionalFields.php index fc5ad30..6e12c7a 100755 --- a/common/models/AdditionalFields.php +++ b/common/models/AdditionalFields.php @@ -2,6 +2,7 @@ namespace common\models; +use common\classes\Debug; use Yii; /** @@ -53,7 +54,12 @@ class AdditionalFields extends \yii\db\ActiveRecord */ public function getFieldsValues() { - return $this->hasMany(FieldsValue::className(), ['field_id' => 'id']); + return $this->hasMany(FieldsValueNew::className(), ['field_id' => 'id']); + } + + public function getObjectValue() + { + } /** diff --git a/common/models/FieldsValueNew.php b/common/models/FieldsValueNew.php index a6bf835..e382edd 100644 --- a/common/models/FieldsValueNew.php +++ b/common/models/FieldsValueNew.php @@ -63,8 +63,4 @@ class FieldsValueNew extends \yii\db\ActiveRecord return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']); } -// public function getadditional_fields() -// { -// -// } } diff --git a/common/models/UseField.php b/common/models/UseField.php index 82d1af7..5e5d35c 100755 --- a/common/models/UseField.php +++ b/common/models/UseField.php @@ -81,4 +81,13 @@ class UseField extends \yii\db\ActiveRecord { return $this->statuses[$this->status_id]; } + + /** + * @return string status text label + */ + public static function getStatusesTextById($id) + { + $model = new self(); + return $model->statuses[$id]; + } }