pdf_timespent::write_file()   F
last analyzed

Complexity

Conditions 46
Paths > 20000

Size

Total Lines 356
Code Lines 222

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 46
eloc 222
nc 1359216668
nop 2
dl 0
loc 356
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* Copyright (C) 2010-2012  Regis Houssin               <[email protected]>
4
 * Copyright (C) 2024		MDW							<[email protected]>
5
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
 * or see https://www.gnu.org/
19
 */
20
21
use Dolibarr\Code\Core\Classes\HookManager;
22
use Dolibarr\Code\Core\Classes\Translate;
23
use Dolibarr\Code\Projet\Classes\ModelePDFProjects;
24
use Dolibarr\Code\Projet\Classes\Project;
25
use Dolibarr\Code\Projet\Classes\Task;
26
use Dolibarr\Code\User\Classes\User;
27
use Dolibarr\Lib\ViewMain;
28
29
/**
30
 *  \file       htdocs/core/modules/project/doc/pdf_timespent.modules.php
31
 *  \ingroup    project
32
 *  \brief      File of class to generate project document Baleine
33
 */
34
35
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php';
36
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/pdf.lib.php';
37
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/date.lib.php';
38
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/functions2.lib.php';
39
40
41
/**
42
 *  Class to manage generation of project document Timespent
43
 */
