Completed
Pull Request — master (#2409)
by mw
102:46 queued 68:04
created

HtmlTable::cell()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Utils;
4
5
use Html;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 3.0
10
 *
11
 * @author mwjames
12
 */
13
class HtmlTable {
14
15
	/**
16
	 * @since 3.0
17
	 *
18
	 * @param string $html
19
	 * @param array $attributes
20
	 *
21
	 * @return string
22
	 */
23
	public static function table( $html = '', array $attributes = array() ) {
24
		return self::open( $attributes ) . $html . self::close();
25
	}
26
27
	/**
28
	 * @since 3.0
29
	 *
30
	 * @param array $attributes
31
	 *
32
	 * @return string
33
	 */
34
	public static function open( array $attributes = array() ) {
35
		return Html::openElement(
36
			'div',
37
			self::mergeAttributes( 'smw-table', $attributes ),
38
			''
39
		);
40
	}
41
42
	/**
43
	 * @since 3.0
44
	 *
45
	 * @param string $html
46
	 * @param array $attributes
47
	 *
48
	 * @return string
49
	 */
50
	public static function header( $html = '', array $attributes = array() ) {
51
		return Html::rawElement(
52
			'div',
53
			self::mergeAttributes( 'smw-table-header', $attributes ),
54
			$html
55
		);
56
	}
57
58
	/**
59
	 * @since 3.0
60
	 *
61
	 * @param string $html
62
	 * @param array $attributes
63
	 *
64
	 * @return string
65
	 */
66
	public static function body( $html = '', array $attributes = array() ) {
67
		return Html::rawElement(
68
			'div',
69
			self::mergeAttributes( 'smw-table-body', $attributes ),
70
			$html
71
		);
72
	}
73
74
	/**
75
	 * @since 3.0
76
	 *
77
	 * @param string $html
78
	 * @param array $attributes
79
	 *
80
	 * @return string
81
	 */
82
	public static function footer( $html = '', array $attributes = array() ) {
83
		return Html::rawElement(
84
			'div',
85
			self::mergeAttributes( 'smw-table-footer', $attributes ),
86
			$html
87
		);
88
	}
89
90
	/**
91
	 * @since 3.0
92
	 *
93
	 * @param string $html
94
	 * @param array $attributes
95
	 *
96
	 * @return string
97
	 */
98
	public static function row( $html = '', array $attributes = array() ) {
99
		return Html::rawElement(
100
			'div',
101
			self::mergeAttributes( 'smw-table-row', $attributes ),
102
			$html
103
		);
104
	}
105
106
	/**
107
	 * @since 3.0
108
	 *
109
	 * @param string $html
110
	 * @param array $attributes
111
	 *
112
	 * @return string
113
	 */
114
	public static function cell( $html = '', array $attributes = array() ) {
115
		return Html::rawElement(
116
			'div',
117
			self::mergeAttributes( 'smw-table-cell', $attributes ),
118
			$html
119
		);
120
	}
121
122
	/**
123
	 * @since 3.0
124
	 *
125
	 * @return string
126
	 */
127
	public static function close() {
128
		return Html::closeElement(
129
			'div'
130
		);
131
	}
132
133
	private static function mergeAttributes( $class, $attributes ) {
134
135
		if ( isset( $attributes['class'] ) ) {
136
			$class .= ' ' . $attributes['class'];
137
			unset( $attributes['class'] );
138
		}
139
140
		$attributes['class'] = $class;
141
142
		return $attributes;
143
	}
144
145
}
146