Commit 214521895249744d6c99302eee7a7a4382ffd1f5

Authored by Timur Kastemirov
1 parent a6795694

feedback calculator final

common/mail/calculator.php
@@ -27,9 +27,21 @@ @@ -27,9 +27,21 @@
27 <td><b><?= \Yii::t('app', 'Email: ') ?></b></td> 27 <td><b><?= \Yii::t('app', 'Email: ') ?></b></td>
28 <td><?= $model->email ?></td> 28 <td><?= $model->email ?></td>
29 </tr> 29 </tr>
30 - <tr>  
31 - <td><b><?= \Yii::t('app', 'JSON string: ') ?></b></td>  
32 - <td><?= $model->calc_json_info ?></td>  
33 - </tr> 30 + <?php
  31 +
  32 + foreach ($model->getCalcJsonInfo() as $attr => $value) {
  33 +
  34 + ?>
  35 +
  36 + <tr>
  37 + <td><b><?= \Yii::t('app', $attr) ?></b></td>
  38 + <td><?= $value ?></td>
  39 + </tr>
  40 +
  41 + <?php
  42 +
  43 + }
  44 +
  45 + ?>
34 </tbody> 46 </tbody>
35 </table> 47 </table>
common/messages/ru/app.php
@@ -214,4 +214,22 @@ return [ @@ -214,4 +214,22 @@ return [
214 'showcase_pr_text3' => 'утвержденных компаниями энергоснабжения наших СЭС', 214 'showcase_pr_text3' => 'утвержденных компаниями энергоснабжения наших СЭС',
215 'showcase_pr_text4' => 'введенная в эксплуатацию коммерческая СЭС на крыше офисного здания в Киеве', 215 'showcase_pr_text4' => 'введенная в эксплуатацию коммерческая СЭС на крыше офисного здания в Киеве',
216 'firsts' => '-ая', 216 'firsts' => '-ая',
  217 +
  218 + // для отсылки на эмэйл
  219 +
  220 + 'adress' => "Адрес",
  221 + 'module_install_angle' => "Угол установки фотомодулей",
  222 + 'latitude' => "Широта",
  223 + 'longitude' => "Долгота",
  224 + 'power_station_type' => "Тип станции",
  225 + 'area' => "Площадь",
  226 + 'power' => "Мощность",
  227 + 'budget' => "Бюджет",
  228 + 'auth_day' => "Суточное потребление в кВт*ч",
  229 + 'auth_month' => "Месячное потребление в кВт*ч",
  230 + 'auth_pwr_all' => "Мощность всех потребителей потребление в кВт*ч",
  231 + 'auth_pwr_days' => "Суток автономности",
  232 +
  233 + // для отсылки на эмэйл
  234 +
217 ]; 235 ];
218 \ No newline at end of file 236 \ No newline at end of file
common/models/Feedback.php
1 <?php 1 <?php
  2 +
2 namespace common\models; 3 namespace common\models;
  4 +
3 /** 5 /**
4 * User: timur 6 * User: timur
5 * Date: 31.01.18 7 * Date: 31.01.18
@@ -7,14 +9,12 @@ @@ -7,14 +9,12 @@
7 */ 9 */
8 10
9 use artbox\core\models\Feedback as ArtboxFeedback; 11 use artbox\core\models\Feedback as ArtboxFeedback;
10 - use yii\helpers\VarDumper;  
11 12
12 /** 13 /**
13 * Class Feedback 14 * Class Feedback
14 * 15 *
15 * @property string $topic 16 * @property string $topic
16 * @property string $calc_json_info 17 * @property string $calc_json_info
17 - *  
18 * @package common\models 18 * @package common\models
19 */ 19 */
20 class Feedback extends ArtboxFeedback 20 class Feedback extends ArtboxFeedback
@@ -22,40 +22,64 @@ @@ -22,40 +22,64 @@
22 22
23 const SCENARIO_CALCULATOR = 'calculator'; 23 const SCENARIO_CALCULATOR = 'calculator';
24 const calculator_attributes = [ 24 const calculator_attributes = [
25 - 'adress', 'module_install_angle', 'latitude', 'longitude',  
26 - 'south_deviation', 'power_station_type', 'area', 'power',  
27 - 'budget', 'auth_day', 'auth_month', 'auth_pwr_all',  
28 - 'auth_pwr_days' 25 + 'adress',
  26 + 'module_install_angle',
  27 + 'latitude',
  28 + 'longitude',
  29 + 'south_deviation',
  30 + 'power_station_type',
  31 + 'area',
  32 + 'power',
  33 + 'budget',
  34 + 'auth_day',
  35 + 'auth_month',
  36 + 'auth_pwr_all',
  37 + 'auth_pwr_days',
29 ]; 38 ];
30 - 39 +
  40 + const translate_attributes = [
  41 + 'adress' => "Адрес",
  42 + 'module_install_angle' => "Угол установки фотомодулей",
  43 + 'latitude' => "Широта",
  44 + 'longitude' => "Долгота",
  45 + 'south_deviation' => "Отклонение от юга",
  46 + 'power_station_type' => "Тип станции",
  47 + 'area' => "Площадь",
  48 + 'power' => "Мощность",
  49 + 'budget' => "Бюджет",
  50 + 'auth_day' => "Суточное потребление в кВт*ч",
  51 + 'auth_month' => "Месячное потребление в кВт*ч",
  52 + 'auth_pwr_all' => "Мощность всех потребителей потребление в кВт*ч",
  53 + 'auth_pwr_days' => "Суток автономности",
  54 + ];
  55 +