44
class pdf_timespent extends ModelePDFProjects
45
{
46
    /**
47
     * @var DoliDB Database handler
48
     */
49
    public $db;
50
51
    /**
52
     * @var string model name
53
     */
54
    public $name;
55
56
    /**
57
     * @var string model description (short text)
58
     */
59
    public $description;
60
61
    /**
62
     * @var int     Save the name of generated file as the main doc when generating a doc with this template
63
     */
64
    public $update_main_doc_field;
65
66
    /**
67
     * @var string document type
68
     */
69
    public $type;
70
71
    /**
72
     * @var int
73
     */
74
    public $posxuser;
75
76
    /**
77
     * Dolibarr version of the loaded document
78
     * @var string
79
     */
80
    public $version = 'dolibarr';
81
82
83
    /**
84
     *  Constructor
85
     *
86
     * @param DoliDB $db Database handler
87
     */
88
    public function __construct($db)
89
    {
90
        global $langs, $mysoc;
91
92
        // Translations
93
        $langs->loadLangs(array("main", "projects", "companies"));
94
95
        $this->db = $db;
96
        $this->name = "timespent";
97
        $this->description = $langs->trans("DocumentModelTimeSpent");
98
        $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
99
100
        // Page size for A4 format
101
        $this->type = 'pdf';
102
        $formatarray = pdf_getFormat();
103
        $this->page_largeur = $formatarray['width'];
104
        $this->page_hauteur = $formatarray['height'];
105
        $this->format = array($this->page_largeur, $this->page_hauteur);
106
        $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
107
        $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
108
        $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
109
        $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
110
111
        $this->option_logo = 1; // Display logo FAC_PDF_LOGO
112
        $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
113
114
        // Get source company
115
        $this->emetteur = $mysoc;
116
        if (!$this->emetteur->country_code) {
117
            $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
118
        }
119
120
        // Define position of columns
121
        $this->posxref = $this->marge_gauche + 1;
122
        $this->posxlabel = $this->marge_gauche + 25;
123
        $this->posxworkload = $this->marge_gauche + 100;
124
        $this->posxtimespent = $this->marge_gauche + 120;
125
        //$this->posxprogress=$this->marge_gauche+140;
126
        $this->posxuser = $this->marge_gauche + 147;
127
        //$this->posxdateend = $this->marge_gauche + 169;
128
        if ($this->page_largeur < 210) { // To work with US executive format
129
            $this->posxref -= 20;
130
            $this->posxlabel -= 20;
131
            $this->posxtimespent -= 20;
132
            //$this->posxprogress-=20;
133
            $this->posxuser -= 20;
134
            //$this->posxdateend -= 20;
135
        }
136
    }
137
138
139
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
140
141
    /**
142
     *  Function to build pdf project onto disk
143
     *
144
     * @param Project $object Object project a generer
145
     * @param Translate $outputlangs Lang output object
146
     * @return int                         1 if OK, <=0 if KO
147
     */
148
    public function write_file($object, $outputlangs)
149
    {
150
        // phpcs:enable
151
        global $conf, $hookmanager, $langs, $user;
152
153
        if (!is_object($outputlangs)) {
154
            $outputlangs = $langs;
155
        }
156
        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
157
        if (getDolGlobalString('MAIN_USE_FPDF')) {
158
            $outputlangs->charset_output = 'ISO-8859-1';
159
        }
160
161
        // Load traductions files required by page
162
        $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
163
164
        if ($conf->project->multidir_output[$object->entity]) {
165
            //$nblines = count($object->lines);  // This is set later with array of tasks
166
167
            $objectref = dol_sanitizeFileName($object->ref);
168
            $dir = $conf->project->multidir_output[$object->entity];
169
            if (!preg_match('/specimen/i', $objectref)) {
170
                $dir .= "/" . $objectref;
171
            }
172
            $file = $dir . "/" . $objectref . ".pdf";
173
174
            if (!file_exists($dir)) {
175
                if (dol_mkdir($dir) < 0) {
176
                    $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
177
                    return 0;
178
                }
179
            }
180
181
            if (file_exists($dir)) {
182
                // Add pdfgeneration hook
183
                if (!is_object($hookmanager)) {
184
                    $hookmanager = new HookManager($this->db);
185
                }
186
                $hookmanager->initHooks(array('pdfgeneration'));
187
                $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
188
                global $action;
189
                $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
190
191
                // Create pdf instance
192
                $pdf = pdf_getInstance($this->format);
193
                $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
194
                $pdf->SetAutoPageBreak(1, 0);
195
196
                $heightforinfotot = 40; // Height reserved to output the info and total part
197
                $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
198
                $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
199
                if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
200
                    $heightforfooter += 6;
201
                }
202
203
                if (class_exists('TCPDF')) {
204
                    $pdf->setPrintHeader(false);
205
                    $pdf->setPrintFooter(false);
206
                }
207
                $pdf->SetFont(pdf_getPDFFont($outputlangs));
208
                // Set path to the background PDF File
209
                if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
210
                    $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
211
                    $tplidx = $pdf->importPage(1);
212
                }
213
214
                // Complete object by loading several other information
215
                $task = new Task($this->db);
216
                $tasksarray = $task->getTasksArray(0, 0, $object->id);
217
218
                if (!$object->id > 0) {  // Special case when used with object = specimen, we may return all lines
219
                    $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
220
                }
221
222
                $object->lines = $tasksarray;
223
                $nblines = count($object->lines);
224
225
                $pdf->Open();
226
                $pagenb = 0;
227
                $pdf->SetDrawColor(128, 128, 128);
228
229
                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
230
                $pdf->SetSubject($outputlangs->transnoentities("Project"));
231
                $pdf->SetCreator("Dolibarr " . DOL_VERSION);
232
                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
233
                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Project"));
234
                if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
235
                    $pdf->SetCompression(false);
236
                }
237
238
                // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
239
                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
240
241
                // New page
242
                $pdf->AddPage();
243
                if (!empty($tplidx)) {
244
                    $pdf->useTemplate($tplidx);
245
                }
246
                $pagenb++;
247
                $this->_pagehead($pdf, $object, 1, $outputlangs);
248
                $pdf->SetFont('', '', $default_font_size - 1);
249
                $pdf->MultiCell(0, 3, ''); // Set interline to 3
250
                $pdf->SetTextColor(0, 0, 0);
251
252
                $tab_top = 50;
253
                $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
254
255
                $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
256
257
                // Show public note
258
                $notetoshow = empty($object->note_public) ? '' : $object->note_public;
259
                if ($notetoshow) {
260
                    $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
261
                    complete_substitutions_array($substitutionarray, $outputlangs, $object);
262
                    $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
263
                    $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
264
265
                    $tab_top -= 2;
266
267
                    $pdf->SetFont('', '', $default_font_size - 1);
268
                    $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($notetoshow), 0, 1);
269
                    $nexY = $pdf->GetY();
270
                    $height_note = $nexY - $tab_top;
271
272
                    // Rect takes a length in 3rd parameter
273
                    $pdf->SetDrawColor(192, 192, 192);
274
                    $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
275
276
                    $tab_height = $tab_height - $height_note;
277
                    $tab_top = $nexY + 6;
278
                } else {
279
                    $height_note = 0;
280
                }
281
282
                $heightoftitleline = 10;
283
                $iniY = $tab_top + $heightoftitleline + 1;
284
                $curY = $tab_top + $heightoftitleline + 1;
285
                $nexY = $tab_top + $heightoftitleline + 1;
