Skip to content

Commit 96cae79

Browse files
committed
Update comments implementation
1 parent acad755 commit 96cae79

2 files changed

Lines changed: 14 additions & 75 deletions

File tree

snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonPage.class.php

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,23 @@
22

33
namespace wcf\page;
44

5-
use wcf\data\comment\StructuredCommentList;
65
use wcf\data\person\Person;
7-
use wcf\system\comment\CommentHandler;
8-
use wcf\system\comment\manager\PersonCommentManager;
96
use wcf\system\exception\IllegalLinkException;
7+
use wcf\system\view\CommentsView;
108
use wcf\system\WCF;
119

1210
/**
1311
* Shows the details of a certain person.
1412
*
15-
* @author Matthias Schmidt
13+
* @author Matthias Schmidt
1614
* @copyright 2001-2021 WoltLab GmbH
17-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1816
*/
1917
class PersonPage extends AbstractPage
2018
{
21-
/**
22-
* list of comments
23-
* @var StructuredCommentList
24-
*/
25-
public $commentList;
26-
27-
/**
28-
* person comment manager object
29-
* @var PersonCommentManager
30-
*/
31-
public $commentManager;
32-
33-
/**
34-
* id of the person comment object type
35-
* @var int
36-
*/
37-
public $commentObjectTypeID = 0;
38-
39-
/**
40-
* shown person
41-
* @var Person
42-
*/
43-
public $person;
44-
45-
/**
46-
* id of the shown person
47-
* @var int
48-
*/
49-
public $personID = 0;
19+
public Person $person;
20+
public int $personID = 0;
21+
public ?CommentsView $commentsView = null;
5022

5123
/**
5224
* @inheritDoc
@@ -56,11 +28,7 @@ public function assignVariables()
5628
parent::assignVariables();
5729

5830
WCF::getTPL()->assign([
59-
'commentCanAdd' => WCF::getSession()->getPermission('user.person.canAddComment'),
60-
'commentList' => $this->commentList,
61-
'commentObjectTypeID' => $this->commentObjectTypeID,
62-
'lastCommentTime' => $this->commentList ? $this->commentList->getMinCommentTime() : 0,
63-
'likeData' => MODULE_LIKE && $this->commentList ? $this->commentList->getLikeData() : [],
31+
'commentsView' => $this->commentsView,
6432
'person' => $this->person,
6533
]);
6634
}
@@ -73,16 +41,11 @@ public function readData()
7341
parent::readData();
7442

7543
if ($this->person->enableComments) {
76-
$this->commentObjectTypeID = CommentHandler::getInstance()->getObjectTypeID(
77-
'com.woltlab.wcf.person.personComment'
78-
);
79-
$this->commentManager = CommentHandler::getInstance()->getObjectType(
80-
$this->commentObjectTypeID
81-
)->getProcessor();
82-
$this->commentList = CommentHandler::getInstance()->getCommentList(
83-
$this->commentManager,
84-
$this->commentObjectTypeID,
85-
$this->person->personID
44+
$this->commentsView = new CommentsView(
45+
'com.woltlab.wcf.person.personComment',
46+
$this->person->personID,
47+
'personCommentList',
48+
WCF::getSession()->getPermission('user.person.canAddComment')
8649
);
8750
}
8851
}

snippets/tutorial/tutorial-series/part-3/templates/person.tpl

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,8 @@
44

55
{include file='header'}
66

7-
{if $person->enableComments}
8-
{if $commentList|count || $commentCanAdd}
9-
<section id="comments" class="section sectionContainerList">
10-
<header class="sectionHeader">
11-
<h2 class="sectionTitle">
12-
{lang}wcf.person.comments{/lang}
13-
{if $person->comments}<span class="badge">{#$person->comments}</span>{/if}
14-
</h2>
15-
</header>
16-
17-
{include file='__commentJavaScript' commentContainerID='personCommentList'}
18-
19-
<div class="personComments">
20-
<ul id="personCommentList" class="commentList containerList" {*
21-
*}data-can-add="{if $commentCanAdd}true{else}false{/if}" {*
22-
*}data-object-id="{$person->personID}" {*
23-
*}data-object-type-id="{$commentObjectTypeID}" {*
24-
*}data-comments="{if $person->comments}{$commentList->countObjects()}{else}0{/if}" {*
25-
*}data-last-comment-time="{$lastCommentTime}" {*
26-
*}>
27-
{include file='commentListAddComment' wysiwygSelector='personCommentListAddComment'}
28-
{include file='commentList'}
29-
</ul>
30-
</div>
31-
</section>
32-
{/if}
7+
{if $commentsView}
8+
{unsafe:$commentsView->render()}
339
{/if}
3410

3511
<footer class="contentFooter">

0 commit comments

Comments
 (0)