diff --git a/common/models/Blog.php b/common/models/Blog.php index aa79dae..6baf9b4 100644 --- a/common/models/Blog.php +++ b/common/models/Blog.php @@ -2,6 +2,7 @@ namespace common\models; + use common\modules\comment\models\Comment; use Yii; use yii\behaviors\BlameableBehavior; use yii\behaviors\TimestampBehavior; @@ -30,7 +31,6 @@ return 'blog'; } - /** * @inheritdoc */ @@ -49,11 +49,11 @@ 'value' => new Expression('NOW()'), ], 'slug' => [ - 'class' => 'common\behaviors\Slug', - 'in_attribute' => 'name', + 'class' => 'common\behaviors\Slug', + 'in_attribute' => 'name', 'out_attribute' => 'link', - 'translit' => true - ] + 'translit' => true, + ], ]; } @@ -64,7 +64,10 @@ { return [ [ - [ 'name', 'description' ], + [ + 'name', + 'description', + ], 'required', ], [ @@ -83,8 +86,9 @@ ]; } - public function getDateCreate(){ - return date('Y-m-d',strtotime($this->date_add)); + public function getDateCreate() + { + return date('Y-m-d', strtotime($this->date_add)); } /** @@ -104,4 +108,10 @@ 'cover' => Yii::t('app', 'Фото главное'), ]; } + + public function getComments() + { + return $this->hasMany(Comment::className(), [ 'model_id' => 'blog_id' ]) + ->where([ 'model' => $this->className() ]); + } } diff --git a/common/modules/comment/widgets/CommentWidget.php b/common/modules/comment/widgets/CommentWidget.php index 52c316f..cf8b2a3 100644 --- a/common/modules/comment/widgets/CommentWidget.php +++ b/common/modules/comment/widgets/CommentWidget.php @@ -197,12 +197,16 @@ if(empty( $view )) { throw new \yii\base\InvalidConfigException("form_options[view] must be set"); } - return $this->render($view, [ - 'model' => $this->comment_class, - 'rating' => $this->rating_class, - 'user' => \Yii::$app->user->identity, - 'dataProvider' => $this->dataProvider, - ]); + if($this->comment_class->guestComment || !empty(\Yii::$app->user->identity)) { + return $this->render($view, [ + 'model' => $this->comment_class, + 'rating' => $this->rating_class, + 'user' => \Yii::$app->user->identity, + 'dataProvider' => $this->dataProvider, + ]); + } else { + return ''; + } } public function renderWidget() diff --git a/common/modules/comment/widgets/views/form-project-comment.php b/common/modules/comment/widgets/views/form-project-comment.php index 240d241..5a76271 100644 --- a/common/modules/comment/widgets/views/form-project-comment.php +++ b/common/modules/comment/widgets/views/form-project-comment.php @@ -22,7 +22,7 @@
- userInfo->image) ?> + userInfo->image)?:'') ?>
name ?> diff --git a/frontend/controllers/CompanyController.php b/frontend/controllers/CompanyController.php index 8c4cb82..9d71d5b 100755 --- a/frontend/controllers/CompanyController.php +++ b/frontend/controllers/CompanyController.php @@ -211,6 +211,7 @@ $article = $query->offset($pagination->offset) ->limit($pagination->limit) + ->with('comments') ->all(); $blog = new ArrayDataProvider([ @@ -232,12 +233,14 @@ throw new BadRequestHttpException('Пользователь не найден'); } - $article = Blog::findOne([ - 'link' => $link, - 'user_id' => $company_id, - ]); - $article->view_count++; - $article->save(); + $article = Blog::find() + ->where([ + 'link' => $link, + 'user_id' => $company_id, + ]) + ->with('comments') + ->one(); + $article->updateCounters([ 'view_count' => 1 ]); return $this->render('blog-view', [ 'company' => $company, diff --git a/frontend/controllers/PerformerController.php b/frontend/controllers/PerformerController.php index 2d0adbc..5631528 100755 --- a/frontend/controllers/PerformerController.php +++ b/frontend/controllers/PerformerController.php @@ -97,7 +97,9 @@ ->all(); $portfolio = new ArrayDataProvider([ - 'allModels' => $user->getPortfolios()->orderBy('portfolio_id')->all(), + 'allModels' => $user->getPortfolios() + ->orderBy('portfolio_id') + ->all(), 'pagination' => [ 'pageSize' => 9, ], @@ -187,6 +189,7 @@ $article = $query->offset($pagination->offset) ->limit($pagination->limit) + ->with('comments') ->all(); $blog = new ArrayDataProvider([ @@ -208,16 +211,17 @@ throw new BadRequestHttpException('Пользователь не найден'); } - $article = Blog::findOne([ - 'link' => $link, - 'user_id' => $performer_id, - ]); + $article = Blog::find() + ->where([ + 'link' => $link, + 'user_id' => $performer_id, + ]) + ->with('comments')->one(); $article->updateCounters([ 'view_count' => 1 ]); return $this->render('blog-view', [ 'user' => $user, 'article' => $article, - ]); } @@ -254,7 +258,8 @@ throw new BadRequestHttpException('Пользователь не найден'); } - $query = Gallery::find()->where([ 'user_id' => $performer_id ]); + $query = Gallery::find() + ->where([ 'user_id' => $performer_id ]); $countQuery = clone $query; diff --git a/frontend/views/company/_blog_list_view.php b/frontend/views/company/_blog_list_view.php index 13fb32a..376bc17 100644 --- a/frontend/views/company/_blog_list_view.php +++ b/frontend/views/company/_blog_list_view.php @@ -3,7 +3,6 @@ * @var Blog $model */ use common\models\Blog; - use common\modules\comment\models\Comment; use frontend\helpers\TextHelper; use yii\helpers\Html; use yii\helpers\Url; @@ -28,12 +27,7 @@
-

where([ - 'model' => $model->className(), - 'model_id' => $model->getPrimaryKey(), - ]) - ->count() ?>

+

comments) ?>

diff --git a/frontend/views/company/blog-view.php b/frontend/views/company/blog-view.php index e7cec73..bdf782a 100755 --- a/frontend/views/company/blog-view.php +++ b/frontend/views/company/blog-view.php @@ -1,10 +1,15 @@ params['company'] = $company; - -$this->title = $article->name ; + $this->params[ 'company' ] = $company; + $this->title = $article->name; ?>
@@ -12,15 +17,15 @@ $this->title = $article->name ;
-

view_count?>

+

view_count ?>

-

view_count?>

+

comments) ?>

