Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
RecentQuestionsFormatter | |
0.00% |
0 / 35 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
formatHeader | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
formatResponses | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
12 | |||
format | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\HomepageModules; |
4 | |
5 | use GrowthExperiments\HelpPanel\QuestionFormatter; |
6 | use GrowthExperiments\HelpPanel\QuestionRecord; |
7 | use IContextSource; |
8 | use MediaWiki\Html\Html; |
9 | |
10 | class RecentQuestionsFormatter { |
11 | |
12 | /** |
13 | * @var QuestionRecord[] |
14 | */ |
15 | private $questionRecords; |
16 | /** |
17 | * @var IContextSource |
18 | */ |
19 | private $contextSource; |
20 | private $dataLinkIdKey; |
21 | /** @var string */ |
22 | private $recentQuestionsCssClass; |
23 | |
24 | /** |
25 | * @param IContextSource $contextSource |
26 | * @param array $questionRecords |
27 | * @param string $dataLinkIdKey |
28 | */ |
29 | public function __construct( |
30 | IContextSource $contextSource, |
31 | array $questionRecords, |
32 | $dataLinkIdKey |
33 | ) { |
34 | $this->questionRecords = $questionRecords; |
35 | $this->contextSource = $contextSource; |
36 | $this->dataLinkIdKey = $dataLinkIdKey; |
37 | $this->recentQuestionsCssClass = 'recent-questions-' . $this->dataLinkIdKey; |
38 | } |
39 | |
40 | public function formatHeader() { |
41 | return Html::element( 'h3', [], $this->contextSource |
42 | ->msg( 'growthexperiments-homepage-recent-questions-header' ) |
43 | ->params( $this->contextSource->getUser() ) |
44 | ->text() |
45 | ); |
46 | } |
47 | |
48 | public function formatResponses() { |
49 | $html = Html::openElement( |
50 | 'div', |
51 | [ 'class' => $this->recentQuestionsCssClass . '-list' ] |
52 | ); |
53 | $html .= Html::openElement( 'ul' ); |
54 | $count = 1; |
55 | foreach ( $this->questionRecords as $questionRecord ) { |
56 | $dataLinkId = $questionRecord->isArchived() ? |
57 | $this->dataLinkIdKey . '-archived-' . $count : |
58 | $this->dataLinkIdKey . '-' . $count; |
59 | $questionFormatter = new QuestionFormatter( |
60 | $this->contextSource, |
61 | $questionRecord, |
62 | $dataLinkId, |
63 | 'growthexperiments-homepage-recent-questions-posted-on', |
64 | 'growthexperiments-homepage-recent-questions-archived', |
65 | 'growthexperiments-homepage-recent-questions-archived-tooltip' |
66 | ); |
67 | $html .= Html::rawElement( 'li', [], $questionFormatter->format() ); |
68 | $count++; |
69 | } |
70 | $html .= Html::closeElement( 'ul' ); |
71 | $html .= Html::closeElement( 'div' ); |
72 | return $html; |
73 | } |
74 | |
75 | public function format() { |
76 | return Html::rawElement( 'div', [ 'class' => $this->recentQuestionsCssClass ], |
77 | $this->questionRecords ? $this->formatHeader() . $this->formatResponses() : '' |
78 | ); |
79 | } |
80 | |
81 | } |