1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace neon\cms\components; |
4
|
|
|
use \neon\daedalus\services\ddsManager\DdsDataDefinitionManager; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* This component allows you to make daedalus calls which then returns the results |
8
|
|
|
* to the template it was requested in. This is different to making a daedalus |
9
|
|
|
* call on a widget which only supplies the data to the widget |
10
|
|
|
*/ |
11
|
|
|
class Daedalus |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Page |
15
|
|
|
*/ |
16
|
|
|
private static $_choices = []; |
17
|
|
|
private static $_maps = []; |
18
|
|
|
protected $params = []; |
19
|
|
|
protected $renderer = null; |
20
|
|
|
|
21
|
|
|
// ---------- Daedalus Tags ---------- // |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Make a Daedalus request from within a template and assign to the template |
25
|
|
|
* |
26
|
|
|
* NOTE - these are requests which means they do not return a result immediately |
27
|
|
|
* but once the page has received all the requests and rerenders the page. Therefore |
28
|
|
|
* you must check to see if variable['data'] is not null before. |
29
|
|
|
* |
30
|
|
|
* The assigned parameter has three parts |
31
|
|
|
* ['data'] => the returned data from the database |
32
|
|
|
* ['meta'] => meta information about the data - currently start, length and total |
33
|
|
|
* |
34
|
|
|
* - edit no longer exists |
35
|
|
|
* ['edit'] => when in edit mode in the CMS this is editable data within the page |
36
|
|
|
* Use this if you want a user to be able to edit a field within the page directly |
37
|
|
|
* You can check 'hasResponse' and 'hasData' to see respectively if the request |
38
|
|
|
* has returned and whether or not there was anything returned. |
39
|
|
|
* |
40
|
|
|
* @param array $params The parameters needed in the tag |
41
|
|
|
* Usage: assuming tag is dds and where [...] implies optional |
42
|
|
|
* |
43
|
|
|
* ``` |
44
|
|
|
* {dds |
45
|
|
|
* class='class name' |
46
|
|
|
* [page=true | nice_id | page_id] |
47
|
|
|
* [filter=[filters]] |
48
|
|
|
* [order=[order clause]] |
49
|
|
|
* [limit=[limit clause]] |
50
|
|
|
* assign=variable} |
51
|
|
|
* ``` |
52
|
|
|
* where |
53
|
|
|
* Filter, order and limit are passed in as arrays. (These can also be passed |
54
|
|
|
* in as "almost JSON" strings with single quotes rather than double quotes, |
55
|
|
|
* but that approach is no longer recommended) |
56
|
|
|
* |
57
|
|
|
* class: [required] this is the dds class to fetch |
58
|
|
|
* page: [optional] - if set then a page filter is added to the class -if true |
59
|
|
|
* this is the current page, otherwise this can be the nice or page id of an |
60
|
|
|
* alternative page and that will be used |
61
|
|
|
* filter: [optional] - this is a list of filters that can be applied |
62
|
|
|
* to the request - e.g. filter=['field','=','value'] for a single |
63
|
|
|
* filter, or filter=[['field1','=','value1'],['field2','LIKE','val%']] |
64
|
|
|
* for multiple ANDed filters. |
65
|
|
|
* |
66
|
|
|
* A filter can also include arbitrary logic as in |
67
|
|
|
* filter=[['field1','=','2','K1'],['field2','>','3','K1'],'logic'=>'K1 AND NOT K2'] |
68
|
|
|
* |
69
|
|
|
* For more information @see IDdsObjectManagement, or Cobe's documentation |
70
|
|
|
* |
71
|
|
|
* order: [optional] - set the order as a series of fields and direction |
72
|
|
|
* e.g. ['field1'=>'ASC', 'field2'=>'DESC'] |
73
|
|
|
* limit: [optional] - set optional 'start', 'length', 'total' sections. |
74
|
|
|
* Default is 0 for start and a maximum of DdsCore::MAX_LENGTH. |
75
|
|
|
* If this is just a number then it is assumed to be the length. |
76
|
|
|
* Tf you want a total of possible results, e.g. for pagination, add a |
77
|
|
|
* 'total'=>true. The total is calculated only if start is zero |
78
|
|
|
* so store the total for subsequent pages. |
79
|
|
|
* e.g. ['start'=>0, 'length'=>5, 'total'=>true] |
80
|
|
|
* |
81
|
|
|
* assign: [required] set the variable you want to contain the returned data |
82
|
|
|
* |
83
|
|
|
* @param object $renderer the renderer e.g. smarty |
84
|
|
|
* @return |
85
|
|
|
*/ |
86
|
|
|
public static function dds($params, $renderer) |
87
|
|
|
{ |
88
|
|
|
(new Daedalus($params, $renderer))->query(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Make a Daedalus query from within a plugin and return the results once collected |
93
|
|
|
* |
94
|
|
|
* @see Daedalus::dds for details of the params object |
95
|
|
|
* @param array $params |
96
|
|
|
*/ |
97
|
|
|
public static function requestData($params) |
98
|
|
|
{ |
99
|
|
|
return (new Daedalus($params))->query(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get the available choices for a class member from within in a template |
104
|
|
|
* |
105
|
|
|
* @param array $params The array of parameters |
106
|
|
|
* Usage: where [...] implies optional |
107
|
|
|
* ``` |
108
|
|
|
* {dds_choice |
109
|
|
|
* [class='classType'] |
110
|
|
|
* member='[classType::]memberRef' |
111
|
|
|
* [order='true|ASC|DESC'] |
112
|
|
|
* assign='variable'} |
113
|
|
|
* ``` |
114
|
|
|
* where |
115
|
|
|
* member: [required] the scoped member reference if class is omitted |
116
|
|
|
* or the unscoped member reference if not. That is you can either |
117
|
|
|
* set this to 'classType::memberRef' or just 'memberRef'. In that |
118
|
|
|
* case you must pass in the classType using the class parameter |
119
|
|
|
* class: [optional] the class type if the member is not scoped by this |
120
|
|
|
* order: [optional] if set then order the choice - true or ASC mean by |
121
|
|
|
* by the value field ascending and DESC means descending. Leave off |
122
|
|
|
* if you want it as defined on the class member |
123
|
|
|
* assign: [required] the name of the variable to hold the results |
124
|
|
|
* |
125
|
|
|
* @param object $renderer |
126
|
|
|
* @return null|error returns errors if not valid |
|
|
|
|
127
|
|
|
*/ |
128
|
|
|
public static function dds_choice($params, $renderer) |
129
|
|
|
{ |
130
|
|
|
(new Daedalus($params, $renderer))->queryChoice(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get the available choices for a class member from within a plugin |
135
|
|
|
* @see dds_choice for details. The assign parameter is not required |
136
|
|
|
* @return null | array |
137
|
|
|
*/ |
138
|
|
|
public static function requestChoice($params) |
139
|
|
|
{ |
140
|
|
|
return (new Daedalus($params))->queryChoice(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get the available map for a class in a template |
145
|
|
|
* |
146
|
|
|
* @param array $params The array of parameters |
147
|
|
|
* Usage: where [...] implies optional |
148
|
|
|
* ``` |
149
|
|
|
* {dds_map class='class' assign='variable' [filters=[] flip=true] } |
150
|
|
|
* ``` |
151
|
|
|
* where |
152
|
|
|
* class: [required] the class type if the member is not scoped by this |
153
|
|
|
* assign: [required] the name of the variable to hold the results |
154
|
|
|
* filters: [optional] any additional field=>value filtering that may be required |
155
|
|
|
* flip: [optional] if set then assign the transpose of the map |
156
|
|
|
* |
157
|
|
|
* @param object $renderer |
158
|
|
|
* @return null|error returns errors if not valid |
159
|
|
|
*/ |
160
|
|
|
public static function dds_map($params, $renderer) |
161
|
|
|
{ |
162
|
|
|
(new Daedalus($params, $renderer))->queryMap(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get the available map for a class from within a plugin |
167
|
|
|
* @see dds_map for details. The assign parameter is not required |
168
|
|
|
* @return null|array |
169
|
|
|
*/ |
170
|
|
|
public static function requestMap($params) |
171
|
|
|
{ |
172
|
|
|
return (new Daedalus($params))->queryMap(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* |
177
|
|
|
* @param array $params any paramters from @see dds and dds_choice |
178
|
|
|
* @param object $renderer the render object |
179
|
|
|
*/ |
180
|
|
|
public function __construct($params, $renderer=null) |
181
|
|
|
{ |
182
|
|
|
$this->params = $params; |
183
|
|
|
$this->renderer = $renderer; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Make a query to the page and await it's return. Once returned assign to |
188
|
|
|
* the requested parameter if we are rendering or as a return parameter |
189
|
|
|
* @return null|errors|array returns errors if not valid, null if called |
|
|
|
|
190
|
|
|
* from within a template and the data if from within a plugin |
191
|
|
|
*/ |
192
|
|
|
protected function query() |
193
|
|
|
{ |
194
|
|
|
try { |
195
|
|
|
$this->params = $this->canonicalise($this->params); |
196
|
|
|
} catch (\Exception $e) { |
197
|
|
|
return $e->getMessage(); |
198
|
|
|
} |
199
|
|
|
self::buildDataFromDdsAttributes($this->params, neon()->cms->getPage()->getId()); |
|
|
|
|
200
|
|
|
$result = ['hasData'=>false, 'hasResponse'=>false, 'data'=>[], 'meta'=>[], 'edit'=>[]]; |
201
|
|
|
if (isset($this->params['data'])) { |
202
|
|
|
$request = self::convertDataRequestToJson($this->params['data']); |
203
|
|
|
$responded = neon()->cms->getPage()->requestWidgetData($request, $data, $id, false, $meta); |
204
|
|
|
if ($responded) { |
205
|
|
|
$result['hasData'] = count($data)>0; |
206
|
|
|
$result['hasResponse'] = true; |
207
|
|
|
$result['data'] = $data; |
208
|
|
|
$result['meta'] = $meta; |
209
|
|
|
// $result['edit'] = $this->createEditable($data); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
if ($this->renderer) |
213
|
|
|
$this->renderer->assign($this->params['assign'], $result); |
214
|
|
|
else |
215
|
|
|
return $result; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* get the choices for a particular class member |
220
|
|
|
* TODO make this use the page to do the query |
221
|
|
|
* Params should contain |
222
|
|
|
* 'class' for the object class |
223
|
|
|
* 'member' for which member you want the choices of |
224
|
|
|
* These can be combined as 'class::member' |
225
|
|
|
* @param boolean $template if true then assign to the template otherwise |
226
|
|
|
* return the value |
227
|
|
|
* @return null|errors|array returns errors if not valid, null if called |
228
|
|
|
* from within a template and the data if from within a plugin |
229
|
|
|
*/ |
230
|
|
|
protected function queryChoice($template=true) |
|
|
|
|
231
|
|
|
{ |
232
|
|
|
// check usage |
233
|
|
|
if (!isset($this->params['member'])) |
234
|
|
|
return "Usage: you must provide a 'member' parameter. You provided ".print_r($this->params,true); |
|
|
|
|
235
|
|
|
if ($this->renderer && !isset($this->params['assign'])) |
236
|
|
|
return "Usage: you must provide an 'assign' parameter. You provided ".print_r($this->params,true); |
237
|
|
|
if (strpos($this->params['member'],':') === false && !isset($this->params['class'])) |
238
|
|
|
return "Usage: if you do not scope the member as class::member then you must provide the class parameter"; |
239
|
|
|
|
240
|
|
|
// extract out class and member |
241
|
|
|
$class = null; |
242
|
|
|
$member = null; |
243
|
|
|
if (strpos($this->params['member'],':') !== false) |
244
|
|
|
list ($class, $member) = explode(':', str_replace('::',':',$this->params['member'])); |
245
|
|
|
else { |
246
|
|
|
$class = $this->params['class']; |
247
|
|
|
$member = $this->params['member']; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
// now find the results |
251
|
|
|
// Q. Should this be something that the page should do in conjunction with Daedalus to |
252
|
|
|
// run all of the queries at one go? Likely to be very few examples on a page though ... |
253
|
|
|
$key = "$class::$member"; |
254
|
|
|
if (!isset(self::$_choices[$key])) { |
255
|
|
|
$dds = neon('dds')->iDdsClassManagement; |
|
|
|
|
256
|
|
|
$result = $dds->getMember($class, $member, ['choices']); |
|
|
|
|
257
|
|
|
if (!empty($result) && isset($result['choices'])) |
258
|
|
|
self::$_choices[$key] = $result['choices']; |
259
|
|
|
else |
260
|
|
|
self::$_choices[$key] = []; |
261
|
|
|
} |
262
|
|
|
$choices = self::$_choices[$key]; |
263
|
|
|
if (isset($this->params['order'])) { |
264
|
|
|
if ($this->params['order'] === 'DESC') { |
265
|
|
|
arsort($choices); |
266
|
|
|
} else { |
267
|
|
|
asort($choices); |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
if ($this->renderer) |
271
|
|
|
$this->renderer->assign($this->params['assign'], $choices); |
272
|
|
|
else |
273
|
|
|
return $choices; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* get the map for a particular class |
278
|
|
|
* TODO make this use the page to do the query |
279
|
|
|
* Params should include |
280
|
|
|
* 'class' => the class you want to use |
281
|
|
|
* 'assign' => what variable you are assigning to if within a template |
282
|
|
|
* 'flip' => flip the map (swap keys and values) |
283
|
|
|
* 'fields' => set to map different fields from the default map field |
284
|
|
|
* in the order you want them combined. |
285
|
|
|
* @return null|errors|data returns errors if not valid, null if called |
|
|
|
|
286
|
|
|
* from within a template and the data if from within a plugin |
287
|
|
|
*/ |
288
|
|
|
protected function queryMap() |
289
|
|
|
{ |
290
|
|
|
// check usage |
291
|
|
|
if (!isset($this->params['class'])) |
292
|
|
|
return "Usage: you must provide a 'class' parameter. You provided ".print_r($this->params,true); |
|
|
|
|
293
|
|
|
|
294
|
|
|
if ($this->renderer && !isset($this->params['assign'])) |
295
|
|
|
return "Usage: you must provide an 'assign' parameter. You provided ".print_r($this->params,true); |
296
|
|
|
|
297
|
|
|
$fields = isset($this->params['fields']) ? $this->params['fields'] : []; |
298
|
|
|
|
299
|
|
|
// extract out class and member |
300
|
|
|
$class = $this->params['class']; |
301
|
|
|
|
302
|
|
|
// and any filters |
303
|
|
|
$filters = (!empty($this->params['filters']) ? $this->params['filters'] : []); |
304
|
|
|
|
305
|
|
|
// now find the results |
306
|
|
|
// Q. Should this be something that the page should do in conjunction with Daedalus to |
307
|
|
|
// run all of the queries at one go? Likely to be very few examples on a page though ... |
308
|
|
|
if (!isset(self::$_maps[$class])) { |
309
|
|
|
$dds = neon('dds')->iDdsObjectManagement; |
|
|
|
|
310
|
|
|
$result = $dds->getObjectMap($class, $filters, $fields); |
311
|
|
|
self::$_maps[$class] = $result; |
312
|
|
|
} |
313
|
|
|
$map = self::$_maps[$class]; |
314
|
|
|
if (isset($this->params['flip'])) |
315
|
|
|
$map = array_flip($map); |
316
|
|
|
|
317
|
|
|
if ($this->renderer) |
318
|
|
|
$this->renderer->assign($this->params['assign'], $map); |
319
|
|
|
return $map; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Get the data request from the data string. |
324
|
|
|
* Override this if you have a different way of defining your data request |
325
|
|
|
* @throws \Exception If request didn't decode from JSON properly |
326
|
|
|
* @return array |
327
|
|
|
*/ |
328
|
|
|
public static function convertDataRequestToJson($data) |
329
|
|
|
{ |
330
|
|
|
$request = null; |
331
|
|
|
$json = trim(str_replace("'", '"', $data)); |
332
|
|
|
if (strlen($json) > 0) { |
333
|
|
|
// for convenience the beginning and ending brackets are optional so add if not supplied |
334
|
|
|
if (strpos($json, '{') !== 0) |
335
|
|
|
$json = '{'.$json.'}'; |
336
|
|
|
$request = json_decode($json, true); |
337
|
|
|
if ($request === null) |
338
|
|
|
throw new \Exception("Failing to json decode the data request: $json converted from $data. "); |
339
|
|
|
} |
340
|
|
|
return $request; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Create a data request from dds_xxx provided parameters in $params |
346
|
|
|
* This is suitable for requests of dynamic content |
347
|
|
|
* These are one of |
348
|
|
|
* dds | dds_class - required |
349
|
|
|
* dds_page - add a page filter set to true for current page or the nice_id |
350
|
|
|
* of another page if you want to filter by that one |
351
|
|
|
* dds_filter - set of filters on the class |
352
|
|
|
* dds_order - ordering for the results |
353
|
|
|
* dds_limit - iterator over the results |
354
|
|
|
* @param array &$params the set of params including the above |
355
|
|
|
* This will have a 'data' key added created from the above |
356
|
|
|
*/ |
357
|
|
|
public static function buildDataFromDdsAttributes(&$params) |
358
|
|
|
{ |
359
|
|
|
$dpa = ['dds', 'dds_class', 'dds_page', 'dds_filter', 'dds_order', 'dds_limit']; |
360
|
|
|
$dps = array_intersect_key($params, array_flip($dpa)); |
361
|
|
|
if (count($dps)) { |
362
|
|
|
$data = []; |
363
|
|
|
if ((isset($dps['dds']) || isset($dps['dds_page'])) && empty($dps['dds_class'])) |
364
|
|
|
$dps['dds_class'] = $params['type']; |
365
|
|
|
if (isset($dps['dds_class'])) |
366
|
|
|
$data[] = "'class':'$dps[dds_class]'"; |
367
|
|
|
|
368
|
|
|
// create the filters |
369
|
|
|
$filters = []; |
370
|
|
|
|
371
|
|
|
// create the page specific filter |
372
|
|
|
if (!empty($dps['dds_page'])) { |
373
|
|
|
$pageId = null; |
374
|
|
|
if ($dps['dds_page'] === true || $dps['dds_page'] === 'true') |
375
|
|
|
$pageId = neon()->cms->getPage()->getId(); |
376
|
|
|
else { |
377
|
|
|
// either a nice id or a page id |
378
|
|
|
// $pageId = self::$page->niceId2PageId($dps['dds_page']); |
379
|
|
|
// if (!$pageId) |
380
|
|
|
// SO: commented out the above because niceId2PageId does not exist as a function on the $page |
381
|
|
|
// object therefore has not worked for a while! |
382
|
|
|
$pageId = $dps['dds_page']; |
383
|
|
|
} |
384
|
|
|
if ($pageId) |
385
|
|
|
$filters[] = "['page_id','=','$pageId']"; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
// add other filters |
389
|
|
|
if (isset($dps['dds_filter']) && !empty($dps['dds_filter'])) { |
390
|
|
|
if (is_array($dps['dds_filter'])) |
391
|
|
|
$filters[] = json_encode($dps['dds_filter']); |
392
|
|
|
// else deprecated json approach |
393
|
|
|
else if (strpos(trim($dps['dds_filter']), '[')!==0) |
394
|
|
|
$filters[] = "[$dps[dds_filter]]"; |
395
|
|
|
else |
396
|
|
|
$filters[] = $dps['dds_filter']; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
// create the filters clause |
400
|
|
|
if (count($filters)) |
401
|
|
|
$data[] = "'filters':".implode(',',$filters); |
402
|
|
|
|
403
|
|
|
// sort out the order |
404
|
|
|
if (isset($dps['dds_order'])) { |
405
|
|
|
if (is_array($dps['dds_order'])) |
406
|
|
|
$data[] = "'order':".json_encode($dps['dds_order']); |
407
|
|
|
// else deprecated json approach |
408
|
|
|
else |
409
|
|
|
$data[] = "'order':{".$dps['dds_order']."}"; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
// sort out the limit |
413
|
|
|
if (isset($dps['dds_limit'])) { |
414
|
|
|
if (is_numeric($dps['dds_limit'])) |
415
|
|
|
$data[] = "'limit':{'length':$dps[dds_limit]}"; |
416
|
|
|
else if (is_array($dps['dds_limit'])) |
417
|
|
|
$data[] = "'limit':".json_encode($dps['dds_limit']); |
418
|
|
|
// else deprecated json approach |
419
|
|
|
else |
420
|
|
|
$data[] = "'limit':{".$dps['dds_limit']."}"; |
421
|
|
|
} |
422
|
|
|
$params['data'] = '{'.implode(', ', $data).'}'; |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* because the component is associated with the smarty tag dds, there is |
428
|
|
|
* no need to prefix the request with dds. However in case they do and |
429
|
|
|
* because the conversion to data is provided to the widget which does |
430
|
|
|
* require the dds_ prefix, we add the prefix here |
431
|
|
|
* @param array $params |
432
|
|
|
* @return array the canonicalised params |
433
|
|
|
*/ |
434
|
|
|
protected function canonicalise($params) |
435
|
|
|
{ |
436
|
|
|
$canon = []; |
437
|
|
|
if (empty($params['assign']) && $this->renderer !== null) |
438
|
|
|
throw new \InvalidArgumentException("You must set an 'assign' parameter when using the 'dds' tag"); |
439
|
|
|
foreach ($params as $k => $v) { |
440
|
|
|
if ($k == 'assign') { |
441
|
|
|
$canon[$k] = $v; |
442
|
|
|
continue; |
443
|
|
|
} |
444
|
|
|
$key = strpos($k, 'dds_') === 0 ? $k : 'dds_'.$k; |
445
|
|
|
$canon[$key] = $v; |
446
|
|
|
} |
447
|
|
|
return $canon; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Create the editable data ($edit) array for use in |
452
|
|
|
* inline editable areas. This must be identical to $this->data if |
453
|
|
|
* the page is not being edited, or allow inline editing if the page is being |
454
|
|
|
* edited. If you override this make sure that is true. |
455
|
|
|
* |
456
|
|
|
* @return & array a reference to the array of $edit |
|
|
|
|
457
|
|
|
* @deprecated |
458
|
|
|
*/ |
459
|
|
|
public static function & createEditable(&$data) |
460
|
|
|
{ |
461
|
|
|
$edit = []; |
462
|
|
|
$page = neon()->cms->getPage(); |
463
|
|
|
if ($page->isInEditMode()) { |
464
|
|
|
foreach ($data as $i => $d) { |
465
|
|
|
$classType = $d['_class_type']; |
466
|
|
|
foreach ($d as $field=>$value) { |
467
|
|
|
// ignore all bookkeeping fields |
468
|
|
|
if (strpos($field, '_')===0) |
469
|
|
|
continue; |
470
|
|
|
$edit[$i][$field] = self::createFieldEditable($classType, $field, $d['_uuid'], $value); |
|
|
|
|
471
|
|
|
} |
472
|
|
|
} |
473
|
|
|
} else { |
474
|
|
|
$edit = &$data; |
475
|
|
|
} |
476
|
|
|
return $edit; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Create an editable version of a dynamic data field |
481
|
|
|
* @param string $key the static content editable type |
482
|
|
|
* @param string $value the value to be displayed |
483
|
|
|
* @return string the editable version of the data |
484
|
|
|
* @todo: This needs to be deprecated - or fixed somehow - this vue component (neon-cobe-editor) only exists |
485
|
|
|
* in an experimental branch based on work by Luke. |
486
|
|
|
* It doesn't exist now. |
487
|
|
|
* A more robust solution is required to cater for using dynamic data in html attributes (typically anchor href tags) |
488
|
|
|
* @deprecated |
489
|
|
|
*/ |
490
|
|
|
public static function createFieldEditable($classType, $field, $key, $value) |
491
|
|
|
{ |
492
|
|
|
if (is_array($value)) |
|
|
|
|
493
|
|
|
return $value; |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* This needs to be changed to generate an appropriate form to edit the |
497
|
|
|
* required form so a person can edit the appropriate database element. |
498
|
|
|
* For now we don't do anything and editing of a daedalus object is |
499
|
|
|
* no longer available. |
500
|
|
|
*/ |
501
|
|
|
return "<neon-cobe-editor value='$value' class-type='$classType' field='$field' uuid='$key' class='cobe-editable' >$value</neon-cobe-editor>"; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
} |
505
|
|
|
|