Skip to content

Commit 57482ff

Browse files
committed
update
1 parent 89e5b3f commit 57482ff

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

Module.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ class Module extends \yii\base\Module
3737
public function init()
3838
{
3939
parent::init();
40-
4140
if (null === $this->userIdentityClass) {
42-
$this->userIdentityClass = Yii::$app->getUser()->identityClass;
41+
$this->userIdentityClass = ($this->params['commentsIdentityClass']) ? $this->params['commentsIdentityClass'] : Yii::$app->getUser()->identityClass;
4342
}
4443
}
4544
}

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ This module provides a comments managing system.
1414
[![Build Status](https://travis-ci.org/yii2mod/yii2-comments.svg?branch=master)](https://travis-ci.org/yii2mod/yii2-comments)
1515
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yii2mod/yii2-comments/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yii2mod/yii2-comments/?branch=master)
1616

17-
## Support us
18-
19-
Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod).
20-
All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
21-
2217
Installation
2318
------------
2419

behaviors/BlameableBehavior.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace yii2mod\comments\behaviors;
4+
5+
use Yii;
6+
use yii\db\BaseActiveRecord;
7+
8+
class BlameableBehavior extends \yii\behaviors\BlameableBehavior
9+
{
10+
/**
11+
* {@inheritdoc}
12+
*
13+
* In case, when the [[value]] property is `null`, the value of [[defaultValue]] will be used as the value.
14+
*/
15+
protected function getValue($event)
16+
{
17+
if ($this->value === null && Yii::$app->has('customer')) {
18+
$userId = Yii::$app->get('customer')->id;
19+
if ($userId === null) {
20+
return $this->getDefaultValue($event);
21+
}
22+
23+
return $userId;
24+
} elseif ($this->value === null) {
25+
return $this->getDefaultValue($event);
26+
}
27+
28+
return parent::getValue($event);
29+
}
30+
}

controllers/DefaultController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ public function actionCreate($entity)
109109
$event = Yii::createObject(['class' => CommentEvent::class, 'commentModel' => $commentModel]);
110110
$commentModel->setAttributes($this->getCommentAttributesFromEntity($entity));
111111
$this->trigger(self::EVENT_BEFORE_CREATE, $event);
112+
112113
if ($commentModel->load(Yii::$app->request->post()) && $commentModel->saveComment()) {
114+
113115
$this->trigger(self::EVENT_AFTER_CREATE, $event);
114116

115117
return ['status' => 'success'];

models/CommentModel.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use paulzi\adjacencyList\AdjacencyListBehavior;
66
use Yii;
7-
use yii\behaviors\BlameableBehavior;
7+
use yii2mod\comments\behaviors\BlameableBehavior;
88
use yii\behaviors\TimestampBehavior;
99
use yii\db\ActiveQuery;
1010
use yii\db\ActiveRecord;
@@ -220,6 +220,9 @@ public function saveComment()
220220
*/
221221
public function getAuthor()
222222
{
223+
if (app()->getModule('comment')->params['commentsIdentityPrimaryId']) {
224+
return $this->hasOne($this->getModule()->userIdentityClass, [app()->getModule('comment')->params['commentsIdentityPrimaryId'] => 'createdBy']);
225+
}
223226
return $this->hasOne($this->getModule()->userIdentityClass, ['id' => 'createdBy']);
224227
}
225228

widgets/views/_list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<?php if (Yii::$app->getUser()->can('admin')) : ?>
1919
<?php echo Html::a('<span class="glyphicon glyphicon-trash"></span> ' . Yii::t('yii2mod.comments', 'Delete'), '#', ['class' => 'delete-comment-btn', 'data' => ['action' => 'delete', 'url' => Url::to(['/comment/default/delete', 'id' => $model->id]), 'comment-id' => $model->id]]); ?>
2020
<?php endif; ?>
21-
<?php if (!Yii::$app->user->isGuest && ($model->level < $maxLevel || is_null($maxLevel))) : ?>
21+
<?php if (!Yii::$app->customer->isGuest && ($model->level < $maxLevel || is_null($maxLevel))) : ?>
2222
<?php echo Html::a("<span class='glyphicon glyphicon-share-alt'></span> " . Yii::t('yii2mod.comments', 'Reply'), '#', ['class' => 'reply-comment-btn', 'data' => ['action' => 'reply', 'comment-id' => $model->id]]); ?>
2323
<?php endif; ?>
2424
</div>

widgets/views/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
],
4343
$listViewConfig
4444
)); ?>
45-
<?php if (!Yii::$app->user->isGuest) : ?>
45+
<?php if (!Yii::$app->customer->isGuest) : ?>
4646
<?php echo $this->render('_form', [
4747
'commentModel' => $commentModel,
4848
'formId' => $formId,

0 commit comments

Comments
 (0)