Skip to content

Commit a3bc958

Browse files
committed
Add comment replies to dynamic data
1 parent 195ad8f commit a3bc958

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Model/Comment.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,47 @@ public function getPublishDate($format = 'Y-m-d H:i:s')
277277
$this->getData('creation_time')
278278
);
279279
}
280+
281+
/**
282+
* @return array|ResourceModel\Comment\Collection
283+
*/
284+
public function getRepliesCollection()
285+
{
286+
$repliesCollection = [];
287+
if (!$this->isReply()) {
288+
$cId = $this->getId();
289+
if (!isset($repliesCollection[$cId])) {
290+
$repliesCollection[$cId] = $this->getChildComments()
291+
->addActiveFilter()
292+
/*->setPageSize($this->getNumberOfReplies())*/
293+
//->setOrder('creation_time', 'DESC'); old sorting
294+
->setOrder('creation_time', 'ASC');
295+
}
296+
297+
return $repliesCollection[$cId];
298+
} else {
299+
return [];
300+
}
301+
}
302+
303+
/**
304+
* @param null $fields
305+
* @return array
306+
*/
307+
public function getDynamicData($fields = null)
308+
{
309+
$data = $this->getData();
310+
311+
if (is_array($fields) && array_key_exists('replies', $fields)) {
312+
$replies = [];
313+
foreach ($this->getRepliesCollection() as $reply) {
314+
$replies[] = $reply->getDynamicData(
315+
isset($fields['replies']) ? $fields['replies'] : null
316+
);
317+
}
318+
$data['replies'] = $replies;
319+
}
320+
321+
return $data;
322+
}
280323
}

0 commit comments

Comments
 (0)