Completed
Push — feature/multiple_order_one_fli... ( 4a4e05 )
by Laurent
02:16
created

Bbcvols::setOrderIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) 2007-2012  Laurent Destailleur <[email protected]>
3
 * Copyright (C) 2014       Juanjo Menent       <[email protected]>
4
 * Copyright (C) 2015       Florian Henry       <[email protected]>
5
 * Copyright (C) 2015       Raphaël Doursenaud  <[email protected]>
6
 * Copyright (C) ---Put here your own copyright and developer email---
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
/**
23
 * \file    flightlog/bbcvols.class.php
24
 * \ingroup flightlog
25
 * \brief   This file is an example for a CRUD class file (Create/Read/Update/Delete)
26
 *          Put some comments here
27
 */
28
29
// Put here all includes required by your class file
30
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
31
require_once DOL_DOCUMENT_ROOT . '/flightballoon/class/bbc_ballons.class.php';
32
require_once DOL_DOCUMENT_ROOT . '/flightlog/class/bbctypes.class.php';
33
require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
34
35
/**
36
 * Class Bbcvols
37
 *
38
 * Put here description of your class
39
 *
40
 * @see CommonObject
41
 */
42
class Bbcvols extends CommonObject
43
{
44
    /**
45
     * @var string Id to identify managed objects
46
     */
47
    public $element = 'flightlog_bbcvols';
48
    /**
49
     * @var string Name of table without prefix where object is stored
50
     */
51
    public $table_element = 'bbc_vols';
52
53
    public $idBBC_vols;
54
    public $date = '';
55
    public $lieuD;
56
    public $lieuA;
57
    public $heureD;
58
    public $heureA;
59
    public $BBC_ballons_idBBC_ballons;
60
    public $nbrPax;
61
    public $remarque;
62
    public $incidents;
63
    public $fk_type;
64
    public $fk_pilot;
65
    public $fk_organisateur;
66
    public $is_facture;
67
    public $kilometers;
68
    public $cost;
69
    public $fk_receiver;
70
    public $justif_kilometers;
71
    public $date_creation;
72
    public $date_update;
73
74
    /**
75
     * @var Bbc_ballons
76
     */
77
    private $balloon;
78
79
    /**
80
     * @var User
81
     */
82
    private $pilot;
83
84
    /**
85
     * @var string
86
     */
87
    private $passengerNames;
88
89
    /**
90
     * @var int[]|array
91
     */
92
    private $orderIds;
93
94
    /**
95
     * @var Commande[]|array
96
     */
97
    private $orders;
98
99
    /**
100
     * @return int
101
     */
102
    public function getIdBBCVols()
103
    {
104
        return (int) $this->idBBC_vols;
105
    }
106
107
    /**
108
     * @return int
109
     */
110
    public function getId()
111
    {
112
        return (int) $this->getIdBBCVols();
113
    }
114
115
    /**
116
     * @param string|int $ref
117
     *
118
     * @return $this
119
     */
120
    public function setRef($ref)
121
    {
122
        $this->ref = $ref;
123
        return $this;
124
    }
125
126
    /**
127
     * Constructor
128
     *
129
     * @param DoliDb $db Database handler
130
     */
131
    public function __construct(DoliDB $db)
132
    {
133
        $this->db = $db;
134
        $this->cost = 0;
135
136
        $this->passengerNames = '';
137
        $this->orderIds = [];
138
    }
139
140
    /**
141
     * Create a flight
142
     *
143
     * @param  User $user      User that creates
144
     * @param  bool $notrigger false=launch triggers after, true=disable triggers
145
     *
146
     * @return int <0 if KO, Id of created object if OK
147
     * @throws Exception
148
     */
149
    public function create(User $user, $notrigger = false)
150
    {
151
        dol_syslog(__METHOD__, LOG_DEBUG);
152
153
        $error = 0;
154
155
        // Clean parameters
156
157
        if (isset($this->idBBC_vols)) {
158
            $this->idBBC_vols = trim($this->idBBC_vols);
159
        }
160
        if (isset($this->lieuD)) {
161
            $this->lieuD = trim($this->lieuD);
162
        }
163
        if (isset($this->lieuA)) {
164
            $this->lieuA = trim($this->lieuA);
165
        }
166
        if (isset($this->heureD)) {
167
            $this->heureD = trim($this->heureD) . '00';
168
        }
169
        if (isset($this->heureA)) {
170
            $this->heureA = trim($this->heureA) . '00';
171
        }
172
        if (isset($this->BBC_ballons_idBBC_ballons)) {
173
            $this->BBC_ballons_idBBC_ballons = trim($this->BBC_ballons_idBBC_ballons);
174
        }
175
        if (isset($this->nbrPax)) {
176
            $this->nbrPax = trim($this->nbrPax);
177
        }
178
        if (isset($this->remarque)) {
179
            $this->remarque = trim($this->remarque);
180
        }
181
        if (isset($this->incidents)) {
182
            $this->incidents = trim($this->incidents);
183
        }
184
        if (isset($this->fk_type)) {
185
            $this->fk_type = trim($this->fk_type);
186
        }
187
        if (isset($this->fk_pilot)) {
188
            $this->fk_pilot = trim($this->fk_pilot);
189
        }
190
        if (isset($this->fk_organisateur)) {
191
            $this->fk_organisateur = trim($this->fk_organisateur);
192
        }
193
        if (isset($this->is_facture)) {
194
            $this->is_facture = trim($this->is_facture);
195
        }
196
        if (isset($this->kilometers)) {
197
            $this->kilometers = trim($this->kilometers);
198
        }
199
        if (isset($this->cost)) {
200
            $this->cost = trim($this->cost);
201
        }
202
        if (isset($this->fk_receiver)) {
203
            $this->fk_receiver = trim($this->fk_receiver);
204
        }
205
        if (isset($this->justif_kilometers)) {
206
            $this->justif_kilometers = trim($this->justif_kilometers);
207
        }
208
        if (isset($this->passengerNames)) {
209
            $this->passengerNames = trim($this->passengerNames);
210
        }
211
212
        // Insert request
213
        $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
214
215
        $sql .= 'date,';
216
        $sql .= 'lieuD,';
217
        $sql .= 'lieuA,';
218
        $sql .= 'heureD,';
219
        $sql .= 'heureA,';
220
        $sql .= 'BBC_ballons_idBBC_ballons,';
221
        $sql .= 'nbrPax,';
222
        $sql .= 'remarque,';
223
        $sql .= 'incidents,';
224
        $sql .= 'fk_type,';
225
        $sql .= 'fk_pilot,';
226
        $sql .= 'fk_organisateur,';
227
        $sql .= 'is_facture,';
228
        $sql .= 'kilometers,';
229
        $sql .= 'cost,';
230
        $sql .= 'fk_receiver,';
231
        $sql .= 'justif_kilometers,';
232
        $sql .= 'date_creation,';
233
        $sql .= 'date_update,';
234
        $sql .= 'passenger_names';
235
236
        $sql .= ') VALUES (';
237
238
        $sql .= ' ' . (!isset($this->date) || dol_strlen($this->date) == 0 ? 'NULL' : "'" . $this->db->idate($this->date) . "'") . ',';
239
        $sql .= ' ' . (!isset($this->lieuD) ? 'NULL' : "'" . $this->db->escape($this->lieuD) . "'") . ',';
240
        $sql .= ' ' . (!isset($this->lieuA) ? 'NULL' : "'" . $this->db->escape($this->lieuA) . "'") . ',';
241
        $sql .= ' ' . (!isset($this->heureD) ? 'NULL' : "'" . $this->heureD . "'") . ',';
242
        $sql .= ' ' . (!isset($this->heureA) ? 'NULL' : "'" . $this->heureA . "'") . ',';
243
        $sql .= ' ' . (!isset($this->BBC_ballons_idBBC_ballons) ? 'NULL' : $this->BBC_ballons_idBBC_ballons) . ',';
244
        $sql .= ' ' . (!isset($this->nbrPax) ? 'NULL' : "'" . $this->db->escape($this->nbrPax) . "'") . ',';
245
        $sql .= ' ' . (!isset($this->remarque) ? 'NULL' : "'" . $this->db->escape($this->remarque) . "'") . ',';
246
        $sql .= ' ' . (!isset($this->incidents) ? 'NULL' : "'" . $this->db->escape($this->incidents) . "'") . ',';
247
        $sql .= ' ' . (!isset($this->fk_type) ? 'NULL' : $this->fk_type) . ',';
248
        $sql .= ' ' . (!isset($this->fk_pilot) ? 'NULL' : $this->fk_pilot) . ',';
249
        $sql .= ' ' . (!isset($this->fk_organisateur) ? 'NULL' : $this->fk_organisateur) . ',';
250
        $sql .= ' ' . (!isset($this->is_facture) ? '0' : $this->is_facture) . ',';
251
        $sql .= ' ' . (!isset($this->kilometers) || empty($this->kilometers) ? '0' : $this->kilometers) . ',';
252
        $sql .= ' ' . (!isset($this->cost) ? 'NULL' : "'" . $this->db->escape($this->cost) . "'") . ',';
253
        $sql .= ' ' . (!isset($this->fk_receiver) ? 'NULL' : $this->fk_receiver) . ',';
254
        $sql .= ' ' . (!isset($this->justif_kilometers) ? 'NULL' : "'" . $this->db->escape($this->justif_kilometers) . "'") . ',';
255
        $sql .= ' ' . "'" . date('Y-m-d H:i:s') . "'" . ',';
256
        $sql .= ' ' . "'" . date('Y-m-d H:i:s') . "'" . ',';
257
        $sql .= ' ' . "'" . $this->passengerNames . "'" . '';
258
259
        $sql .= ')';
260
261
        $this->db->begin();
262
263
        $resql = $this->db->query($sql);
264
        if (!$resql) {
265
            $error++;
266
            $this->errors[] = 'Error ' . $this->db->lasterror();
267
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
268
        }
269
270
        if (!$error) {
271
            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
272
273
            if (!$notrigger) {
274
                $result = $this->call_trigger('BBC_FLIGHT_CREATED', $user);
275
                if ($result < 0) {
276
                    $error++;
277
                }
278
            }
279
        }
280
281
        // Commit or rollback
282
        if ($error) {
283
            $this->db->rollback();
284
285
            return -1 * $error;
286
        }
287
288
        $this->db->commit();
289
        return $this->id;
290
    }
291
292
    /**
293
     * Load object in memory from the database
294
     *
295
     * @param int    $id  Id object
296
     * @param string $ref Ref
297
     *
298
     * @return int <0 if KO, 0 if not found, >0 if OK
299
     * @throws Exception
300
     */
301
    public function fetch($id, $ref = null)
302
    {
303
        dol_syslog(__METHOD__, LOG_DEBUG);
304
305
        $sql = 'SELECT';
306
        $sql .= " t.idBBC_vols,";
307
        $sql .= " t.date,";
308
        $sql .= " t.lieuD,";
309
        $sql .= " t.lieuA,";
310
        $sql .= " t.heureD,";
311
        $sql .= " t.heureA,";
312
        $sql .= " t.BBC_ballons_idBBC_ballons,";
313
        $sql .= " t.nbrPax,";
314
        $sql .= " t.remarque,";
315
        $sql .= " t.incidents,";
316
        $sql .= " t.fk_type,";
317
        $sql .= " t.fk_pilot,";
318
        $sql .= " t.fk_organisateur,";
319
        $sql .= " t.is_facture,";
320
        $sql .= " t.kilometers,";
321
        $sql .= " t.cost,";
322
        $sql .= " t.fk_receiver,";
323
        $sql .= " t.justif_kilometers,";
324
        $sql .= " t.date_creation,";
325
        $sql .= " t.date_update,";
326
        $sql .= " t.passenger_names";
327
328
329
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
330 View Code Duplication
        if (null !== $ref) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
331
            $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\'';
332
        } else {
333
            $sql .= ' WHERE t.idBBC_vols = ' . $id;
334
        }
335
336
        $resql = $this->db->query($sql);
337
        if ($resql) {
338
            $numrows = $this->db->num_rows($resql);
339
            if ($numrows) {
340
                $obj = $this->db->fetch_object($resql);
341
342
                $this->id = $obj->idBBC_vols;
343
344
                $this->idBBC_vols = $obj->idBBC_vols;
345
                $this->date = $this->db->jdate($obj->date);
346
                $this->lieuD = $obj->lieuD;
347
                $this->lieuA = $obj->lieuA;
348
                $this->heureD = $obj->heureD;
349
                $this->heureA = $obj->heureA;
350
                $this->BBC_ballons_idBBC_ballons = $obj->BBC_ballons_idBBC_ballons;
351
                $this->nbrPax = $obj->nbrPax;
352
                $this->remarque = $obj->remarque;
353
                $this->incidents = $obj->incidents;
354
                $this->fk_type = $obj->fk_type;
355
                $this->fk_pilot = $obj->fk_pilot;
356
                $this->fk_organisateur = $obj->fk_organisateur;
357
                $this->is_facture = $obj->is_facture;
358
                $this->kilometers = $obj->kilometers;
359
                $this->cost = $obj->cost;
360
                $this->fk_receiver = $obj->fk_receiver;
361
                $this->justif_kilometers = $obj->justif_kilometers;
362
                $this->date_creation = $obj->date_creation;
363
                $this->date_update = $obj->date_update;
364
                $this->passengerNames = $obj->passenger_names;
365
366
                $this->balloon = $this->fetchBalloon();
367
                $this->pilot = $this->fetchUser($this->fk_pilot);
368
                $this->fetchOrder();
369
            }
370
            $this->db->free($resql);
371
372
            if ($numrows) {
373
                return 1;
374
            } else {
375
                return 0;
376
            }
377
        }
378
379
        $this->errors[] = 'Error ' . $this->db->lasterror();
380
        dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
381
        return -1;
382
    }
