Commit f51c0b7cf84f79221f2c282951daf95d3cdc2082

Authored by Anastasia
1 parent e47109b0

- support in card

frontend/controllers/BookController.php
... ... @@ -9,6 +9,7 @@
9 9 namespace frontend\controllers;
10 10  
11 11 use common\models\Book;
  12 + use common\models\Support;
12 13 use yii\data\ActiveDataProvider;
13 14 use yii\web\Controller;
14 15 use yii\web\UploadedFile;
... ... @@ -83,7 +84,12 @@
83 84 $dataProvider = new ActiveDataProvider(
84 85 [
85 86 'query' => Book::find()
86   - ->with(['author', 'alias'])
  87 + ->with(
  88 + [
  89 + 'author',
  90 + 'alias',
  91 + ]
  92 + )
87 93 ->where([ 'status' => Book::STATUS_ACTIVE ]),
88 94 'pagination' => [
89 95 'pageSize' => 10,
... ... @@ -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 130 \ No newline at end of file
... ...
frontend/views/book/view.php
... ... @@ -53,18 +53,26 @@
53 53 <div class="style card-title"><?=$model->title?></div>
54 54 <div class="style card-autor-wrapp">
55 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 57 </div>
58 58 <div class="autor-name"><?=$model->author->name?> <?=$model->author->secondname?></div>
59 59 </div>
60 60 <div class="style card-btns-price-wr">
61 61 <?php if ($model->price == null){ ?>
62 62 <div>
  63 +
63 64 <div class="price-block">
64 65 <!--"необхідно" выводится без класса '.have'-->
65 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 76 </div>
69 77 <div class="style books-btn books-btn-new">
70 78 <a href="<?=Url::to(['support/index', 'book_id' => $model->id])?>" class="btn_">Підтримати</a>
... ...