31 public $attributeValues = []; 56 public $attributeValues = [];
32 57
33 public function __set($name, $value) 58 public function __set($name, $value)
34 { 59 {
35 - if(in_array($name, self::calculator_attributes)){  
36 - if(isset($value) && !empty($value)){  
37 - $this->attributeValues[$name] = $value; 60 + if (in_array($name, self::calculator_attributes)) {
  61 + if (isset($value) && !empty($value)) {
  62 + $this->attributeValues[ $name ] = $value;
38 } 63 }
39 - }  
40 - else{ 64 + } else {
41 parent::__set($name, $value); 65 parent::__set($name, $value);
42 } 66 }
43 } 67 }
44 68
45 public function __get($name) 69 public function __get($name)
46 { 70 {
47 - if(in_array($name, self::calculator_attributes)){  
48 - return $this->attributeValues[$name]??'';  
49 - }  
50 - else{ 71 + if (in_array($name, self::calculator_attributes)) {
  72 + return $this->attributeValues[ $name ]??'';
  73 + } else {
51 return parent::__get($name); 74 return parent::__get($name);
52 } 75 }
53 } 76 }
54 -  
55 - public function getCalculatorAttributes(){ 77 +
  78 + public function getCalculatorAttributes()
  79 + {
56 return $this->attributeValues; 80 return $this->attributeValues;
57 } 81 }
58 - 82 +
59 public function scenarios() 83 public function scenarios()
60 { 84 {
61 return array_merge( 85 return array_merge(
@@ -79,16 +103,17 @@ @@ -79,16 +103,17 @@
79 [ 103 [
80 'name', 104 'name',
81 'phone', 105 'phone',
  106 + 'email',
82 'returnUrl', 107 'returnUrl',
83 'topic', 108 'topic',
84 'calc_json_info', 109 'calc_json_info',
85 ], 110 ],
86 self::calculator_attributes 111 self::calculator_attributes
87 - ) 112 + ),
88 ] 113 ]
89 ); 114 );
90 } 115 }
91 - 116 +
92 public function rules() 117 public function rules()
93 { 118 {
94 119
@@ -113,15 +138,14 @@ @@ -113,15 +138,14 @@
113 'name', 138 'name',
114 'phone', 139 'phone',
115 'email', 140 'email',
116 - 'topic',  
117 'calc_json_info', 141 'calc_json_info',
118 142
119 'adress', 143 'adress',
120 - 'module_install_angle' 144 + 'module_install_angle',
121 ], 145 ],
122 'required', 146 'required',
123 'on' => self::SCENARIO_CALCULATOR, 147 'on' => self::SCENARIO_CALCULATOR,
124 - ] 148 + ],
125 ] 149 ]
126 ); 150 );
127 } 151 }
@@ -131,7 +155,7 @@ @@ -131,7 +155,7 @@
131 $this->calc_json_info = json_encode($this->attributeValues); 155 $this->calc_json_info = json_encode($this->attributeValues);
132 } 156 }
133 157
134 - public function getCalcJsonInfo() : array 158 + public function getCalcJsonInfo()
135 { 159 {
136 return json_decode($this->calc_json_info); 160 return json_decode($this->calc_json_info);
137 } 161 }
frontend/controllers/SiteController.php
@@ -55,21 +55,28 @@ @@ -55,21 +55,28 @@
55 55
56 $slider = Slider::find() 56 $slider = Slider::find()
57 ->with("slides.lang.image") 57 ->with("slides.lang.image")
58 - ->where(['on_home_page'=>true]) 58 + ->where([ 'on_home_page' => true ])
59 ->one(); 59 ->one();
60 - 60 +
61 $objects = Objectkb::find() 61 $objects = Objectkb::find()
62 - ->with('lang.alias')  
63 - ->where([  
64 - 'id' => array(7,37,38,39)  
65 - ])  
66 - ->orderBy('id')  
67 - ->all();  
68 - 62 + ->with('lang.alias')
  63 + ->where(
  64 + [
  65 + 'id' => [
  66 + 7,
  67 + 37,
  68 + 38,
  69 + 39,
  70 + ],
  71 + ]
  72 + )
  73 + ->orderBy('id')
  74 + ->all();
  75 +