383
384
    /**
385
     * @param  User $user      User that modifies
386
     * @param  bool $notrigger false=launch triggers after, true=disable triggers
387
     *
388
     * @return int <0 if KO, >0 if OK
389
     * @throws Exception
390
     */
391
    public function update(User $user, $notrigger = false)
392
    {
393
        $error = 0;
394
395
        dol_syslog(__METHOD__, LOG_DEBUG);
396
397
        // Clean parameters
398
399
        if (isset($this->idBBC_vols)) {
400
            $this->idBBC_vols = trim($this->idBBC_vols);
401
        }
402
        if (isset($this->lieuD)) {
403
            $this->lieuD = trim($this->lieuD);
404
        }
405
        if (isset($this->lieuA)) {
406
            $this->lieuA = trim($this->lieuA);
407
        }
408
        if (isset($this->heureD)) {
409
            $this->heureD = trim($this->heureD);
410
        }
411
        if (isset($this->heureA)) {
412
            $this->heureA = trim($this->heureA);
413
        }
414
        if (isset($this->BBC_ballons_idBBC_ballons)) {
415
            $this->BBC_ballons_idBBC_ballons = trim($this->BBC_ballons_idBBC_ballons);
416
        }
417
        if (isset($this->nbrPax)) {
418
            $this->nbrPax = trim($this->nbrPax);
419
        }
420
        if (isset($this->remarque)) {
421
            $this->remarque = trim($this->remarque);
422
        }
423
        if (isset($this->incidents)) {
424
            $this->incidents = trim($this->incidents);
425
        }
426
        if (isset($this->fk_type)) {
427
            $this->fk_type = trim($this->fk_type);
428
        }
429
        if (isset($this->fk_pilot)) {
430
            $this->fk_pilot = trim($this->fk_pilot);
431
        }
432
        if (isset($this->fk_organisateur)) {
433
            $this->fk_organisateur = trim($this->fk_organisateur);
434
        }
435
        if (isset($this->is_facture)) {
436
            $this->is_facture = trim($this->is_facture);
437
        }
438
        if (isset($this->kilometers)) {
439
            $this->kilometers = trim($this->kilometers);
440
        }
441
        if (isset($this->cost)) {
442
            $this->cost = trim($this->cost);
443
        }
444
        if (isset($this->fk_receiver)) {
445
            $this->fk_receiver = trim($this->fk_receiver);
446
        }
447
        if (isset($this->justif_kilometers)) {
448
            $this->justif_kilometers = trim($this->justif_kilometers);
449
        }
450
        if (isset($this->passengerNames)) {
451
            $this->passengerNames = trim($this->passengerNames);
452
        }
453
454
        // Check parameters
455
        // Put here code to add a control on parameters values
456
457
        // Update request
458
        $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
459
460
        $sql .= ' date = ' . (!isset($this->date) || dol_strlen($this->date) != 0 ? "'" . $this->db->idate($this->date) . "'" : 'null') . ',';
461
        $sql .= ' lieuD = ' . (isset($this->lieuD) ? "'" . $this->db->escape($this->lieuD) . "'" : "null") . ',';
462
        $sql .= ' lieuA = ' . (isset($this->lieuA) ? "'" . $this->db->escape($this->lieuA) . "'" : "null") . ',';
463
        $sql .= ' heureD = ' . (isset($this->heureD) ? "'" . $this->heureD . "'" : "null") . ',';
464
        $sql .= ' heureA = ' . (isset($this->heureA) ? "'" . $this->heureA . "'" : "null") . ',';
465
        $sql .= ' BBC_ballons_idBBC_ballons = ' . (isset($this->BBC_ballons_idBBC_ballons) ? $this->BBC_ballons_idBBC_ballons : "null") . ',';
466
        $sql .= ' nbrPax = ' . (isset($this->nbrPax) ? "'" . $this->db->escape($this->nbrPax) . "'" : "null") . ',';
467
        $sql .= ' remarque = ' . (isset($this->remarque) ? "'" . $this->db->escape($this->remarque) . "'" : "null") . ',';
468
        $sql .= ' incidents = ' . (isset($this->incidents) ? "'" . $this->db->escape($this->incidents) . "'" : "null") . ',';
469
        $sql .= ' fk_type = ' . (isset($this->fk_type) ? $this->fk_type : "null") . ',';
470
        $sql .= ' fk_pilot = ' . (isset($this->fk_pilot) ? $this->fk_pilot : "null") . ',';
471
        $sql .= ' fk_organisateur = ' . (isset($this->fk_organisateur) ? $this->fk_organisateur : "null") . ',';
472
        $sql .= ' is_facture = ' . (isset($this->is_facture) ? $this->is_facture : "0") . ',';
473
        $sql .= ' kilometers = ' . (!empty($this->kilometers) ? $this->kilometers : "0") . ',';
474
        $sql .= ' cost = ' . (isset($this->cost) ? "'" . $this->db->escape($this->cost) . "'" : "''") . ',';
475
        $sql .= ' fk_receiver = ' . (isset($this->fk_receiver) ? $this->fk_receiver : "null") . ',';
476
        $sql .= ' justif_kilometers = ' . (isset($this->justif_kilometers) ? "'" . $this->db->escape($this->justif_kilometers) . "'," : "'',");
477
        $sql .= ' date_update = ' . "'" . date('Y-m-d H:i:s') . "',";
478
        $sql .= ' passenger_names = ' . "'" . trim($this->passengerNames) . "'";
479
480
        $sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols;
481
482
        $this->db->begin();
483
484
        $resql = $this->db->query($sql);
485
        if (!$resql) {
486
            $error++;
487
            $this->errors[] = 'Error ' . $this->db->lasterror();
488
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
489
        }
490
491
        if (!$error && !$notrigger) {
492
            $result = $this->call_trigger('BBC_FLIGHT_UPDATED', $user);
493
            if ($result < 0) {
494
                $error++;
495
            }
496
        }
497
498
        // Commit or rollback
499
        if ($error) {
500
            $this->db->rollback();
501
502
            return -1 * $error;
503
        }
504
505
        $this->db->commit();
506
        return 1;
507
    }
