Completed
Push — master ( 3a683c...464735 )
by Laurent
01:31
created

Bbcvols::getPassengerNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
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
34
/**
35
 * Class Bbcvols
36
 *
37
 * Put here description of your class
38
 *
39
 * @see CommonObject
40
 */
41
class Bbcvols extends CommonObject
42
{
43
    /**
44
     * @var string Id to identify managed objects
45
     */
46
    public $element = 'flightlog_bbcvols';
47
    /**
48
     * @var string Name of table without prefix where object is stored
49
     */
50
    public $table_element = 'bbc_vols';
51
52
    /**
53
     * @var BbcvolsLine[] Lines
54
     */
55
    public $lines = array();
56
57
    public $idBBC_vols;
58
    public $date = '';
59
    public $lieuD;
60
    public $lieuA;
61
    public $heureD;
62
    public $heureA;
63
    public $BBC_ballons_idBBC_ballons;
64
    public $nbrPax;
65
    public $remarque;
66
    public $incidents;
67
    public $fk_type;
68
    public $fk_pilot;
69
    public $fk_organisateur;
70
    public $is_facture;
71
    public $kilometers;
72
    public $cost;
73
    public $fk_receiver;
74
    public $justif_kilometers;
75
    public $date_creation;
76
    public $date_update;
77
78
    /**
79
     * @var Bbc_ballons
80
     */
81
    private $balloon;
82
83
    /**
84
     * @var User
85
     */
86
    private $pilot;
87
88
    /**
89
     * @var string
90
     */
91
    private $passengerNames;
92
93
    /**
94
     * @return int
95
     */
96
    public function getIdBBCVols()
97
    {
98
        return (int) $this->idBBC_vols;
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public function getId()
105
    {
106
        return (int) $this->getIdBBCVols();
107
    }
108
109
    /**
110
     * @param string|int $ref
111
     *
112
     * @return $this
113
     */
114
    public function setRef($ref)
115
    {
116
        $this->ref = $ref;
117
        return $this;
118
    }
119
120
    /**
121
     * Constructor
122
     *
123
     * @param DoliDb $db Database handler
124
     */
125
    public function __construct(DoliDB $db)
126
    {
127
        $this->db = $db;
128
        $this->cost = 0;
129
130
        $this->passengerNames = '';
131
    }
132
133
    /**
134
     * Create a flight
135
     *
136
     * @param  User $user      User that creates
137
     * @param  bool $notrigger false=launch triggers after, true=disable triggers
138
     *
139
     * @return int <0 if KO, Id of created object if OK
140
     */
141
    public function create(User $user, $notrigger = false)
142
    {
143
        dol_syslog(__METHOD__, LOG_DEBUG);
144
145
        $error = 0;
146
147
        // Clean parameters
148
149
        if (isset($this->idBBC_vols)) {
150
            $this->idBBC_vols = trim($this->idBBC_vols);
151
        }
152
        if (isset($this->lieuD)) {
153
            $this->lieuD = trim($this->lieuD);
154
        }
155
        if (isset($this->lieuA)) {
156
            $this->lieuA = trim($this->lieuA);
157
        }
158
        if (isset($this->heureD)) {
159
            $this->heureD = trim($this->heureD) . '00';
160
        }
161
        if (isset($this->heureA)) {
162
            $this->heureA = trim($this->heureA) . '00';
163
        }
164
        if (isset($this->BBC_ballons_idBBC_ballons)) {
165
            $this->BBC_ballons_idBBC_ballons = trim($this->BBC_ballons_idBBC_ballons);
166
        }
167
        if (isset($this->nbrPax)) {
168
            $this->nbrPax = trim($this->nbrPax);
169
        }
170
        if (isset($this->remarque)) {
171
            $this->remarque = trim($this->remarque);
172
        }
173
        if (isset($this->incidents)) {
174
            $this->incidents = trim($this->incidents);
175
        }
176
        if (isset($this->fk_type)) {
177
            $this->fk_type = trim($this->fk_type);
178
        }
179
        if (isset($this->fk_pilot)) {
180
            $this->fk_pilot = trim($this->fk_pilot);
181
        }
182
        if (isset($this->fk_organisateur)) {
183
            $this->fk_organisateur = trim($this->fk_organisateur);
184
        }
185
        if (isset($this->is_facture)) {
186
            $this->is_facture = trim($this->is_facture);
187
        }
188
        if (isset($this->kilometers)) {
189
            $this->kilometers = trim($this->kilometers);
190
        }
191
        if (isset($this->cost)) {
192
            $this->cost = trim($this->cost);
193
        }
194
        if (isset($this->fk_receiver)) {
195
            $this->fk_receiver = trim($this->fk_receiver);
196
        }
197
        if (isset($this->justif_kilometers)) {
198
            $this->justif_kilometers = trim($this->justif_kilometers);
199
        }
200
        if (isset($this->passengerNames)) {
201
            $this->passengerNames = trim($this->passengerNames);
202
        }
203
204
        // Insert request
205
        $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
206
207
        $sql .= 'date,';
208
        $sql .= 'lieuD,';
209
        $sql .= 'lieuA,';
210
        $sql .= 'heureD,';
211
        $sql .= 'heureA,';
212
        $sql .= 'BBC_ballons_idBBC_ballons,';
213
        $sql .= 'nbrPax,';
214
        $sql .= 'remarque,';
215
        $sql .= 'incidents,';
216
        $sql .= 'fk_type,';
217
        $sql .= 'fk_pilot,';
218
        $sql .= 'fk_organisateur,';
219
        $sql .= 'is_facture,';
220
        $sql .= 'kilometers,';
221
        $sql .= 'cost,';
222
        $sql .= 'fk_receiver,';
223
        $sql .= 'justif_kilometers,';
224
        $sql .= 'date_creation,';
225
        $sql .= 'date_update,';
226
        $sql .= 'passenger_names';
227
228
        $sql .= ') VALUES (';
229
230
        $sql .= ' ' . (!isset($this->date) || dol_strlen($this->date) == 0 ? 'NULL' : "'" . $this->db->idate($this->date) . "'") . ',';
231
        $sql .= ' ' . (!isset($this->lieuD) ? 'NULL' : "'" . $this->db->escape($this->lieuD) . "'") . ',';
232
        $sql .= ' ' . (!isset($this->lieuA) ? 'NULL' : "'" . $this->db->escape($this->lieuA) . "'") . ',';
233
        $sql .= ' ' . (!isset($this->heureD) ? 'NULL' : "'" . $this->heureD . "'") . ',';
234
        $sql .= ' ' . (!isset($this->heureA) ? 'NULL' : "'" . $this->heureA . "'") . ',';
235
        $sql .= ' ' . (!isset($this->BBC_ballons_idBBC_ballons) ? 'NULL' : $this->BBC_ballons_idBBC_ballons) . ',';
236
        $sql .= ' ' . (!isset($this->nbrPax) ? 'NULL' : "'" . $this->db->escape($this->nbrPax) . "'") . ',';
237
        $sql .= ' ' . (!isset($this->remarque) ? 'NULL' : "'" . $this->db->escape($this->remarque) . "'") . ',';
238
        $sql .= ' ' . (!isset($this->incidents) ? 'NULL' : "'" . $this->db->escape($this->incidents) . "'") . ',';
239
        $sql .= ' ' . (!isset($this->fk_type) ? 'NULL' : $this->fk_type) . ',';
240
        $sql .= ' ' . (!isset($this->fk_pilot) ? 'NULL' : $this->fk_pilot) . ',';
241
        $sql .= ' ' . (!isset($this->fk_organisateur) ? 'NULL' : $this->fk_organisateur) . ',';
242
        $sql .= ' ' . (!isset($this->is_facture) ? '0' : $this->is_facture) . ',';
243
        $sql .= ' ' . (!isset($this->kilometers) || empty($this->kilometers) ? '0' : $this->kilometers) . ',';
244
        $sql .= ' ' . (!isset($this->cost) ? 'NULL' : "'" . $this->db->escape($this->cost) . "'") . ',';
245
        $sql .= ' ' . (!isset($this->fk_receiver) ? 'NULL' : $this->fk_receiver) . ',';
246
        $sql .= ' ' . (!isset($this->justif_kilometers) ? 'NULL' : "'" . $this->db->escape($this->justif_kilometers) . "'") . ',';
247
        $sql .= ' ' . "'" . date('Y-m-d H:i:s') . "'" . ',';
248
        $sql .= ' ' . "'" . date('Y-m-d H:i:s') . "'" . ',';
249
        $sql .= ' ' . "'" . $this->passengerNames . "'" . '';
250
251
        $sql .= ')';
252
253
        $this->db->begin();
254
255
        $resql = $this->db->query($sql);
256 View Code Duplication
        if (!$resql) {
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...
257
            $error++;
258
            $this->errors[] = 'Error ' . $this->db->lasterror();
259
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
260
        }
261
262
        if (!$error) {
263
            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
264
265
            if (!$notrigger) {
266
                $result = $this->call_trigger('BBC_FLIGHT_CREATED', $user);
267
                if ($result < 0) {
268
                    $error++;
269
                }
270
            }
271
        }
272
273
        // Commit or rollback
274
        if ($error) {
275
            $this->db->rollback();
276
277
            return -1 * $error;
278
        }
279
280
        $this->db->commit();
281
        return $this->id;
282
    }
283
284
    /**
285
     * Load object in memory from the database
286
     *
287
     * @param int    $id  Id object
288
     * @param string $ref Ref
289
     *
290
     * @return int <0 if KO, 0 if not found, >0 if OK
291
     */
292
    public function fetch($id, $ref = null)
293
    {
294
        dol_syslog(__METHOD__, LOG_DEBUG);
295
296
        $sql = 'SELECT';
297
        $sql .= " t.idBBC_vols,";
298
        $sql .= " t.date,";
299
        $sql .= " t.lieuD,";
300
        $sql .= " t.lieuA,";
301
        $sql .= " t.heureD,";
302
        $sql .= " t.heureA,";
303
        $sql .= " t.BBC_ballons_idBBC_ballons,";
304
        $sql .= " t.nbrPax,";
305
        $sql .= " t.remarque,";
306
        $sql .= " t.incidents,";
307
        $sql .= " t.fk_type,";
308
        $sql .= " t.fk_pilot,";
309
        $sql .= " t.fk_organisateur,";
310
        $sql .= " t.is_facture,";
311
        $sql .= " t.kilometers,";
312
        $sql .= " t.cost,";
313
        $sql .= " t.fk_receiver,";
314
        $sql .= " t.justif_kilometers,";
315
        $sql .= " t.date_creation,";
316
        $sql .= " t.date_update,";
317
        $sql .= " t.passenger_names";
318
319
320
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
321 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...
322
            $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\'';
323
        } else {
324
            $sql .= ' WHERE t.idBBC_vols = ' . $id;
325
        }
326
327
        $resql = $this->db->query($sql);
328
        if ($resql) {
329
            $numrows = $this->db->num_rows($resql);
330
            if ($numrows) {
331
                $obj = $this->db->fetch_object($resql);
332
333
                $this->id = $obj->idBBC_vols;
334
335
                $this->idBBC_vols = $obj->idBBC_vols;
336
                $this->date = $this->db->jdate($obj->date);
337
                $this->lieuD = $obj->lieuD;
338
                $this->lieuA = $obj->lieuA;
339
                $this->heureD = $obj->heureD;
340
                $this->heureA = $obj->heureA;
341
                $this->BBC_ballons_idBBC_ballons = $obj->BBC_ballons_idBBC_ballons;
342
                $this->nbrPax = $obj->nbrPax;
343
                $this->remarque = $obj->remarque;
344
                $this->incidents = $obj->incidents;
345
                $this->fk_type = $obj->fk_type;
346
                $this->fk_pilot = $obj->fk_pilot;
347
                $this->fk_organisateur = $obj->fk_organisateur;
348
                $this->is_facture = $obj->is_facture;
349
                $this->kilometers = $obj->kilometers;
350
                $this->cost = $obj->cost;
351
                $this->fk_receiver = $obj->fk_receiver;
352
                $this->justif_kilometers = $obj->justif_kilometers;
353
                $this->date_creation = $obj->date_creation;
354
                $this->date_update = $obj->date_update;
355
                $this->passengerNames = $obj->passenger_names;
356
357
                $this->balloon = $this->fetchBalloon();
358
                $this->pilot = $this->fetchUser($this->fk_pilot);
359
            }
360
            $this->db->free($resql);
361
362
            if ($numrows) {
363
                return 1;
364
            } else {
365
                return 0;
366
            }
367
        }
368
369
        $this->errors[] = 'Error ' . $this->db->lasterror();
370
        dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
371
        return -1;
372
    }
373
374
    /**
375
     * @param  User $user      User that modifies
376
     * @param  bool $notrigger false=launch triggers after, true=disable triggers
377
     *
378
     * @return int <0 if KO, >0 if OK
379
     */
380
    public function update(User $user, $notrigger = false)
381
    {
382
        $error = 0;
383
384
        dol_syslog(__METHOD__, LOG_DEBUG);
385
386
        // Clean parameters
387
388
        if (isset($this->idBBC_vols)) {
389
            $this->idBBC_vols = trim($this->idBBC_vols);
390
        }
391
        if (isset($this->lieuD)) {
392
            $this->lieuD = trim($this->lieuD);
393
        }
394
        if (isset($this->lieuA)) {
395
            $this->lieuA = trim($this->lieuA);
396
        }
397
        if (isset($this->heureD)) {
398
            $this->heureD = trim($this->heureD);
399
        }
400
        if (isset($this->heureA)) {
401
            $this->heureA = trim($this->heureA);
402
        }
403
        if (isset($this->BBC_ballons_idBBC_ballons)) {
404
            $this->BBC_ballons_idBBC_ballons = trim($this->BBC_ballons_idBBC_ballons);
405
        }
406
        if (isset($this->nbrPax)) {
407
            $this->nbrPax = trim($this->nbrPax);
408
        }
409
        if (isset($this->remarque)) {
410
            $this->remarque = trim($this->remarque);
411
        }
412
        if (isset($this->incidents)) {
413
            $this->incidents = trim($this->incidents);
414
        }
415
        if (isset($this->fk_type)) {
416
            $this->fk_type = trim($this->fk_type);
417
        }
418
        if (isset($this->fk_pilot)) {
419
            $this->fk_pilot = trim($this->fk_pilot);
420
        }
421
        if (isset($this->fk_organisateur)) {
422
            $this->fk_organisateur = trim($this->fk_organisateur);
423
        }
424
        if (isset($this->is_facture)) {
425
            $this->is_facture = trim($this->is_facture);
426
        }
427
        if (isset($this->kilometers)) {
428
            $this->kilometers = trim($this->kilometers);
429
        }
430
        if (isset($this->cost)) {
431
            $this->cost = trim($this->cost);
432
        }
433
        if (isset($this->fk_receiver)) {
434
            $this->fk_receiver = trim($this->fk_receiver);
435
        }
436
        if (isset($this->justif_kilometers)) {
437
            $this->justif_kilometers = trim($this->justif_kilometers);
438
        }
439
        if (isset($this->passengerNames)) {
440
            $this->passengerNames = trim($this->passengerNames);
441
        }
442
443
444
        // Check parameters
445
        // Put here code to add a control on parameters values
446
447
        // Update request
448
        $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
449
450
        $sql .= ' date = ' . (!isset($this->date) || dol_strlen($this->date) != 0 ? "'" . $this->db->idate($this->date) . "'" : 'null') . ',';
451
        $sql .= ' lieuD = ' . (isset($this->lieuD) ? "'" . $this->db->escape($this->lieuD) . "'" : "null") . ',';
452
        $sql .= ' lieuA = ' . (isset($this->lieuA) ? "'" . $this->db->escape($this->lieuA) . "'" : "null") . ',';
453
        $sql .= ' heureD = ' . (isset($this->heureD) ? "'" . $this->heureD . "'" : "null") . ',';
454
        $sql .= ' heureA = ' . (isset($this->heureA) ? "'" . $this->heureA . "'" : "null") . ',';
455
        $sql .= ' BBC_ballons_idBBC_ballons = ' . (isset($this->BBC_ballons_idBBC_ballons) ? $this->BBC_ballons_idBBC_ballons : "null") . ',';
456
        $sql .= ' nbrPax = ' . (isset($this->nbrPax) ? "'" . $this->db->escape($this->nbrPax) . "'" : "null") . ',';
457
        $sql .= ' remarque = ' . (isset($this->remarque) ? "'" . $this->db->escape($this->remarque) . "'" : "null") . ',';
458
        $sql .= ' incidents = ' . (isset($this->incidents) ? "'" . $this->db->escape($this->incidents) . "'" : "null") . ',';
459
        $sql .= ' fk_type = ' . (isset($this->fk_type) ? $this->fk_type : "null") . ',';
460
        $sql .= ' fk_pilot = ' . (isset($this->fk_pilot) ? $this->fk_pilot : "null") . ',';
461
        $sql .= ' fk_organisateur = ' . (isset($this->fk_organisateur) ? $this->fk_organisateur : "null") . ',';
462
        $sql .= ' is_facture = ' . (isset($this->is_facture) ? $this->is_facture : "0") . ',';
463
        $sql .= ' kilometers = ' . (!empty($this->kilometers) ? $this->kilometers : "0") . ',';
464
        $sql .= ' cost = ' . (isset($this->cost) ? "'" . $this->db->escape($this->cost) . "'" : "''") . ',';
465
        $sql .= ' fk_receiver = ' . (isset($this->fk_receiver) ? $this->fk_receiver : "null") . ',';
466
        $sql .= ' justif_kilometers = ' . (isset($this->justif_kilometers) ? "'" . $this->db->escape($this->justif_kilometers) . "'," : "'',");
467
        $sql .= ' date_update = ' . "'" . date('Y-m-d H:i:s') . "',";
468
        $sql .= ' passenger_names = ' . "'" . trim($this->passengerNames) . "'";
469
470
        $sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols;
471
472
        $this->db->begin();
473
474
        $resql = $this->db->query($sql);
475 View Code Duplication
        if (!$resql) {
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...
476
            $error++;
477
            $this->errors[] = 'Error ' . $this->db->lasterror();
478
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
479
        }
480
481
        if (!$error && !$notrigger) {
482
            $result = $this->call_trigger('BBC_FLIGHT_UPDATED', $user);
483
            if ($result < 0) {
484
                $error++;
485
            }
486
        }
487
488
        // Commit or rollback
489
        if ($error) {
490
            $this->db->rollback();
491
492
            return -1 * $error;
493
        }
494
495
        $this->db->commit();
496
        return 1;
497
    }
498
499
    /**
500
     * Delete object in database
501
     *
502
     * @param User $user      User that deletes
503
     * @param bool $notrigger false=launch triggers after, true=disable triggers
504
     *
505
     * @return int <0 if KO, >0 if OK
506
     */
507
    public function delete(User $user, $notrigger = false)
508
    {
509
        dol_syslog(__METHOD__, LOG_DEBUG);
510
511
        $error = 0;
512
513
        $this->db->begin();
514
515
        if (!$error) {
516
            if (!$notrigger) {
517
                $result = $this->call_trigger('BBC_FLIGHT_DELETED', $user);
518
                if ($result < 0) {
519
                    $error++;
520
                }
521
            }
522
        }
523
524
        if (!$error) {
525
            $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
526
            $sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols;
527
528
            $resql = $this->db->query($sql);
529 View Code Duplication
            if (!$resql) {
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...
530
                $error++;
531
                $this->errors[] = 'Error ' . $this->db->lasterror();
532
                dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
533
            }
534
        }
535
536
        // Commit or rollback
537
        if ($error) {
538
            $this->db->rollback();
539
            return -1 * $error;
540
        }
541
542
        $this->db->commit();
543
        return 1;
544
    }
545
546
    /**
547
     *  Return a link to the user card (with optionaly the picto)
548
     *    Use this->id,this->lastname, this->firstname
549
     *
550
     * @param    int     $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
551
     * @param    string  $option    On what the link point to
552
     * @param    integer $notooltip 1=Disable tooltip
553
     * @param    int     $maxlen    Max length of visible user name
554
     * @param  string    $morecss   Add more css on link
555
     *
556
     * @return    string                        String with URL
557
     */
558
    public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
559
    {
560
        global $langs;
561
562
        $result = '';
563
564
        $label = '<u>' . $langs->trans("MyModule") . '</u>';
565
        $label .= '<div width="100%">';
566
        $label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->idBBC_vols . '<br>';
567
        $label .= '<b>' . $langs->trans('Date') . ':</b> ' . dol_print_date($this->date, '%d-%m-%Y');
568
        $label .= '</div>';
569
570
        $link = '<a href="' . DOL_URL_ROOT . '/flightlog/card.php?id=' . $this->idBBC_vols . '"';
571
        $link .= ($notooltip ? '' : ' title="' . dol_escape_htmltag($label,
572
                1) . '" class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"');
573
        $link .= '>';
574
        $linkend = '</a>';
575
576 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...
577
            $result .= ($link . img_object(($notooltip ? '' : $label), 'label',
578
                    ($notooltip ? '' : 'class="classfortooltip"')) . $linkend);
579
            if ($withpicto != 2) {
580
                $result .= ' ';
581
            }
582
        }
583
        $result .= $link . $this->idBBC_vols . $linkend;
584
        return $result;
585
    }
