Blame view

common/widgets/FieldEditor.php 811 Bytes
2ff00662   Administrator   firs page
1
  <?php
4668085e   Administrator   firs page
2
  namespace common\widgets;
2ff00662   Administrator   firs page
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  use common\models\Fields;
  use yii\base\Widget;
  
  
  class FieldEditor extends Widget
  {
      public $item_id;
      public $model;
      public $template;
  
      public function init(){
  
          parent::init();
  
      }
  
  
      public function run()
      {
          if($this->item_id && $this->model){
              $widgetData = $this->findModel();
          } else {
              $widgetData= [new Fields()];
          }
  
  
          return $this->render($this->template.'_field',['model'=>$widgetData]);
      }
  
      protected function findModel()
      {
          if (($model = Fields::find()->where(['table_id'=>$this->item_id, 'table_name'=>$this->model, 'field_type'=>$this->template])->all()) !== null) {
  
              return $model;
  
          } else {
              return [new Fields()];
          }
      }
  }