508
509
    /**
510
     * Delete object in database
511
     *
512
     * @param User $user      User that deletes
513
     * @param bool $notrigger false=launch triggers after, true=disable triggers
514
     *
515
     * @return int <0 if KO, >0 if OK
516
     * @throws Exception
517
     */
518
    public function delete(User $user, $notrigger = false)
519
    {
520
        dol_syslog(__METHOD__, LOG_DEBUG);
521
522
        $error = 0;
523
524
        $this->db->begin();
525
526
        if (!$error) {
527
            if (!$notrigger) {
528
                $result = $this->call_trigger('BBC_FLIGHT_DELETED', $user);
529
                if ($result < 0) {
530
                    $error++;
531
                }
532
            }
533
        }
534
535 View Code Duplication
        if (!$error) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
536
            $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
537
            $sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols;
538
539
            $resql = $this->db->query($sql);
540
            if (!$resql) {
541
                $error++;
542
                $this->errors[] = 'Error ' . $this->db->lasterror();
543
                dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
544
            }
545
        }
546
547
        // Commit or rollback
548
        if ($error) {
549
            $this->db->rollback();
550
            return -1 * $error;
551
        }
552
553
        $this->db->commit();
554
        return 1;
555
    }
556
557
    /**
558
     *  Return a link to the user card (with optionaly the picto)
559
     *    Use this->id,this->lastname, this->firstname
560
     *
561
     * @param    int     $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
562
     * @param    string  $option    On what the link point to
563
     * @param    integer $notooltip 1=Disable tooltip
564
     * @param    int     $maxlen    Max length of visible user name
565
     * @param  string    $morecss   Add more css on link
566
     *
567
     * @return    string                        String with URL
568
     */
