Completed
Push — master ( 9b2539...51b667 )
by Daniel
02:30
created

getFieldOutputEnumSetReadOnly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2015 Daniel Popiniuc
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
 * SOFTWARE.
26
 *
27
 */
28
29
namespace danielgp\common_lib;
30
31
/**
32
 * usefull functions to get quick results
33
 *
34
 * @author Daniel Popiniuc
35
 */
36
trait MySQLiAdvancedOutput
37
{
38
39
    use MySQLiByDanielGPstructures;
40
41
    protected $advCache = null;
42
43
    /**
44
     * Establish Database and Table intended to work with
45
     * (in case the DB is ommited get the default one)
46
     *
47
     * @param string $tblSrc
48
     */
49
    private function establishDatabaseAndTable($tblSrc)
50
    {
51
        if (strpos($tblSrc, '.') === false) {
52
            if (!array_key_exists('workingDatabase', $this->advCache)) {
53
                $this->advCache['workingDatabase'] = $this->getMySqlCurrentDatabase();
54
            }
55
            return [$this->advCache['workingDatabase'], $tblSrc];
56
        }
57
        return explode('.', str_replace('`', '', $tblSrc));
58
    }
59
60
    /**
61
     * Returns the name of a field for displaying
62
     *
63
     * @param array $details
64
     * @return string
65
     */
66
    private function getFieldNameForDisplay($details)
67
    {
68
        $tableUniqueId = $details['TABLE_SCHEMA'] . '.' . $details['TABLE_NAME'];
69
        if ($details['COLUMN_COMMENT'] != '') {
70
            return $details['COLUMN_COMMENT'];
71
        } elseif (isset($this->advCache['tableStructureLocales'][$tableUniqueId][$details['COLUMN_NAME']])) {
72
            return $this->advCache['tableStructureLocales'][$tableUniqueId][$details['COLUMN_NAME']];
73
        }
74
        return $details['COLUMN_NAME'];
75
    }
76
77
    /**
78
     * Returns a Date field 2 use in a form
79
     *
80
     * @param array $value
81
     * @return string
82
     */
83
    private function getFieldOutputDate($value)
84
    {
85
        $defaultValue = $this->getFieldValue($value);
86
        if (is_null($defaultValue)) {
87
            $defaultValue = date('Y-m-d');
88
        }
89
        $inA = [
90
            'type'      => 'text',
91
            'name'      => $value['Field'],
92
            'id'        => $value['Field'],
93
            'value'     => $defaultValue,
94
            'size'      => 10,
95
            'maxlength' => 10,
96
            'onfocus'   => implode('', [
97
                'javascript:NewCssCal(\'' . $value['Field'],
98
                '\',\'yyyyMMdd\',\'dropdown\',false,\'24\',false);',
99
            ]),
100
        ];
101
        return $this->setStringIntoShortTag('input', $inA) . $this->setCalendarControl($value['Field']);
102
    }
103
104
    /**
105
     * Returns a Enum or Set field to use in form
106
     *
107
     * @param string $tblSrc
108
     * @param string $fldType
109
     * @param array $val
110
     * @param array $iar
111
     * @return string
112
     */
113
    private function getFieldOutputEnumSet($tblSrc, $fldType, $val, $iar = [])
114
    {
115
        $adnlThings = $this->establishDefaultEnumSet($fldType);
116
        if (array_key_exists('readonly', $val)) {
117
            return $this->getFieldOutputEnumSetReadOnly($val, $adnlThings);
118
        }
119
        $inAdtnl = $adnlThings['additional'];
120
        if ($iar !== []) {
121
            $inAdtnl = array_merge($inAdtnl, $iar);
122
        }
123
        $vlSlct    = explode(',', $this->getFieldValue($val));
124
        $slctOptns = $this->getSetOrEnum2Array($tblSrc, $val['COLUMN_NAME']);
125
        return $this->setArrayToSelect($slctOptns, $vlSlct, $val['COLUMN_NAME'] . $adnlThings['suffix'], $inAdtnl);
126
    }
127
128
    /**
129
     * Returns a Numeric field 2 use in a form
130
     *
131
     * @param string $tblSrc
132
     * @param array $value
133
     * @param array $iar
134
     * @return string
135
     */
136
    private function getFieldOutputNumeric($tblSrc, $value, $iar = [])
137
    {
138
        if ($value['EXTRA'] == 'auto_increment') {
139
            return $this->getFieldOutputNumericAI($value, $iar);
140
        }
141
        $fkArray = $this->getForeignKeysToArray($this->advCache['workingDatabase'], $tblSrc, $value['COLUMN_NAME']);
142
        if (is_null($fkArray)) {
143
            $fldNos = $this->setFieldNumbers($value);
144
            return $this->getFieldOutputTT($value, min(50, $fldNos['l']), $iar);
145
        }
146
        return $this->getFieldOutputNumericNonFK($fkArray, $value, $iar);
147
    }
148
149
    /**
150
     * Handles creation of Auto Increment numeric field type output
151
     *
152
     * @param array $value
153
     * @param array $iar
154
     * @return string
155
     */
156
    private function getFieldOutputNumericAI($value, $iar = [])
157
    {
158
        if ($this->getFieldValue($value) == '') {
159
            $spF = ['id' => $value['COLUMN_NAME'], 'style' => 'font-style:italic;'];
160
            return $this->setStringIntoTag('auto-numar', 'span', $spF);
161
        }
162
        $inAdtnl = [
163
            'type'  => 'hidden',
164
            'name'  => $value['COLUMN_NAME'],
165
            'id'    => $value['COLUMN_NAME'],
166
            'value' => $this->getFieldValue($value),
167
        ];
168
        if ($iar !== []) {
169
            $inAdtnl = array_merge($inAdtnl, $iar);
170
        }
171
        return '<b>' . $this->getFieldValue($value) . '</b>' . $this->setStringIntoShortTag('input', $inAdtnl);
172
    }
173
174
    /**
175
     * Builds field output type for numeric types if not FK
176
     *
177
     * @param array $fkArray
178
     * @param array $value
179
     * @param array $iar
180
     * @return string
181
     */
182
    private function getFieldOutputNumericNonFK($fkArray, $value, $iar = [])
183
    {
184
        $query         = $this->sQueryGenericSelectKeyValue([
185
            $fkArray[$value['COLUMN_NAME']][1],
186
            $fkArray[$value['COLUMN_NAME']][2],
187
            $fkArray[$value['COLUMN_NAME']][0],
188
        ]);
189
        $selectOptions = $this->setMySQLquery2Server($query, 'array_key_value')['result'];
190
        $selectValue   = $this->getFieldValue($value);
191
        $inAdtnl       = ['size' => 1];
192
        if ($value['IS_NULLABLE'] == 'YES') {
193
            $inAdtnl = array_merge($inAdtnl, ['include_null']);
194
        }
195
        if ($iar !== []) {
196
            $inAdtnl = array_merge($inAdtnl, $iar);
197
        }
198
        return $this->setArrayToSelect($selectOptions, $selectValue, $value['COLUMN_NAME'], $inAdtnl);
199
    }
200
201
    /**
202
     * Returns a Char field 2 use in a form
203
     *
204
     * @param string $tbl
205
     * @param string $fieldType
206
     * @param array $value
207
     * @param array $iar
208
     * @return string
209
     */
210
    private function getFieldOutputText($tbl, $fieldType, $value, $iar = [])
211
    {
212
        if (!in_array($fieldType, ['char', 'tinytext', 'varchar'])) {
213
            return '';
214
        }
215
        $foreignKeysArray = $this->getFieldOutputTextPrerequisites($tbl, $value);
216
        if (!is_null($foreignKeysArray)) {
217
            return $this->getFieldOutputTextFK($foreignKeysArray, $value, $iar);
218
        }
219
        return $this->getFieldOutputTextNonFK($value, $iar);
220
    }
221
222
    /**
223
     * Returns a Text field 2 use in a form
224
     *
225
     * @param string $fieldType
226
     * @param array $value
227
     * @param array $iar
228
     * @return string
229
     */
230
    private function getFieldOutputTextLarge($fieldType, $value, $iar = [])
231
    {
232
        if (!in_array($fieldType, ['blob', 'text'])) {
233
            return '';
234
        }
235
        $inAdtnl = [
236
            'name' => $value['COLUMN_NAME'],
237
            'id'   => $value['COLUMN_NAME'],
238
            'rows' => 4,
239
            'cols' => 55,
240
        ];
241
        if ($iar !== []) {
242
            $inAdtnl = array_merge($inAdtnl, $iar);
243
        }
244
        return $this->setStringIntoTag($this->getFieldValue($value), 'textarea', $inAdtnl);
245
    }
246
247
    /**
248
     * Prepares the text output fields
249
     *
250
     * @param string $tbl
251
     * @param array $value
252
     * @return null|array
253
     */
254
    private function getFieldOutputTextPrerequisites($tbl, $value)
255
    {
256
        $foreignKeysArray = null;
257
        if (($tbl != 'user_rights') && ($value['COLUMN_NAME'] != 'eid')) {
258
            $database = $this->advCache['workingDatabase'];
259
            if (strpos($tbl, '`.`')) {
260
                $database = substr($tbl, 0, strpos($tbl, '`.`'));
261
            }
262
            $foreignKeysArray = $this->getForeignKeysToArray($database, $tbl, $value['COLUMN_NAME']);
263
        }
264
        return $foreignKeysArray;
265
    }
266
267
    /**
268
     * Returns a Time field 2 use in a form
269
     *
270
     * @param array $value
271
     * @param array $iar
272
     * @return string
273
     */
274
    private function getFieldOutputTime($value, $iar = [])
275
    {
276
        return $this->getFieldOutputTT($value, 8, $iar);
277
    }
278
279
    /**
280
     * Returns a Timestamp field 2 use in a form
281
     *
282
     * @param array $dtl
283
     * @param array $iar
284
     * @return string
285
     */
286
    private function getFieldOutputTimestamp($dtl, $iar = [])
287
    {
288
        if (($dtl['COLUMN_DEFAULT'] == 'CURRENT_TIMESTAMP') || ($dtl['EXTRA'] == 'on update CURRENT_TIMESTAMP')) {
289
            return $this->getTimestamping($dtl)['input'];
290
        }
291
        $input = $this->getFieldOutputTT($dtl, 19, $iar);
292
        if (!array_key_exists('readonly', $iar)) {
293
            $input .= $this->setCalendarControlWithTime($dtl['COLUMN_NAME']);
294
        }
295
        return $input;
296
    }
297
298
    /**
299
     * Returns a Year field 2 use in a form
300
     *
301
     * @param array $details
302
     * @param array $iar
303
     * @return string
304
     */
305
    private function getFieldOutputYear($tblName, $details, $iar)
306
    {
307
        $listOfValues = [];
308
        for ($cntr = 1901; $cntr <= 2155; $cntr++) {
309
            $listOfValues[$cntr] = $cntr;
310
        }
311
        if ($iar == []) {
312
            $slDflt = $this->getFieldValue($details);
313
            return $this->setArrayToSelect($listOfValues, $slDflt, $details['COLUMN_NAME'], ['size' => 1]);
314
        }
315
        return $this->getFieldOutputText($tblName, 'varchar', $details, $iar);
316
    }
317
318
    /**
319
     * Returns an array with fields referenced by a Foreign key
320
     *
321
     * @param string $database
322
     * @param string $tblName
323
     * @param string|array $onlyCol
324
     * @return array
325
     */
326
    private function getForeignKeysToArray($database, $tblName, $onlyCol = '')
327
    {
328
        $this->setTableForeignKeyCache($database, $this->fixTableSource($tblName));
329
        $array2return = null;
330
        if (isset($this->advCache['tableFKs'][$database][$tblName])) {
331
            foreach ($this->advCache['tableFKs'][$database][$tblName] as $value) {
332
                if ($value['COLUMN_NAME'] == $onlyCol) {
333
                    $query                  = $this->getForeignKeysQuery($value);
334
                    $targetTblTxtFlds       = $this->setMySQLquery2Server($query, 'full_array_key_numbered')['result'];
335
                    $array2return[$onlyCol] = [
336
                        $this->glueDbTb($value['REFERENCED_TABLE_SCHEMA'], $value['REFERENCED_TABLE_NAME']),
337
                        $value['REFERENCED_COLUMN_NAME'],
338
                        '`' . $targetTblTxtFlds[0]['COLUMN_NAME'] . '`',
339
                    ];
340
                }
341
            }
342
        }
343
        return $array2return;
344
    }
345
346
    /**
347
     * Build label html tag
348
     *
349
     * @param array $details
350
     * @return string
351
     */
352
    private function getLabel($details)
353
    {
354
        return '<span class="fake_label">' . $this->getFieldNameForDisplay($details) . '</span>';
355
    }
356
357
    /**
358
     * Returns an array with possible values of a SET or ENUM column
359
     *
360
     * @param string $refTbl
361
     * @param string $refCol
362
     * @return array
363
     */
364
    protected function getSetOrEnum2Array($refTbl, $refCol)
365
    {
366
        $dat = $this->establishDatabaseAndTable($refTbl);
367
        foreach ($this->advCache['tableStructureCache'][$dat[0]][$dat[1]] as $value) {
368
            if ($value['COLUMN_NAME'] == $refCol) {
369
                $clndVls = explode(',', str_replace([$value['DATA_TYPE'], '(', "'", ')'], '', $value['COLUMN_TYPE']));
370
                $enmVls  = array_combine($clndVls, $clndVls);
371
                if ($value['IS_NULLABLE'] === 'YES') {
372
                    $enmVls['NULL'] = '';
373
                }
374
            }
375
        }
376
        ksort($enmVls);
377
        return $enmVls;
378
    }
379
380
    /**
381
     * Returns a timestamp field value
382
     *
383
     * @param array $dtl
384
     * @return array
385
     */
386
    private function getTimestamping($dtl)
387
    {
388
        $fieldValue = $this->getFieldValue($dtl);
389
        $inM        = $this->setStringIntoTag($fieldValue, 'span');
390
        if (in_array($fieldValue, ['', 'CURRENT_TIMESTAMP', 'NULL'])) {
391
            $mCN = [
392
                'InsertDateTime'        => 'data/timpul ad. informatiei',
393
                'ModificationDateTime'  => 'data/timpul modificarii inf.',
394
                'modification_datetime' => 'data/timpul modificarii inf.',
395
            ];
396
            if (array_key_exists($dtl['COLUMN_NAME'], $mCN)) {
397
                $inM = $this->setStringIntoTag($mCN[$dtl['COLUMN_NAME']], 'span', ['style' => 'font-style:italic;']);
398
            }
399
        }
400
        return ['label' => $this->getLabel($dtl), 'input' => $inM];
401
    }
402
403
    /**
404
     * Builds field output w. special column name
405
     *
406
     * @param string $tableSource
407
     * @param array $dtl
408
     * @param array $features
409
     * @param string $fieldLabel
410
     * @return array
411
     */
412
    private function setField($tableSource, $dtl, $features, $fieldLabel)
413
    {
414
        if ($dtl['COLUMN_NAME'] == 'host') {
415
            $inVl = gethostbyaddr($this->tCmnRequest->server->get('REMOTE_ADDR'));
416
            return [
417
                'label' => '<label for="' . $dtl['COLUMN_NAME'] . '">Numele calculatorului</label>',
418
                'input' => '<input type="text" name="host" size="15" readonly value="' . $inVl . '" />',
419
            ];
420
        }
421
        $result = $this->setFieldInput($tableSource, $dtl, $features);
422
        return ['label' => $this->setFieldLabel($dtl, $features, $fieldLabel), 'input' => $result];
423
    }
424
425
    /**
426
     * Builds field output w. another special column name
427
     *
428
     * @param string $tableSource
429
     * @param array $dtl
430
     * @param array $features
431
     * @return string
432
     */
433
    private function setFieldInput($tableSource, $dtl, $features)
434
    {
435
        if ($dtl['COLUMN_NAME'] == 'ChoiceId') {
436
            return '<input type="text" name="ChoiceId" value="'
437
                    . $this->tCmnRequest->request->get($dtl['COLUMN_NAME']) . '" />';
438
        }
439
        return $this->setNeededFieldByType($tableSource, $dtl, $features);
440
    }
441
442
    /**
443
     * Returns a generic form based on a given table
444
     *
445
     * @param string $tblSrc
446
     * @param array $feat
447
     * @param array $hdnInf
448
     *
449
     * @return string Form to add/modify detail for a single row within a table
450
     */
451
    protected function setFormGenericSingleRecord($tblSrc, $feat, $hdnInf = [])
452
    {
453
        echo $this->setStringIntoTag('', 'div', ['id' => 'loading']);
454
        $this->setTableCache($tblSrc);
455
        if (strpos($tblSrc, '.') !== false) {
456
            $tblSrc = explode('.', str_replace('`', '', $tblSrc))[1];
457
        }
458
        $sReturn = [];
459
        if (count($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc]) != 0) {
460
            foreach ($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc] as $value) {
461
                $sReturn[] = $this->setNeededField($tblSrc, $value, $feat);
462
            }
463
        }
