Commit e47109b0d13e3d8c5774dbf67607cb2af569214c
1 parent
ad2187ad
- support
Showing
8 changed files
with
267 additions
and
26 deletions
Show diff stats
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + | ||
7 | + /** | ||
8 | + * This is the model class for table "support". | ||
9 | + * | ||
10 | + * @property int $id | ||
11 | + * @property int $book_id | ||
12 | + * @property string $email | ||
13 | + * @property int $sum | ||
14 | + * @property int $status | ||
15 | + * @property Book $book | ||
16 | + */ | ||
17 | + class Support extends \yii\db\ActiveRecord | ||
18 | + { | ||
19 | + /** | ||
20 | + * {@inheritdoc} | ||
21 | + */ | ||
22 | + public static function tableName() | ||
23 | + { | ||
24 | + return 'support'; | ||
25 | + } | ||
26 | + | ||
27 | + /** | ||
28 | + * {@inheritdoc} | ||
29 | + */ | ||
30 | + public function rules() | ||
31 | + { | ||
32 | + return [ | ||
33 | + [ | ||
34 | + [ | ||
35 | + 'book_id', | ||
36 | + 'sum', | ||
37 | + 'status', | ||
38 | + ], | ||
39 | + 'default', | ||
40 | + 'value' => null, | ||
41 | + ], | ||
42 | + [ | ||
43 | + [ | ||
44 | + 'book_id', | ||
45 | + 'sum', | ||
46 | + 'status', | ||
47 | + ], | ||
48 | + 'integer', | ||
49 | + ], | ||
50 | + ['email', 'email'], | ||
51 | + [ | ||
52 | + [ 'email', 'name' ], | ||
53 | + 'string', | ||
54 | + 'max' => 255, | ||
55 | + ], | ||
56 | + [ | ||
57 | + [ 'book_id' ], | ||
58 | + 'exist', | ||
59 | + 'skipOnError' => true, | ||
60 | + 'targetClass' => Book::className(), | ||
61 | + 'targetAttribute' => [ 'book_id' => 'id' ], | ||
62 | + ], | ||
63 | + [ | ||
64 | + ['email', 'sum'], 'required' | ||
65 | + ] | ||
66 | + ]; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * {@inheritdoc} | ||
71 | + */ | ||
72 | + public function attributeLabels() | ||
73 | + { | ||
74 | + return [ | ||
75 | + 'id' => Yii::t('app', 'ID'), | ||
76 | + 'book_id' => Yii::t('app', 'Book ID'), | ||
77 | + 'email' => Yii::t('app', 'Email'), | ||
78 | + 'sum' => Yii::t('app', 'Sum'), | ||
79 | + 'status' => Yii::t('app', 'Status'), | ||
80 | + ]; | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * @return \yii\db\ActiveQuery | ||
85 | + */ | ||
86 | + public function getBook() | ||
87 | + { | ||
88 | + return $this->hasOne(Book::className(), [ 'id' => 'book_id' ]); | ||
89 | + } | ||
90 | + } |
console/migrations/m180614_103157_create_support_table.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +/** | ||
6 | + * Handles the creation of table `support`. | ||
7 | + */ | ||
8 | +class m180614_103157_create_support_table extends Migration | ||
9 | +{ | ||
10 | + /** | ||
11 | + * {@inheritdoc} | ||
12 | + */ | ||
13 | + public function safeUp() | ||
14 | + { | ||
15 | + $this->createTable('support', [ | ||
16 | + 'id' => $this->primaryKey(), | ||
17 | + 'book_id' => $this->integer(), | ||
18 | + 'name' => $this->string(), | ||
19 | + 'email' => $this->string(), | ||
20 | + 'sum' => $this->integer(), | ||
21 | + 'status' => $this->integer() | ||
22 | + ]); | ||
23 | + | ||
24 | + $this->addForeignKey('support_book_fk', | ||
25 | + 'support', | ||
26 | + 'book_id', | ||
27 | + 'book', | ||
28 | + 'id', | ||
29 | + 'CASCADE', | ||
30 | + 'CASCADE'); | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * {@inheritdoc} | ||
35 | + */ | ||
36 | + public function safeDown() | ||
37 | + { | ||
38 | + $this->dropForeignKey('support_book_fk', 'support'); | ||
39 | + $this->dropTable('support'); | ||
40 | + } | ||
41 | +} |
1 | +<?php | ||
2 | + /** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: stes | ||
5 | + * Date: 14.06.18 | ||
6 | + * Time: 13:40 | ||
7 | + */ | ||
8 | + | ||
9 | + namespace frontend\controllers; | ||
10 | + | ||
11 | + use common\models\Book; | ||
12 | + use common\models\Support; | ||
13 | + use yii\web\Controller; | ||
14 | + | ||
15 | + class SupportController extends Controller | ||
16 | + { | ||
17 | + public function actionIndex($book_id = null){ | ||
18 | + $model = new Support([ | ||
19 | + 'book_id' => $book_id, | ||
20 | + 'status' => 0 | ||
21 | + ]); | ||
22 | + $book = Book::find()->with('author')->where(['id' => $book_id])->one(); | ||
23 | + if ($model->load(\Yii::$app->request->post()) and $model->save()){ | ||
24 | + \Yii::$app->session->setFlash('success', 'Дякуємо за ваш запит. Найближчим часом, наш менеджер зв\'яжеться з Вами для уточнення деталей'); | ||
25 | + return $this->redirect(['site/index']); | ||
26 | + } | ||
27 | + return $this->render('index', [ | ||
28 | + 'model' => $model, | ||
29 | + 'book' => $book | ||
30 | + ]); | ||
31 | + } | ||
32 | + } | ||
0 | \ No newline at end of file | 33 | \ No newline at end of file |
frontend/views/book/_book.php
@@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
19 | </div> | 19 | </div> |
20 | <?php if ($model->price == null){?> | 20 | <?php if ($model->price == null){?> |
21 | <div class="style books-btn books-btn-new"> | 21 | <div class="style books-btn books-btn-new"> |
22 | - <a href="#" class="btn_">Підтримати</a> | 22 | + <a href="<?=Url::to(['support/index', 'book_id' => $model->id])?>" class="btn_">Підтримати</a> |
23 | </div> | 23 | </div> |
24 | <?php } else{?> | 24 | <?php } else{?> |
25 | <div class="style price-books-catalog"><div>вартість <b><?=$model->price?></b> грн.</div></div> | 25 | <div class="style price-books-catalog"><div>вартість <b><?=$model->price?></b> грн.</div></div> |
frontend/views/book/view.php
@@ -67,7 +67,7 @@ | @@ -67,7 +67,7 @@ | ||
67 | <p><b>460</b> <span class="supporters">підтримувачів</span></p> | 67 | <p><b>460</b> <span class="supporters">підтримувачів</span></p> |
68 | </div> | 68 | </div> |
69 | <div class="style books-btn books-btn-new"> | 69 | <div class="style books-btn books-btn-new"> |
70 | - <a href="#" class="btn_">Підтримати</a> | 70 | + <a href="<?=Url::to(['support/index', 'book_id' => $model->id])?>" class="btn_">Підтримати</a> |
71 | </div> | 71 | </div> |
72 | </div> | 72 | </div> |
73 | <?php } else {?> | 73 | <?php } else {?> |
@@ -83,9 +83,9 @@ | @@ -83,9 +83,9 @@ | ||
83 | <p>поділитися в соціальних мережах</p> | 83 | <p>поділитися в соціальних мережах</p> |
84 | <!--вставлять ссылку на эту страницу сюда {link-this-page}--> | 84 | <!--вставлять ссылку на эту страницу сюда {link-this-page}--> |
85 | <ul> | 85 | <ul> |
86 | - <li class="card-s1"><a target="_blank" rel="nofollow" href="http://www.facebook.com/sharer/sharer.php?u=http://{link-this-page}"></a></li> | ||
87 | - <li class="card-s2"><a target="_blank" rel="nofollow" href="https://twitter.com/intent/tweet?text=Hello%20world&url=http://{link-this-page}"></a></li> | ||
88 | - <li class="card-s3"><a target="_blank" rel="nofollow" href="https://plus.google.com/share?url=http://{link-this-page}"></a></li> | 86 | + <li class="card-s1"><a target="_blank" rel="nofollow" href="http://www.facebook.com/sharer/sharer.php?u=<?=\Yii::$app->request->absoluteUrl?>"></a></li> |
87 | + <li class="card-s2"><a target="_blank" rel="nofollow" href="https://twitter.com/intent/tweet?text=Hello%20world&url=<?=\Yii::$app->request->absoluteUrl?>"></a></li> | ||
88 | + <li class="card-s3"><a target="_blank" rel="nofollow" href="https://plus.google.com/share?url=<?=\Yii::$app->request->absoluteUrl?>"></a></li> | ||
89 | </ul> | 89 | </ul> |
90 | </div> | 90 | </div> |
91 | </div> | 91 | </div> |
frontend/views/layouts/main.php
@@ -47,6 +47,14 @@ | @@ -47,6 +47,14 @@ | ||
47 | ] | 47 | ] |
48 | ); | 48 | ); |
49 | $module = \Yii::$app->getModule('feedback'); | 49 | $module = \Yii::$app->getModule('feedback'); |
50 | + | ||
51 | + if (\Yii::$app->session->hasFlash('success')) { | ||
52 | + $message = \Yii::$app->session->getFlash('success'); | ||
53 | + $js = <<<JS | ||
54 | + success("$message"); | ||
55 | +JS; | ||
56 | + $this->registerJs($js, View::POS_READY); | ||
57 | + } | ||
50 | ?> | 58 | ?> |
51 | 59 | ||
52 | <?php $this->beginPage() ?> | 60 | <?php $this->beginPage() ?> |
1 | +<?php | ||
2 | + /** | ||
3 | + * @var \common\models\Book $book | ||
4 | + * @var \common\models\Support $model | ||
5 | + */ | ||
6 | + use yii\helpers\Html; | ||
7 | + use yii\widgets\ActiveForm; | ||
8 | + | ||
9 | +?> | ||
10 | +<section class="section-books-support"> | ||
11 | + <div class="container"> | ||
12 | + <div class="row"> | ||
13 | + <div class="col-xs-12"> | ||
14 | + <div class="title-blocks title-support">Підтримати</div> | ||
15 | + </div> | ||
16 | + </div> | ||
17 | + <div class="row"> | ||
18 | + <div class="hidden-xs col-sm-4"></div> | ||
19 | + <div class="col-xs-12 col-sm-4 support-form-col"> | ||
20 | + <div class="style support-form-wr"> | ||
21 | + <?php $form = ActiveForm::begin()?> | ||
22 | + <div class="style title-support-form"><?=$book->title?></div> | ||
23 | + <div class="style autor-support-form"> Автор: <?=$book->author->name?> <?=$book->author->secondname?></div> | ||
24 | + <div class="input-wr"> | ||
25 | + <?=$form->field($model, 'name')->label('Ім\'я')?> | ||
26 | + </div> | ||
27 | + <div class="input-wr"> | ||
28 | + <?=$form->field($model, 'email')->label('Пошта')?> | ||
29 | + </div> | ||
30 | + | ||
31 | + <div class="input-wr price-input-wr"> | ||
32 | + <div class="price-input"> | ||
33 | + <?=$form->field($model, 'sum')->label('Cума в гривнях')?> | ||
34 | + </div> | ||
35 | + </div> | ||
36 | + <?=$form->field($model, 'book_id')->hiddenInput()->label(false);?> | ||
37 | + <?=$form->field($model, 'status')->hiddenInput()->label(false);?> | ||
38 | + <div class="button-wr"> | ||
39 | + <?=Html::submitButton('Продовжити')?> | ||
40 | + </div> | ||
41 | + <?php ActiveForm::end()?> | ||
42 | + </div> | ||
43 | + </div> | ||
44 | + </div> | ||
45 | + </div> | ||
46 | +</section> |
frontend/web/js/script.js
@@ -97,12 +97,12 @@ $(document).ready(function() { | @@ -97,12 +97,12 @@ $(document).ready(function() { | ||
97 | block.addClass('vis_'); | 97 | block.addClass('vis_'); |
98 | $('body, html').animate({scrollTop:block.offset().top - 36},500) | 98 | $('body, html').animate({scrollTop:block.offset().top - 36},500) |
99 | 99 | ||
100 | - }) | ||
101 | - $('body').on('click','.hidden-comments-form-card button', function () { | ||
102 | - $('.hidden-comments-form-card').removeClass('vis_'); | ||
103 | - | ||
104 | - alert('thiiiis') | ||
105 | - }) | 100 | + }); |
101 | +// $('body').on('click','.hidden-comments-form-card button', function () { | ||
102 | +// $('.hidden-comments-form-card').removeClass('vis_'); | ||
103 | +// | ||
104 | +// alert('thiiiis') | ||
105 | +// }) | ||
106 | 106 | ||
107 | } | 107 | } |
108 | 108 | ||
@@ -252,23 +252,47 @@ $(document).ready(function() { | @@ -252,23 +252,47 @@ $(document).ready(function() { | ||
252 | } | 252 | } |
253 | //после удачной отправки формы запускать success() | 253 | //после удачной отправки формы запускать success() |
254 | // success() | 254 | // success() |
255 | - function success() { | ||
256 | - var pos = ($(window).scrollTop()) + 30; | ||
257 | - $('.forms_').animate({opacity: 0, top: '0'}, 200,function(){ | ||
258 | - $(this).css('display', 'none'); | 255 | +// function success(message) { |
256 | +// var pos = ($(window).scrollTop()) + 30; | ||
257 | +// $('.forms_').animate({opacity: 0, top: '0'}, 200,function(){ | ||
258 | +// $(this).css('display', 'none'); | ||
259 | +// }); | ||
260 | +// setTimeout(function () { | ||
261 | +// $('#overlay').fadeIn(400); | ||
262 | +// $('#success_form').find('.txt-success').html(message); | ||
263 | +// $('#success_form').css('display', 'block').animate({opacity: 1, top: pos}, 700); | ||
264 | +// },400) | ||
265 | +// } | ||
266 | + | ||
267 | + | ||
268 | + | ||
269 | +}); | ||
270 | +function success(message) { | ||
271 | + document.querySelector('#success_form .txt-success').innerHTML = message; | ||
272 | + var pos = ($(window) | ||
273 | + .scrollTop()) + 30 + 60; | ||
274 | + $('.forms_') | ||
275 | + .animate({ | ||
276 | + opacity: 0, | ||
277 | + top: '0' | ||
278 | + }, 200, function() { | ||
279 | + $(this) | ||
280 | + .css('display', 'none'); | ||
259 | }); | 281 | }); |
260 | - setTimeout(function () { | ||
261 | - $('#overlay').fadeIn(400); | ||
262 | - $('#success_form').css('display', 'block').animate({opacity: 1, top: pos}, 700); | ||
263 | - },400) | ||
264 | - } | ||
265 | - | ||
266 | - | ||
267 | - | ||
268 | - | ||
269 | - | ||
270 | -}) | 282 | + setTimeout(function() { |
283 | + $('#overlay') | ||
284 | + .fadeIn(400, function() { | ||
285 | + $('#success_form') | ||
286 | + .css('display', 'block') | ||
287 | + .animate({ | ||
288 | + opacity: 1, | ||
289 | + top: pos | ||
290 | + }, 700); | ||
291 | + }); | ||
292 | + }, 400) | ||
293 | +} | ||
271 | 294 | ||
295 | +window.success = success; | ||
272 | 296 | ||
273 | 297 | ||
274 | 298 |