569
    public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
570
    {
571
        global $langs;
572
573
        $result = '';
574
575
        $label = '<u>' . $langs->trans("MyModule") . '</u>';
576
        $label .= '<div width="100%">';
577
        $label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->idBBC_vols . '<br>';
578
        $label .= '<b>' . $langs->trans('Date') . ':</b> ' . dol_print_date($this->date, '%d-%m-%Y') . '<br/>';
579
        $label .= '<b>' . $langs->trans('From') . ':</b> ' . $this->lieuD . '<br/>';
580
        $label .= '<b>' . $langs->trans('To') . ':</b> ' . $this->lieuA . '<br/>';
581
        $label .= '</div>';
582
583
        $link = '<a href="' . DOL_URL_ROOT . '/flightlog/card.php?id=' . $this->idBBC_vols . '"';
584
        $link .= ($notooltip ? '' : ' title="' . dol_escape_htmltag($label,
585
                1) . '" class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"');
586
        $link .= '>';
587
        $linkend = '</a>';
588
589 View Code Duplication
        if ($withpicto) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
590
            $result .= ($link . img_object(($notooltip ? '' : $label), 'label',
591
                    ($notooltip ? '' : 'class="classfortooltip"')) . $linkend);
592
            if ($withpicto != 2) {
593
                $result .= ' ';
594
            }
595
        }
