mirror of
https://github.com/humhub/humhub.git
synced 2025-02-12 03:26:25 +01:00
Inline sub comments
This commit is contained in:
parent
05892a7a95
commit
57de3afa8c
@ -89,7 +89,10 @@ class Events extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
if (Yii::$app->getModule('comment')->canComment($event->sender->object->content)) {
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('comment');
|
||||
|
||||
if ($module->canComment($event->sender->object)) {
|
||||
$event->sender->addWidget(widgets\CommentLink::class, ['object' => $event->sender->object], ['sortOrder' => 10]);
|
||||
}
|
||||
}
|
||||
@ -107,8 +110,8 @@ class Events extends Component
|
||||
/**
|
||||
* Handles the SearchAttributesEvent and adds related comments
|
||||
*
|
||||
* @since 1.2.3
|
||||
* @param SearchAttributesEvent $event
|
||||
* @since 1.2.3
|
||||
*/
|
||||
public static function onSearchAttributes(SearchAttributesEvent $event)
|
||||
{
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace humhub\modules\comment;
|
||||
|
||||
use humhub\modules\comment\models\Comment;
|
||||
use humhub\modules\content\components\ContentActiveRecord;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
@ -47,19 +49,25 @@ class Module extends \humhub\components\Module
|
||||
*/
|
||||
public function getNotifications()
|
||||
{
|
||||
return [
|
||||
'humhub\modules\comment\notifications\NewComment'
|
||||
];
|
||||
return [
|
||||
'humhub\modules\comment\notifications\NewComment'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given content object can be commented
|
||||
*
|
||||
* @param \humhub\modules\content\models\Content $content
|
||||
* @param Comment|ContentActiveRecord $object
|
||||
* @return boolean can comment
|
||||
*/
|
||||
public function canComment(\humhub\modules\content\models\Content $content)
|
||||
public function canComment($object)
|
||||
{
|
||||
// Only allow one level of subcomments
|
||||
if ($object instanceof Comment && $object->object_model === Comment::class) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$content = $object->content;
|
||||
|
||||
if ($content->container instanceof \humhub\modules\space\models\Space) {
|
||||
$space = $content->container;
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use humhub\libs\Html;
|
||||
use humhub\widgets\ModalDialog;
|
||||
use humhub\modules\comment\widgets\Form;
|
||||
|
||||
?>
|
||||
|
||||
@ -12,16 +13,15 @@ use humhub\widgets\ModalDialog;
|
||||
<div class="comment" id="comments_area_<?= $id; ?>">
|
||||
<?= $output; ?>
|
||||
</div>
|
||||
<?= humhub\modules\comment\widgets\Form::widget(['object' => $object]); ?>
|
||||
<?= Form::widget(['object' => $object]); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php ModalDialog::end() ?>
|
||||
<script <?= Html::nonce() ?>>
|
||||
|
||||
<script <?= Html::nonce() ?>>
|
||||
// scroll to top of list
|
||||
$(".comment-modal-body").animate({scrollTop: 0}, 200);
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
@ -54,7 +54,7 @@ class CommentLink extends Widget
|
||||
$this->mode = self::MODE_INLINE;
|
||||
}
|
||||
|
||||
if (!$module->canComment($this->object->content)) {
|
||||
if (!$module->canComment($this->object)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@ -63,11 +63,6 @@ class CommentLink extends Widget
|
||||
if ($this->object instanceof CommentModel) {
|
||||
$objectModel = CommentModel::class;
|
||||
$objectId = $this->object->id;
|
||||
|
||||
if ($this->object->getSource() instanceof CommentModel) {
|
||||
// Dont allow comments of comments
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('link', [
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace humhub\modules\comment\widgets;
|
||||
|
||||
use humhub\modules\comment\models\Comment as CommentModel;
|
||||
use humhub\modules\content\components\ContentActiveRecord;
|
||||
|
||||
/**
|
||||
* This widget is used include the comments functionality to a wall entry.
|
||||
@ -17,7 +18,7 @@ class Comments extends \yii\base\Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Content Object
|
||||
* @var Comment|ContentActiveRecord
|
||||
*/
|
||||
public $object;
|
||||
|
||||
@ -26,20 +27,20 @@ class Comments extends \yii\base\Widget
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$modelName = $this->object->content->object_model;
|
||||
$modelId = $this->object->content->object_id;
|
||||
$objectModel = get_class($this->object);
|
||||
$objectId = $this->object->getPrimaryKey();
|
||||
|
||||
// Count all Comments
|
||||
$commentCount = CommentModel::GetCommentCount($modelName, $modelId);
|
||||
$comments = CommentModel::GetCommentsLimited($modelName, $modelId, 2);
|
||||
$commentCount = CommentModel::GetCommentCount($objectModel, $objectId);
|
||||
$comments = CommentModel::GetCommentsLimited($objectModel, $objectId, 2);
|
||||
|
||||
$isLimited = ($commentCount > 2);
|
||||
|
||||
return $this->render('comments', [
|
||||
'object' => $this->object,
|
||||
'comments' => $comments,
|
||||
'modelName' => $modelName,
|
||||
'modelId' => $modelId,
|
||||
'modelName' => $objectModel,
|
||||
'modelId' => $objectId,
|
||||
'id' => $this->object->getUniqueId(),
|
||||
'isLimited' => $isLimited,
|
||||
'total' => $commentCount
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
namespace humhub\modules\comment\widgets;
|
||||
|
||||
use humhub\modules\comment\Module;
|
||||
use Yii;
|
||||
use humhub\modules\comment\models\Comment as CommentModel;
|
||||
|
||||
@ -37,16 +38,15 @@ class Form extends \yii\base\Widget
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!Yii::$app->getModule('comment')->canComment($this->object->content)) {
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('comment');
|
||||
|
||||
if (!$module->canComment($this->object)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$objectModel = $this->object->content->object_model;
|
||||
$objectId = $this->object->content->object_id;
|
||||
if ($this->object instanceof CommentModel) {
|
||||
$objectModel = CommentModel::class;
|
||||
$objectId = $this->object->id;
|
||||
}
|
||||
$objectModel = get_class($this->object);
|
||||
$objectId = $this->object->getPrimaryKey();
|
||||
|
||||
return $this->render('form', [
|
||||
'modelName' => $objectModel,
|
||||
|
@ -7,6 +7,7 @@ use humhub\modules\user\widgets\Image as UserImage;
|
||||
use humhub\modules\file\widgets\ShowFiles;
|
||||
use humhub\modules\like\widgets\LikeLink;
|
||||
use humhub\modules\comment\widgets\CommentLink;
|
||||
use humhub\modules\comment\widgets\Comments;
|
||||
|
||||
/* @var $comment \humhub\modules\comment\models\Comment */
|
||||
/* @var $deleteUrl string */
|
||||
@ -80,8 +81,14 @@ use humhub\modules\comment\widgets\CommentLink;
|
||||
<div class="wall-entry-controls">
|
||||
<?= LikeLink::widget(['object' => $comment]); ?>
|
||||
·
|
||||
<?= CommentLink::widget(['object' => $comment, 'mode' => CommentLink::MODE_POPUP]); ?>
|
||||
<?= CommentLink::widget(['object' => $comment]); ?>
|
||||
|
||||
<div style="border:1px solid red;padding-top:12px">
|
||||
<?= Comments::widget(['object' => $comment]); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user