464
        $frmFtrs = ['id' => $feat['id'], 'action' => $feat['action'], 'method' => $feat['method']];
465
        return $this->setStringIntoTag(implode('', $sReturn) . $this->setFormButtons($feat, $hdnInf), 'form', $frmFtrs)
466
                . $this->setFormJavascriptFinal($feat['id']);
467
    }
468
469
    /**
470
     * Analyse the field and returns the proper line 2 use in forms
471
     *
472
     * @param string $tableSource
473
     * @param array $details
474
     * @param array $features
475
     * @return string|array
476
     */
477
    private function setNeededField($tableSource, $details, $features)
478
    {
479
        if (isset($features['hidden'])) {
480
            if (in_array($details['COLUMN_NAME'], $features['hidden'])) {
481
                return null;
482
            }
483
        }
484
        $fieldLabel = $this->getFieldNameForDisplay($details);
485
        if ($fieldLabel == 'hidden') {
486
            return null;
487
        }
488
        return $this->setNeededFieldFinal($tableSource, $details, $features, $fieldLabel);
489
    }
490
491
    /**
492
     * Analyse the field type and returns the proper lines 2 use in forms
493
     *
494
     * @param string $tblName
495
     * @param array $dtls
496
     * @param array $features
497
     * @return string|array
498
     */