@@ -28,3 +33,29 @@ $this->title = $article->name ;
+ $this, + 'model' => $article::className(), + 'model_id' => $article->blog_id, + 'comment_class' => \common\modules\comment\models\Comment::className(), + 'rating_class' => \common\modules\comment\models\Rating::className(), + 'class_options' => [ + 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST, + 'user_id' => \Yii::$app->user->getId(), + 'guestComment' => true, + 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE, + ], + 'list_options' => [ + 'view' => 'list-comment', + ], + 'form_options' => [ + 'view' => 'form-comment', + 'tag' => 'div', + 'class' => 'artbox_comment_form', + ], + 'options' => [ + 'class' => 'new-portf-comments-wr style', + ], + ]); +?> diff --git a/frontend/views/company/vacancy-view.php b/frontend/views/company/vacancy-view.php index 79345a4..41b3ff4 100755 --- a/frontend/views/company/vacancy-view.php +++ b/frontend/views/company/vacancy-view.php @@ -78,7 +78,7 @@ 'link' => $similar_vacancy->link, ]), [ 'class' => 'performer-vacant-reclam-bl-title' ]) ?> -
city ?>. formatter->asDatetime($similar_vacancy->date_add, 'Y-MM-dd') ?>. +
city ?>. formatter->asDatetime($similar_vacancy->date_add, 'dd.MM.Y') ?>. salary )) { ?> diff --git a/frontend/views/performer/_blog_list_view.php b/frontend/views/performer/_blog_list_view.php index 6e568f8..86fedbe 100644 --- a/frontend/views/performer/_blog_list_view.php +++ b/frontend/views/performer/_blog_list_view.php @@ -28,12 +28,7 @@
-

where([ - 'model' => $model->className(), - 'model_id' => $model->getPrimaryKey(), - ]) - ->count() ?>

+

comments) ?>

diff --git a/frontend/views/performer/blog-list.php b/frontend/views/performer/blog-list.php index dd72750..0cda4ef 100755 --- a/frontend/views/performer/blog-list.php +++ b/frontend/views/performer/blog-list.php @@ -1,28 +1,28 @@ params['user'] = $user; -$this->title = 'My Yii Application'; + $this->params[ 'user' ] = $user; + $this->title = 'My Yii Application'; ?>
- $blog, - 'itemView'=>'_blog_list_view', - 'summary'=>'', - ] ); - ?> + 'itemView' => '_blog_list_view', + 'summary' => '', + ]); ?>
diff --git a/frontend/views/performer/blog-view.php b/frontend/views/performer/blog-view.php index 4fe67cd..1257703 100755 --- a/frontend/views/performer/blog-view.php +++ b/frontend/views/performer/blog-view.php @@ -1,10 +1,13 @@ params['user'] = $user; + $this->params[ 'user' ] = $user; - $this->title = $article->name ; + $this->title = $article->name; ?>
@@ -12,15 +15,15 @@
-

view_count?>

+

view_count ?>

-

view_count?>

+

comments) ?>

@@ -28,3 +31,29 @@
+ $this, + 'model' => $article::className(), + 'model_id' => $article->blog_id, + 'comment_class' => \common\modules\comment\models\Comment::className(), + 'rating_class' => \common\modules\comment\models\Rating::className(), + 'class_options' => [ + 'scenario' => is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\Comment::SCENARIO_USER : \common\modules\comment\models\Comment::SCENARIO_GUEST, + 'user_id' => \Yii::$app->user->getId(), + 'guestComment' => true, + 'status' => \common\modules\comment\models\Comment::STATUS_ACTIVE, + ], + 'list_options' => [ + 'view' => 'list-comment', + ], + 'form_options' => [ + 'view' => 'form-comment', + 'tag' => 'div', + 'class' => 'artbox_comment_form', + ], + 'options' => [ + 'class' => 'new-portf-comments-wr style', + ], + ]); +?> diff --git a/frontend/views/tender/view.php b/frontend/views/tender/view.php index 9d45d06..cc1a799 100755 --- a/frontend/views/tender/view.php +++ b/frontend/views/tender/view.php @@ -47,7 +47,7 @@ $this->title = 'My Yii Application';
-
+
user->owner->name ?>
-- libgit2 0.21.4