Blame view

backend/components/FieldEditor/FieldEditor.php 849 Bytes
0716cf79   Mihail   fixed testing iss...
1
  <?php
40acb401   Mihail   add delete price ...
2
3
  namespace backend\components\FieldEditor;
  use common\models\DetailsCriteria;
0716cf79   Mihail   fixed testing iss...
4
5
6
7
8
  use yii\base\Widget;
  
  
  class FieldEditor extends Widget
  {
40acb401   Mihail   add delete price ...
9
10
      public $name;
      public $brand;
0716cf79   Mihail   fixed testing iss...
11
12
13
14
15
16
17
18
19
20
21
22
      public $model;
      public $template;
  
      public function init(){
  
          parent::init();
  
      }
  
  
      public function run()
      {
40acb401   Mihail   add delete price ...
23
          if($this->name && $this->brand && $this->model){
0716cf79   Mihail   fixed testing iss...
24
25
              $widgetData = $this->findModel();
          } else {
40acb401   Mihail   add delete price ...
26
              $widgetData= [new DetailsCriteria()];
0716cf79   Mihail   fixed testing iss...
27
28
29
30
31
32
33
34
          }
  
  
          return $this->render($this->template.'_field',['model'=>$widgetData]);
      }
  
      protected function findModel()
      {
40acb401   Mihail   add delete price ...
35
          if (($model = DetailsCriteria::find()->where(['name'=>$this->name, 'brand'=>$this->brand])->all()) !== null) {
0716cf79   Mihail   fixed testing iss...
36
37
38
39
  
              return $model;
  
          } else {
40acb401   Mihail   add delete price ...
40
              return [new DetailsCriteria()];
0716cf79   Mihail   fixed testing iss...
41
42
43
          }
      }
  }