|
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\PdfLetterTrait; |
|
7
|
|
|
use Nip\Records\Traits\AbstractTrait\RecordTrait as Record; |
|
8
|
|
|
use \ByTIC\Models\SmartProperties\RecordsTraits\HasTypes\RecordTrait as HasTypeRecordTrait; |
|
9
|
|
|
use setasign\Fpdi\Fpdi; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class FieldTrait |
|
13
|
|
|
* @package ByTIC\DocumentGenerator\PdfLetters\Models\Fields |
|
14
|
|
|
* |
|
15
|
|
|
* @property string $id_letter |
|
16
|
|
|
* @property string $field |
|
17
|
|
|
* @property string $size |
|
18
|
|
|
* @property string $color |
|
19
|
|
|
* @property string $align |
|
20
|
|
|
* @property string $x |
|
21
|
|
|
* @property string $y |
|
22
|
|
|
* |
|
23
|
|
|
* @method FieldsTrait getManager() |
|
24
|
|
|
* @method AbstractType getType() |
|
25
|
|
|
*/ |
|
26
|
|
|
trait FieldTrait |
|
27
|
|
|
{ |
|
28
|
|
|
use HasTypeRecordTrait; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getName() |
|
34
|
|
|
{ |
|
35
|
|
|
return translator()->translate($this->field); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getTypeValue() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->getManager()->getFieldTypeFromMergeTag($this->field); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param PdfLetterTrait $letter |
|
48
|
|
|
*/ |
|
49
|
|
|
public function populateFromLetter($letter) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->id_letter = $letter->id; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param Fpdi $pdf |
|
56
|
|
|
* @param Record $model |
|
57
|
|
|
*/ |
|
58
|
|
|
public function addToPdf($pdf, $model) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->getType()->addToPdf($pdf, $model); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param Record $model |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function getValue($model) |
|
68
|
|
|
{ |
|
69
|
1 |
|
if ($model->id > 0) { |
|
70
|
|
|
$valueType = $this->getType()->getValue($model); |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
return $valueType; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
return '<<'.$this->field.'>>'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return PdfLetterTrait |
|
80
|
|
|
*/ |
|
81
|
|
|
abstract public function getPdfLetter(); |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public function hasColor() |
|
87
|
|
|
{ |
|
88
|
|
|
return substr_count($this->color, ',') == 2; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return array|null |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getColorArray() |
|
95
|
|
|
{ |
|
96
|
|
|
if ($this->hasColor()) { |
|
97
|
|
|
list ($red, $green, $blue) = explode(',', $this->color); |
|
98
|
|
|
if ($red && $green && $blue) { |
|
99
|
|
|
return [intval($red), intval($green), intval($blue)]; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return null; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param Fpdi $pdf |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function pdfPrepareFont($pdf) |
|
110
|
|
|
{ |
|
111
|
|
|
$pdf->SetFont('freesans', '', $this->size, '', true); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.