499
    private function setNeededFieldByType($tblName, $dtls, $features)
500
    {
501
        if (isset($features['special']) && isset($features['special'][$dtls['COLUMN_NAME']])) {
502
            $sOpt = $this->setMySQLquery2Server($features['special'][$dtls['COLUMN_NAME']], 'array_key_value');
503
            return $this->setArrayToSelect($sOpt, $this->getFieldValue($dtls), $dtls['COLUMN_NAME'], ['size' => 1]);
0 ignored issues
show
Bug introduced by
It seems like $sOpt defined by $this->setMySQLquery2Ser...']], 'array_key_value') on line 502 can also be of type string; however, danielgp\common_lib\DomC...lGP::setArrayToSelect() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
504
        }
505
        return $this->setNeededFieldKnown($tblName, $dtls, $features);
506
    }
507
508
    private function setNeededFieldKnown($tblName, $dtls, $features)
509
    {
510
        $iar      = $this->handleFeatures($dtls['COLUMN_NAME'], $features);
511
        $sReturn  = '';
512
        $numTypes = ['bigint', 'int', 'mediumint', 'smallint', 'tinyint', 'float', 'double', 'decimal', 'numeric'];
513
        if (in_array($dtls['DATA_TYPE'], $numTypes)) {
514
            $sReturn = $this->getFieldOutputNumeric($tblName, $dtls, $iar);
515
        } elseif (in_array($dtls['DATA_TYPE'], ['char', 'tinytext', 'varchar', 'enum', 'set', 'text', 'blob'])) {
516
            $sReturn = $this->setNeededFieldTextRelated($tblName, $dtls, $iar);
517
        } elseif (in_array($dtls['DATA_TYPE'], ['date', 'datetime', 'time', 'timestamp', 'year'])) {
518
            $sReturn = $this->setNeededFieldSingleType($tblName, $dtls, $iar);
519
        }
520
        return $this->getFieldCompletionType($dtls) . $sReturn;
521
    }
