Commit 4ff3ca88bfd39408db85647e2b196ade9d05be25
1 parent
fa284ab0
test
Showing
12 changed files
with
146 additions
and
75 deletions
Show diff stats
common/models/Blog.php
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | namespace common\models; |
| 4 | 4 | |
| 5 | + use common\modules\comment\models\Comment; | |
| 5 | 6 | use Yii; |
| 6 | 7 | use yii\behaviors\BlameableBehavior; |
| 7 | 8 | use yii\behaviors\TimestampBehavior; |
| ... | ... | @@ -30,7 +31,6 @@ |
| 30 | 31 | return 'blog'; |
| 31 | 32 | } |
| 32 | 33 | |
| 33 | - | |
| 34 | 34 | /** |
| 35 | 35 | * @inheritdoc |
| 36 | 36 | */ |
| ... | ... | @@ -49,11 +49,11 @@ |
| 49 | 49 | 'value' => new Expression('NOW()'), |
| 50 | 50 | ], |
| 51 | 51 | 'slug' => [ |
| 52 | - 'class' => 'common\behaviors\Slug', | |
| 53 | - 'in_attribute' => 'name', | |
| 52 | + 'class' => 'common\behaviors\Slug', | |
| 53 | + 'in_attribute' => 'name', | |
| 54 | 54 | 'out_attribute' => 'link', |
| 55 | - 'translit' => true | |
| 56 | - ] | |
| 55 | + 'translit' => true, | |
| 56 | + ], | |
| 57 | 57 | ]; |
| 58 | 58 | } |
| 59 | 59 | |
| ... | ... | @@ -64,7 +64,10 @@ |
| 64 | 64 | { |
| 65 | 65 | return [ |
| 66 | 66 | [ |
| 67 | - [ 'name', 'description' ], | |
| 67 | + [ | |
| 68 | + 'name', | |
| 69 | + 'description', | |
| 70 | + ], | |
| 68 | 71 | 'required', |
| 69 | 72 | ], |
| 70 | 73 | [ |
| ... | ... | @@ -83,8 +86,9 @@ |
| 83 | 86 | ]; |
| 84 | 87 | } |
| 85 | 88 | |
| 86 | - public function getDateCreate(){ | |
| 87 | - return date('Y-m-d',strtotime($this->date_add)); | |
| 89 | + public function getDateCreate() | |
| 90 | + { | |
| 91 | + return date('Y-m-d', strtotime($this->date_add)); | |
| 88 | 92 | } |
| 89 | 93 | |
| 90 | 94 | /** |
| ... | ... | @@ -104,4 +108,10 @@ |
| 104 | 108 | 'cover' => Yii::t('app', 'Фото главное'), |
| 105 | 109 | ]; |
| 106 | 110 | } |
| 111 | + | |
| 112 | + public function getComments() | |
| 113 | + { | |
| 114 | + return $this->hasMany(Comment::className(), [ 'model_id' => 'blog_id' ]) | |
| 115 | + ->where([ 'model' => $this->className() ]); | |
| 116 | + } | |
| 107 | 117 | } | ... | ... |
common/modules/comment/widgets/CommentWidget.php
| ... | ... | @@ -197,12 +197,16 @@ |
| 197 | 197 | if(empty( $view )) { |
| 198 | 198 | throw new \yii\base\InvalidConfigException("form_options[view] must be set"); |
| 199 | 199 | } |
| 200 | - return $this->render($view, [ | |
| 201 | - 'model' => $this->comment_class, | |
| 202 | - 'rating' => $this->rating_class, | |
| 203 | - 'user' => \Yii::$app->user->identity, | |
| 204 | - 'dataProvider' => $this->dataProvider, | |
| 205 | - ]); | |
| 200 | + if($this->comment_class->guestComment || !empty(\Yii::$app->user->identity)) { | |
| 201 | + return $this->render($view, [ | |
| 202 | + 'model' => $this->comment_class, | |
| 203 | + 'rating' => $this->rating_class, | |
| 204 | + 'user' => \Yii::$app->user->identity, | |
| 205 | + 'dataProvider' => $this->dataProvider, | |
| 206 | + ]); | |
| 207 | + } else { | |
| 208 | + return ''; | |
| 209 | + } | |
| 206 | 210 | } |
| 207 | 211 | |
| 208 | 212 | public function renderWidget() | ... | ... |
common/modules/comment/widgets/views/form-project-comment.php
| ... | ... | @@ -22,7 +22,7 @@ |
| 22 | 22 | <div class="form-value-wr style"> |
| 23 | 23 | <div class="form-ico-ded-wr"> |
| 24 | 24 | <div class="header-cabinet-foto"> |
| 25 | - <?= Html::img($user->userInfo->image) ?> | |
| 25 | + <?= Html::img(($user->userInfo->image)?:'') ?> | |
| 26 | 26 | </div> |
| 27 | 27 | <div class="form-value-ded-name"> |
| 28 | 28 | <?= $user->name ?> | ... | ... |
frontend/controllers/CompanyController.php
| ... | ... | @@ -211,6 +211,7 @@ |
| 211 | 211 | |
| 212 | 212 | $article = $query->offset($pagination->offset) |
| 213 | 213 | ->limit($pagination->limit) |
| 214 | + ->with('comments') | |
| 214 | 215 | ->all(); |
| 215 | 216 | |
| 216 | 217 | $blog = new ArrayDataProvider([ |
| ... | ... | @@ -232,12 +233,14 @@ |
| 232 | 233 | throw new BadRequestHttpException('Пользователь не найден'); |
| 233 | 234 | } |
| 234 | 235 | |
| 235 | - $article = Blog::findOne([ | |
| 236 | - 'link' => $link, | |
| 237 | - 'user_id' => $company_id, | |
| 238 | - ]); | |
| 239 | - $article->view_count++; | |
| 240 | - $article->save(); | |
| 236 | + $article = Blog::find() | |
| 237 | + ->where([ | |
| 238 | + 'link' => $link, | |
| 239 | + 'user_id' => $company_id, | |
| 240 | + ]) | |
| 241 | + ->with('comments') | |
| 242 | + ->one(); | |
| 243 | + $article->updateCounters([ 'view_count' => 1 ]); | |
| 241 | 244 | |
| 242 | 245 | return $this->render('blog-view', [ |
| 243 | 246 | 'company' => $company, | ... | ... |
frontend/controllers/PerformerController.php
| ... | ... | @@ -97,7 +97,9 @@ |
| 97 | 97 | ->all(); |
| 98 | 98 | |
| 99 | 99 | $portfolio = new ArrayDataProvider([ |
| 100 | - 'allModels' => $user->getPortfolios()->orderBy('portfolio_id')->all(), | |
| 100 | + 'allModels' => $user->getPortfolios() | |
| 101 | + ->orderBy('portfolio_id') | |
| 102 | + ->all(), | |
| 101 | 103 | 'pagination' => [ |
| 102 | 104 | 'pageSize' => 9, |
| 103 | 105 | ], |
| ... | ... | @@ -187,6 +189,7 @@ |
| 187 | 189 | |
| 188 | 190 | $article = $query->offset($pagination->offset) |
| 189 | 191 | ->limit($pagination->limit) |
| 192 | + ->with('comments') | |
| 190 | 193 | ->all(); |
| 191 | 194 | |
| 192 | 195 | $blog = new ArrayDataProvider([ |
| ... | ... | @@ -208,16 +211,17 @@ |
| 208 | 211 | throw new BadRequestHttpException('Пользователь не найден'); |
| 209 | 212 | } |
| 210 | 213 | |
| 211 | - $article = Blog::findOne([ | |
| 212 | - 'link' => $link, | |
| 213 | - 'user_id' => $performer_id, | |
| 214 | - ]); | |
| 214 | + $article = Blog::find() | |
| 215 | + ->where([ | |
| 216 | + 'link' => $link, | |
| 217 | + 'user_id' => $performer_id, | |
| 218 | + ]) | |
| 219 | + ->with('comments')->one(); | |
| 215 | 220 | $article->updateCounters([ 'view_count' => 1 ]); |
| 216 | 221 | |
| 217 | 222 | return $this->render('blog-view', [ |
| 218 | 223 | 'user' => $user, |
| 219 | 224 | 'article' => $article, |
| 220 | - | |
| 221 | 225 | ]); |
| 222 | 226 | } |
| 223 | 227 | |
| ... | ... | @@ -254,7 +258,8 @@ |
| 254 | 258 | throw new BadRequestHttpException('Пользователь не найден'); |
| 255 | 259 | } |
| 256 | 260 | |
| 257 | - $query = Gallery::find()->where([ 'user_id' => $performer_id ]); | |
| 261 | + $query = Gallery::find() | |
| 262 | + ->where([ 'user_id' => $performer_id ]); | |
| 258 | 263 | |
| 259 | 264 | $countQuery = clone $query; |
| 260 | 265 | ... | ... |
frontend/views/company/_blog_list_view.php
| ... | ... | @@ -3,7 +3,6 @@ |
| 3 | 3 | * @var Blog $model |
| 4 | 4 | */ |
| 5 | 5 | use common\models\Blog; |
| 6 | - use common\modules\comment\models\Comment; | |
| 7 | 6 | use frontend\helpers\TextHelper; |
| 8 | 7 | use yii\helpers\Html; |
| 9 | 8 | use yii\helpers\Url; |
| ... | ... | @@ -28,12 +27,7 @@ |
| 28 | 27 | </div> |
| 29 | 28 | <div class="blog-post-comm-num"> |
| 30 | 29 | <span></span> |
| 31 | - <p><?= Comment::find() | |
| 32 | - ->where([ | |
| 33 | - 'model' => $model->className(), | |
| 34 | - 'model_id' => $model->getPrimaryKey(), | |
| 35 | - ]) | |
| 36 | - ->count() ?></p> | |
| 30 | + <p><?= count($model->comments) ?></p> | |
| 37 | 31 | </div> |
| 38 | 32 | </div> |
| 39 | 33 | <div class="blog-post-content style"> | ... | ... |
frontend/views/company/blog-view.php
| 1 | 1 | <?php |
| 2 | -use \yii\helpers\Html; | |
| 2 | + /** | |
| 3 | + * @var View $this | |
| 4 | + * @var Blog $article | |
| 5 | + * @var User $company | |
| 6 | + */ | |
| 7 | + use common\models\Blog; | |
| 8 | + use common\models\User; | |
| 9 | + use yii\web\View; | |
| 3 | 10 | |
| 4 | -/* @var $this yii\web\View */ | |
| 5 | -$this->params['company'] = $company; | |
| 6 | - | |
| 7 | -$this->title = $article->name ; | |
| 11 | + $this->params[ 'company' ] = $company; | |
| 12 | + $this->title = $article->name; | |
| 8 | 13 | ?> |
| 9 | 14 | <div class="performer-vacancy-vacant-title-reclam-wr style"> |
| 10 | 15 | <div class="blog-post-wr"> |
| ... | ... | @@ -12,15 +17,15 @@ $this->title = $article->name ; |
| 12 | 17 | <div class="blog-post-icons-wr style"> |
| 13 | 18 | <div class="blog-post-date"> |
| 14 | 19 | <span></span> |
| 15 | - <p><?= $article->dateCreate?></p> | |
| 20 | + <p><?= \Yii::$app->formatter->asDate($article->dateCreate, 'php:d.m.Y') ?></p> | |
| 16 | 21 | </div> |
| 17 | 22 | <div class="blog-post-views"> |
| 18 | 23 | <span></span> |
| 19 | - <p><?= $article->view_count?></p> | |
| 24 | + <p><?= $article->view_count ?></p> | |
| 20 | 25 | </div> |
| 21 | 26 | <div class="blog-post-comm-num"> |
| 22 | 27 | <span></span> |
| 23 | - <p><?= $article->view_count?></p> | |
| 28 | + <p><?= count($article->comments) ?></p> | |
| 24 | 29 | </div> |
| 25 | 30 | </div> |
| 26 | 31 | <div class="blog-post-content style"> |
| ... | ... | @@ -28,3 +33,29 @@ $this->title = $article->name ; |
| 28 | 33 | </div> |
| 29 | 34 | </div> |
| 30 | 35 | </div> |
| 36 | +<?php | |
| 37 | + echo \common\modules\comment\widgets\CommentWidget::widget([ | |
| 38 | + 'context' => $this, | |
| 39 | + 'model' => $article::className(), | |
| 40 | + 'model_id' => $article->blog_id, | |
| 41 | + 'comment_class' => \common\modules\comment\models\Comment::className(), | |
| 42 | + 'rating_class' => \common\modules\comment\models\Rating::className(), | |
| 43 | + 'class_options' => [ | |
| 44 | + 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST, | |
| 45 | + 'user_id' => \Yii::$app->user->getId(), | |
| 46 | + 'guestComment' => true, | |
| 47 | + 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE, | |
| 48 | + ], | |
| 49 | + 'list_options' => [ | |
| 50 | + 'view' => 'list-comment', | |
| 51 | + ], | |
| 52 | + 'form_options' => [ | |
| 53 | + 'view' => 'form-comment', | |
| 54 | + 'tag' => 'div', | |
| 55 | + 'class' => 'artbox_comment_form', | |
| 56 | + ], | |
| 57 | + 'options' => [ | |
| 58 | + 'class' => 'new-portf-comments-wr style', | |
| 59 | + ], | |
| 60 | + ]); | |
| 61 | +?> | ... | ... |
frontend/views/company/vacancy-view.php
| ... | ... | @@ -78,7 +78,7 @@ |
| 78 | 78 | 'link' => $similar_vacancy->link, |
| 79 | 79 | ]), [ 'class' => 'performer-vacant-reclam-bl-title' ]) ?> |
| 80 | 80 | |
| 81 | - <div class="performer-vacant-reclam-bl-title-two"><?= $similar_vacancy->city ?>. <?= \Yii::$app->formatter->asDatetime($similar_vacancy->date_add, 'Y-MM-dd') ?>. | |
| 81 | + <div class="performer-vacant-reclam-bl-title-two"><?= $similar_vacancy->city ?>. <?= \Yii::$app->formatter->asDatetime($similar_vacancy->date_add, 'dd.MM.Y') ?>. | |
| 82 | 82 | <?php |
| 83 | 83 | if(!empty( $similar_vacancy->salary )) { |
| 84 | 84 | ?> | ... | ... |
frontend/views/performer/_blog_list_view.php
| ... | ... | @@ -28,12 +28,7 @@ |
| 28 | 28 | </div> |
| 29 | 29 | <div class="blog-post-comm-num"> |
| 30 | 30 | <span></span> |
| 31 | - <p><?= Comment::find() | |
| 32 | - ->where([ | |
| 33 | - 'model' => $model->className(), | |
| 34 | - 'model_id' => $model->getPrimaryKey(), | |
| 35 | - ]) | |
| 36 | - ->count() ?></p> | |
| 31 | + <p><?= count($model->comments) ?></p> | |
| 37 | 32 | </div> |
| 38 | 33 | </div> |
| 39 | 34 | <div class="blog-post-content style"> | ... | ... |
frontend/views/performer/blog-list.php
| 1 | 1 | <?php |
| 2 | + /** | |
| 3 | + * @var ArrayDataProvider $blog | |
| 4 | + * @var Pagination $pagination | |
| 5 | + * @var yii\web\View $this | |
| 6 | + */ | |
| 7 | + use yii\data\ArrayDataProvider; | |
| 8 | + use yii\data\Pagination; | |
| 9 | + use yii\widgets\LinkPager; | |
| 10 | + use yii\widgets\ListView; | |
| 2 | 11 | |
| 3 | -use \yii\helpers\Html; | |
| 4 | -use yii\widgets\LinkPager; | |
| 5 | -use yii\widgets\ListView; | |
| 6 | - | |
| 7 | -/* @var $this yii\web\View */ | |
| 8 | -$this->params['user'] = $user; | |
| 9 | -$this->title = 'My Yii Application'; | |
| 12 | + $this->params[ 'user' ] = $user; | |
| 13 | + $this->title = 'My Yii Application'; | |
| 10 | 14 | ?> |
| 11 | 15 | <div class="performer-vacancy-vacant-title-reclam-wr style"> |
| 12 | 16 | |
| 13 | - <?= | |
| 14 | - ListView::widget( [ | |
| 17 | + <?= ListView::widget([ | |
| 15 | 18 | 'dataProvider' => $blog, |
| 16 | - 'itemView'=>'_blog_list_view', | |
| 17 | - 'summary'=>'', | |
| 18 | - ] ); | |
| 19 | - ?> | |
| 19 | + 'itemView' => '_blog_list_view', | |
| 20 | + 'summary' => '', | |
| 21 | + ]); ?> | |
| 20 | 22 | </div> |
| 21 | 23 | <div class="navi-buttons-wr style"> |
| 22 | - <?= | |
| 23 | - LinkPager::widget([ | |
| 24 | + <?= LinkPager::widget([ | |
| 24 | 25 | 'pagination' => $pagination, |
| 25 | - ]); | |
| 26 | - ?> | |
| 26 | + ]); ?> | |
| 27 | 27 | </div> |
| 28 | 28 | ... | ... |
frontend/views/performer/blog-view.php
| 1 | 1 | <?php |
| 2 | - use \yii\helpers\Html; | |
| 2 | + /** | |
| 3 | + * @var yii\web\View $this | |
| 4 | + * @var Blog $article | |
| 5 | + */ | |
| 6 | + use common\models\Blog; | |
| 3 | 7 | |
| 4 | - /* @var $this yii\web\View */ | |
| 5 | - $this->params['user'] = $user; | |
| 8 | + $this->params[ 'user' ] = $user; | |
| 6 | 9 | |
| 7 | - $this->title = $article->name ; | |
| 10 | + $this->title = $article->name; | |
| 8 | 11 | ?> |
| 9 | 12 | <div class="performer-vacancy-vacant-title-reclam-wr style"> |
| 10 | 13 | <div class="blog-post-wr"> |
| ... | ... | @@ -12,15 +15,15 @@ |
| 12 | 15 | <div class="blog-post-icons-wr style"> |
| 13 | 16 | <div class="blog-post-date"> |
| 14 | 17 | <span></span> |
| 15 | - <p><?= $article->dateCreate?></p> | |
| 18 | + <p><?= \Yii::$app->formatter->asDate($article->date_add, 'php:d.m.Y') ?></p> | |
| 16 | 19 | </div> |
| 17 | 20 | <div class="blog-post-views"> |
| 18 | 21 | <span></span> |
| 19 | - <p><?= $article->view_count?></p> | |
| 22 | + <p><?= $article->view_count ?></p> | |
| 20 | 23 | </div> |
| 21 | 24 | <div class="blog-post-comm-num"> |
| 22 | 25 | <span></span> |
| 23 | - <p><?= $article->view_count?></p> | |
| 26 | + <p><?= count($article->comments) ?></p> | |
| 24 | 27 | </div> |
| 25 | 28 | </div> |
| 26 | 29 | <div class="blog-post-content style"> |
| ... | ... | @@ -28,3 +31,29 @@ |
| 28 | 31 | </div> |
| 29 | 32 | </div> |
| 30 | 33 | </div> |
| 34 | +<?php | |
| 35 | + echo \common\modules\comment\widgets\CommentWidget::widget([ | |
| 36 | + 'context' => $this, | |
| 37 | + 'model' => $article::className(), | |
| 38 | + 'model_id' => $article->blog_id, | |
| 39 | + 'comment_class' => \common\modules\comment\models\Comment::className(), | |
| 40 | + 'rating_class' => \common\modules\comment\models\Rating::className(), | |
| 41 | + 'class_options' => [ | |
| 42 | + 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST, | |
| 43 | + 'user_id' => \Yii::$app->user->getId(), | |
| 44 | + 'guestComment' => true, | |
| 45 | + 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE, | |
| 46 | + ], | |
| 47 | + 'list_options' => [ | |
| 48 | + 'view' => 'list-comment', | |
| 49 | + ], | |
| 50 | + 'form_options' => [ | |
| 51 | + 'view' => 'form-comment', | |
| 52 | + 'tag' => 'div', | |
| 53 | + 'class' => 'artbox_comment_form', | |
| 54 | + ], | |
| 55 | + 'options' => [ | |
| 56 | + 'class' => 'new-portf-comments-wr style', | |
| 57 | + ], | |
| 58 | + ]); | |
| 59 | +?> | ... | ... |
frontend/views/tender/view.php
| ... | ... | @@ -47,7 +47,7 @@ $this->title = 'My Yii Application'; |
| 47 | 47 | <div class="section-box"> |
| 48 | 48 | <div class="cabinet-message-read-autor-wr style"> |
| 49 | 49 | <div class="cabinet-message-read-foto-wr"> |
| 50 | - <div class="cabinet-message-read-foto"><img src="<?= $model->user->userInfo->image ?>" alt=""/></div> | |
| 50 | + <div class="cabinet-message-read-foto"><img src="<?= ($model->user->userInfo->image)?:'' ?>" alt=""/></div> | |
| 51 | 51 | </div> |
| 52 | 52 | <div class="cab-mes-read-cont"> |
| 53 | 53 | <div class="cab-mes-read-cont-title"><?= $model->user->owner->name ?></div> | ... | ... |