Feedback.php
4.95 KB
1
2
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace common\models;
/**
* User: timur
* Date: 31.01.18
* Time: 10:56
*/
use artbox\core\models\Feedback as ArtboxFeedback;
/**
* Class Feedback
*
* @property string $topic
* @property string $calc_json_info
* @package common\models
*/
class Feedback extends ArtboxFeedback
{
const SCENARIO_CALCULATOR = 'calculator';
const calculator_attributes = [
'adress',
'module_install_angle',
'latitude',
'longitude',
'south_deviation',
'power_station_type',
'area',
'power',
'budget',
'auth_day',
'auth_month',
'auth_pwr_all',
'auth_pwr_days',
];
const translate_attributes = [
'adress' => "Адрес",
'module_install_angle' => "Угол установки фотомодулей",
'latitude' => "Широта",
'longitude' => "Долгота",
'south_deviation' => "Отклонение от юга",
'power_station_type' => "Тип станции",
'area' => "Площадь",
'power' => "Мощность",
'budget' => "Бюджет",
'auth_day' => "Суточное потребление в кВт*ч",
'auth_month' => "Месячное потребление в кВт*ч",
'auth_pwr_all' => "Мощность всех потребителей потребление в кВт*ч",
'auth_pwr_days' => "Суток автономности",
];
public $attributeValues = [];
public function __set($name, $value)
{
if (in_array($name, self::calculator_attributes)) {
if (isset($value) && !empty($value)) {
$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;
}
public function scenarios()
{
return array_merge(
parent::scenarios(),
[
parent::SCENARIO_FEEDBACK => [
'name',
'email',
'phone',
'message',
'returnUrl',
'topic',
],
parent::SCENARIO_CALLBACK => [
'name',
'phone',
'message',
'returnUrl',
'topic',
],
self::SCENARIO_CALCULATOR => array_merge(
[
'name',
'phone',
'email',
'returnUrl',
'topic',
'calc_json_info',
],
self::calculator_attributes
),
]
);
}
public function rules()
{
return array_merge(
parent::rules(),
[
[
[
'topic',
],
'required',
],
[
[
'topic',
],
'string',
'max' => 100,
],
[
[
'name',
'phone',
'email',
'calc_json_info',
'adress',
'module_install_angle',
],
'required',
'on' => self::SCENARIO_CALCULATOR,
],
]
);
}
public function setCalcJsonInfo()
{
$this->calc_json_info = json_encode($this->attributeValues);
}
public function getCalcJsonInfo()
{
return json_decode($this->calc_json_info);
}
}