586
587
    /**
588
     *  Retourne le libelle du status d'un user (actif, inactif)
589
     *
590
     * @param    int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
591
     *
592
     * @return    string                   Label of status
593
     */
594
    public function getLibStatut($mode = 0)
595
    {
596
        return $this->LibStatut($this->is_facture, $mode);
597
    }
598
599
    /**
600
     * Renvoi le libelle d'un status donne
601
     *
602
     * @param int $status Id status
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
    private function LibStatut($status, $mode = 0)
608
    {
609
        global $langs;
610
611
        $billDone = $langs->trans('Facturé');
612
        $billNotDone = $langs->trans('Ouvert');
613
614
        if ($mode == 0) {
615
            if ($status == 1) {
616
                return $billDone;
617
            }
618
            if ($status == 0) {
619
                return $billNotDone;
620
            }
621
        }
622
        if ($mode == 1) {
623
            if ($status == 1) {
624
                return $billDone;
625
            }
626
            if ($status == 0) {
627
                return $billNotDone;
628
            }
629
        }
630
        if ($mode == 2) {
631
            if ($status == 1) {
632
                return img_picto($billDone, 'statut4') . ' ' . $billDone;
633
            }
634
            if ($status == 0) {
635
                return img_picto($billNotDone, 'statut5') . ' ' . $billNotDone;
636
            }
637
        }
638
        if ($mode == 3) {
639
            if ($status == 1) {
640
                return img_picto($billDone, 'statut4');
641
            }
642
            if ($status == 0) {
643
                return img_picto($billNotDone, 'statut5');
644
            }
645
        }
646
        if ($mode == 4) {
647
            if ($status == 1) {
648
                return img_picto($billDone, 'statut4') . ' ' . $billDone;
649
            }
650
            if ($status == 0) {
651
                return img_picto($billNotDone, 'statut5') . ' ' . $billNotDone;
652
            }
653
        }
654
        if ($mode == 5) {
655
            if ($status == 1) {
656
                return $billDone . ' ' . img_picto($billDone, 'statut4');
657
            }
658
            if ($status == 0) {
659
                return $billNotDone . ' ' . img_picto($billNotDone, 'statut5');
660
            }
661
        }
662
663
        return "";
664
    }
665
666
    /**
667
     * @return string
668
     */