596
        $result .= $link . $this->idBBC_vols . $linkend;
597
        return $result;
598
    }
599
600
    /**
601
     *  Retourne le libelle du status d'un user (actif, inactif)
602
     *
603
     * @param    int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
604
     *
605
     * @return    string                   Label of status
606
     */
607
    public function getLibStatut($mode = 0)
608
    {
609
        return $this->LibStatut($this->is_facture, $mode);
610
    }
611
612
    /**
613
     * Renvoi le libelle d'un status donne
614
     *
615
     * @param int $status Id status
616
     * @param int $mode   0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
617
     *
618
     * @return string                    Label of status
619
     */
620
    private function LibStatut($status, $mode = 0)
621
    {
622
        global $langs;
623
624
        $billDone = $langs->trans('Facturé');
625
        $billNotDone = $langs->trans('Ouvert');
626
627 View Code Duplication
        if ($mode == 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
628
            if ($status == 1) {
629
                return $billDone;
630
            }
631
            if ($status == 0) {
632
                return $billNotDone;
633
            }
634
        }
635 View Code Duplication
        if ($mode == 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
636
            if ($status == 1) {
637
                return $billDone;
638
            }
639
            if ($status == 0) {
640
                return $billNotDone;
641
            }
642
        }
643 View Code Duplication
        if ($mode == 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
644
            if ($status == 1) {
645
                return img_picto($billDone, 'statut4') . ' ' . $billDone;
646
            }
647
            if ($status == 0) {
648
                return img_picto($billNotDone, 'statut5') . ' ' . $billNotDone;
649
            }
650
        }
651
        if ($mode == 3) {
652
            if ($status == 1) {
653
                return img_picto($billDone, 'statut4');
654
            }
655
            if ($status == 0) {
656
                return img_picto($billNotDone, 'statut5');
657
            }
658
        }
659 View Code Duplication
        if ($mode == 4) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
660
            if ($status == 1) {
661
                return img_picto($billDone, 'statut4') . ' ' . $billDone;
662
            }
663
            if ($status == 0) {
664
                return img_picto($billNotDone, 'statut5') . ' ' . $billNotDone;
665
            }
666
        }