69 return $this->render( 76 return $this->render(
70 'index', 77 'index',
71 [ 78 [
72 - 'slider' => $slider, 79 + 'slider' => $slider,
73 'objects' => $objects, 80 'objects' => $objects,
74 ] 81 ]
75 ); 82 );
@@ -161,33 +168,32 @@ @@ -161,33 +168,32 @@
161 throw new BadRequestHttpException(); 168 throw new BadRequestHttpException();
162 } else { 169 } else {
163 $post = Yii::$app->request->post('Feedback'); 170 $post = Yii::$app->request->post('Feedback');
164 - switch ($post['topic']){ 171 + switch ($post[ 'topic' ]) {
165 case Feedback::SCENARIO_FEEDBACK : 172 case Feedback::SCENARIO_FEEDBACK :
166 - $model = new Feedback(['scenario' => Feedback::SCENARIO_FEEDBACK]); 173 + $model = new Feedback([ 'scenario' => Feedback::SCENARIO_FEEDBACK ]);
167 $view = 'feedback'; 174 $view = 'feedback';
168 $isLoaded = $model->load(Yii::$app->request->post()); 175 $isLoaded = $model->load(Yii::$app->request->post());
169 break; 176 break;
170 - 177 +
171 case Feedback::SCENARIO_CALLBACK : 178 case Feedback::SCENARIO_CALLBACK :
172 - $model = new Feedback(['scenario' => Feedback::SCENARIO_CALLBACK]); 179 + $model = new Feedback([ 'scenario' => Feedback::SCENARIO_CALLBACK ]);
173 $view = 'feedback'; 180 $view = 'feedback';
174 $isLoaded = $model->load(Yii::$app->request->post()); 181 $isLoaded = $model->load(Yii::$app->request->post());
175 break; 182 break;
176 - 183 +
177 case Feedback::SCENARIO_CALCULATOR: 184 case Feedback::SCENARIO_CALCULATOR:
178 - $model = new Feedback(['scenario' => Feedback::SCENARIO_CALCULATOR]); 185 + $model = new Feedback([ 'scenario' => Feedback::SCENARIO_CALCULATOR ]);
179 $view = 'calculator'; 186 $view = 'calculator';
180 $isLoaded = $model->load(Yii::$app->request->post()); 187 $isLoaded = $model->load(Yii::$app->request->post());
181 $model->setCalcJsonInfo(); 188 $model->setCalcJsonInfo();
182 break; 189 break;
183 - 190 +
184 default: 191 default:
185 $model = new Feedback(); 192 $model = new Feedback();
186 $view = 'feedback'; 193 $view = 'feedback';
187 $isLoaded = $model->load(Yii::$app->request->post()); 194 $isLoaded = $model->load(Yii::$app->request->post());
188 } 195 }
189 196
190 -  
191 if ($isLoaded && $model->save()) { 197 if ($isLoaded && $model->save()) {
192 198
193 $mailer->compose( 199 $mailer->compose(
@@ -198,19 +204,19 @@ @@ -198,19 +204,19 @@
198 ) 204 )
199 ->setFrom('artbox@domain.com')// ->setTo($settings->email) 205 ->setFrom('artbox@domain.com')// ->setTo($settings->email)
200 ->setTo( 206 ->setTo(
201 - [  
202 - 'tamerlan8.05.92@gmail.com',  
203 - 'mpav@artweb.ua',  
204 - ]  
205 - ) 207 + [
  208 + 'tamerlan8.05.92@gmail.com',
  209 + 'mpav@artweb.ua',
  210 + ]
  211 + )
206 ->setSubject(\Yii::t('app', 'Feedback')) 212 ->setSubject(\Yii::t('app', 'Feedback'))
207 ->send(); 213 ->send();
208 214
209 return [ 215 return [
210 'success' => true, 216 'success' => true,
211 'message' => 'Success message', 217 'message' => 'Success message',
212 - 'view' => $view,  
213 - 'model' => $model->attributeValues, 218 + 'view' => $view,
  219 + 'model' => $model->attributeValues,
214 'alert' => $this->renderPartial('success_alert'), 220 'alert' => $this->renderPartial('success_alert'),
215 ]; 221 ];
216 } else { 222 } else {
frontend/views/site/index.php
@@ -15,9 +15,13 @@ @@ -15,9 +15,13 @@
15 $settings = Settings::getInstance(); 15 $settings = Settings::getInstance();
16 $this->title = 'KB Energy'; 16 $this->title = 'KB Energy';
17 17
  18 + $coordinates = [];
  19 + $coordinates['lat'] = empty($settings->lat) ? 0 : $settings->lat;
  20 + $coordinates['lon'] = empty($settings->lon) ? 0 : $settings->lon;
  21 +
18 $js = <<< JS 22 $js = <<< JS
19 -window.lat = {$settings->lat};  
20 -window.lon = {$settings->lon}; 23 +window.lat = {$coordinates['lat']};
  24 +window.lon = {$coordinates['lon']};
21 JS; 25 JS;
22 26
23 $this->registerJs($js, View::POS_END); 27 $this->registerJs($js, View::POS_END);