286
287
                $tmpuser = new User($this->db);
288
289
                // TODO We should loop on record of times spent grouped by user instead of lines of tasks
290
291
                // Loop on each lines
292
                for ($i = 0; $i < $nblines; $i++) {
293
                    $curY = $nexY;
294
                    $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
295
                    $pdf->SetTextColor(0, 0, 0);
296
297
                    $pdf->setTopMargin($tab_top_newpage);
298
                    $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
299
                    $pageposbefore = $pdf->getPage();
300
301
                    // Description of line
302
                    $ref = $object->lines[$i]->ref;
303
                    $libelleline = $object->lines[$i]->label;
304
                    //$progress=($object->lines[$i]->progress?$object->lines[$i]->progress.'%':'');
305
                    $datestart = dol_print_date($object->lines[$i]->date_start, 'day');
306
                    $dateend = dol_print_date($object->lines[$i]->date_end, 'day');
307
                    $duration = convertSecondToTime((int)$object->lines[$i]->duration, 'allhourmin');
308
309
                    $showpricebeforepagebreak = 1;
310
311
                    $pdf->startTransaction();
312
                    // Label
313
                    $pdf->SetXY($this->posxlabel, $curY);
314
                    $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
315
                    $pageposafter = $pdf->getPage();
316
                    if ($pageposafter > $pageposbefore) {   // There is a pagebreak
317
                        $pdf->rollbackTransaction(true);
318
                        $pageposafter = $pageposbefore;
319
                        //print $pageposafter.'-'.$pageposbefore;exit;
320
                        $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
321
                        // Label
322
                        $pdf->SetXY($this->posxlabel, $curY);
323
                        $posybefore = $pdf->GetY();
324
                        $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
325
                        $pageposafter = $pdf->getPage();
326
                        $posyafter = $pdf->GetY();
327
                        if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
328
                            if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
329
                                $pdf->AddPage('', '', true);
330
                                if (!empty($tplidx)) {
331
                                    $pdf->useTemplate($tplidx);
332
                                }
333
                                if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
334
                                    $this->_pagehead($pdf, $object, 0, $outputlangs);
335
                                }
336
                                $pdf->setPage($pageposafter + 1);
337
                            }
338
                        } else {
339
                            // We found a page break
340
341
                            // Allows data in the first page if description is long enough to break in multiples pages
342
                            if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
343
                                $showpricebeforepagebreak = 1;
344
                            } else {
345
                                $showpricebeforepagebreak = 0;
346
                            }
347
348
                            $forcedesconsamepage = 1;
349
                            if ($forcedesconsamepage) {
350
                                $pdf->rollbackTransaction(true);
351
                                $pageposafter = $pageposbefore;
352
                                $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
353
354
                                $pdf->AddPage('', '', true);
355
                                if (!empty($tplidx)) {
356
                                    $pdf->useTemplate($tplidx);
357
                                }
358
                                if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
359
                                    $this->_pagehead($pdf, $object, 0, $outputlangs);
360
                                }
361
                                $pdf->setPage($pageposafter + 1);
362
                                $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default
363
                                $pdf->MultiCell(0, 3, ''); // Set interline to 3
364
                                $pdf->SetTextColor(0, 0, 0);
365
366
                                $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
367
                                $curY = $tab_top_newpage + $heightoftitleline + 1;
368
369
                                // Label
370
                                $pdf->SetXY($this->posxlabel, $curY);
371
                                $posybefore = $pdf->GetY();
372
                                $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
373
                                $pageposafter = $pdf->getPage();
374
                                $posyafter = $pdf->GetY();
375
                            }
376
                        }
377
                        //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur -  ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak);
378
                    } else { // No pagebreak
379
                        $pdf->commitTransaction();
380
                    }
381
                    $posYAfterDescription = $pdf->GetY();
382
383
                    $nexY = $pdf->GetY();
384
                    $pageposafter = $pdf->getPage();
385
                    $pdf->setPage($pageposbefore);
386
                    $pdf->setTopMargin($this->marge_haute);
387
                    $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
388
389
                    // We suppose that a too long description is moved completely on next page
390
                    if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
391
                        //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak);
392
                        $pdf->setPage($pageposafter);
393
                        $curY = $tab_top_newpage + $heightoftitleline + 1;
394
                    }
395
396
                    $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
397
398
                    // Ref of task
399
                    $pdf->SetXY($this->posxref, $curY);