667 View Code Duplication
        if ($mode == 5) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
668
            if ($status == 1) {
669
                return $billDone . ' ' . img_picto($billDone, 'statut4');
670
            }
671
            if ($status == 0) {
672
                return $billNotDone . ' ' . img_picto($billNotDone, 'statut5');
673
            }
674
        }
675
676
        return "";
677
    }
678
679
    /**
680
     * @return string
681
     */
682
    public function __toString()
683
    {
684
        return $this->idBBC_vols . " " . $this->getPlaces();
685
    }
686
687
    /**
688
     * @return string
689
     */
690
    public function toString()
691
    {
692
        return "" . $this;
693
    }
694
695
    /**
696
     * @return string
697
     */
698
    public function getStatus()
699
    {
700
        return $this->statut;
701
    }
702
703
    /**
704
     * @return boolean
705
     */
706
    public function hasFacture()
707
    {
708
        return count($this->linkedObjectsIds) > 0;
709
    }
710
711
    /**
712
     * @param int $userId
713
     *
714
     * @return User
715
     */
716
    private function fetchUser($userId)
717
    {
718
        $user = new User($this->db);
719
        $user->fetch($userId);
720
721
        return $user;
722
    }
723
724
    /**
725
     * @return Bbc_ballons
726
     */
727
    private function fetchBalloon()
