Blame view

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