400
                    $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0, 'L');
401
                    // timespent
402
                    $pdf->SetXY($this->posxtimespent, $curY);
403
                    $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration : '', 0, 'R');
404
                    // Progress
405
                    //$pdf->SetXY($this->posxprogress, $curY);
406
                    //$pdf->MultiCell($this->posxuser-$this->posxprogress, 3, $progress, 0, 'R');
407
408
                    // User spending time
409
                    /*var_dump($object->lines[$i]);exit;
410
                    $tmpuser->fetch($object->lines[$i]->fk_user);
411
                    $pdf->SetXY($this->posxuser, $curY);
412
                    $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, $tmpuser->getFullName($outputlangs, 0, -1, 20), 0, 'C');
413
                    */
414
415
                    // Add line
416
                    if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
417
                        $pdf->setPage($pageposafter);
418
                        $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
419
                        //$pdf->SetDrawColor(190,190,200);
420
                        $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
421
                        $pdf->SetLineStyle(array('dash' => 0));
422
                    }
423
424
                    $nexY += 2; // Add space between lines
425
426
                    // Detect if some page were added automatically and output _tableau for past pages
427
                    while ($pagenb < $pageposafter) {
428
                        $pdf->setPage($pagenb);
429
                        if ($pagenb == 1) {
430
                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
431
                        } else {
432
                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
433
                        }
434
                        $this->_pagefoot($pdf, $object, $outputlangs, 1);
435
                        $pagenb++;
436
                        $pdf->setPage($pagenb);
437
                        $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
438
                        if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
439
                            $this->_pagehead($pdf, $object, 0, $outputlangs);
440
                        }
441
                        if (!empty($tplidx)) {
442
                            $pdf->useTemplate($tplidx);
443
                        }
444
                    }
445
                    if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
446
                        if ($pagenb == 1) {
447
                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
448
                        } else {
449
                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
450
                        }
451
                        $this->_pagefoot($pdf, $object, $outputlangs, 1);
452
                        // New page
453
                        $pdf->AddPage();
454
                        if (!empty($tplidx)) {
455
                            $pdf->useTemplate($tplidx);
456
                        }
457
                        $pagenb++;
458
                        if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
459
                            $this->_pagehead($pdf, $object, 0, $outputlangs);
460
                        }
461
                    }
462
                }
463
464
                // Show square
465
                if ($pagenb == 1) {
466
                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
467
                } else {
468
                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
469
                }
470
                $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
471
472
                // Footer of the page
473
                $this->_pagefoot($pdf, $object, $outputlangs);
474
                if (method_exists($pdf, 'AliasNbPages')) {
475
                    $pdf->AliasNbPages();
476
                }
477
478
                $pdf->Close();
479
480
                $pdf->Output($file, 'F');
481
482
                // Add pdfgeneration hook
483
                $hookmanager->initHooks(array('pdfgeneration'));
484
                $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
485
                global $action;
486
                $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
487
                if ($reshook < 0) {
488
                    $this->error = $hookmanager->error;
489
                    $this->errors = $hookmanager->errors;
490
                }
491
492
                dolChmod($file);
493
494
                $this->result = array('fullpath' => $file);
495
496
                return 1; // No error
497
            } else {
498
                $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
499
                return 0;
500
            }
501
        } else {
502
            $this->error = $langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR");
503
            return 0;
504
        }
505
    }
506
507
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
508
509
    /**
510
     *   Show table for lines
511
     *
512
     * @param TCPDF $pdf Object PDF
513
     * @param float|int $tab_top Top position of table
514
     * @param float|int $tab_height Height of table (rectangle)
515
     * @param int $nexY Y
516
     * @param Translate $outputlangs Langs object
517
     * @param int $hidetop Hide top bar of array
518
     * @param int $hidebottom Hide bottom bar of array
519
     * @return    void
520
     */
521
    protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
522
    {
523
        global $conf, $mysoc;
524
525
        $heightoftitleline = 10;
526
527
        $default_font_size = pdf_getPDFFontSize($outputlangs);
528
529
        $pdf->SetDrawColor(128, 128, 128);
530
531
        // Draw rect of all tab (title + lines). Rect takes a length in 3rd parameter
532
        $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
533
534
        // Line takes a position y in 3rd parameter
535
        $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
536
537
        $pdf->SetTextColor(0, 0, 0);
538
        $pdf->SetFont('', '', $default_font_size);
539
540
        $pdf->SetXY($this->posxref, $tab_top + 1);
541
        $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities("Tasks"), '', 'L');
