Blame view

common/models/Feedback.php 3.84 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
27
28
29
          const calculator_attributes = [
              'adress', 'module_install_angle', 'latitude', 'longitude',
              'south_deviation', 'power_station_type', 'area', 'power',
              'budget', 'day_consumption', 'month_consumption', 'consumptors_total_power',
              'autonomous_days'
          ];
a78f6f00   Timur Kastemirov   feedback mail
30
          
31257104   Timur Kastemirov   feedback calculator
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
          private $attributeValues = [];
          
          public function __set($name, $value)
          {
              if(in_array($name, self::calculator_attributes)){
                  $this->attributeValues[$name] = $value;
              }
              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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
          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
76
77
78
79
80
81
82
83
84
85
                      self::SCENARIO_CALCULATOR => array_merge(
                          [
                              'name',
                              'phone',
                              'returnUrl',
                              'topic',
                              'calc_json_info',
                          ],
                          self::calculator_attributes
                      )
a78f6f00   Timur Kastemirov   feedback mail
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
                  ]
              );
          }
      
          public function rules()
          {
              
              return array_merge(
                  parent::rules(),
                  [
                      [
                          [
                              'topic',
                          ],
                          'required',
                      ],
                      [
                          [
                              'topic',
                          ],
                          'string',
                          'max' => 100,
                      ],
                      [
                          [
31257104   Timur Kastemirov   feedback calculator
111
112
113
114
115
116
117
118
119
                              'name',
                              'phone',
                              'email',
                              'returnUrl',
                              'topic',
                              'calc_json_info',
                              
                              'adress',
                              'module_install_angle'
a78f6f00   Timur Kastemirov   feedback mail
120
121
122
123
124
125
126
127
                          ],
                          'required',
                          'on' => self::SCENARIO_CALCULATOR,
                      ]
                  ]
              );
          }
          
31257104   Timur Kastemirov   feedback calculator
128
129
130
131
          public function setCalcJsonInfo( array $value)
          {
              $this->calc_json_info = json_encode($value);
          }
a78f6f00   Timur Kastemirov   feedback mail
132
          
31257104   Timur Kastemirov   feedback calculator
133
134
135
136
          public function getCalcJsonInfo() : array
          {
              return json_decode($this->calc_json_info);
          }
a78f6f00   Timur Kastemirov   feedback mail
137
      }