Commit 214521895249744d6c99302eee7a7a4382ffd1f5

Authored by Timur Kastemirov
1 parent a6795694

feedback calculator final

common/mail/calculator.php
... ... @@ -27,9 +27,21 @@
27 27 <td><b><?= \Yii::t('app', 'Email: ') ?></b></td>
28 28 <td><?= $model->email ?></td>
29 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 46 </tbody>
35 47 </table>
... ...
common/messages/ru/app.php
... ... @@ -214,4 +214,22 @@ return [
214 214 'showcase_pr_text3' => 'утвержденных компаниями энергоснабжения наших СЭС',
215 215 'showcase_pr_text4' => 'введенная в эксплуатацию коммерческая СЭС на крыше офисного здания в Киеве',
216 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 236 \ No newline at end of file
... ...
common/models/Feedback.php
1 1 <?php
  2 +
2 3 namespace common\models;
  4 +
3 5 /**
4 6 * User: timur
5 7 * Date: 31.01.18
... ... @@ -7,14 +9,12 @@
7 9 */
8 10  
9 11 use artbox\core\models\Feedback as ArtboxFeedback;
10   - use yii\helpers\VarDumper;
11 12  
12 13 /**
13 14 * Class Feedback
14 15 *
15 16 * @property string $topic
16 17 * @property string $calc_json_info
17   - *
18 18 * @package common\models
19 19 */
20 20 class Feedback extends ArtboxFeedback
... ... @@ -22,40 +22,64 @@
22 22  
23 23 const SCENARIO_CALCULATOR = 'calculator';
24 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 56 public $attributeValues = [];
32 57  
33 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 65 parent::__set($name, $value);
42 66 }
43 67 }
44 68  
45 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 74 return parent::__get($name);
52 75 }
53 76 }
54   -
55   - public function getCalculatorAttributes(){
  77 +
  78 + public function getCalculatorAttributes()
  79 + {
56 80 return $this->attributeValues;
57 81 }
58   -
  82 +
59 83 public function scenarios()
60 84 {
61 85 return array_merge(
... ... @@ -79,16 +103,17 @@
79 103 [
80 104 'name',
81 105 'phone',
  106 + 'email',
82 107 'returnUrl',
83 108 'topic',
84 109 'calc_json_info',
85 110 ],
86 111 self::calculator_attributes
87   - )
  112 + ),
88 113 ]
89 114 );
90 115 }
91   -
  116 +
92 117 public function rules()
93 118 {
94 119  
... ... @@ -113,15 +138,14 @@
113 138 'name',
114 139 'phone',
115 140 'email',
116   - 'topic',
117 141 'calc_json_info',
118 142  
119 143 'adress',
120   - 'module_install_angle'
  144 + 'module_install_angle',
121 145 ],
122 146 'required',
123 147 'on' => self::SCENARIO_CALCULATOR,
124   - ]
  148 + ],
125 149 ]
126 150 );
127 151 }
... ... @@ -131,7 +155,7 @@
131 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 160 return json_decode($this->calc_json_info);
137 161 }
... ...
frontend/controllers/SiteController.php
... ... @@ -55,21 +55,28 @@
55 55  
56 56 $slider = Slider::find()
57 57 ->with("slides.lang.image")
58   - ->where(['on_home_page'=>true])
  58 + ->where([ 'on_home_page' => true ])
59 59 ->one();
60   -
  60 +
61 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 76 return $this->render(
70 77 'index',
71 78 [
72   - 'slider' => $slider,
  79 + 'slider' => $slider,
73 80 'objects' => $objects,
74 81 ]
75 82 );
... ... @@ -161,33 +168,32 @@
161 168 throw new BadRequestHttpException();
162 169 } else {
163 170 $post = Yii::$app->request->post('Feedback');
164   - switch ($post['topic']){
  171 + switch ($post[ 'topic' ]) {
165 172 case Feedback::SCENARIO_FEEDBACK :
166   - $model = new Feedback(['scenario' => Feedback::SCENARIO_FEEDBACK]);
  173 + $model = new Feedback([ 'scenario' => Feedback::SCENARIO_FEEDBACK ]);
167 174 $view = 'feedback';
168 175 $isLoaded = $model->load(Yii::$app->request->post());
169 176 break;
170   -
  177 +
171 178 case Feedback::SCENARIO_CALLBACK :
172   - $model = new Feedback(['scenario' => Feedback::SCENARIO_CALLBACK]);
  179 + $model = new Feedback([ 'scenario' => Feedback::SCENARIO_CALLBACK ]);
173 180 $view = 'feedback';
174 181 $isLoaded = $model->load(Yii::$app->request->post());
175 182 break;
176   -
  183 +
177 184 case Feedback::SCENARIO_CALCULATOR:
178   - $model = new Feedback(['scenario' => Feedback::SCENARIO_CALCULATOR]);
  185 + $model = new Feedback([ 'scenario' => Feedback::SCENARIO_CALCULATOR ]);
179 186 $view = 'calculator';
180 187 $isLoaded = $model->load(Yii::$app->request->post());
181 188 $model->setCalcJsonInfo();
182 189 break;
183   -
  190 +
184 191 default:
185 192 $model = new Feedback();
186 193 $view = 'feedback';
187 194 $isLoaded = $model->load(Yii::$app->request->post());
188 195 }
189 196  
190   -
191 197 if ($isLoaded && $model->save()) {
192 198  
193 199 $mailer->compose(
... ... @@ -198,19 +204,19 @@
198 204 )
199 205 ->setFrom('artbox@domain.com')// ->setTo($settings->email)
200 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 212 ->setSubject(\Yii::t('app', 'Feedback'))
207 213 ->send();
208 214  
209 215 return [
210 216 'success' => true,
211 217 'message' => 'Success message',
212   - 'view' => $view,
213   - 'model' => $model->attributeValues,
  218 + 'view' => $view,
  219 + 'model' => $model->attributeValues,
214 220 'alert' => $this->renderPartial('success_alert'),
215 221 ];
216 222 } else {
... ...
frontend/views/site/index.php
... ... @@ -15,9 +15,13 @@
15 15 $settings = Settings::getInstance();
16 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 22 $js = <<< JS
19   -window.lat = {$settings->lat};
20   -window.lon = {$settings->lon};
  23 +window.lat = {$coordinates['lat']};
  24 +window.lon = {$coordinates['lon']};
21 25 JS;
22 26  
23 27 $this->registerJs($js, View::POS_END);
... ...