Blame view

common/models/Feedback.php 3.85 KB
a78f6f00   Timur Kastemirov   feedback mail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  <?php
      namespace common\models;
      /**
       * User: timur
       * Date: 31.01.18
       * Time: 10:56
       */
      
      use artbox\core\models\Feedback as ArtboxFeedback;
      use yii\helpers\VarDumper;
  
      /**
       * Class Feedback
       *
       * @property string $topic
31257104   Timur Kastemirov   feedback calculator
16
       * @property string $calc_json_info
a78f6f00   Timur Kastemirov   feedback mail
17
18
19
20
21
22
23
       *
       * @package common\models
       */
      class Feedback extends ArtboxFeedback
      {
          
          const SCENARIO_CALCULATOR = 'calculator';
31257104   Timur Kastemirov   feedback calculator
24
25
26
          const calculator_attributes = [
              'adress', 'module_install_angle', 'latitude', 'longitude',
              'south_deviation', 'power_station_type', 'area', 'power',
a6795694   Timur Kastemirov   feedback calculat...
27
28
              'budget', 'auth_day', 'auth_month', 'auth_pwr_all',
              'auth_pwr_days'
31257104   Timur Kastemirov   feedback calculator
29
          ];
a6795694   Timur Kastemirov   feedback calculat...
30
31
      
          public $attributeValues = [];
31257104   Timur Kastemirov   feedback calculator
32
33
34
35
          
          public function __set($name, $value)
          {
              if(in_array($name, self::calculator_attributes)){
a6795694   Timur Kastemirov   feedback calculat...
36
37
38
                  if(isset($value) && !empty($value)){
                      $this->attributeValues[$name] = $value;
                  }
31257104   Timur Kastemirov   feedback calculator
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
              }
              else{
                  parent::__set($name, $value);
              }
          }
          
          public function __get($name)
          {
              if(in_array($name, self::calculator_attributes)){
                  return $this->attributeValues[$name]??'';
              }
              else{
                  return parent::__get($name);
              }
          }
      
          public function getCalculatorAttributes(){
              return $this->attributeValues;
          }
      
a78f6f00   Timur Kastemirov   feedback mail
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
          public function scenarios()
          {
              return array_merge(
                  parent::scenarios(),
                  [
                      parent::SCENARIO_FEEDBACK => [
                          'name',
                          'email',
                          'message',
                          'returnUrl',
                          'topic',
                      ],
                      parent::SCENARIO_CALLBACK => [
                          'name',
                          'phone',
                          'message',
                          'returnUrl',
                          'topic',
                      ],
31257104   Timur Kastemirov   feedback calculator
78
79
80
81
82
83
84
85
86
87
                      self::SCENARIO_CALCULATOR => array_merge(
                          [
                              'name',
                              'phone',
                              'returnUrl',
                              'topic',
                              'calc_json_info',
                          ],
                          self::calculator_attributes
                      )
a78f6f00   Timur Kastemirov   feedback mail
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
                  ]
              );
          }
      
          public function rules()
          {
              
              return array_merge(
                  parent::rules(),
                  [
                      [
                          [
                              'topic',
                          ],
                          'required',
                      ],
                      [
                          [
                              'topic',
                          ],
                          'string',
                          'max' => 100,
                      ],
                      [
                          [
31257104   Timur Kastemirov   feedback calculator
113
114
115
                              'name',
                              'phone',
                              'email',
31257104   Timur Kastemirov   feedback calculator
116
117
118
119
120
                              'topic',
                              'calc_json_info',
                              
                              'adress',
                              'module_install_angle'
a78f6f00   Timur Kastemirov   feedback mail
121
122
123
124
125
126
127
128
                          ],
                          'required',
                          'on' => self::SCENARIO_CALCULATOR,
                      ]
                  ]
              );
          }
          
a6795694   Timur Kastemirov   feedback calculat...
129
          public function setCalcJsonInfo()
31257104   Timur Kastemirov   feedback calculator
130
          {
a6795694   Timur Kastemirov   feedback calculat...
131
              $this->calc_json_info = json_encode($this->attributeValues);
31257104   Timur Kastemirov   feedback calculator
132
          }
a78f6f00   Timur Kastemirov   feedback mail
133
          
31257104   Timur Kastemirov   feedback calculator
134
135
136
137
          public function getCalcJsonInfo() : array
          {
              return json_decode($this->calc_json_info);
          }
a78f6f00   Timur Kastemirov   feedback mail
138
      }