542
543
        $pdf->SetXY($this->posxlabel, $tab_top + 1);
544
        $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->transnoentities("Description"), 0, 'L');
545
546
        $pdf->SetXY($this->posxtimespent, $tab_top + 1);
547
        $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $outputlangs->transnoentities("TimeSpent"), 0, 'R');
548
549
        //$pdf->SetXY($this->posxprogress, $tab_top+1);
550
        //$pdf->MultiCell($this->posxuser - $this->posxprogress, 3, '%', 0, 'R');
551
552
        $pdf->SetXY($this->posxuser, $tab_top + 1);
553
        $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, '', 0, 'C');
554
    }
555
556
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
557
558
    /**
559
     *  Show top header of page.
560
     *
561
     * @param TCPDF $pdf Object PDF
562
     * @param Project $object Object to show
563
     * @param int $showaddress 0=no, 1=yes
564
     * @param Translate $outputlangs Object lang for output
565
     * @return float|int                   Return topshift value
566
     */
567
    protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
568
    {
569
        global $langs, $conf, $mysoc;
570
571
        $default_font_size = pdf_getPDFFontSize($outputlangs);
572
573
        pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
574
575
        $pdf->SetTextColor(0, 0, 60);
576
        $pdf->SetFont('', 'B', $default_font_size + 3);
577
578
        $posx = $this->page_largeur - $this->marge_droite - 100;
579
        $posy = $this->marge_haute;
580
581
        $pdf->SetXY($this->marge_gauche, $posy);
582
583
        // Logo
584
        $logo = $conf->mycompany->dir_output . '/logos/' . $mysoc->logo;
585
        if ($mysoc->logo) {
586
            if (is_readable($logo)) {
587
                $height = pdf_getHeightForLogo($logo);
588
                $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
589
            } else {
590
                $pdf->SetTextColor(200, 0, 0);
591
                $pdf->SetFont('', 'B', $default_font_size - 2);
592
                $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
593
                $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
594
            }
595
        } else {
596
            $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
597
        }
598
599
        $pdf->SetFont('', 'B', $default_font_size + 3);
600
        $pdf->SetXY($posx, $posy);
601
        $pdf->SetTextColor(0, 0, 60);
602
        $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project") . " " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
603
        $pdf->SetFont('', '', $default_font_size + 2);
604
605
        $posy += 6;
606
        $pdf->SetXY($posx, $posy);
607
        $pdf->SetTextColor(0, 0, 60);
608
        $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart") . " : " . dol_print_date($object->date_start, 'day', false, $outputlangs, true), '', 'R');
609
610
        $posy += 6;
611
        $pdf->SetXY($posx, $posy);
612
        $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd") . " : " . dol_print_date($object->date_end, 'day', false, $outputlangs, true), '', 'R');
613
614
        if (is_object($object->thirdparty)) {
615
            $posy += 6;
616
            $pdf->SetXY($posx, $posy);
617
            $pdf->MultiCell(100, 4, $outputlangs->transnoentities("ThirdParty") . " : " . $object->thirdparty->getFullName($outputlangs), '', 'R');
618
        }
619
620
        $pdf->SetTextColor(0, 0, 60);
621
622
        // Add list of linked objects
623
        /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
624
        $object->fetchObjectLinked();
625
626
        foreach($object->linkedObjects as $objecttype => $objects)
627
        {
628
            //var_dump($objects);exit;
629
            if ($objecttype == 'commande')
630
            {
631
                $outputlangs->load('orders');
632
                $num=count($objects);
633
                for ($i=0;$i<$num;$i++)
634
                {
635
                    $posy+=4;
636
                    $pdf->SetXY($posx,$posy);
637
                    $pdf->SetFont('','', $default_font_size - 1);
638
                    $text=$objects[$i]->ref;
639
                    if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
640
                    $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
641
                }
642
            }
643
        }
644
        */
645
646
        return 0;
647
    }
648
649
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
650
651
    /**
652
     *  Show footer of page. Need this->emetteur object
653
     *
654
     * @param TCPDF $pdf PDF
655
     * @param Project $object Object to show
656
     * @param Translate $outputlangs Object lang for output
657
     * @param int $hidefreetext 1=Hide free text
658
     * @return integer
659
     */
660
    protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
661
    {
662
        $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
663
        return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
664
    }
665
}
666