Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ChoiceField | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Interactive\Form; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfNumber; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | |
| 13 | /** |
| 14 | * Choice field (/FT /Ch) - covers list boxes and combo boxes. |
| 15 | */ |
| 16 | #[RequiresPdfVersion(PdfVersion::V1_2)] |
| 17 | class ChoiceField extends Field |
| 18 | { |
| 19 | public ?PdfArray $opt = null; // /Opt - options |
| 20 | public ?int $ti = null; // /TI - top index |
| 21 | public ?PdfArray $i = null; // /I - selected indices |
| 22 | |
| 23 | public function __construct() |
| 24 | { |
| 25 | $this->ft = new PdfName('Ch'); |
| 26 | } |
| 27 | |
| 28 | public function toPdf(): string |
| 29 | { |
| 30 | $dict = $this->buildFieldDictionary(); |
| 31 | |
| 32 | if ($this->opt !== null) { |
| 33 | $dict->set('Opt', $this->opt); |
| 34 | } |
| 35 | if ($this->ti !== null) { |
| 36 | $dict->set('TI', new PdfNumber($this->ti)); |
| 37 | } |
| 38 | if ($this->i !== null) { |
| 39 | $dict->set('I', $this->i); |
| 40 | } |
| 41 | |
| 42 | return $dict->toPdf(); |
| 43 | } |
| 44 | } |