1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* UIX Grid |
4
|
|
|
* |
5
|
|
|
* @package ui |
6
|
|
|
* @author David Cramer |
7
|
|
|
* @license GPL-2.0+ |
8
|
|
|
* @link |
9
|
|
|
* @copyright 2016 David Cramer |
10
|
|
|
*/ |
11
|
|
|
namespace uix\ui; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A Grid system for layout control |
15
|
|
|
* |
16
|
|
|
* @since 1.0.0 |
17
|
|
|
* @see \uix\uix |
18
|
|
|
*/ |
19
|
|
|
class grid extends section { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The type of object |
23
|
|
|
* |
24
|
|
|
* @since 1.0.0 |
25
|
|
|
* @access public |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $type = 'grid'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* List of attributes to apply to the wrapper element |
32
|
|
|
* |
33
|
|
|
* @since 1.0.0 |
34
|
|
|
* @access public |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
public $attributes = array( 'class' => 'uix-grid' ); |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Set the grid params |
42
|
|
|
* |
43
|
|
|
* @since 1.0.0 |
44
|
|
|
* @access public |
45
|
|
|
*/ |
46
|
|
|
public function setup() { |
47
|
|
|
|
48
|
|
|
if ( ! empty( $this->struct['row'] ) ) { |
49
|
|
|
$this->struct['grid'] = $this->struct['row']; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ( ! empty( $this->struct['column'] ) ) { |
53
|
|
|
$this->struct['grid'] = $this->struct['column']; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
parent::setup(); |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get Data from all controls of this section |
62
|
|
|
* |
63
|
|
|
* @since 1.0.0 |
64
|
|
|
* @see \uix\load |
65
|
|
|
* @return array|null Array of sections data structured by the controls |
66
|
|
|
*/ |
67
|
|
|
public function get_data() { |
68
|
|
|
|
69
|
|
|
$data = $this->get_child_data(); |
70
|
|
|
if ( empty( $data ) ) { |
71
|
|
|
$data = null; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $data; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Sets the data for all children |
79
|
|
|
* |
80
|
|
|
* @since 1.0.0 |
81
|
|
|
* @access public |
82
|
|
|
*/ |
83
|
|
|
public function set_data( $data ) { |
84
|
|
|
|
85
|
|
|
foreach ( $this->child as $child ) { |
86
|
|
|
if ( method_exists( $child, 'set_data' ) ) { |
87
|
|
|
$child->set_data( $data ); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
$this->data = $data; |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get Data from all controls of this section |
96
|
|
|
* |
97
|
|
|
* @since 1.0.0 |
98
|
|
|
* @see \uix\load |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
public function is_row_column() { |
102
|
|
|
return ! empty( $this->struct['row'] ) || ! empty( $this->struct['column'] ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Sets the wrappers attributes |
107
|
|
|
* |
108
|
|
|
* @since 1.0.0 |
109
|
|
|
* @access public |
110
|
|
|
*/ |
111
|
|
View Code Duplication |
public function set_attributes() { |
|
|
|
|
112
|
|
|
|
113
|
|
|
if ( ! empty( $this->struct['column'] ) ) { |
114
|
|
|
$this->attributes['class'] = 'row'; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
if ( ! empty( $this->struct['size'] ) ) { |
118
|
|
|
$this->attributes['class'] = $this->struct['size']; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
parent::set_attributes(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Render the complete section |
126
|
|
|
* |
127
|
|
|
* @since 1.0.0 |
128
|
|
|
* @access public |
129
|
|
|
* @return string|null HTML of rendered notice |
130
|
|
|
*/ |
131
|
|
|
public function render() { |
132
|
|
|
|
133
|
|
|
$output = '<div ' . $this->build_attributes() . '>'; |
134
|
|
|
$output .= $this->render_children(); |
135
|
|
|
$output .= '</div>'; |
136
|
|
|
|
137
|
|
|
return $output; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Define core header styles |
142
|
|
|
* |
143
|
|
|
* @since 1.0.0 |
144
|
|
|
* @access public |
145
|
|
|
*/ |
146
|
|
|
public function set_assets() { |
147
|
|
|
|
148
|
|
|
$this->assets['style']['grid'] = $this->url . 'assets/css/grid' . UIX_ASSET_DEBUG . '.css'; |
149
|
|
|
|
150
|
|
|
parent::set_assets(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
} |
154
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.