728
    {
729
        $balloon = new Bbc_ballons($this->db);
730
        $balloon->fetch($this->BBC_ballons_idBBC_ballons);
731
732
        return $balloon;
733
    }
734
735
    /**
736
     * @return Bbc_ballons
737
     */
738
    public function getBalloon()
739
    {
740
        if (!$this->balloon) {
741
            $this->balloon = $this->fetchBalloon();
742
        }
743
744
        return $this->balloon;
745
    }
746
747
    /**
748
     * @return User
749
     */
750
    public function getPilot()
751
    {
752
        if (!$this->pilot) {
753
            $this->pilot = $this->fetchUser($this->fk_pilot);
754
        }
755
756
        return $this->pilot;
757
    }
758
759
    /**
760
     * @return int
761
     */
762
    public function getPilotId()
763
    {
764
        return (int) $this->fk_pilot;
765
    }
766
767
    /**
768
     * @return int
769
     */
770
    public function getOrganisatorId()
771
    {
772
        return (int) $this->fk_organisateur;
773
    }
774
775
    /**
776
     * @return Bbctypes
777
     */
778
    public function getFlightType()
779
    {
780
        $flightType = new Bbctypes($this->db);
781
        $flightType->fetch($this->fk_type);
782
783
        return $flightType;
784
    }
785
786
    /**
787
     * @return string
788
     */
789
    public function getComment()
790
    {
791
        return $this->remarque;
792
    }
793
794
    /**
795
     * @return string
796
     */
797
    public function getIncident()
798
    {
799
        return $this->incidents;
800
    }
801
802
    /**
803
     * Return true if the number of pax is greater than 0
804
     *
805
     * @return boolean
806
     */
807
    public function hasPax()
808
    {
809
        return (int) $this->nbrPax > 0;
810
    }
