Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
TocTopicListFormatter | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
formatApi | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace Flow\Formatter; |
4 | |
5 | use Flow\Data\Pager\PagerPage; |
6 | use Flow\Model\Workflow; |
7 | use Flow\Templating; |
8 | |
9 | // The output of this is a strict subset of TopicListFormatter. |
10 | // Anything accessible from the output of this should be accessible with the same path |
11 | // from the output of TopicListFormatter. However, this output is much more minimal. |
12 | class TocTopicListFormatter extends BaseTopicListFormatter { |
13 | /** |
14 | * @var Templating |
15 | */ |
16 | protected $templating; |
17 | |
18 | public function __construct( Templating $templating ) { |
19 | $this->templating = $templating; |
20 | } |
21 | |
22 | /** |
23 | * Formats the response |
24 | * |
25 | * @param Workflow $listWorkflow Workflow corresponding to board/list of topics |
26 | * @param array $topicRootRevisionsByWorkflowId Associative array mapping topic ID (in alphadecimal form) |
27 | * to PostRevision for the topic root. |
28 | * @param array $workflowsByWorkflowId Associative array mapping topic ID (in alphadecimal form) to |
29 | * workflow |
30 | * @param PagerPage $page page from query, to support pagination |
31 | * |
32 | * @return array Array formatted for response |
33 | */ |
34 | public function formatApi( Workflow $listWorkflow, $topicRootRevisionsByWorkflowId, $workflowsByWorkflowId, PagerPage $page ) { |
35 | $result = $this->buildEmptyResult( $listWorkflow ); |
36 | |
37 | foreach ( $topicRootRevisionsByWorkflowId as $topicId => $postRevision ) { |
38 | $result['roots'][] = $topicId; |
39 | $revisionId = $postRevision->getRevisionId()->getAlphadecimal(); |
40 | $result['posts'][$topicId] = [ $revisionId ]; |
41 | |
42 | $contentFormat = 'topic-title-wikitext'; |
43 | |
44 | $workflow = $workflowsByWorkflowId[$topicId]; |
45 | |
46 | $moderatedRevision = $this->templating->getModeratedRevision( $postRevision ); |
47 | $moderationData = $moderatedRevision->isModerated() ? |
48 | [ |
49 | 'isModerated' => true, |
50 | 'moderateState' => $moderatedRevision->getModerationState(), |
51 | ] : |
52 | [ |
53 | 'isModerated' => false |
54 | ]; |
55 | $result['revisions'][$revisionId] = [ |
56 | // Keep this as a minimal subset of |
57 | // RevisionFormatter->formatApi, and keep the same content |
58 | // format for topic titles as specified in that class for |
59 | // topic titles. |
60 | |
61 | 'content' => [ |
62 | // no need to check permissions before fetching content; that should've |
63 | // been done by whatever caller supplies $topicRootRevisionsByWorkflowId, |
64 | 'content' => $this->templating->getContent( |
65 | $postRevision, |
66 | $contentFormat |
67 | ), |
68 | 'format' => $contentFormat, |
69 | 'plaintext' => $this->templating->getContent( $postRevision, 'topic-title-plaintext' ) |
70 | ], |
71 | 'last_updated' => $workflow->getLastUpdatedObj()->getTimestamp() * 1000, |
72 | ] + $moderationData; |
73 | } |
74 | |
75 | $pagingOption = $page->getPagingLinksOptions(); |
76 | $result['links']['pagination'] = $this->buildPaginationLinks( |
77 | $listWorkflow, |
78 | $pagingOption |
79 | ); |
80 | |
81 | return $result; |
82 | } |
83 | } |