-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass-papi-property-table.php
More file actions
111 lines (91 loc) · 1.91 KB
/
class-papi-property-table.php
File metadata and controls
111 lines (91 loc) · 1.91 KB
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
<?php
/**
* Table property.
*/
class Papi_Property_Table extends Papi_Property {
/**
* The convert type.
*
* @var string
*/
public $convert_type = 'array';
/**
* Build table from array data.
*
* @param array $arr
* @param bool $child
*
* @return stringe
*/
protected function build_table( array $arr, $child = false ) {
$html = '<div class="papi-property-table"><table class="papi-table">';
if ( $child ) {
$html .= '<thead>';
foreach ( $arr[0] as $key => $value ) {
$html .= sprintf( '<th>%s</th>', $key );
}
$html .= '</thead>';
}
foreach ( $arr as $key => $value ) {
$html .= '<tr>';
foreach ( $value as $key2 => $value2 ) {
if ( is_array( $value2 ) ) {
$value2 = $this->build_table( $value2, true );
}
$html .= sprintf( '<td>%s</td>', papi_convert_to_string( $value2 ) );
}
$html .= '</tr>';
}
return $html . '</table></div>';
}
/**
* Render property html.
*/
public function html() {
$value = $this->get_value();
$data = $this->get_setting( 'items' );
if ( is_array( $data ) ) {
echo $this->build_table( $data );
} else {
echo 'Missing data';
}
}
/**
* Output property css.
*/
public function css() {
?>
<style>
.papi-property-table {
margin-right: -31px;
}
.papi-property-table > table {
margin: -11px 0 -10px -15px;
}
.papi-property-table > table th {
border-right: 1px solid #eaeaea;
padding: 10px 16px 10px 15px;
text-align: left;
vertical-align: top;
}
.papi-property-table > table th:last-child {
border-right: 0;
}
.papi-property-table > table td:first-child {
font-weight: bold;
}
.papi-property-table > table table td:first-child {
background: #fff;
font-weight: normal;
width: auto;
}
</style>
<?php
}
/**
* Setup actions.
*/
public function setup_actions() {
add_action( 'admin_head', [$this, 'css'] );
}
}