669
    public function __toString()
670
    {
671
        return $this->idBBC_vols . " " . $this->getPlaces();
672
    }
673
674
    /**
675
     * @return string
676
     */
677
    public function toString()
678
    {
679
        return "" . $this;
680
    }
681
682
    /**
683
     * @return string
684
     */
685
    public function getStatus()
686
    {
687
        return $this->statut;
688
    }
689
690
    /**
691
     * @return boolean
692
     */
693
    public function hasFacture()
694
    {
695
        return count($this->linkedObjectsIds) > 0;
696
    }
697
698
    /**
699
     * @param int $userId
700
     *
701
     * @return User
702
     */
703
    private function fetchUser($userId)
704
    {
705
        $user = new User($this->db);
706
        $user->fetch($userId);
707
708
        return $user;
709
    }
710
711
    /**
712
     * @return Bbc_ballons
713
     */
714
    private function fetchBalloon()
715
    {
716
        $balloon = new Bbc_ballons($this->db);
717
        $balloon->fetch($this->BBC_ballons_idBBC_ballons);
718
719
        return $balloon;
720
    }
721
722
    /**
723
     * @return Bbc_ballons
724
     */
725
    public function getBalloon()
726
    {
727
        if (!$this->balloon) {
728
            $this->balloon = $this->fetchBalloon();
729
        }
730
731
        return $this->balloon;
732
    }
