Passed
Push — developer ( 5a7d78...6a35f4 )
by Radosław
17:06
created

Vtiger_Basic_InventoryField::getTemplateName()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 9.4888
c 0
b 0
f 0
cc 5
nc 5
nop 2
crap 5
1
<?php
2
3
/**
4
 * Inventory Basic Field Class.
5
 *
6
 * @package   InventoryField
7
 *
8
 * @copyright YetiForce S.A.
9
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
10
 * @author    Mariusz Krzaczkowski <[email protected]>
11
 * @author    Radosław Skrzypczak <[email protected]>
12
 */
13
class Vtiger_Basic_InventoryField extends \App\Base
14
{
15
	/**
16
	 * Field visible everywhere.
17
	 */
18
	private const FIELD_VISIBLE_EVERYWHERE = 0;
19
	/**
20
	 * Field visible in detail view.
21
	 */
22
	private const FIELD_VISIBLE_IN_DETAIL = 2;
23
	/**
24
	 * Field hidden.
25
	 */
26
	private const FIELD_HIDDEN = 5;
27
	/**
28
	 * Field read-only.
29
	 */
30
	private const FIELD_READONLY = 10;
31
32
	protected $columnName = '';
33
	protected $moduleName = '';
34
35
	protected $type;
36
	protected $colSpan = 10;
37
	protected $defaultValue = '';
38
	protected $params = [];
39
	protected $dbType = 'string';
40
	protected $customColumn = [];
41
	protected $summationValue = false;
42
	protected $onlyOne = true;
43
	protected $displayType = self::FIELD_VISIBLE_EVERYWHERE;
44
	protected $displayTypeBase = [
45
		self::FIELD_VISIBLE_EVERYWHERE => 'LBL_DISPLAYTYPE_ALL',
46
		self::FIELD_VISIBLE_IN_DETAIL => 'LBL_DISPLAYTYPE_ONLY_DETAIL',
47
		self::FIELD_HIDDEN => 'LBL_DISPLAYTYPE_HIDDEN',
48
		self::FIELD_READONLY => 'LBL_DISPLAYTYPE_READONLY'
49
	];
50
	protected $blocks = [1];
51
	protected $fieldDataType = 'inventory';
52
	protected $maximumLength = 255;
53
	protected $defaultLabel = '';
54
	protected $purifyType = '';
55
	protected $customPurifyType = [];
56
	protected $customMaximumLength = [];
57
	/** @var array Default values for custom fields */
58
	protected $customDefault = [];
59
	/** @var bool Field is synchronized */
60
	protected $sync = false;
61
	/** @var array List of changes */
62
	protected $changes = [];
63
64
	/**
65
	 * Gets inventory field instance.
66
	 *
67 2
	 * @param string      $moduleName
68
	 * @param string|null $type
69 2
	 *
70 2
	 * @throws \App\Exceptions\AppException
71 2
	 *
72
	 * @return self
73 2
	 */
74 2
	public static function getInstance(string $moduleName, ?string $type = 'Basic')
75 2
	{
76 2
		$cacheName = "$moduleName:$type";
77
		if (\App\Cache::has(__METHOD__, $cacheName)) {
78 2
			$instance = \App\Cache::get(__METHOD__, $cacheName);
79
		} else {
80
			$className = Vtiger_Loader::getComponentClassName('InventoryField', $type, $moduleName);
81
			$instance = new $className();
82
			$instance->setModuleName($moduleName);
83
			\App\Cache::save(__METHOD__, $cacheName, $instance);
84
		}
85
		return clone $instance;
86 2
	}
87
88 2
	/**
89
	 * Function returns module name.
90
	 *
91
	 * @return string
92
	 */
93
	public function getModuleName(): string
94
	{
95
		return $this->moduleName;
96
	}
97
98 2
	/**
99
	 * Function to get the Id.
100 2
	 *
101 2
	 * @return int Field ID
102
	 */
103
	public function getId(): int
104
	{
105
		return (int) $this->get('id');
106
	}
107
108
	/**
109
	 * Sets module name.
110
	 *
111
	 * @param string $moduleName
112
	 *
113
	 * @return \Vtiger_Basic_InventoryField
114
	 */
115
	public function setModuleName(string $moduleName): self
116
	{
117
		$this->moduleName = $moduleName;
118
		return $this;
119
	}
120
121
	/**
122
	 * Getting onlyOne field.
123
	 *
124
	 * @return bool
125
	 */
126
	public function isOnlyOne()
127
	{
128
		return $this->onlyOne;
129
	}
130
131
	public function getBlocks()
132
	{
133
		return $this->blocks;
134
	}
135
136
	/**
137
	 * Getting database-type of field.
138 2
	 *
139
	 * @return string|yii\db\ColumnSchemaBuilder dbType
140 2
	 */
141 2
	public function getDBType()
142
	{
143 2
		$columnCriteria = $this->dbType;
144 2
		if (\is_array($columnCriteria)) {
0 ignored issues
show
introduced by
The condition is_array($columnCriteria) is always false.
Loading history...
145
			[$type, $length, $default, $unsigned] = array_pad($columnCriteria, 4, null);
146
			$columnCriteria = \App\Db::getInstance()->getSchema()->createColumnSchemaBuilder($type, $length);
147
			if (null !== $default) {
148
				$columnCriteria->defaultValue($default);
149
			}
150
			if (null !== $unsigned) {
151
				$columnCriteria->unsigned();
152
			}
153
		}
154
155
		return $columnCriteria;
156
	}
157 2
158
	/**
159 2
	 * Gets value for save.
160
	 *
161
	 * @param array  $item
162
	 * @param bool   $userFormat
163
	 * @param string $column
164
	 *
165
	 * @return mixed
166
	 */
167
	public function getValueForSave(array $item, bool $userFormat = false, string $column = null)
168
	{
169
		if (null === $column) {
170
			$column = $this->getColumnName();
171
		}
172
		$value = $item[$column] ?? null;
173
		return $userFormat ? $this->getDBValue($value) : $value;
174
	}
175
176
	/**
177
	 * Getting all params field.
178
	 *
179
	 * @return array
180
	 */
181
	public function getParams()
182
	{
183
		return $this->params;
184
	}
185
186
	/**
187
	 * Get params value.
188
	 *
189
	 * @return array
190
	 */
191
	public function getParamsConfig()
192
	{
193
		return $this->get('params') ? \App\Json::decode($this->get('params')) : [];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('param...et('params')) : array() also could return the type string which is incompatible with the documented return type array.
Loading history...
194
	}
195
196
	/**
197
	 * Getting all values display Type.
198
	 *
199
	 * @return array
200
	 */
201
	public function displayTypeBase()
202
	{
203
		return $this->displayTypeBase;
204
	}
205
206
	/**
207
	 * Gets display type.
208
	 *
209
	 * @return int
210
	 */
211
	public function getDisplayType(): int
212
	{
213
		return $this->has('displaytype') ? $this->get('displaytype') : $this->displayType;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->has('displ...') : $this->displayType could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
214
	}
215
216
	public function getColSpan()
217
	{
218
		return $this->has('colspan') ? $this->get('colspan') : $this->colSpan;
219
	}
220
221
	public function getRangeValues()
222
	{
223
		return $this->maximumLength;
224
	}
225
226
	/**
227
	 * Get template name for edit.
228
	 *
229
	 * @return string
230
	 */
231
	public function getEditTemplateName()
232
	{
233
		return 'inventoryTypes/Base.tpl';
234
	}
235
236
	/**
237
	 * Getting template name.
238
	 *
239
	 * @param string $view
240
	 * @param string $moduleName
241
	 *
242
	 * @return string templateName
243
	 */
244
	public function getTemplateName($view, $moduleName)
245
	{
246
		$tpl = $view . $this->type . '.tpl';
247 1
		$filename = 'layouts' . DIRECTORY_SEPARATOR . \App\Layout::getActiveLayout() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl;
248
		if (is_file($filename)) {
249 1
			return $tpl;
250
		}
251
		$filename = 'layouts' . DIRECTORY_SEPARATOR . \App\Layout::getActiveLayout() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'Vtiger' . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl;
252
		if (is_file($filename)) {
253
			return $tpl;
254
		}
255
		$filename = 'layouts' . DIRECTORY_SEPARATOR . Vtiger_Viewer::getDefaultLayoutName() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl;
256
		if (is_file($filename)) {
257 2
			return $tpl;
258
		}
259 2
		$filename = 'layouts' . DIRECTORY_SEPARATOR . Vtiger_Viewer::getDefaultLayoutName() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'Vtiger' . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl;
260
		if (is_file($filename)) {
261
			return $tpl;
262
		}
263
		return $view . 'Base' . '.tpl';
264
	}
265
266
	/**
267 2
	 * Getting default label.
268
	 *
269 2
	 * @return string defaultLabel
270
	 */
271
	public function getDefaultLabel()
272 2
	{
273
		return $this->defaultLabel;
274 2
	}
275
276
	/**
277 1
	 * Getting field type.
278
	 *
279 1
	 * @return string
280
	 */
281
	public function getType()
282
	{
283
		return $this->type;
284
	}
285
286
	/**
287
	 * Getting column name.
288
	 *
289
	 * @return string columnName
290
	 */
291
	public function getColumnName()
292
	{
293
		return $this->has('columnname') ? $this->get('columnname') : $this->columnName;
294
	}
295
296
	/**
297
	 * Get label.
298
	 *
299
	 * @return string
300
	 */
301
	public function getLabel(): string
302
	{
303
		return $this->get('label');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('label') could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
304
	}
305
306
	/**
307
	 * Getting column name.
308
	 *
309
	 * @return array customColumn
310
	 */
311
	public function getCustomColumn()
312
	{
313
		$columns = [];
314
		$schame = \App\Db::getInstance()->getSchema();
315
		foreach ($this->customColumn as $name => $columnCriteria) {
316
			if (\is_array($columnCriteria)) {
317
				[$type, $length, $default, $unsigned] = array_pad($columnCriteria, 4, null);
318
				$columnCriteria = $schame->createColumnSchemaBuilder($type, $length);
319
				if (null !== $default) {
320
					$columnCriteria->defaultValue($default);
321
				}
322
				if (null !== $unsigned) {
323
					$columnCriteria->unsigned();
324
				}
325
			}
326
			$columns[$name] = $columnCriteria;
327
		}
328
329
		return $columns;
330
	}
331
332
	/**
333
	 * Check if the field is summed up.
334
	 *
335
	 * @return bool
336
	 */
337
	public function isSummary(): bool
338
	{
339
		return $this->summationValue;
340
	}
341
342
	/**
343
	 * Gets default value by field.
344
	 *
345
	 * @param string $columnName
346
	 *
347
	 * @return mixed
348
	 */
349
	public function getDefaultValue(string $columnName = '')
350
	{
351
		if (!$columnName || $columnName === $this->getColumnName()) {
352
			$value = $this->has('defaultvalue') ? $this->get('defaultvalue') : $this->defaultValue;
353
		} else {
354
			$value = $this->customDefault[$columnName] ?? '';
355
		}
356
357
		return $value;
358
	}
359
360
	/**
361
	 * Getting value to display.
362
	 *
363
	 * @param mixed $value
364
	 * @param array $rowData
365
	 * @param bool  $rawText
366
	 *
367
	 * @return string
368
	 */
369
	public function getDisplayValue($value, array $rowData = [], bool $rawText = false)
370
	{
371
		return $value ? \App\Purifier::encodeHtml($value) : '';
372
	}
373
374
	/**
375
	 * Function to get the list value in display view.
376
	 *
377
	 * @param mixed $value
378
	 * @param array $rowData
379
	 * @param bool  $rawText
380
	 *
381
	 * @return mixed
382
	 */
383
	public function getListViewDisplayValue($value, array $rowData = [], bool $rawText = false)
384
	{
385
		return $this->getDisplayValue($value, $rowData, $rawText);
386
	}
387 2
388
	/**
389 2
	 * Get value for Edit view.
390 2
	 *
391 2
	 * @param array  $itemData
392 2
	 * @param string $column
393
	 *
394
	 * @return string|int
395 2
	 */
396
	public function getEditValue(array $itemData, string $column = '')
397
	{
398
		if (!$column) {
399
			$column = $this->getColumnName();
400
		}
401
		$value = '';
402
		if (isset($itemData[$column])) {
403
			$value = $itemData[$column];
404
		} elseif (($default = \App\Config::module($this->getModuleName(), 'defaultInventoryData', [])[$column] ?? null) !== null) {
405
			$value = $default;
406
		} elseif ($column === $this->getColumnName()) {
407 1
			$value = $this->getDefaultValue();
408
		}
409 1
410 1
		return $value;
411 1
	}
412 1
413 1
	/**
414 1
	 * Function to check if the current field is mandatory or not.
415
	 *
416 1
	 * @return bool
417
	 */
418
	public function isMandatory()
419
	{
420
		return true;
421
	}
422
423
	/**
424
	 * Function to check whether the current field is visible.
425
	 *
426
	 * @return bool
427
	 */
428
	public function isVisible()
429
	{
430
		return self::FIELD_HIDDEN !== $this->get('displaytype');
431
	}
432 2
433
	/**
434 2
	 * Function to check if field is visible in detail view.
435
	 *
436
	 * @return bool
437
	 */
438
	public function isVisibleInDetail()
439
	{
440
		return \in_array($this->get('displaytype'), [self::FIELD_VISIBLE_EVERYWHERE, self::FIELD_READONLY, self::FIELD_VISIBLE_IN_DETAIL]);
441
	}
442
443
	/**
444
	 * Function to check whether the current field is editable.
445
	 *
446
	 * @return bool
447 2
	 */
448
	public function isEditable(): bool
449 2
	{
450
		return \in_array($this->get('displaytype'), [self::FIELD_VISIBLE_EVERYWHERE, self::FIELD_READONLY]);
451
	}
452 2
453
	/**
454
	 * Function checks if the field is read-only.
455 2
	 *
456
	 * @return bool
457
	 */
458
	public function isReadOnly()
459
	{
460
		return self::FIELD_READONLY === $this->get('displaytype');
461
	}
462
463
	/** {@inheritdoc} */
464
	public function set($key, $value, $register = false)
465
	{
466
		if ($this->getId() && !\in_array($key, ['id']) && (\array_key_exists($key, $this->value) && $this->value[$key] != $value)) {
467
			$this->changes[$key] = $this->get($key);
468
		}
469
		return parent::set($key, $value);
470
	}
471
472
	/**
473
	 * Sum the field value for each row.
474
	 *
475
	 * @param array    $data
476
	 * @param int|null $groupId
477
	 *
478
	 * @return int|float
479
	 */
480
	public function getSummaryValuesFromData($data, ?int $groupId = null)
481
	{
482
		$sum = 0;
483
		if (\is_array($data)) {
0 ignored issues
show
introduced by
The condition is_array($data) is always true.
Loading history...
484
			foreach ($data as $row) {
485
				if (null !== $groupId && $groupId !== $row['groupid'] ?? -1) {
486
					continue;
487
				}
488
				$sum += $row[$this->getColumnName()];
489
			}
490
		}
491 2
		return $sum;
492
	}
493 2
494 2
	/**
495 2
	 * Gets relation field.
496 2
	 *
497 2
	 * @param string $related
498
	 *
499 2
	 * @throws \App\Exceptions\AppException
500 2
	 *
501 2
	 * @return bool|\Vtiger_Field_Model
502 2
	 */
503 2
	public function getMapDetail(string $related)
504 2
	{
505 2
		$inventory = Vtiger_Inventory_Model::getInstance($this->getModuleName());
506
		$fields = $inventory->getAutoCompleteFields();
507
		$field = false;
508 2
		if ($mapDetail = $fields[$related][$this->getColumnName()] ?? false) {
509
			$moduleModel = Vtiger_Module_Model::getInstance($related);
510
			$field = Vtiger_Field_Model::getInstance($mapDetail['field'], $moduleModel);
511
		}
512
		return $field;
513
	}
514
515 1
	public function getFieldDataType()
516
	{
517 1
		return $this->fieldDataType;
518
	}
519
520
	/**
521
	 * Gets database value.
522
	 *
523
	 * @param mixed       $value
524
	 * @param string|null $name
525
	 *
526
	 * @return mixed
527
	 */
528
	public function getDBValue($value, ?string $name = '')
529
	{
530
		return $value;
531
	}
532
533
	/**
534
	 * Verification of data.
535
	 *
536
	 * @param mixed  $value
537
	 * @param string $columnName
538
	 * @param bool   $isUserFormat
539
	 * @param mixed  $originalValue
540
	 *
541
	 * @throws \App\Exceptions\Security
542
	 */
543
	public function validate($value, string $columnName, bool $isUserFormat, $originalValue = null)
544
	{
545
		if (!is_numeric($value) && (\is_string($value) && $value !== strip_tags($value))) {
546
			throw new \App\Exceptions\Security('ERR_ILLEGAL_FIELD_VALUE||' . ($columnName ?? $this->getColumnName()) . '||' . $this->getModuleName() . '||' . $value, 406);
547
		}
548
		if (App\TextUtils::getTextLength($value) > $this->maximumLength) {
549
			throw new \App\Exceptions\Security('ERR_VALUE_IS_TOO_LONG||' . ($columnName ?? $this->getColumnName()) . '||' . $this->getModuleName() . '||' . $value, 406);
550
		}
551
	}
552
553
	/**
554
	 * Sets default data config.
555
	 *
556
	 * @return $this
557
	 */
558
	public function setDefaultDataConfig()
559
	{
560
		$this->set('columnname', $this->columnName)
561
			->set('label', $this->defaultLabel)
562
			->set('presence', 0)
563
			->set('defaultvalue', $this->defaultValue)
564
			->set('displaytype', $this->displayType)
565
			->set('invtype', $this->type)
566
			->set('block', current($this->blocks))
567
			->set('colspan', $this->colSpan);
568
569
		return $this;
570
	}
571
572
	/**
573
	 * Field required to make an entry.
574
	 *
575
	 * @return bool
576
	 */
577
	public function isRequired()
578
	{
579
		return false;
580
	}
581
582
	/**
583
	 * Sets value data.
584
	 *
585
	 * @param \Vtiger_Record_Model $recordModel
586
	 * @param array                $item
587
	 * @param bool                 $userFormat
588
	 *
589
	 * @throws \App\Exceptions\AppException
590
	 * @throws \App\Exceptions\Security
591
	 */
592
	public function setValueToRecord(Vtiger_Record_Model $recordModel, array $item, bool $userFormat)
593
	{
594
		$column = $this->getColumnName();
595
		$baseValue = $item[$column] ?? null;
596
		$value = $this->getValueForSave($item, $userFormat, $column);
597
		if ($userFormat && $baseValue) {
598
			$baseValue = $this->getDBValue($baseValue, $column);
599
		}
600
		$this->validate($value, $column, false, $baseValue);
601
602
		$itemId = $item['id'];
603
		$addToChanges = !$recordModel->isNew() && is_numeric($itemId) && !$this->compare($value, $recordModel->getInventoryData()[$itemId][$column] ?? '', $column);
604
		$recordModel->setInventoryItemPart($itemId, $column, $value, $addToChanges);
605
		if ($customColumn = $this->getCustomColumn()) {
606
			foreach (array_keys($customColumn) as $column) {
607
				$value = $this->getValueForSave($item, $userFormat, $column);
608
				$this->validate($value, $column, false);
609
				$addToChanges = !$recordModel->isNew() && is_numeric($itemId) && !$this->compare($value, $recordModel->getInventoryData()[$itemId][$column] ?? '', $column);
610
				$recordModel->setInventoryItemPart($itemId, $column, $value, $addToChanges);
611
			}
612
		}
613
	}
614
615
	/**
616
	 * Compare two values.
617
	 *
618
	 * @param mixed  $value
619
	 * @param mixed  $prevValue
620
	 * @param string $column
621
	 *
622
	 * @return bool
623
	 */
624
	public function compare($value, $prevValue, string $column): bool
625
	{
626
		return $prevValue === $value;
627
	}
628
629
	/**
630
	 * Gets purify type.
631
	 *
632
	 * @return array
633
	 */
634
	public function getPurifyType()
635
	{
636
		return [$this->getColumnName() => $this->purifyType] + $this->customPurifyType;
637
	}
638
639
	/**
640
	 * Get information about field.
641
	 *
642
	 * @return array
643
	 */
644
	public function getFieldInfo(): array
645
	{
646
		return [
647
			'maximumlength' => $this->maximumLength
648
		];
649
	}
650
651
	/**
652
	 * Get maximum length by column.
653
	 *
654
	 * @param string $columnName
655
	 *
656
	 * @return int|string
657
	 */
658
	public function getMaximumLengthByColumn(string $columnName)
659
	{
660
		if ($columnName === $this->getColumnName()) {
661
			$value = $this->maximumLength;
662
		} else {
663
			$value = $this->customMaximumLength[$columnName] ?? '';
664
		}
665
666
		return $value;
667
	}
668
669
	/**
670
	 * Get pervious value by field.
671
	 *
672
	 * @param string $fieldName
673
	 *
674
	 * @return mixed
675
	 */
676
	public function getPreviousValue(string $fieldName = '')
677
	{
678
		return $fieldName ? ($this->changes[$fieldName] ?? null) : $this->changes;
679
	}
680
681
	/**
682
	 * Check if the field is synchronized.
683
	 *
684
	 * @return bool
685
	 */
686
	public function isSync(): bool
687
	{
688
		return $this->sync;
689
	}
690
691
	/**
692
	 * Gets config fields data.
693
	 *
694
	 * @return array
695
	 */
696
	public function getConfigFieldsData(): array
697
	{
698
		$row = [
699
			'invtype' => [
700
				'name' => 'invtype',
701
				'column' => 'invtype',
702
				'uitype' => 1,
703
				'label' => 'LBL_NAME_FIELD',
704
				'maximumlength' => '30',
705
				'typeofdata' => 'V~M',
706
				'purifyType' => \App\Purifier::STANDARD,
707
				'isEditableReadOnly' => true,
708
			],
709
			'label' => [
710
				'name' => 'label',
711
				'label' => 'LBL_LABEL_NAME',
712
				'uitype' => 1,
713
				'maximumlength' => '50',
714
				'typeofdata' => 'V~M',
715
				'purifyType' => \App\Purifier::TEXT,
716
			],
717
			'displaytype' => [
718
				'name' => 'displaytype',
719
				'label' => 'LBL_DISPLAY_TYPE',
720
				'uitype' => 16,
721
				'maximumlength' => '127',
722
				'typeofdata' => 'V~M',
723
				'purifyType' => \App\Purifier::INTEGER,
724
				'picklistValues' => [],
725
			],
726
			'colspan' => [
727
				'name' => 'colspan',
728
				'label' => 'LBL_COLSPAN',
729
				'uitype' => 7,
730
				'maximumlength' => '0,100',
731
				'typeofdata' => 'N~M',
732
				'purifyType' => \App\Purifier::INTEGER,
733
				'tooltip' => 'LBL_MAX_WIDTH_COLUMN_INFO'
734
			]
735
		];
736
737
		$qualifiedModuleName = 'Settings:LayoutEditor';
738
		foreach ($this->displayTypeBase() as $key => $value) {
739
			$row['displaytype']['picklistValues'][$key] = \App\Language::translate($value, $qualifiedModuleName);
740
		}
741
742
		return $row;
743
	}
744
745
	/**
746
	 * Gets config fields.
747
	 *
748
	 * @return Vtiger_Field_Model[]
749
	 */
750
	public function getConfigFields(): array
751
	{
752
		$module = 'LayoutEditor';
753
		$fields = [];
754
		foreach ($this->getConfigFieldsData() as $name => $data) {
755
			$fieldModel = \Vtiger_Field_Model::init($module, $data, $name);
756
			if (null !== $this->get($name)) {
757
				$fieldModel->set('fieldvalue', $this->get($name));
758
			} elseif (isset($this->getParamsConfig()[$name])) {
759
				$fieldModel->set('fieldvalue', $this->getParamsConfig()[$name]);
760
			} elseif (property_exists($this, $name) && null !== $this->{$name} && '' !== $this->{$name}) {
761
				$fieldModel->set('fieldvalue', $this->{$name});
762
			} elseif (($default = $fieldModel->get('defaultvalue')) !== null) {
763
				$fieldModel->set('fieldvalue', $default);
764
			}
765
			$fields[$name] = $fieldModel;
766
		}
767
768
		return $fields;
769
	}
770
}
771