522
523
    private function setNeededFieldFinal($tableSource, $details, $features, $fieldLabel)
524
    {
525
        $sReturn = $this->setField($tableSource, $details, $features, $fieldLabel);
526
        $lmts    = $this->setFieldNumbers($details);
527
        return '<div>' . $sReturn['label']
528
                . $this->setStringIntoTag($sReturn['input'], 'span', ['class' => 'labell'])
529
                . '<span style="font-size:x-small;font-style:italic;">&nbsp;(max. '
530
                . $lmts['M'] . (isset($lmts['d']) ? ' w. ' . $lmts['d'] . ' decimals' : '') . ')</span>'
531
                . '</div>';
532
    }
533
534
    private function setNeededFieldSingleType($tblName, $dtls, $iar)
535
    {
536
        if ($dtls['DATA_TYPE'] == 'date') {
537
            return $this->getFieldOutputDate($dtls);
538
        } elseif ($dtls['DATA_TYPE'] == 'time') {
539
            return $this->getFieldOutputTime($dtls, $iar);
540
        } elseif (in_array($dtls['DATA_TYPE'], ['datetime', 'timestamp'])) {
541
            return $this->getFieldOutputTimestamp($dtls, $iar);
542
        }
543
        return $this->getFieldOutputYear($tblName, $dtls, $iar);
544
    }