733
734
    /**
735
     * @return User
736
     */
737
    public function getPilot()
738
    {
739
        if (!$this->pilot) {
740
            $this->pilot = $this->fetchUser($this->fk_pilot);
741
        }
742
743
        return $this->pilot;
744
    }
745
746
    /**
747
     * @return Bbctypes
748
     */
749
    public function getFlightType()
750
    {
751
        $flightType = new Bbctypes($this->db);
752
        $flightType->fetch($this->fk_type);
753
754
        return $flightType;
755
    }
756
757
    /**
758
     * @return string
759
     */
760
    public function getComment()
761
    {
762
        return $this->remarque;
763
    }
764
765
    /**
766
     * @return string
767
     */
768
    public function getIncident()
769
    {
770
        return $this->incidents;
771
    }
772
773
    /**
774
     * Return true if the number of pax is greater than 0
775
     *
776
     * @return boolean
777
     */
778
    public function hasPax()
779
    {
780
        return (int) $this->nbrPax > 0;
781
    }
782
783
    /**
784
     * Regarding the type of the flight give an indication if the flight must have pax to be valid.
785
     *
786
     * @return boolean
787
     */
788
    public function mustHavePax()
789
    {
790
        return $this->getFlightType()->isPaxRequired();
791
    }
792
793
    /**
794
     * Returns true if the amount requested by the flight is 0.
795
     *
796
     * @return boolean
797
     */
