1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\DocumentGenerator\PdfLetters\Models\Fields; |
4
|
|
|
|
5
|
|
|
use ByTIC\DocumentGenerator\PdfLetters\Models\Fields\Types\AbstractType; |
6
|
|
|
use ByTIC\DocumentGenerator\PdfLetters\Models\PdfLetters\PdfLettersTrait; |
7
|
|
|
use Nip\MailModule\Models\EmailsTable\EmailTrait; |
|
|
|
|
8
|
|
|
use Nip\Records\EventManager\Events\Event; |
9
|
|
|
use Nip\Records\Traits\AbstractTrait\RecordsTrait as AbstractRecordsTrait; |
10
|
|
|
use ByTIC\Models\SmartProperties\RecordsTraits\HasTypes\RecordsTrait as HasTypeRecordsTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class FieldsTrait |
14
|
|
|
* @package ByTIC\DocumentGenerator\PdfLetters\Models\Fields |
15
|
|
|
*/ |
16
|
|
|
trait FieldsTrait |
17
|
|
|
{ |
18
|
|
|
use AbstractRecordsTrait; |
19
|
|
|
use HasTypeRecordsTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var null|array |
23
|
|
|
*/ |
24
|
|
|
protected $mergeFields = null; |
25
|
|
|
/** |
26
|
|
|
* @var null |
27
|
|
|
*/ |
28
|
|
|
protected $mergeFieldsType = null; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
public function bootFieldsTrait() |
32
|
|
|
{ |
33
|
|
|
static::creating(function (Event $event) { |
34
|
|
|
|
35
|
|
|
/** @var FieldTrait|\Nip\Records\Record $record */ |
36
|
|
|
$record = $event->getRecord(); |
37
|
|
|
|
38
|
|
|
$record->setIf('metadata', '{}', function () use ($record) { |
39
|
|
|
return count($record->metadata) < 1; |
|
|
|
|
40
|
|
|
}); |
41
|
|
|
}); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function getMergeFields() |
48
|
|
|
{ |
49
|
|
|
if ($this->mergeFields === null) { |
50
|
|
|
$this->initMergeFields(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->mergeFields; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param AbstractType $type |
58
|
|
|
*/ |
59
|
|
|
public function populateTagsFromType($type) |
60
|
|
|
{ |
61
|
|
|
$typeTags = (array)$type->providesTags(); |
62
|
|
|
foreach ($typeTags as $tag) { |
63
|
|
|
$this->mergeFields[$type->getCategory()][] = $tag; |
64
|
|
|
$this->mergeFieldsType[$tag] = $type->getName(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $tag |
70
|
|
|
* @return null|string |
71
|
|
|
*/ |
72
|
|
|
public function getFieldTypeFromMergeTag($tag) |
73
|
|
|
{ |
74
|
|
|
if ($this->mergeFieldsType === null) { |
75
|
|
|
$this->initMergeFields(); |
76
|
|
|
} |
77
|
|
|
if (isset($this->mergeFieldsType[$tag])) { |
78
|
|
|
return $this->mergeFieldsType[$tag]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return null; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param array $params |
86
|
|
|
*/ |
87
|
|
|
public function injectParams(&$params = []) |
88
|
|
|
{ |
89
|
|
|
/** @noinspection PhpUndefinedClassInspection */ |
90
|
|
|
parent::injectParams($params); |
91
|
|
|
$params['order'][] = ['Y', 'ASC']; |
92
|
|
|
$params['order'][] = ['X', 'ASC', false]; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return PdfLettersTrait |
97
|
|
|
*/ |
98
|
|
|
abstract public function getLetterManager(); |
99
|
|
|
|
100
|
|
|
protected function initMergeFields() |
101
|
|
|
{ |
102
|
|
|
/** @var AbstractType[] $types */ |
103
|
|
|
$types = $this->getTypes(); |
104
|
|
|
$this->mergeFields = []; |
105
|
|
|
foreach ($types as $type) { |
106
|
|
|
$this->populateTagsFromType($type); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
protected function registerSmartPropertyType() |
111
|
|
|
{ |
112
|
|
|
$this->registerSmartProperty('field', 'Type'); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths