Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 109
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
DefaultWord
0.00% covered (danger)
0.00%
0 / 109
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 createFirstPage
0.00% covered (danger)
0.00%
0 / 54
0.00% covered (danger)
0.00%
0 / 1
2
 createSecondPage
0.00% covered (danger)
0.00%
0 / 52
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   Modules\Media
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15/**
16 * Default Word class.
17 *
18 * @package Modules\Media
19 * @license OMS License 2.0
20 * @link    https://jingga.app
21 * @since   1.0.0
22 */
23class DefaultWord extends \PhpOffice\PhpWord\PhpWord
24{
25    /**
26     * Font
27     *
28     * @var string
29     * @since 1.0.0
30     */
31    public string $fontName = 'helvetica';
32
33    /**
34     * Font size
35     *
36     * @var int
37     * @since 1.0.0
38     */
39    public int $fontSize = 8;
40
41    /**
42     * Doc language
43     *
44     * @var string
45     * @since 1.0.0
46     */
47    public string $language = 'en';
48
49    /**
50     * Localization
51     *
52     * @var array
53     * @since 1.0.0
54     */
55    public array $lang = [
56        'en' => [
57            'Page'        => 'Page',
58            'CEO'         => 'CEO',
59            'TaxOffice'   => 'Tax office',
60            'TaxNumber'   => 'Tax number',
61            'Swift'       => 'BIC',
62            'BankAccount' => 'Account',
63        ],
64        'de' => [
65            'Page'        => 'Seite',
66            'CEO'         => 'Geschäftsführer',
67            'TaxOffice'   => 'Finanzamt',
68            'TaxNumber'   => 'Steuernummer',
69            'Swift'       => 'BIC',
70            'BankAccount' => 'IBAN',
71        ],
72    ];
73
74    /**
75     * Attributes
76     *
77     * @var string[]
78     * @since 1.0.0
79     */
80    public array $attributes = [
81        'logo'         => __DIR__ . '/../Web/Backend/img/logo.png',
82        'title_name'   => 'Jingga',
83        'slogan'       => 'Business solutions made simple.',
84        'legal_name'   => '',
85        'address'      => '',
86        'city'         => '',
87        'country'      => '',
88        'ceo'          => '',
89        'tax_office'   => '',
90        'tax_number'   => '',
91        'bank_name'    => '',
92        'swift'        => '',
93        'bank_account' => '',
94        'website'      => '',
95        'email'        => '',
96        'phone'        => '',
97    ];
98
99    /**
100     * Constructor.
101     *
102     * @since 1.0.0
103     */
104    public function __construct()
105    {
106        parent::__construct();
107
108        $generalTableStyle = ['cellMargin' => 100, 'bgColor' => 'f5f5f5'];
109        $this->addTableStyle('FooterTableStyle', $generalTableStyle);
110    }
111
112    /**
113     * Create the first page
114     *
115     * @return \PhpOffice\PhpWord\Element\Section
116     *
117     * @since 1.0.0
118     */
119    public function createFirstPage()
120    {
121        $section = $this->addSection([
122            'marginLeft'   => 1000,
123            'marginRight'  => 1000,
124            'marginTop'    => 2000,
125            'marginBottom' => 2000,
126        //    'headerHeight' => 50,
127        //    'footerHeight' => 50,
128        ]);
129
130        // first page header
131        $firstHeader = $section->addHeader();
132        $firstHeader->firstPage();
133
134        $table = $firstHeader->addTable();
135        $table->addRow();
136
137        // first column
138        $table->addCell(1300)->addImage($this->attributes['logo'], ['width' => 50, 'height' => 50]);
139
140        //second column
141        $cell    = $table->addCell(8700, ['valign' => 'bottom']);
142        $textrun = $cell->addTextRun();
143        $textrun->addText($this->attributes['title_name'], ['name' => $this->fontName, 'bold' => true, 'size' => 20]);
144
145        $textrun = $cell->addTextRun();
146        $textrun->addText($this->attributes['slogan'], ['name' => $this->fontName, 'size' => 10]);
147
148        // first page footer
149        $firstFooter = $section->addFooter();
150        $firstFooter->firstPage();
151        $firstFooter->addPreserveText($this->lang[$this->language]['Page'] . ' {PAGE}/{NUMPAGES}', ['name' => $this->fontName, 'italic' => true], ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END]);
152        $firstFooter->addTextRun();
153
154        $table = $firstFooter->addTable('FooterTableStyle');
155        $table->addRow();
156
157        // columns
158        $cell = $table->addCell(500);
159
160        $cell    = $table->addCell(2000);
161        $textrun = $cell->addTextRun();
162        $textrun->addText($this->attributes['legal_name'], ['name' => $this->fontName, 'size' => 7]);
163        $textrun = $cell->addTextRun();
164        $textrun->addText($this->attributes['address'], ['name' => $this->fontName, 'size' => 7]);
165        $textrun = $cell->addTextRun();
166        $textrun->addText($this->attributes['city'], ['name' => $this->fontName, 'size' => 7]);
167
168        $cell    = $table->addCell(2700);
169        $textrun = $cell->addTextRun();
170        $textrun->addText($this->lang[$this->language]['CEO']. ': ' . $this->attributes['ceo'], ['name' => $this->fontName, 'size' => 7]);
171        $textrun = $cell->addTextRun();
172        $textrun->addText($this->lang[$this->language]['TaxOffice']. ': ' . $this->attributes['tax_office'], ['name' => $this->fontName, 'size' => 7]);
173        $textrun = $cell->addTextRun();
174        $textrun->addText($this->lang[$this->language]['TaxNumber']. ': ' . $this->attributes['tax_number'], ['name' => $this->fontName, 'size' => 7]);
175
176        $cell    = $table->addCell(2700);
177        $textrun = $cell->addTextRun();
178        $textrun->addText($this->attributes['bank_name'], ['name' => $this->fontName, 'size' => 7]);
179        $textrun = $cell->addTextRun();
180        $textrun->addText($this->lang[$this->language]['Swift']. ': ' . $this->attributes['swift'], ['name' => $this->fontName, 'size' => 7]);
181        $textrun = $cell->addTextRun();
182        $textrun->addText($this->lang[$this->language]['BankAccount']. ': ' . $this->attributes['bank_account'], ['name' => $this->fontName, 'size' => 7]);
183
184        $cell    = $table->addCell(2100);
185        $textrun = $cell->addTextRun();
186        $textrun->addText($this->attributes['website'], ['name' => $this->fontName, 'size' => 7]);
187        $textrun = $cell->addTextRun();
188        $textrun->addText($this->attributes['email'], ['name' => $this->fontName, 'size' => 7]);
189        $textrun = $cell->addTextRun();
190        $textrun->addText($this->attributes['phone'], ['name' => $this->fontName, 'size' => 7]);
191
192        return $section;
193    }
194
195    /**
196     * Create second page
197     *
198     * @return \PhpOffice\PhpWord\Element\Section
199     *
200     * @since 1.0.0
201     */
202    public function createSecondPage()
203    {
204        $section = $this->addSection([
205            'marginLeft'   => 1000,
206            'marginRight'  => 1000,
207            'marginTop'    => 2000,
208            'marginBottom' => 2000,
209        //    'headerHeight' => 50,
210        //    'footerHeight' => 50,
211        ]);
212
213        $header = $section->addHeader();
214        $table  = $header->addTable();
215        $table->addRow();
216
217        // first column
218        $table->addCell(1300)->addImage(__DIR__ . '/../Web/Backend/img/logo.png', ['width' => 50, 'height' => 50]);
219
220        //second column
221        $cell    = $table->addCell(8700, ['valign' => 'bottom']);
222        $textrun = $cell->addTextRun();
223        $textrun->addText('Jingga', ['name' => $this->fontName, 'bold' => true, 'size' => 20]);
224
225        $textrun = $cell->addTextRun();
226        $textrun->addText('Business solutions made simple.', ['name' => $this->fontName, 'size' => 10]);
227
228        $footer = $section->addFooter();
229        $footer->addPreserveText($this->lang[$this->language]['Page'] . ' {PAGE}/{NUMPAGES}', ['name' => $this->fontName, 'italic' => true], ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END]);
230        $footer->addTextRun();
231
232        $table = $footer->addTable('FooterTableStyle');
233        $table->addRow();
234
235        // columns
236        $cell = $table->addCell(500);
237
238        $cell    = $table->addCell(2000);
239        $textrun = $cell->addTextRun();
240        $textrun->addText($this->attributes['legal_name'], ['name' => $this->fontName, 'size' => 7]);
241        $textrun = $cell->addTextRun();
242        $textrun->addText($this->attributes['address'], ['name' => $this->fontName, 'size' => 7]);
243        $textrun = $cell->addTextRun();
244        $textrun->addText($this->attributes['city'], ['name' => $this->fontName, 'size' => 7]);
245
246        $cell    = $table->addCell(2700);
247        $textrun = $cell->addTextRun();
248        $textrun->addText($this->lang[$this->language]['CEO']. ': ' . $this->attributes['ceo'], ['name' => $this->fontName, 'size' => 7]);
249        $textrun = $cell->addTextRun();
250        $textrun->addText($this->lang[$this->language]['TaxOffice']. ': ' . $this->attributes['tax_office'], ['name' => $this->fontName, 'size' => 7]);
251        $textrun = $cell->addTextRun();
252        $textrun->addText($this->lang[$this->language]['TaxNumber']. ': ' . $this->attributes['tax_number'], ['name' => $this->fontName, 'size' => 7]);
253
254        $cell    = $table->addCell(2700);
255        $textrun = $cell->addTextRun();
256        $textrun->addText($this->attributes['bank_name'], ['name' => $this->fontName, 'size' => 7]);
257        $textrun = $cell->addTextRun();
258        $textrun->addText($this->lang[$this->language]['Swift']. ': ' . $this->attributes['swift'], ['name' => $this->fontName, 'size' => 7]);
259        $textrun = $cell->addTextRun();
260        $textrun->addText($this->lang[$this->language]['BankAccount']. ': ' . $this->attributes['bank_account'], ['name' => $this->fontName, 'size' => 7]);
261
262        $cell    = $table->addCell(2100);
263        $textrun = $cell->addTextRun();
264        $textrun->addText($this->attributes['website'], ['name' => $this->fontName, 'size' => 7]);
265        $textrun = $cell->addTextRun();
266        $textrun->addText($this->attributes['email'], ['name' => $this->fontName, 'size' => 7]);
267        $textrun = $cell->addTextRun();
268        $textrun->addText($this->attributes['phone'], ['name' => $this->fontName, 'size' => 7]);
269
270        return $section;
271    }
272}