811
812
    /**
813
     * Regarding the type of the flight give an indication if the flight must have pax to be valid.
814
     *
815
     * @return boolean
816
     */
817
    public function mustHavePax()
818
    {
819
        return $this->getFlightType()->isPaxRequired();
820
    }
821
822
    /**
823
     * Returns true if the amount requested by the flight is 0.
824
     *
825
     * @return boolean
826
     */
827
    public function isFree()
828
    {
829
        return empty($this->cost);
830
    }
831
832
    /**
833
     * @return int
834
     */
835
    public function getAmountReceived()
836
    {
837
        return $this->cost;
838
    }
839
840
    /**
841
     * @return int
842
     */
843
    public function getAmountPerPassenger()
844
    {
845
        return $this->cost / $this->nbrPax;
846
    }
847
848
    /**
849
     * @return boolean
850
     */
851
    public function hasReceiver()
852
    {
853
        return !empty($this->fk_receiver);
854
    }
855
856
    /**
857
     * @return boolean
858
     */
859
    public function hasKilometers()
860
    {
861
        return !empty($this->kilometers);
862
    }
863
864
    /**
865
     * @return boolean
866
     */
867
    public function hasKilometersDescription()
868
    {
869
        return !empty(trim($this->justif_kilometers));
870
    }
871
872
    /**
873
     * @return int
874
     */
875
    public function getKilometers()
876
    {
877
        return (int) $this->kilometers;
878
    }
879
880
    /**
881
     * @return string
882
     */
883
    public function getPlaces()
884
    {
885
        return $this->lieuD . ' -> ' . $this->lieuA;
886
    }
887
888
    /**
889
     * @return string
890
     */
891
    public function getDescription()
892
    {
893
        return $this->__toString() . ' - ' . $this->passengerNames;
894
    }
895
896
    /**
897
     * @return string
898
     */
899
    public function getPassengerNames()
900
    {
901
        return $this->passengerNames;
902
    }
903
904
    /**
905
     * @param string $passengerNames
906
     *
907
     * @return Bbcvols
908
     */
909
    public function setPassengerNames($passengerNames)
910
    {
911
        $this->passengerNames = $passengerNames;
912
        return $this;
913
    }
914
915
    /**
916
     * @return int
917
     */
918
    public function getNumberOfPassengers()
919
    {
920
        return (int) $this->nbrPax;
921
    }
922
923
    /**
924
     * @return int[]|array
925
     */
926
    public function getOrderIds()
927
    {
928
        return $this->orderIds;
929
    }
930
931
    /**
932
     * @param int[]|array $orderIds
933
     *
934
     * @return Bbcvols
935
     */
936
    public function setOrderIds($orderIds)
937
    {
938
        $this->orderIds = $orderIds;
939
        return $this;
940
    }
941
942
    /**
943
     * Is an instruction flight (T6/T7)
944
     */
945
    public function isInstruction()
946
    {
947
        return $this->getFlightType()->isInstruction();
948
    }
949
950
    /**
951
     * @return bool
952
     */
953
    public function isLinkedToOrder()
954
    {
955
        return !empty($this->orderIds);
956
    }
957
958
    /**
959
     * Fetch the order based on the order id.
960
     */
961
    public function fetchOrder()
962
    {
963
        if (!$this->isLinkedToOrder()) {
964
            return $this;
965
        }
966
967
        foreach ($this->getOrderIds() as $currentOrderId) {
968
            $order = new Commande($this->db);
969
            $order->fetch((int) $currentOrderId);
970
971
            $this->orders[] = $order;
972
        }
973
974
975
        return $this;
976
    }
977
978
    /**
979
     * @return Commande[]|array
980
     */
981
    public function getOrders()
982
    {
983
        return $this->orders;
984
    }
985
986
    /**
987
     * Flag the flight as billed
988
     *
989
     * @return $this
990
     */
991
    public function bill()
992
    {
993
        $this->is_facture = true;
994
        return $this;
995
    }
996
997
    /**
998
     * @return boolean
999
     */
1000
    public function isBilled()
1001
    {
1002
        return !empty($this->is_facture);
1003
    }
1004
1005
}
1006