Commit f51c0b7cf84f79221f2c282951daf95d3cdc2082
1 parent
e47109b0
- support in card
Showing
2 changed files
with
39 additions
and
7 deletions
Show diff stats
frontend/controllers/BookController.php
@@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
9 | namespace frontend\controllers; | 9 | namespace frontend\controllers; |
10 | 10 | ||
11 | use common\models\Book; | 11 | use common\models\Book; |
12 | + use common\models\Support; | ||
12 | use yii\data\ActiveDataProvider; | 13 | use yii\data\ActiveDataProvider; |
13 | use yii\web\Controller; | 14 | use yii\web\Controller; |
14 | use yii\web\UploadedFile; | 15 | use yii\web\UploadedFile; |
@@ -83,7 +84,12 @@ | @@ -83,7 +84,12 @@ | ||
83 | $dataProvider = new ActiveDataProvider( | 84 | $dataProvider = new ActiveDataProvider( |
84 | [ | 85 | [ |
85 | 'query' => Book::find() | 86 | 'query' => Book::find() |
86 | - ->with(['author', 'alias']) | 87 | + ->with( |
88 | + [ | ||
89 | + 'author', | ||
90 | + 'alias', | ||
91 | + ] | ||
92 | + ) | ||
87 | ->where([ 'status' => Book::STATUS_ACTIVE ]), | 93 | ->where([ 'status' => Book::STATUS_ACTIVE ]), |
88 | 'pagination' => [ | 94 | 'pagination' => [ |
89 | 'pageSize' => 10, | 95 | 'pageSize' => 10, |
@@ -98,8 +104,26 @@ | @@ -98,8 +104,26 @@ | ||
98 | ); | 104 | ); |
99 | } | 105 | } |
100 | 106 | ||
101 | - public function actionView($id){ | ||
102 | - $model = Book::find()->with(['author', 'activeComments']) ->where(['id' => $id])->one(); | ||
103 | - return $this->render('view', ['model' => $model]); | 107 | + public function actionView($id) |
108 | + { | ||
109 | + $model = Book::find() | ||
110 | + ->with( | ||
111 | + [ | ||
112 | + 'author', | ||
113 | + 'activeComments', | ||
114 | + ] | ||
115 | + ) | ||
116 | + ->where([ 'id' => $id ]) | ||
117 | + ->one(); | ||
118 | + $support = Support::find() | ||
119 | + ->where([ 'book_id' => $model->id ]) | ||
120 | + ->all(); | ||
121 | + return $this->render( | ||
122 | + 'view', | ||
123 | + [ | ||
124 | + 'model' => $model, | ||
125 | + 'support' => $support, | ||
126 | + ] | ||
127 | + ); | ||
104 | } | 128 | } |
105 | } | 129 | } |
106 | \ No newline at end of file | 130 | \ No newline at end of file |
frontend/views/book/view.php
@@ -53,18 +53,26 @@ | @@ -53,18 +53,26 @@ | ||
53 | <div class="style card-title"><?=$model->title?></div> | 53 | <div class="style card-title"><?=$model->title?></div> |
54 | <div class="style card-autor-wrapp"> | 54 | <div class="style card-autor-wrapp"> |
55 | <div class="autor-img"> | 55 | <div class="autor-img"> |
56 | - <div><img src="images/card/autor.jpg" alt=""></div> | 56 | + <div><img src="/images/card/autor.jpg" alt=""></div> |
57 | </div> | 57 | </div> |
58 | <div class="autor-name"><?=$model->author->name?> <?=$model->author->secondname?></div> | 58 | <div class="autor-name"><?=$model->author->name?> <?=$model->author->secondname?></div> |
59 | </div> | 59 | </div> |
60 | <div class="style card-btns-price-wr"> | 60 | <div class="style card-btns-price-wr"> |
61 | <?php if ($model->price == null){ ?> | 61 | <?php if ($model->price == null){ ?> |
62 | <div> | 62 | <div> |
63 | + | ||
63 | <div class="price-block"> | 64 | <div class="price-block"> |
64 | <!--"необхідно" выводится без класса '.have'--> | 65 | <!--"необхідно" выводится без класса '.have'--> |
65 | <!--<p><b>110000</b> грн. <span>необхідно</span></p>--> | 66 | <!--<p><b>110000</b> грн. <span>необхідно</span></p>--> |
66 | - <p><b>37620</b> грн. <span class="have">зібрано</span></p> | ||
67 | - <p><b>460</b> <span class="supporters">підтримувачів</span></p> | 67 | + <?php if (!empty($support)){ |
68 | + $sum = 0; | ||
69 | + foreach ($support as $item){ | ||
70 | + $sum += $item->sum; | ||
71 | + } | ||
72 | + ?> | ||
73 | + <p><b><?=$sum?></b> грн. <span class="have">зібрано</span></p> | ||
74 | + <p><b><?=count($support)?></b> <span class="supporters">підтримувачів</span></p> | ||
75 | + <?php } ?> | ||
68 | </div> | 76 | </div> |
69 | <div class="style books-btn books-btn-new"> | 77 | <div class="style books-btn books-btn-new"> |
70 | <a href="<?=Url::to(['support/index', 'book_id' => $model->id])?>" class="btn_">Підтримати</a> | 78 | <a href="<?=Url::to(['support/index', 'book_id' => $model->id])?>" class="btn_">Підтримати</a> |