mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
Add JSON serialize methods
Change-Id: Iaa24c39842cbe76370aaeba01eab2c991d290b8c
This commit is contained in:
parent
221f5c5884
commit
2a03b6e420
|
@ -35,6 +35,16 @@ class CommentItem extends ThreadItem {
|
|||
$this->author = $author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array JSON-serializable array
|
||||
*/
|
||||
public function jsonSerialize() : array {
|
||||
return array_merge( parent::jsonSerialize(), [
|
||||
'timestamp' => $this->timestamp,
|
||||
'author' => $this->author,
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML of this comment's body
|
||||
*
|
||||
|
|
|
@ -16,6 +16,15 @@ class HeadingItem extends ThreadItem {
|
|||
$this->placeholderHeading = $placeholderHeading;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array JSON-serializable array
|
||||
*/
|
||||
public function jsonSerialize() : array {
|
||||
return array_merge( parent::jsonSerialize(), [
|
||||
'placeholderHeading' => $this->placeholderHeading,
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
namespace MediaWiki\Extension\DiscussionTools;
|
||||
|
||||
use DOMNode;
|
||||
use JsonSerializable;
|
||||
use Wikimedia\Parsoid\Utils\DOMCompat;
|
||||
|
||||
/**
|
||||
* A thread item, either a heading or a comment
|
||||
*/
|
||||
abstract class ThreadItem {
|
||||
abstract class ThreadItem implements JsonSerializable {
|
||||
protected $type;
|
||||
protected $range;
|
||||
protected $rootNode;
|
||||
|
@ -31,6 +32,20 @@ abstract class ThreadItem {
|
|||
$this->range = $range;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array JSON-serializable array
|
||||
*/
|
||||
public function jsonSerialize() : array {
|
||||
return [
|
||||
'type' => $this->type,
|
||||
'level' => $this->level,
|
||||
'id' => $this->id,
|
||||
'replies' => array_map( function ( CommentItem $comment ) {
|
||||
return $comment->getId();
|
||||
}, $this->replies )
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of authors in the comment tree below this thread item.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue