@@ -71,11 +71,11 @@ class Options extends Ext
71
71
/** @var bool Indicate if options should always be refreshed */
72
72
private $ _alwaysRefresh = true ;
73
73
74
- /** @var string Table to get the information from */
75
- private $ _table ;
74
+ /** @var callable|null */
75
+ private $ _customFn ;
76
76
77
- /** @var string Column name containing the value */
78
- private $ _value ;
77
+ /** @var string[] List of columns to include in the output */
78
+ private $ _includes = [] ;
79
79
80
80
/** @var string[] Column names for the label(s) */
81
81
private $ _label = [];
@@ -86,22 +86,26 @@ class Options extends Ext
86
86
/** @var int|null Row limit */
87
87
private $ _limit ;
88
88
89
+ /** @var array List of label / values to use if not database retrieved */
90
+ private $ _manualAdd = [];
91
+
92
+ /** @var string|bool ORDER BY clause */
93
+ private $ _order = true ;
94
+
89
95
/** @var callable Callback function to do rendering of labels */
90
96
private $ _renderer ;
91
97
92
98
/** @var bool Indicate if options should get got for create/edit or on search only */
93
99
private $ _searchOnly = false ;
94
100
101
+ /** @var string Table to get the information from */
102
+ private $ _table ;
103
+
95
104
/** @var callable Callback function to add where conditions */
96
105
private $ _where ;
97
106
98
- /** @var string|bool ORDER BY clause */
99
- private $ _order = true ;
100
-
101
- private $ _manualAdd = [];
102
-
103
- /** @var callable|null */
104
- private $ _customFn ;
107
+ /** @var string Column name containing the value */
108
+ private $ _value ;
105
109
106
110
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
107
111
* Public methods
@@ -156,6 +160,29 @@ public function fn($_ = null)
156
160
return $ this ->_getSet ($ this ->_customFn , $ _ );
157
161
}
158
162
163
+ /**
164
+ * Column names from `value()` and `label()` that should be included in the output object for
165
+ * each option, in addition to the value and label.
166
+ *
167
+ * @param string|string[] $inc The list of columns to include in the output
168
+ *
169
+ * @return ($_ is null ? string[] : $this)
170
+ */
171
+ public function include ($ inc = null )
172
+ {
173
+ if ($ inc === null ) {
174
+ return $ this ->_includes ;
175
+ }
176
+
177
+ if (is_array ($ inc )) {
178
+ $ this ->_includes = array_merge ($ this ->_includes , $ inc );
179
+ } else {
180
+ $ this ->_includes [] = $ inc ;
181
+ }
182
+
183
+ return $ this ;
184
+ }
185
+
159
186
/**
160
187
* Get / set the column(s) to use as the label value of the options.
161
188
*
@@ -392,10 +419,21 @@ public function exec($db, $refresh, $search = null)
392
419
// Apply the search to the rendered label. Need to do it here rather than in SQL since
393
420
// the label is rendered in PHP.
394
421
if ($ search === null || $ search === '' || stripos ($ rowLabel , $ search ) === 0 ) {
395
- $ out [] = [
422
+ $ option = [
396
423
'label ' => $ rowLabel ,
397
424
'value ' => $ rowValue ,
398
425
];
426
+
427
+ // Add in any columns that are needed for extra data (includes)
428
+ for ($ j = 0 ; $ j < count ($ this ->_includes ); ++$ j ) {
429
+ $ inc = $ this ->_includes [$ j ];
430
+
431
+ if (isset ($ rows [$ i ][$ inc ])) {
432
+ $ option [$ inc ] = $ rows [$ i ][$ inc ];
433
+ }
434
+ }
435
+
436
+ $ out [] = $ option ;
399
437
}
400
438
401
439
// Limit needs to be done in PHP to allow for the PHP based filtering above, and also
0 commit comments