798
    public function isFree()
799
    {
800
        return empty($this->cost);
801
    }
802
803
    /**
804
     * @return int
805
     */
806
    public function getAmountReceived()
807
    {
808
        return $this->cost;
809
    }
810
811
    /**
812
     * @return int
813
     */
814
    public function getAmountPerPassenger()
815
    {
816
        return $this->cost / $this->nbrPax;
817
    }
818
819
    /**
820
     * @return boolean
821
     */
822
    public function hasReceiver()
823
    {
824
        return !empty($this->fk_receiver);
825
    }
826
827
    /**
828
     * @return boolean
829
     */
830
    public function hasKilometers()
831
    {
832
        return !empty($this->kilometers);
833
    }
834
835
    /**
836
     * @return boolean
837
     */
838
    public function hasKilometersDescription()
839
    {
840
        return !empty(trim($this->justif_kilometers));
841
    }
842
843
    /**
844
     * @return int
845
     */
846
    public function getKilometers()
847
    {
848
        return (int) $this->kilometers;
849
    }
850
851
    /**
852
     * @return string
853
     */
854
    public function getPlaces()
855
    {
856
        return $this->lieuD . ' -> ' . $this->lieuA;
857
    }
858
859
    /**
860
     * @return string
861
     */
862
    public function getDescription()
