| @@ -2,9 +2,11 @@ | |||||||
|  |  | ||||||
| namespace backend\modules\company\controllers; | namespace backend\modules\company\controllers; | ||||||
|  |  | ||||||
|  | use common\models\FieldsValueNew; | ||||||
| use Yii; | use Yii; | ||||||
| use backend\modules\company\models\Company; | use backend\modules\company\models\Company; | ||||||
| use backend\modules\company\models\CompanySearch; | use backend\modules\company\models\CompanySearch; | ||||||
|  | use yii\data\ActiveDataProvider; | ||||||
| use yii\web\Controller; | use yii\web\Controller; | ||||||
| use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||||
| use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||||
| @@ -52,8 +54,17 @@ class CompanyController extends Controller | |||||||
|      */ |      */ | ||||||
|     public function actionView($id) |     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', [ |         return $this->render('view', [ | ||||||
|             'model' => $this->findModel($id), |             'model' => $this->findModel($id), | ||||||
|  |             'dataProviderF' => $dataProviderF | ||||||
|         ]); |         ]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ | |||||||
| namespace backend\modules\company\models; | namespace backend\modules\company\models; | ||||||
|  |  | ||||||
| use common\models\FieldsValue; | use common\models\FieldsValue; | ||||||
|  | use common\models\FieldsValueNew; | ||||||
|  |  | ||||||
| class Company extends \common\models\Company | class Company extends \common\models\Company | ||||||
| { | { | ||||||
| @@ -12,17 +13,21 @@ class Company extends \common\models\Company | |||||||
|     { |     { | ||||||
|         parent::init(); |         parent::init(); | ||||||
|  |  | ||||||
|         $fieldValue = FieldsValue::find()->where( |         $fieldValue = FieldsValueNew::find() | ||||||
|  |             ->where( | ||||||
|             [ |             [ | ||||||
|                 'company_id' => \Yii::$app->request->get('id'), |                 'item_id' => \Yii::$app->request->get('id'), | ||||||
|                 'project_id' => null, |                 'item_type' => FieldsValueNew::TYPE_COMPANY, | ||||||
|                 'card_id' => null, |  | ||||||
|             ]) |             ]) | ||||||
|             ->all(); |             ->all(); | ||||||
|         $array = []; |         $array = []; | ||||||
|         if(!empty($fieldValue)){ |         if(!empty($fieldValue)){ | ||||||
|             foreach ($fieldValue as $item){ |             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; |             $this->fields = $array; | ||||||
|         } |         } | ||||||
| @@ -32,6 +37,7 @@ class Company extends \common\models\Company | |||||||
|                     'field_id'   => null, |                     'field_id'   => null, | ||||||
|                     'value'  => null, |                     'value'  => null, | ||||||
|                     'order' => null, |                     'order' => null, | ||||||
|  |                     'field_name' => null, | ||||||
|                 ], |                 ], | ||||||
|             ]; |             ]; | ||||||
|         } |         } | ||||||
| @@ -44,11 +50,12 @@ class Company extends \common\models\Company | |||||||
|         FieldsValue::deleteAll(['company_id' => $this->id]); |         FieldsValue::deleteAll(['company_id' => $this->id]); | ||||||
|  |  | ||||||
|         foreach ( $post['fields'] as $item) { |         foreach ( $post['fields'] as $item) { | ||||||
|             $fildsValue = new FieldsValue(); |             $fildsValue = new FieldsValueNew(); | ||||||
|             $fildsValue->field_id = $item['field_id']; |             $fildsValue->field_id = $item['field_id']; | ||||||
|             $fildsValue->value = $item['value']; |             $fildsValue->value = $item['value']; | ||||||
|             $fildsValue->order = $item['order']; |             $fildsValue->order = $item['order']; | ||||||
|             $fildsValue->company_id = $this->id; |             $fildsValue->item_id = $this->id; | ||||||
|  |             $fildsValue->item_type = FieldsValueNew::TYPE_COMPANY; | ||||||
|  |  | ||||||
|             $fildsValue->save(); |             $fildsValue->save(); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -1,9 +1,11 @@ | |||||||
| <?php | <?php | ||||||
|  |  | ||||||
|  | use yii\grid\GridView; | ||||||
| use yii\helpers\Html; | use yii\helpers\Html; | ||||||
| use yii\widgets\DetailView; | use yii\widgets\DetailView; | ||||||
|  |  | ||||||
| /* @var $this yii\web\View */ | /* @var $this yii\web\View */ | ||||||
|  | /* @var $dataProviderF \yii\data\ActiveDataProvider | ||||||
| /* @var $model backend\modules\company\models\Company */ | /* @var $model backend\modules\company\models\Company */ | ||||||
|  |  | ||||||
| $this->title = $model->name; | $this->title = $model->name; | ||||||
| @@ -12,6 +14,7 @@ $this->params['breadcrumbs'][] = $this->title; | |||||||
| ?> | ?> | ||||||
| <div class="company-view"> | <div class="company-view"> | ||||||
|     <p> |     <p> | ||||||
|  |         <?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?> | ||||||
|         <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> |         <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | ||||||
|         <?= Html::a('Delete', ['delete', 'id' => $model->id], [ |         <?= Html::a('Delete', ['delete', 'id' => $model->id], [ | ||||||
|             'class' => 'btn btn-danger', |             'class' => 'btn btn-danger', | ||||||
| @@ -34,4 +37,17 @@ $this->params['breadcrumbs'][] = $this->title; | |||||||
|         ], |         ], | ||||||
|     ]) ?> |     ]) ?> | ||||||
|  |  | ||||||
|  |     <h2>Дополнительные сведения</h2> | ||||||
|  |     <?= GridView::widget([ | ||||||
|  |         'dataProvider' => $dataProviderF, | ||||||
|  |         'layout' => "{items}", | ||||||
|  |         'columns' => [ | ||||||
|  |             'field.name:text:Поле', | ||||||
|  |             [ | ||||||
|  |                 'attribute' => 'value', | ||||||
|  |                 'label' => 'Значение' | ||||||
|  |             ], | ||||||
|  |         ], | ||||||
|  |     ]); ?> | ||||||
|  |  | ||||||
| </div> | </div> | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ | |||||||
|  |  | ||||||
| namespace backend\modules\settings\models; | namespace backend\modules\settings\models; | ||||||
|  |  | ||||||
|  | use common\classes\Debug; | ||||||
| use Yii; | use Yii; | ||||||
| use yii\base\Model; | use yii\base\Model; | ||||||
| use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||||
| @@ -62,7 +63,7 @@ class AdditionalFieldsSearch extends AdditionalFields | |||||||
|         ]); |         ]); | ||||||
|  |  | ||||||
|         $query->andFilterWhere(['like', 'name', $this->name]); |         $query->andFilterWhere(['like', 'name', $this->name]); | ||||||
|  | //        Debug::dd($query->createCommand()->rawSql); | ||||||
|         return $dataProvider; |         return $dataProvider; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -0,0 +1,6 @@ | |||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * @var $model \yii\db\ActiveRecord | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | echo \common\models\UseField::getStatusesTextById($model->use); | ||||||
| @@ -1,7 +1,9 @@ | |||||||
| <?php | <?php | ||||||
|  |  | ||||||
|  | use yii\data\ActiveDataProvider; | ||||||
| use yii\helpers\Html; | use yii\helpers\Html; | ||||||
| use yii\grid\GridView; | use yii\grid\GridView; | ||||||
|  | use yii\widgets\ListView; | ||||||
|  |  | ||||||
| /* @var $this yii\web\View */ | /* @var $this yii\web\View */ | ||||||
| /* @var $searchModel backend\modules\card\models\AdditionalFieldsSearch */ | /* @var $searchModel backend\modules\card\models\AdditionalFieldsSearch */ | ||||||
| @@ -23,10 +25,23 @@ $this->params['breadcrumbs'][] = $this->title; | |||||||
|         'filterModel' => $searchModel, |         'filterModel' => $searchModel, | ||||||
|         'columns' => [ |         'columns' => [ | ||||||
|             ['class' => 'yii\grid\SerialColumn'], |             ['class' => 'yii\grid\SerialColumn'], | ||||||
|  |  | ||||||
|             'id', |  | ||||||
|             'name', |             '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'], |             ['class' => 'yii\grid\ActionColumn'], | ||||||
|         ], |         ], | ||||||
|     ]); ?> |     ]); ?> | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ | |||||||
|  |  | ||||||
| namespace common\models; | namespace common\models; | ||||||
|  |  | ||||||
|  | use common\classes\Debug; | ||||||
| use Yii; | use Yii; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -53,7 +54,12 @@ class AdditionalFields extends \yii\db\ActiveRecord | |||||||
|      */ |      */ | ||||||
|     public function getFieldsValues() |     public function getFieldsValues() | ||||||
|     { |     { | ||||||
|         return $this->hasMany(FieldsValue::className(), ['field_id' => 'id']); |         return $this->hasMany(FieldsValueNew::className(), ['field_id' => 'id']); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function getObjectValue() | ||||||
|  |     { | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -63,8 +63,4 @@ class FieldsValueNew extends \yii\db\ActiveRecord | |||||||
|         return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']); |         return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| //    public function getadditional_fields() |  | ||||||
| //    { |  | ||||||
| // |  | ||||||
| //    } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -81,4 +81,13 @@ class UseField extends \yii\db\ActiveRecord | |||||||
|     { |     { | ||||||
|         return $this->statuses[$this->status_id]; |         return $this->statuses[$this->status_id]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @return string status text label | ||||||
|  |      */ | ||||||
|  |     public static function getStatusesTextById($id) | ||||||
|  |     { | ||||||
|  |         $model = new self(); | ||||||
|  |         return $model->statuses[$id]; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 GitHub
						GitHub