1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WikibaseQuality\ConstraintReport\Html; |
4
|
|
|
|
5
|
|
|
use Html; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
use Wikimedia\Assert\Assert; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author BP2014N1 |
11
|
|
|
* @license GPL-2.0-or-later |
12
|
|
|
*/ |
13
|
|
|
class HtmlTableHeaderBuilder { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Html content of the header |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $content; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Determines, whether the column should be sortable or not. |
24
|
|
|
* |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private $isSortable; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Determines, whether the content is raw html or should be escaped. |
31
|
|
|
* |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
private $isRawContent; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $content HTML |
38
|
|
|
* @param bool $isSortable |
39
|
|
|
* @param bool $isRawContent |
40
|
|
|
* |
41
|
|
|
* @throws InvalidArgumentException |
42
|
|
|
*/ |
43
|
|
|
public function __construct( $content, $isSortable = false, $isRawContent = false ) { |
44
|
|
|
Assert::parameterType( 'string', $content, '$content' ); |
45
|
|
|
Assert::parameterType( 'boolean', $isSortable, '$isSortable' ); |
46
|
|
|
Assert::parameterType( 'boolean', $isRawContent, '$isRawContent' ); |
47
|
|
|
|
48
|
|
|
$this->content = $content; |
49
|
|
|
$this->isSortable = $isSortable; |
50
|
|
|
$this->isRawContent = $isRawContent; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getContent() { |
57
|
|
|
return $this->content; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
public function getIsSortable() { |
64
|
|
|
return $this->isSortable; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns header as html. |
69
|
|
|
* |
70
|
|
|
* @return string HTML |
71
|
|
|
*/ |
72
|
|
|
public function toHtml() { |
73
|
|
|
$attributes = [ 'role' => 'columnheader button' ]; |
74
|
|
|
|
75
|
|
|
if ( !$this->isSortable ) { |
76
|
|
|
$attributes['class'] = 'unsortable'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$content = $this->content; |
80
|
|
|
if ( !$this->isRawContent ) { |
81
|
|
|
$content = htmlspecialchars( $this->content ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return Html::rawElement( 'th', $attributes, $content ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|