545
546
    private function setNeededFieldTextRelated($tblName, $dtls, $iar)
547
    {
548
        if (in_array($dtls['DATA_TYPE'], ['char', 'tinytext', 'varchar'])) {
549
            return $this->getFieldOutputText($tblName, $dtls['DATA_TYPE'], $dtls, $iar);
550
        } elseif (in_array($dtls['DATA_TYPE'], ['text', 'blob'])) {
551
            return $this->getFieldOutputTextLarge($dtls['DATA_TYPE'], $dtls, $iar);
552
        }
553
        return $this->getFieldOutputEnumSet($tblName, $dtls['DATA_TYPE'], $dtls, $iar);
554
    }
555
556
    /**
557
     * create a Cache for given table to use it in many places
558
     *
559
     * @param string $tblSrc
560
     */
561
    private function setTableCache($tblSrc)
562
    {
563
        $dat = $this->establishDatabaseAndTable($tblSrc);
564
        if (!isset($this->advCache['tableStructureCache'][$dat[0]][$dat[1]])) {
565
            $this->advCache['workingDatabase']                       = $dat[0];
566
            $this->advCache['tableStructureCache'][$dat[0]][$dat[1]] = $this->getMySQLlistColumns([
567
                'TABLE_SCHEMA' => $dat[0],
568
                'TABLE_NAME'   => $dat[1],
569
            ]);
570
            $this->setTableForeignKeyCache($dat[0], $dat[1]);
571
        }
572
    }
573
574
    private function setTableForeignKeyCache($dbName, $tblName)
575
    {
576
        $frgnKs = $this->getMySQLlistIndexes([
577
            'TABLE_SCHEMA'          => $dbName,
578
            'TABLE_NAME'            => $tblName,
579
            'REFERENCED_TABLE_NAME' => 'NOT NULL',
580
        ]);
581
        if (!is_null($frgnKs)) {
582
            $this->advCache['tableFKs'][$dbName][$tblName] = $frgnKs;
583
            $this->advCache['FKcol'][$dbName][$tblName]    = array_column($frgnKs, 'COLUMN_NAME', 'CONSTRAINT_NAME');
584
        }
585
    }
586
}
587