863
    {
864
        return $this->__toString() . ' - ' . $this->passengerNames;
865
    }
866
867
    /**
868
     * @return string
869
     */
870
    public function getPassengerNames()
871
    {
872
        return $this->passengerNames;
873
    }
874
875
    /**
876
     * @param string $passengerNames
877
     *
878
     * @return Bbcvols
879
     */
880
    public function setPassengerNames($passengerNames)
881
    {
882
        $this->passengerNames = $passengerNames;
883
        return $this;
884
    }
885
886
    /**
887
     * @return int
888
     */
889
    public function getNumberOfPassengers()
890
    {
891
        return (int) $this->nbrPax;
892
    }
893
}
894
895
/**
896
 * Class BbcvolsLine
897
 */
898
class BbcvolsLine
899
{
900
    /**
901
     * @var int ID
902
     */
903
    public $id;
904
    /**
905
     * @var mixed Sample line property 1
906
     */
907
908
    public $idBBC_vols;
909
    public $date = '';
910
    public $lieuD;
911
    public $lieuA;
912
    public $heureD;
913
    public $heureA;
914
    public $BBC_ballons_idBBC_ballons;
915
    public $nbrPax;
916
    public $remarque;
917
    public $incidents;
918
    public $fk_type;
919
    public $fk_pilot;
920
    public $fk_organisateur;
921
    public $is_facture;
922
    public $kilometers;
923
    public $cost;
924
    public $fk_receiver;
925
    public $justif_kilometers;
926
    public $date_creation;
927
    public $date_update;
928
}
929