Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
CargoListFormat | |
0.00% |
0 / 37 |
|
0.00% |
0 / 4 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
allowedParameters | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
displayRow | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
110 | |||
display | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * @author Yaron Koren |
4 | * @ingroup Cargo |
5 | */ |
6 | |
7 | class CargoListFormat extends CargoDisplayFormat { |
8 | |
9 | /** @var string[] */ |
10 | protected $undisplayedFields = []; |
11 | |
12 | public function __construct( $output, $parser = null ) { |
13 | parent::__construct( $output, $parser ); |
14 | $this->mOutput->addModules( [ 'ext.cargo.main' ] ); |
15 | } |
16 | |
17 | public static function allowedParameters() { |
18 | return [ |
19 | 'delimiter' => [ 'type' => 'string', 'label' => wfMessage( 'cargo-viewdata-delimiterparam' ) ] |
20 | ]; |
21 | } |
22 | |
23 | /** |
24 | * @param array $row |
25 | * @param array $fieldDescriptions |
26 | * @return string |
27 | */ |
28 | public function displayRow( $row, $fieldDescriptions ) { |
29 | $text = ''; |
30 | $startParenthesisAdded = false; |
31 | $firstField = true; |
32 | foreach ( $fieldDescriptions as $fieldName => $fieldDescription ) { |
33 | if ( !array_key_exists( $fieldName, $row ) ) { |
34 | continue; |
35 | } |
36 | $fieldValue = $row[$fieldName] ?? ''; |
37 | if ( trim( $fieldValue ) == '' ) { |
38 | continue; |
39 | } |
40 | if ( $firstField ) { |
41 | $text = $fieldValue; |
42 | $firstField = false; |
43 | } elseif ( in_array( $fieldName, $this->undisplayedFields ) ) { |
44 | // Do nothing. |
45 | } else { |
46 | if ( !$startParenthesisAdded ) { |
47 | $text .= ' ('; |
48 | $startParenthesisAdded = true; |
49 | } else { |
50 | $text .= ', '; |
51 | } |
52 | if ( !$fieldName || strpos( $fieldName, 'Blank value ' ) !== false ) { |
53 | $text .= $fieldValue; |
54 | } else { |
55 | $text .= "<span class=\"cargoFieldName\">$fieldName:</span> $fieldValue"; |
56 | } |
57 | } |
58 | } |
59 | if ( $startParenthesisAdded ) { |
60 | $text .= ')'; |
61 | } |
62 | return $text; |
63 | } |
64 | |
65 | /** |
66 | * @param array $valuesTable Unused |
67 | * @param array $formattedValuesTable |
68 | * @param array $fieldDescriptions |
69 | * @param array $displayParams |
70 | * @return string |
71 | */ |
72 | public function display( $valuesTable, $formattedValuesTable, $fieldDescriptions, $displayParams ) { |
73 | $text = ''; |
74 | $delimiter = ( array_key_exists( 'delimiter', $displayParams ) ) ? |
75 | $displayParams['delimiter'] : wfMessage( 'comma-separator' )->text(); |
76 | $delimiter = str_replace( '\n', "\n", $delimiter ); |
77 | foreach ( $formattedValuesTable as $i => $row ) { |
78 | if ( $i > 0 ) { |
79 | $text .= $delimiter . ' '; |
80 | } |
81 | $text .= $this->displayRow( $row, $fieldDescriptions ); |
82 | } |
83 | return $text; |
84 | } |
85 | |
86 | } |