Commit fce22ac2e5793b0b57b83b34607d38579450cf7c
1 parent
4d688be7
- visits
Showing
11 changed files
with
548 additions
and
29 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | + namespace backend\controllers; | |
4 | + | |
5 | + use artbox\core\admin\actions\Delete; | |
6 | + use artbox\core\admin\actions\Index; | |
7 | + use artbox\core\admin\actions\View; | |
8 | + use artbox\core\admin\interfaces\ControllerInterface; | |
9 | + use artbox\core\admin\widgets\Form; | |
10 | + use common\models\Feedback; | |
11 | + use common\models\Visit; | |
12 | + use yii\filters\AccessControl; | |
13 | + use yii\filters\VerbFilter; | |
14 | + use yii\web\Controller; | |
15 | + use yii\web\NotFoundHttpException; | |
16 | + | |
17 | + /** | |
18 | + * FeedbackController implements the CRUD actions for Feedback model. | |
19 | + */ | |
20 | + class VisitController extends Controller implements ControllerInterface | |
21 | + { | |
22 | + public function behaviors() | |
23 | + { | |
24 | + return [ | |
25 | + 'verbs' => [ | |
26 | + 'class' => VerbFilter::className(), | |
27 | + 'actions' => [ | |
28 | + 'delete' => [ 'POST' ], | |
29 | + ], | |
30 | + ], | |
31 | + 'access' => [ | |
32 | + 'class' => AccessControl::className(), | |
33 | + 'rules' => [ | |
34 | + [ | |
35 | + 'allow' => true, | |
36 | + 'roles' => [ '@' ], | |
37 | + ], | |
38 | + ], | |
39 | + ], | |
40 | + ]; | |
41 | + } | |
42 | + public function actions() | |
43 | + { | |
44 | + return [ | |
45 | + 'index' => [ | |
46 | + 'class' => Index::className(), | |
47 | + 'columns' => [ | |
48 | + 'name' => [ | |
49 | + 'type' => Index::ACTION_COL, | |
50 | + ], | |
51 | + 'email' => [ | |
52 | + 'type' => Index::STRING_COL | |
53 | + ], | |
54 | + 'phone' => [ | |
55 | + 'type' => Index::STRING_COL | |
56 | + ], | |
57 | + 'status' => [ | |
58 | + 'type' => Index::STATUS_COL, | |
59 | + ], | |
60 | + 'created_at' => [ | |
61 | + 'type' => Index::DATETIME_COL, | |
62 | + ] | |
63 | + ], | |
64 | + 'model' => Visit::className(), | |
65 | + 'hasLanguage' => false, | |
66 | + 'enableMassDelete' => true, | |
67 | + 'modelPrimaryKey' => 'id', | |
68 | + 'defaultSort' => [ | |
69 | + 'created_at' => 'DESC', | |
70 | + ], | |
71 | + 'create' => false, | |
72 | + ], | |
73 | + 'view' => [ | |
74 | + 'class' => View::className(), | |
75 | + 'model' => Visit::className(), | |
76 | + 'hasAlias' => false, | |
77 | + 'hasGallery' => false, | |
78 | + | |
79 | + 'languageFields' => [ | |
80 | + ], | |
81 | + 'fields' => [ | |
82 | + [ | |
83 | + 'name' => 'name', | |
84 | + 'type' => Form::STRING, | |
85 | + ], | |
86 | + [ | |
87 | + 'name' => 'email', | |
88 | + 'type' => Form::STRING, | |
89 | + ], | |
90 | + [ | |
91 | + 'name' => 'phone', | |
92 | + 'type' => Form::STRING, | |
93 | + ], | |
94 | + [ | |
95 | + 'name' => 'message', | |
96 | + 'type' => Form::TEXTAREA, | |
97 | + ], | |
98 | + [ | |
99 | + 'name' => 'created_at', | |
100 | + 'type' => Form::STRING, | |
101 | + ], | |
102 | + | |
103 | + ], | |
104 | + ], | |
105 | + 'delete' => [ | |
106 | + 'class' => Delete::className(), | |
107 | + ], | |
108 | + ]; | |
109 | + } | |
110 | + public function actionUpdate($id) | |
111 | + { | |
112 | + $model = $this->findModel($id); | |
113 | + | |
114 | + $model->status = true; | |
115 | + $model->save(false, [ 'status' ]); | |
116 | + | |
117 | + if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |
118 | + return $this->redirect('index'); | |
119 | + } else { | |
120 | + return $this->render( | |
121 | + 'update', | |
122 | + [ | |
123 | + 'model' => $model, | |
124 | + ] | |
125 | + ); | |
126 | + } | |
127 | + } | |
128 | + public function findModel($id) | |
129 | + { | |
130 | + $model = Visit::find() | |
131 | + ->where([ 'id' => $id ]) | |
132 | + ->one(); | |
133 | + if ($model !== null) { | |
134 | + return $model; | |
135 | + } else { | |
136 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
137 | + } | |
138 | + } | |
139 | + | |
140 | + public function newModel() | |
141 | + { | |
142 | + return new Visit(); | |
143 | + } | |
144 | + | |
145 | + public function deleteModel($id) | |
146 | + { | |
147 | + $category = Visit::find() | |
148 | + ->where( | |
149 | + [ | |
150 | + 'id' => $id, | |
151 | + ] | |
152 | + ) | |
153 | + ->one(); | |
154 | + | |
155 | + return $category->delete(); | |
156 | + } | |
157 | + | |
158 | + protected static function fieldsConfig() | |
159 | + { | |
160 | + return [ | |
161 | + 'model' => Visit::className(), | |
162 | + 'hasAlias' => false, | |
163 | + 'hasGallery' => false, | |
164 | + 'languageFields' => [ | |
165 | + ], | |
166 | + [ | |
167 | + 'name' => 'name', | |
168 | + 'type' => Form::STRING, | |
169 | + ], | |
170 | + [ | |
171 | + 'name' => 'email', | |
172 | + 'type' => Form::STRING, | |
173 | + ], | |
174 | + [ | |
175 | + 'name' => 'phone', | |
176 | + 'type' => Form::STRING, | |
177 | + ], | |
178 | + [ | |
179 | + 'name' => 'message', | |
180 | + 'type' => Form::TEXTAREA, | |
181 | + ], | |
182 | + [ | |
183 | + 'name' => 'updated_at', | |
184 | + 'type' => Form::STRING, | |
185 | + ], | |
186 | + ]; | |
187 | + } | |
188 | + | |
189 | + | |
190 | + } | ... | ... |
backend/views/layouts/menu_items.php
1 | +<?php | |
2 | + | |
3 | + use yii\helpers\Html; | |
4 | + use yii\widgets\ActiveForm; | |
5 | + | |
6 | + /* @var $this yii\web\View */ | |
7 | + /* @var $model \common\models\Visit */ | |
8 | + /* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="feedback-form"> | |
12 | + | |
13 | + <?php $form = ActiveForm::begin(); ?> | |
14 | + | |
15 | + <?= $form->field($model, 'name') | |
16 | + ->textInput([ 'maxlength' => true ]) ?> | |
17 | + | |
18 | + <?= $form->field($model, 'email') | |
19 | + ->textInput([ 'maxlength' => true ]) ?> | |
20 | + | |
21 | + <?= $form->field($model, 'phone') | |
22 | + ->textInput([ 'maxlength' => true ]) ?> | |
23 | + | |
24 | + <?= $form->field($model, 'message') | |
25 | + ->textarea([ 'rows' => 6 ]) ?> | |
26 | + | |
27 | + <?= $form->field($model, 'status') | |
28 | + ->checkbox( | |
29 | + [ | |
30 | + 'class' => 'flat', | |
31 | + ] | |
32 | + ) ?> | |
33 | + <?php | |
34 | + if ($model->entity !== null){ | |
35 | + $entity = call_user_func(array($model->entity, 'find'))->where(['id' => $model->entity_id])->one(); | |
36 | + echo ("<p>".$entity->title."</p>"); | |
37 | + } | |
38 | + ?> | |
39 | + <div class="form-group"> | |
40 | + <?= Html::submitButton( | |
41 | + $model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), | |
42 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
43 | + ) ?> | |
44 | + </div> | |
45 | + | |
46 | + <?php ActiveForm::end(); ?> | |
47 | + | |
48 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | + use yiister\gentelella\widgets\Panel; | |
4 | + | |
5 | + /* @var $this yii\web\View */ | |
6 | + /* @var $model \common\models\Visit */ | |
7 | + | |
8 | + $this->title = Yii::t( | |
9 | + 'core', | |
10 | + 'Update {modelClass}: ', | |
11 | + [ | |
12 | + 'modelClass' => 'Visit', | |
13 | + ] | |
14 | + ) . $model->name; | |
15 | + $this->params[ 'breadcrumbs' ][] = [ | |
16 | + 'label' => Yii::t('core', 'Visits'), | |
17 | + 'url' => [ 'index' ], | |
18 | + ]; | |
19 | + $this->params[ 'breadcrumbs' ][] = [ | |
20 | + 'label' => $model->name, | |
21 | + 'url' => [ | |
22 | + 'view', | |
23 | + 'id' => $model->id, | |
24 | + ], | |
25 | + ]; | |
26 | + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); | |
27 | +?> | |
28 | + | |
29 | +<?php $panel = Panel::begin( | |
30 | + [ | |
31 | + 'header' => $this->title, | |
32 | + 'options' => [ | |
33 | + 'class' => 'x_panel feedback-update', | |
34 | + ], | |
35 | + ] | |
36 | +) ?> | |
37 | + | |
38 | +<?= $this->render( | |
39 | + '_form', | |
40 | + [ | |
41 | + 'model' => $model, | |
42 | + ] | |
43 | +) ?> | |
44 | + | |
45 | +<?php $panel::end(); ?> | ... | ... |
common/config/main.php
1 | +<?php | |
2 | + | |
3 | + namespace common\models; | |
4 | + | |
5 | + use Yii; | |
6 | + use yii\behaviors\TimestampBehavior; | |
7 | + | |
8 | + /** | |
9 | + * This is the model class for table "visit". | |
10 | + * | |
11 | + * @property int $id | |
12 | + * @property string $name | |
13 | + * @property string $phone | |
14 | + * @property string $message | |
15 | + * @property string $entity | |
16 | + * @property int $entity_id | |
17 | + */ | |
18 | + class Visit extends \yii\db\ActiveRecord | |
19 | + { | |
20 | + /** | |
21 | + * @inheritdoc | |
22 | + */ | |
23 | + public function behaviors() | |
24 | + { | |
25 | + return [ | |
26 | + [ | |
27 | + 'class' => TimestampBehavior::className(), | |
28 | + 'updatedAtAttribute' => false, | |
29 | + ], | |
30 | + ]; | |
31 | + } | |
32 | + /** | |
33 | + * {@inheritdoc} | |
34 | + */ | |
35 | + public static function tableName() | |
36 | + { | |
37 | + return 'visit'; | |
38 | + } | |
39 | + | |
40 | + /** | |
41 | + * {@inheritdoc} | |
42 | + */ | |
43 | + public function rules() | |
44 | + { | |
45 | + return [ | |
46 | + [ | |
47 | + [ | |
48 | + 'phone' | |
49 | + ], | |
50 | + 'required' | |
51 | + ], | |
52 | + [ | |
53 | + [ | |
54 | + 'status' | |
55 | + ], | |
56 | + 'boolean' | |
57 | + ], | |
58 | + [ | |
59 | + [ | |
60 | + 'email' | |
61 | + ], | |
62 | + 'email' | |
63 | + ], | |
64 | + [ | |
65 | + [ 'message' ], | |
66 | + 'string', | |
67 | + ], | |
68 | + [ | |
69 | + [ 'entity_id' ], | |
70 | + 'default', | |
71 | + 'value' => null, | |
72 | + ], | |
73 | + [ | |
74 | + [ 'entity_id', 'created_at' ], | |
75 | + 'integer', | |
76 | + ], | |
77 | + [ | |
78 | + [ | |
79 | + 'name', | |
80 | + 'phone', | |
81 | + 'entity', | |
82 | + 'email' | |
83 | + ], | |
84 | + 'string', | |
85 | + 'max' => 255, | |
86 | + ], | |
87 | + ]; | |
88 | + } | |
89 | + | |
90 | + /** | |
91 | + * {@inheritdoc} | |
92 | + */ | |
93 | + public function attributeLabels() | |
94 | + { | |
95 | + return [ | |
96 | + 'id' => Yii::t('app', 'ID'), | |
97 | + 'name' => Yii::t('app', 'Name'), | |
98 | + 'phone' => Yii::t('app', 'Phone'), | |
99 | + 'message' => Yii::t('app', 'Message'), | |
100 | + 'entity' => Yii::t('app', 'Entity'), | |
101 | + 'entity_id' => Yii::t('app', 'Entity ID'), | |
102 | + 'email' => Yii::t('app', 'Email'), | |
103 | + ]; | |
104 | + } | |
105 | + | |
106 | + public function getEntity(){ | |
107 | + if ($this->entity !== null){ | |
108 | + return $this->hasOne($this->entity, ['id' => 'entity_id']); | |
109 | + } | |
110 | + return null; | |
111 | + } | |
112 | + } | ... | ... |
console/migrations/m180601_065055_create_visit_table.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +use yii\db\Migration; | |
4 | + | |
5 | +/** | |
6 | + * Handles the creation of table `visit`. | |
7 | + */ | |
8 | +class m180601_065055_create_visit_table extends Migration | |
9 | +{ | |
10 | + /** | |
11 | + * {@inheritdoc} | |
12 | + */ | |
13 | + public function safeUp() | |
14 | + { | |
15 | + $this->createTable('visit', [ | |
16 | + 'id' => $this->primaryKey(), | |
17 | + 'name' => $this->string(), | |
18 | + 'phone' => $this->string(), | |
19 | + 'message' => $this->text(), | |
20 | + 'entity' => $this->string(), | |
21 | + 'entity_id' => $this->integer(), | |
22 | + 'email' => $this->string(), | |
23 | + 'status' => $this->boolean(), | |
24 | + 'created_at'=> $this->integer() | |
25 | + ]); | |
26 | + } | |
27 | + | |
28 | + /** | |
29 | + * {@inheritdoc} | |
30 | + */ | |
31 | + public function safeDown() | |
32 | + { | |
33 | + $this->dropTable('visit'); | |
34 | + } | |
35 | +} | ... | ... |
frontend/config/main.php
... | ... | @@ -188,6 +188,76 @@ |
188 | 188 | }', |
189 | 189 | |
190 | 190 | ], |
191 | + | |
192 | + 'visit' => [ | |
193 | + 'class' => 'artbox\core\forms\Module', | |
194 | + 'activeRecord' => "common\models\Visit", | |
195 | + 'attributes' => [ | |
196 | + 'name', | |
197 | + 'phone', | |
198 | + 'email', | |
199 | + 'message', | |
200 | + | |
201 | + 'entity', | |
202 | + 'entity_id' | |
203 | + ], | |
204 | + 'rules' => [ | |
205 | + [ | |
206 | + [ | |
207 | + 'phone', | |
208 | + ], | |
209 | + 'required', | |
210 | + ] | |
211 | + ], | |
212 | + 'labels' => [ | |
213 | + 'name' => 'ФИО', | |
214 | + 'email' => 'Email', | |
215 | + 'phone' => 'Телефон', | |
216 | + 'message' => 'Сообщение', | |
217 | + 'entity_id' => false, | |
218 | + 'entity' => false | |
219 | + ], | |
220 | + | |
221 | + 'inputOptions' => [ | |
222 | + 'entity' => [ | |
223 | + 'type' => 'hiddenInput' | |
224 | + ], | |
225 | + 'entity_id' => [ | |
226 | + 'type' => 'hiddenInput' | |
227 | + ], | |
228 | + 'name' => [ | |
229 | + 'template' => '<div class="input-wr">{input}</div>' | |
230 | + ], | |
231 | + 'email' => [ | |
232 | + 'template' => '<div class="input-wr">{input}</div>' | |
233 | + ], | |
234 | + 'phone' => [ | |
235 | + 'template' => '<div class="input-wr required phones_mask">{input}</div>', | |
236 | + 'options' => [ | |
237 | + 'placeholder' => '(0__)___-__-__' | |
238 | + ] | |
239 | + ], | |
240 | + 'message' => [ | |
241 | + 'type' => 'textarea', | |
242 | + 'options' => ['cols' => 30, 'rows'=> 10], | |
243 | + 'template' => '<div class="input-wr">{input}</div>' | |
244 | + ], | |
245 | + ], | |
246 | + 'buttonTemplate' => '<div class="button-wr submit-close-wr-c-a">{button} <div class="submit-close-c-a"><span>Закрыть окно</span></div></div>', | |
247 | + 'buttonOptions' => [], | |
248 | + 'buttonContent' => 'Отправить', | |
249 | + 'sendEmail' => false, | |
250 | + 'ajax' => true, | |
251 | + 'formId' => 'visit-form', | |
252 | + 'scenario' => 'default', | |
253 | + 'successCallback' => 'function (data) { | |
254 | + document.getElementById("visit-form").reset(); | |
255 | + var data = $("#visit-form").data(\'yiiActiveForm\'); | |
256 | + data.validated = false; | |
257 | + success(); | |
258 | + }', | |
259 | + | |
260 | + ], | |
191 | 261 | ], |
192 | 262 | 'components' => [ |
193 | 263 | 'assetManager' => [ | ... | ... |
frontend/views/layouts/main.php
... | ... | @@ -18,6 +18,7 @@ |
18 | 18 | use artbox\core\seo\widgets\SeoBreadcrumbs; |
19 | 19 | use common\models\Service; |
20 | 20 | use common\models\Settings; |
21 | + use common\models\Visit; | |
21 | 22 | use frontend\assets\AppAsset; |
22 | 23 | use frontend\assets\SliderAsset; |
23 | 24 | use frontend\widgets\ArtboxModalWidget; |
... | ... | @@ -408,31 +409,39 @@ |
408 | 409 | ArtboxModalWidget::end(); |
409 | 410 | ?> |
410 | 411 | |
411 | - <div id="write-to" class="forms_" style="display: none;"> | |
412 | - <span id="modal_close"></span> | |
413 | - <div class="style form-title">Записаться на прием</div> | |
414 | - <form action=""> | |
415 | - <div class="input-wr"> | |
416 | - <label for="inp-11">Имя</label> | |
417 | - <input id="inp-11" type="text"> | |
418 | - </div> | |
419 | - <div class="input-wr phones_mask"> | |
420 | - <label for="inp-22">Телефон</label> | |
421 | - <input id="inp-22" type="text" placeholder="(0__)___-__-__"> | |
422 | - </div> | |
423 | - <div class="input-wr"> | |
424 | - <label for="inp-42">Email</label> | |
425 | - <input id="inp-42" type="text"> | |
426 | - </div> | |
427 | - <div class="input-wr"> | |
428 | - <label for="inp-33">Сообщение</label> | |
429 | - <textarea id="inp-33" name="" cols="30" rows="10"></textarea> | |
430 | - </div> | |
431 | - <div class="button-wr"> | |
432 | - <button type="submit">отправить</button> | |
433 | - </div> | |
434 | - </form> | |
435 | - </div> | |
412 | + <?php | |
413 | + /* @var \artbox\core\forms\Module $moduleVisit*/ | |
414 | + $moduleVisit = \Yii::$app->getModule('visit'); | |
415 | + if (isset($this->params['entity']) and isset($this->params['entity_id'])){ | |
416 | + $moduleVisit->inputOptions = array_merge($moduleVisit->inputOptions, ['entity' => [ | |
417 | + 'type' => 'hiddenInput', | |
418 | + 'options' => ['value' => $this->params['entity']], | |
419 | + ], | |
420 | + 'entity_id' => [ | |
421 | + 'type' => 'hiddenInput', | |
422 | + 'options' => ['value' => $this->params['entity_id']], | |
423 | + ] | |
424 | + ]); | |
425 | + } | |
426 | + ArtboxModalWidget::begin([ | |
427 | + 'modalTagOptions' => [ | |
428 | + 'id' => 'write-to' | |
429 | + ], | |
430 | + 'titleTagOptions' => [ | |
431 | + 'class' => 'style form-title' | |
432 | + ], | |
433 | + 'headerText' => \Yii::t('app', 'Записаться на прием'), | |
434 | + 'closeTagButton' => 'span', | |
435 | + 'closeTagContent' => '', | |
436 | + 'closeButtonOptions' => [ | |
437 | + 'id' => 'modal_close' | |
438 | + ] | |
439 | + ]); | |
440 | + | |
441 | + $moduleVisit->renderForm($this); | |
442 | + | |
443 | + ArtboxModalWidget::end(); | |
444 | + ?> | |
436 | 445 | |
437 | 446 | <div id="success_form" style="display: none;"> |
438 | 447 | <span id="modal_close"></span> | ... | ... |
frontend/views/service/view.php
... | ... | @@ -4,8 +4,13 @@ |
4 | 4 | * @var \common\models\Service[] $others; |
5 | 5 | * @var \artbox\core\forms\Module $moduleComment; |
6 | 6 | * @var \artbox\core\forms\Module $moduleQuestion; |
7 | + * @var \yii\web\View $this | |
7 | 8 | */ |
8 | 9 | use artbox\core\helpers\Url; |
10 | + use common\models\Service; | |
11 | + | |
12 | + $this->params['entity'] = Service::className(); | |
13 | + $this->params['entity_id'] = $model->id; | |
9 | 14 | |
10 | 15 | $moduleComment = \Yii::$app->getModule('comments'); |
11 | 16 | $this->params[ 'breadcrumbs' ][] = $model->title; | ... | ... |
frontend/web/js/script.js
... | ... | @@ -154,11 +154,11 @@ $(document).ready(function() { |
154 | 154 | var text = $(this).val(); |
155 | 155 | $(this).val(text); |
156 | 156 | if(($(this).val())== '') {$(this).val('(0')} |
157 | - }) | |
157 | + }); | |
158 | 158 | $(phoneInput).focusout(function () { |
159 | 159 | var phoneVal = $(this).val() |
160 | 160 | //if(phoneVal == '+38(0' || phoneVal == '+38(' || phoneVal == '+38' || phoneVal == '+3' || phoneVal == '+') {$(this).val('')} |
161 | - if(phoneVal.length <17) {$(this).val('')} | |
161 | + if(phoneVal.length <15) {$(this).val('')} | |
162 | 162 | }) |
163 | 163 | } |
164 | 164 | } |
... | ... | @@ -312,7 +312,7 @@ $(document).ready(function() { |
312 | 312 | },400) |
313 | 313 | } |
314 | 314 | |
315 | - | |
315 | + window.success = success; | |
316 | 316 | if($(window).width() >= 768) { |
317 | 317 | animations(); |
318 | 318 | } | ... | ... |