summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/Utils/HtmlDivTable.php
blob: d968919b17cf1deab965498abd5a3bc57b6d3873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php

namespace SMW\Utils;

use Html;

/**
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class HtmlDivTable {

	/**
	 * @since 3.0
	 *
	 * @param string $html
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function table( $html = '', array $attributes = [] ) {
		return self::open( $attributes ) . $html . self::close();
	}

	/**
	 * @since 3.0
	 *
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function open( array $attributes = [] ) {
		return Html::openElement(
			'div',
			self::mergeAttributes( 'smw-table', $attributes ),
			''
		);
	}

	/**
	 * @since 3.0
	 *
	 * @param string $html
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function header( $html = '', array $attributes = [] ) {
		return Html::rawElement(
			'div',
			self::mergeAttributes( 'smw-table-header', $attributes ),
			$html
		);
	}

	/**
	 * @since 3.0
	 *
	 * @param string $html
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function body( $html = '', array $attributes = [] ) {
		return Html::rawElement(
			'div',
			self::mergeAttributes( 'smw-table-body', $attributes ),
			$html
		);
	}

	/**
	 * @since 3.0
	 *
	 * @param string $html
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function footer( $html = '', array $attributes = [] ) {
		return Html::rawElement(
			'div',
			self::mergeAttributes( 'smw-table-footer', $attributes ),
			$html
		);
	}

	/**
	 * @since 3.0
	 *
	 * @param string $html
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function row( $html = '', array $attributes = [] ) {
		return Html::rawElement(
			'div',
			self::mergeAttributes( 'smw-table-row', $attributes ),
			$html
		);
	}

	/**
	 * @since 3.0
	 *
	 * @param string $html
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function cell( $html = '', array $attributes = [] ) {
		return Html::rawElement(
			'div',
			self::mergeAttributes( 'smw-table-cell', $attributes ),
			$html
		);
	}

	/**
	 * @since 3.0
	 *
	 * @return string
	 */
	public static function close() {
		return Html::closeElement(
			'div'
		);
	}

	private static function mergeAttributes( $class, $attr ) {

		$attributes = [];

		// A bit of attribute order
		if ( isset( $attr['id'] ) ) {
			$attributes['id'] = $attr['id'];
		}

		if ( isset( $attr['class'] ) ) {
			$attributes['class'] = $class . ' ' . $attr['class'];
		} else {
			$attributes['class'] = $class;
		}

		return $attributes += $attr;
	}

}