Completed
Push — master ( 0cae82...3ae2ae )
by Laurent
02:11
created

Bbcvols::getLibStatut()   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 1
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
 * @see CommonObject
39
 */
40
class Bbcvols extends CommonObject
41
{
42
    /**
43
     * @var string Id to identify managed objects
44
     */
45
    public $element = 'flightlog_bbcvols';
46
    /**
47
     * @var string Name of table without prefix where object is stored
48
     */
49
    public $table_element = 'bbc_vols';
50
51
    /**
52
     * @var BbcvolsLine[] Lines
53
     */
54
    public $lines = array();
55
56
    public $idBBC_vols;
57
    public $date = '';
58
    public $lieuD;
59
    public $lieuA;
60
    public $heureD;
61
    public $heureA;
62
    public $BBC_ballons_idBBC_ballons;
63
    public $nbrPax;
64
    public $remarque;
65
    public $incidents;
66
    public $fk_type;
67
    public $fk_pilot;
68
    public $fk_organisateur;
69
    public $is_facture;
70
    public $kilometers;
71
    public $cost;
72
    public $fk_receiver;
73
    public $justif_kilometers;
74
    public $date_creation;
75
    public $date_update;
76
77
    /**
78
     * @var Bbc_ballons
79
     */
80
    private $balloon;
81
82
    /**
83
     * @var User
84
     */
85
    private $pilot;
86
87
    /**
88
     * @return int
89
     */
90
    public function getIdBBCVols()
91
    {
92
        return $this->idBBC_vols;
93
    }
94
95
    /**
96
     * @return int
97
     */
98
    public function getId()
99
    {
100
        return $this->getIdBBCVols();
101
    }
102
103
    /**
104
     * @param string|int $ref
105
     *
106
     * @return $this
107
     */
108
    public function setRef($ref)
109
    {
110
        $this->ref = $ref;
111
        return $this;
112
    }
113
114
    /**
115
     * Constructor
116
     *
117
     * @param DoliDb $db Database handler
118
     */
119
    public function __construct(DoliDB $db)
120
    {
121
        $this->db = $db;
122
        $this->cost = 0;
123
    }
124
125
    /**
126
     * Create object into database
127
     *
128
     * @param  User $user      User that creates
129
     * @param  bool $notrigger false=launch triggers after, true=disable triggers
130
     *
131
     * @return int <0 if KO, Id of created object if OK
132
     */
133
    public function create(User $user, $notrigger = false)
134
    {
135
        dol_syslog(__METHOD__, LOG_DEBUG);
136
137
        $error = 0;
138
139
        // Clean parameters
140
141
        if (isset($this->idBBC_vols)) {
142
            $this->idBBC_vols = trim($this->idBBC_vols);
143
        }
144
        if (isset($this->lieuD)) {
145
            $this->lieuD = trim($this->lieuD);
146
        }
147
        if (isset($this->lieuA)) {
148
            $this->lieuA = trim($this->lieuA);
149
        }
150
        if (isset($this->heureD)) {
151
            $this->heureD = trim($this->heureD);
152
        }
153
        if (isset($this->heureA)) {
154
            $this->heureA = trim($this->heureA);
155
        }
156
        if (isset($this->BBC_ballons_idBBC_ballons)) {
157
            $this->BBC_ballons_idBBC_ballons = trim($this->BBC_ballons_idBBC_ballons);
158
        }
159
        if (isset($this->nbrPax)) {
160
            $this->nbrPax = trim($this->nbrPax);
161
        }
162
        if (isset($this->remarque)) {
163
            $this->remarque = trim($this->remarque);
164
        }
165
        if (isset($this->incidents)) {
166
            $this->incidents = trim($this->incidents);
167
        }
168
        if (isset($this->fk_type)) {
169
            $this->fk_type = trim($this->fk_type);
170
        }
171
        if (isset($this->fk_pilot)) {
172
            $this->fk_pilot = trim($this->fk_pilot);
173
        }
174
        if (isset($this->fk_organisateur)) {
175
            $this->fk_organisateur = trim($this->fk_organisateur);
176
        }
177
        if (isset($this->is_facture)) {
178
            $this->is_facture = trim($this->is_facture);
179
        }
180
        if (isset($this->kilometers)) {
181
            $this->kilometers = trim($this->kilometers);
182
        }
183
        if (isset($this->cost)) {
184
            $this->cost = trim($this->cost);
185
        }
186
        if (isset($this->fk_receiver)) {
187
            $this->fk_receiver = trim($this->fk_receiver);
188
        }
189
        if (isset($this->justif_kilometers)) {
190
            $this->justif_kilometers = trim($this->justif_kilometers);
191
        }
192
193
194
        // Check parameters
195
        // Put here code to add control on parameters values
196
197
        // Insert request
198
        $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
199
200
        $sql .= 'date,';
201
        $sql .= 'lieuD,';
202
        $sql .= 'lieuA,';
203
        $sql .= 'heureD,';
204
        $sql .= 'heureA,';
205
        $sql .= 'BBC_ballons_idBBC_ballons,';
206
        $sql .= 'nbrPax,';
207
        $sql .= 'remarque,';
208
        $sql .= 'incidents,';
209
        $sql .= 'fk_type,';
210
        $sql .= 'fk_pilot,';
211
        $sql .= 'fk_organisateur,';
212
        $sql .= 'is_facture,';
213
        $sql .= 'kilometers,';
214
        $sql .= 'cost,';
215
        $sql .= 'fk_receiver,';
216
        $sql .= 'justif_kilometers,';
217
        $sql .= 'date_creation,';
218
        $sql .= 'date_update';
219
220
221
        $sql .= ') VALUES (';
222
223
        $sql .= ' ' . (!isset($this->date) || dol_strlen($this->date) == 0 ? 'NULL' : "'" . $this->db->idate($this->date) . "'") . ',';
224
        $sql .= ' ' . (!isset($this->lieuD) ? 'NULL' : "'" . $this->db->escape($this->lieuD) . "'") . ',';
225
        $sql .= ' ' . (!isset($this->lieuA) ? 'NULL' : "'" . $this->db->escape($this->lieuA) . "'") . ',';
226
        $sql .= ' ' . (!isset($this->heureD) ? 'NULL' : "'" . $this->heureD . "'") . ',';
227
        $sql .= ' ' . (!isset($this->heureA) ? 'NULL' : "'" . $this->heureA . "'") . ',';
228
        $sql .= ' ' . (!isset($this->BBC_ballons_idBBC_ballons) ? 'NULL' : $this->BBC_ballons_idBBC_ballons) . ',';
229
        $sql .= ' ' . (!isset($this->nbrPax) ? 'NULL' : "'" . $this->db->escape($this->nbrPax) . "'") . ',';
230
        $sql .= ' ' . (!isset($this->remarque) ? 'NULL' : "'" . $this->db->escape($this->remarque) . "'") . ',';
231
        $sql .= ' ' . (!isset($this->incidents) ? 'NULL' : "'" . $this->db->escape($this->incidents) . "'") . ',';
232
        $sql .= ' ' . (!isset($this->fk_type) ? 'NULL' : $this->fk_type) . ',';
233
        $sql .= ' ' . (!isset($this->fk_pilot) ? 'NULL' : $this->fk_pilot) . ',';
234
        $sql .= ' ' . (!isset($this->fk_organisateur) ? 'NULL' : $this->fk_organisateur) . ',';
235
        $sql .= ' ' . (!isset($this->is_facture) ? '0' : $this->is_facture) . ',';
236
        $sql .= ' ' . (!isset($this->kilometers) || empty($this->kilometers) ? '0' : $this->kilometers) . ',';
237
        $sql .= ' ' . (!isset($this->cost) ? 'NULL' : "'" . $this->db->escape($this->cost) . "'") . ',';
238
        $sql .= ' ' . (!isset($this->fk_receiver) ? 'NULL' : $this->fk_receiver) . ',';
239
        $sql .= ' ' . (!isset($this->justif_kilometers) ? 'NULL' : "'" . $this->db->escape($this->justif_kilometers) . "'") . ',';
240
        $sql .= ' ' . "'" . date('Y-m-d H:i:s') . "'" . ',';
241
        $sql .= ' ' . "'" . date('Y-m-d H:i:s') . "'" . '';
242
243
244
        $sql .= ')';
245
246
        $this->db->begin();
247
248
        $resql = $this->db->query($sql);
249
        if (!$resql) {
250
            $error++;
251
            $this->errors[] = 'Error ' . $this->db->lasterror();
252
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
253
        }
254
255 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...
256
            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
257
258
            if (!$notrigger) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
259
                // Uncomment this and change MYOBJECT to your own tag if you
260
                // want this action to call a trigger.
261
262
                //// Call triggers
263
                //$result=$this->call_trigger('MYOBJECT_CREATE',$user);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
264
                //if ($result < 0) $error++;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
265
                //// End call triggers
266
            }
267
        }
268
269
        // Commit or rollback
270
        if ($error) {
271
            $this->db->rollback();
272
273
            return -1 * $error;
274
        } else {
275
            $this->db->commit();
276
277
            return $this->id;
278
        }
279
    }
280
281
    /**
282
     * Load object in memory from the database
283
     *
284
     * @param int    $id  Id object
285
     * @param string $ref Ref
286
     *
287
     * @return int <0 if KO, 0 if not found, >0 if OK
288
     */
289
    public function fetch($id, $ref = null)
290
    {
291
        dol_syslog(__METHOD__, LOG_DEBUG);
292
293
        $sql = 'SELECT';
294
        $sql .= " t.idBBC_vols,";
295
        $sql .= " t.date,";
296
        $sql .= " t.lieuD,";
297
        $sql .= " t.lieuA,";
298
        $sql .= " t.heureD,";
299
        $sql .= " t.heureA,";
300
        $sql .= " t.BBC_ballons_idBBC_ballons,";
301
        $sql .= " t.nbrPax,";
302
        $sql .= " t.remarque,";
303
        $sql .= " t.incidents,";
304
        $sql .= " t.fk_type,";
305
        $sql .= " t.fk_pilot,";
306
        $sql .= " t.fk_organisateur,";
307
        $sql .= " t.is_facture,";
308
        $sql .= " t.kilometers,";
309
        $sql .= " t.cost,";
310
        $sql .= " t.fk_receiver,";
311
        $sql .= " t.justif_kilometers,";
312
        $sql .= " t.date_creation,";
313
        $sql .= " t.date_update";
314
315
316
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
317 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...
318
            $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\'';
319
        } else {
320
            $sql .= ' WHERE t.idBBC_vols = ' . $id;
321
        }
322
323
        $resql = $this->db->query($sql);
324
        if ($resql) {
325
            $numrows = $this->db->num_rows($resql);
326
            if ($numrows) {
327
                $obj = $this->db->fetch_object($resql);
328
329
                $this->id = $obj->idBBC_vols;
330
331
                $this->idBBC_vols = $obj->idBBC_vols;
332
                $this->date = $this->db->jdate($obj->date);
333
                $this->lieuD = $obj->lieuD;
334
                $this->lieuA = $obj->lieuA;
335
                $this->heureD = $obj->heureD;
336
                $this->heureA = $obj->heureA;
337
                $this->BBC_ballons_idBBC_ballons = $obj->BBC_ballons_idBBC_ballons;
338
                $this->nbrPax = $obj->nbrPax;
339
                $this->remarque = $obj->remarque;
340
                $this->incidents = $obj->incidents;
341
                $this->fk_type = $obj->fk_type;
342
                $this->fk_pilot = $obj->fk_pilot;
343
                $this->fk_organisateur = $obj->fk_organisateur;
344
                $this->is_facture = $obj->is_facture;
345
                $this->kilometers = $obj->kilometers;
346
                $this->cost = $obj->cost;
347
                $this->fk_receiver = $obj->fk_receiver;
348
                $this->justif_kilometers = $obj->justif_kilometers;
349
                $this->date_creation = $obj->date_creation;
350
                $this->date_update = $obj->date_update;
351
                
352
                $this->balloon = $this->fetchBalloon();
353
                $this->pilot = $this->fetchUser($this->fk_pilot);
354
            }
355
            $this->db->free($resql);
356
357
            if ($numrows) {
358
                return 1;
359
            } else {
360
                return 0;
361
            }
362 View Code Duplication
        } else {
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...
363
            $this->errors[] = 'Error ' . $this->db->lasterror();
364
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
365
366
            return -1;
367
        }
368
    }
369
370
    /**
371
     * Load object in memory from the database
372
     *
373
     * @param string $sortorder  Sort Order
374
     * @param string $sortfield  Sort field
375
     * @param int    $limit      offset limit
376
     * @param int    $offset     offset limit
377
     * @param array  $filter     filter array
378
     * @param string $filtermode filter mode (AND or OR)
379
     *
380
     * @return int <0 if KO, >0 if OK
381
     */
382
    public function fetchAll(
383
        $sortorder = '',
384
        $sortfield = '',
385
        $limit = 0,
386
        $offset = 0,
387
        array $filter = array(),
388
        $filtermode = 'AND'
389
    ) {
390
        dol_syslog(__METHOD__, LOG_DEBUG);
391
392
        $sql = 'SELECT';
393
        $sql .= " t.idBBC_vols,";
394
        $sql .= " t.date,";
395
        $sql .= " t.lieuD,";
396
        $sql .= " t.lieuA,";
397
        $sql .= " t.heureD,";
398
        $sql .= " t.heureA,";
399
        $sql .= " t.BBC_ballons_idBBC_ballons,";
400
        $sql .= " t.nbrPax,";
401
        $sql .= " t.remarque,";
402
        $sql .= " t.incidents,";
403
        $sql .= " t.fk_type,";
404
        $sql .= " t.fk_pilot,";
405
        $sql .= " t.fk_organisateur,";
406
        $sql .= " t.is_facture,";
407
        $sql .= " t.kilometers,";
408
        $sql .= " t.cost,";
409
        $sql .= " t.fk_receiver,";
410
        $sql .= " t.justif_kilometers,";
411
        $sql .= " t.date_creation,";
412
        $sql .= " t.date_update";
413
414
415
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
416
417
        // Manage filter
418
        $sqlwhere = array();
419
        if (count($filter) > 0) {
420
            foreach ($filter as $key => $value) {
421
                $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
422
            }
423
        }
424 View Code Duplication
        if (count($sqlwhere) > 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...
425
            $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere);
426
        }
427
428
        if (!empty($sortfield)) {
429
            $sql .= $this->db->order($sortfield, $sortorder);
430
        }
431
        if (!empty($limit)) {
432
            $sql .= ' ' . $this->db->plimit($limit + 1, $offset);
433
        }
434
        $this->lines = array();
435
436
        $resql = $this->db->query($sql);
437
        if ($resql) {
438
            $num = $this->db->num_rows($resql);
439
440
            while ($obj = $this->db->fetch_object($resql)) {
441
                $line = new BbcvolsLine();
442
443
                $line->id = $obj->idBBC_vols;
444
445
                $line->idBBC_vols = $obj->idBBC_vols;
446
                $line->date = $this->db->jdate($obj->date);
447
                $line->lieuD = $obj->lieuD;
448
                $line->lieuA = $obj->lieuA;
449
                $line->heureD = $obj->heureD;
450
                $line->heureA = $obj->heureA;
451
                $line->BBC_ballons_idBBC_ballons = $obj->BBC_ballons_idBBC_ballons;
452
                $line->nbrPax = $obj->nbrPax;
453
                $line->remarque = $obj->remarque;
454
                $line->incidents = $obj->incidents;
455
                $line->fk_type = $obj->fk_type;
456
                $line->fk_pilot = $obj->fk_pilot;
457
                $line->fk_organisateur = $obj->fk_organisateur;
458
                $line->is_facture = $obj->is_facture;
459
                $line->kilometers = $obj->kilometers;
460
                $line->cost = $obj->cost;
461
                $line->fk_receiver = $obj->fk_receiver;
462
                $line->justif_kilometers = $obj->justif_kilometers;
463
                $line->date_creation = $obj->date_creation;
464
                $line->date_update = $obj->date_update;
465
466
467
                $this->lines[$line->id] = $line;
468
            }
469
            $this->db->free($resql);
470
471
            return $num;
472 View Code Duplication
        } else {
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...
473
            $this->errors[] = 'Error ' . $this->db->lasterror();
474
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
475
476
            return -1;
477
        }
478
    }
479
480
    /**
481
     * Update object into database
482
     *
483
     * @param  User $user      User that modifies
484
     * @param  bool $notrigger false=launch triggers after, true=disable triggers
485
     *
486
     * @return int <0 if KO, >0 if OK
487
     */
488
    public function update(User $user, $notrigger = false)
489
    {
490
        $error = 0;
491
492
        dol_syslog(__METHOD__, LOG_DEBUG);
493
494
        // Clean parameters
495
496
        if (isset($this->idBBC_vols)) {
497
            $this->idBBC_vols = trim($this->idBBC_vols);
498
        }
499
        if (isset($this->lieuD)) {
500
            $this->lieuD = trim($this->lieuD);
501
        }
502
        if (isset($this->lieuA)) {
503
            $this->lieuA = trim($this->lieuA);
504
        }
505
        if (isset($this->heureD)) {
506
            $this->heureD = trim($this->heureD);
507
        }
508
        if (isset($this->heureA)) {
509
            $this->heureA = trim($this->heureA);
510
        }
511
        if (isset($this->BBC_ballons_idBBC_ballons)) {
512
            $this->BBC_ballons_idBBC_ballons = trim($this->BBC_ballons_idBBC_ballons);
513
        }
514
        if (isset($this->nbrPax)) {
515
            $this->nbrPax = trim($this->nbrPax);
516
        }
517
        if (isset($this->remarque)) {
518
            $this->remarque = trim($this->remarque);
519
        }
520
        if (isset($this->incidents)) {
521
            $this->incidents = trim($this->incidents);
522
        }
523
        if (isset($this->fk_type)) {
524
            $this->fk_type = trim($this->fk_type);
525
        }
526
        if (isset($this->fk_pilot)) {
527
            $this->fk_pilot = trim($this->fk_pilot);
528
        }
529
        if (isset($this->fk_organisateur)) {
530
            $this->fk_organisateur = trim($this->fk_organisateur);
531
        }
532
        if (isset($this->is_facture)) {
533
            $this->is_facture = trim($this->is_facture);
534
        }
535
        if (isset($this->kilometers)) {
536
            $this->kilometers = trim($this->kilometers);
537
        }
538
        if (isset($this->cost)) {
539
            $this->cost = trim($this->cost);
540
        }
541
        if (isset($this->fk_receiver)) {
542
            $this->fk_receiver = trim($this->fk_receiver);
543
        }
544
        if (isset($this->justif_kilometers)) {
545
            $this->justif_kilometers = trim($this->justif_kilometers);
546
        }
547
548
549
        // Check parameters
550
        // Put here code to add a control on parameters values
551
552
        // Update request
553
        $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
554
555
        $sql .= ' date = ' . (!isset($this->date) || dol_strlen($this->date) != 0 ? "'" . $this->db->idate($this->date) . "'" : 'null') . ',';
556
        $sql .= ' lieuD = ' . (isset($this->lieuD) ? "'" . $this->db->escape($this->lieuD) . "'" : "null") . ',';
557
        $sql .= ' lieuA = ' . (isset($this->lieuA) ? "'" . $this->db->escape($this->lieuA) . "'" : "null") . ',';
558
        $sql .= ' heureD = ' . (isset($this->heureD) ? "'" . $this->heureD . "'" : "null") . ',';
559
        $sql .= ' heureA = ' . (isset($this->heureA) ? "'" . $this->heureA . "'" : "null") . ',';
560
        $sql .= ' BBC_ballons_idBBC_ballons = ' . (isset($this->BBC_ballons_idBBC_ballons) ? $this->BBC_ballons_idBBC_ballons : "null") . ',';
561
        $sql .= ' nbrPax = ' . (isset($this->nbrPax) ? "'" . $this->db->escape($this->nbrPax) . "'" : "null") . ',';
562
        $sql .= ' remarque = ' . (isset($this->remarque) ? "'" . $this->db->escape($this->remarque) . "'" : "null") . ',';
563
        $sql .= ' incidents = ' . (isset($this->incidents) ? "'" . $this->db->escape($this->incidents) . "'" : "null") . ',';
564
        $sql .= ' fk_type = ' . (isset($this->fk_type) ? $this->fk_type : "null") . ',';
565
        $sql .= ' fk_pilot = ' . (isset($this->fk_pilot) ? $this->fk_pilot : "null") . ',';
566
        $sql .= ' fk_organisateur = ' . (isset($this->fk_organisateur) ? $this->fk_organisateur : "null") . ',';
567
        $sql .= ' is_facture = ' . (isset($this->is_facture) ? $this->is_facture : "0") . ',';
568
        $sql .= ' kilometers = ' . (!empty($this->kilometers) ? $this->kilometers : "0") . ',';
569
        $sql .= ' cost = ' . (isset($this->cost) ? "'" . $this->db->escape($this->cost) . "'" : "''") . ',';
570
        $sql .= ' fk_receiver = ' . (isset($this->fk_receiver) ? $this->fk_receiver : "null") . ',';
571
        $sql .= ' justif_kilometers = ' . (isset($this->justif_kilometers) ? "'" . $this->db->escape($this->justif_kilometers) . "'," : "'',");
572
        $sql .= ' date_update = ' . "'" . date('Y-m-d H:i:s') . "'";
573
574
        $sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols;
575
576
        $this->db->begin();
577
578
        $resql = $this->db->query($sql);
579
        if (!$resql) {
580
            $error++;
581
            $this->errors[] = 'Error ' . $this->db->lasterror();
582
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
583
        }
584
585
        if (!$error && !$notrigger) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
586
            // Uncomment this and change MYOBJECT to your own tag if you
587
            // want this action calls a trigger.
588
589
            //// Call triggers
590
            //$result=$this->call_trigger('MYOBJECT_MODIFY',$user);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
591
            //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
592
            //// End call triggers
593
        }
594
595
        // Commit or rollback
596
        if ($error) {
597
            $this->db->rollback();
598
599
            return -1 * $error;
600
        } else {
601
            $this->db->commit();
602
603
            return 1;
604
        }
605
    }
606
607
    /**
608
     * Delete object in database
609
     *
610
     * @param User $user      User that deletes
611
     * @param bool $notrigger false=launch triggers after, true=disable triggers
612
     *
613
     * @return int <0 if KO, >0 if OK
614
     */
615 View Code Duplication
    public function delete(User $user, $notrigger = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
616
    {
617
        dol_syslog(__METHOD__, LOG_DEBUG);
618
619
        $error = 0;
620
621
        $this->db->begin();
622
623
        if (!$error) {
624
            if (!$notrigger) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
625
                // Uncomment this and change MYOBJECT to your own tag if you
626
                // want this action calls a trigger.
627
628
                //// Call triggers
629
                //$result=$this->call_trigger('MYOBJECT_DELETE',$user);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
630
                //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
631
                //// End call triggers
632
            }
633
        }
634
635
        if (!$error) {
636
            $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
637
            $sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols;
638
639
            $resql = $this->db->query($sql);
640
            if (!$resql) {
641
                $error++;
642
                $this->errors[] = 'Error ' . $this->db->lasterror();
643
                dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
644
            }
645
        }
646
647
        // Commit or rollback
648
        if ($error) {
649
            $this->db->rollback();
650
651
            return -1 * $error;
652
        } else {
653
            $this->db->commit();
654
655
            return 1;
656
        }
657
    }
658
659
    /**
660
     *  Return a link to the user card (with optionaly the picto)
661
     *    Use this->id,this->lastname, this->firstname
662
     *
663
     * @param    int     $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
664
     * @param    string  $option    On what the link point to
665
     * @param    integer $notooltip 1=Disable tooltip
666
     * @param    int     $maxlen    Max length of visible user name
667
     * @param  string    $morecss   Add more css on link
668
     *
669
     * @return    string                        String with URL
670
     */
671
    function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
672
    {
673
        global $langs, $conf, $db;
674
        global $dolibarr_main_authentication, $dolibarr_main_demo;
675
        global $menumanager;
676
677
        $result = '';
678
        $companylink = '';
0 ignored issues
show
Unused Code introduced by
$companylink is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
679
680
        $label = '<u>' . $langs->trans("MyModule") . '</u>';
681
        $label .= '<div width="100%">';
682
        $label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->idBBC_vols . '<br>';
683
        $label .= '<b>' . $langs->trans('Date') . ':</b> ' . dol_print_date($this->date, '%d-%m-%Y');
684
        $label .= '</div>';
685
686
        $link = '<a href="' . DOL_URL_ROOT . '/flightlog/card.php?id=' . $this->idBBC_vols . '"';
687
        $link .= ($notooltip ? '' : ' title="' . dol_escape_htmltag($label,
688
                1) . '" class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"');
689
        $link .= '>';
690
        $linkend = '</a>';
691
692 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...
693
            $result .= ($link . img_object(($notooltip ? '' : $label), 'label',
694
                    ($notooltip ? '' : 'class="classfortooltip"')) . $linkend);
695
            if ($withpicto != 2) {
696
                $result .= ' ';
697
            }
698
        }
699
        $result .= $link . $this->idBBC_vols . $linkend;
700
        return $result;
701
    }
702
703
    /**
704
     *  Retourne le libelle du status d'un user (actif, inactif)
705
     *
706
     * @param    int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
707
     *
708
     * @return    string                   Label of status
709
     */
710
    function getLibStatut($mode = 0)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
711
    {
712
        return $this->LibStatut($this->is_facture, $mode);
713
    }
714
715
    /**
716
     *  Renvoi le libelle d'un status donne
717
     *
718
     * @param    int $status Id status
719
     * @param  int   $mode   0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
720
     *
721
     * @return string                    Label of status
722
     */
723 View Code Duplication
    private function LibStatut($status, $mode = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
724
    {
725
        global $langs;
726
727
        if ($mode == 0) {
728
            $prefix = '';
0 ignored issues
show
Unused Code introduced by
$prefix is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
729
            if ($status == 1) {
730
                return $langs->trans('Enabled');
731
            }
732
            if ($status == 0) {
733
                return $langs->trans('Disabled');
734
            }
735
        }
736
        if ($mode == 1) {
737
            if ($status == 1) {
738
                return $langs->trans('Enabled');
739
            }
740
            if ($status == 0) {
741
                return $langs->trans('Disabled');
742
            }
743
        }
744
        if ($mode == 2) {
745
            if ($status == 1) {
746
                return img_picto($langs->trans('Enabled'), 'statut4') . ' ' . $langs->trans('Enabled');
747
            }
748
            if ($status == 0) {
749
                return img_picto($langs->trans('Disabled'), 'statut5') . ' ' . $langs->trans('Disabled');
750
            }
751
        }
752
        if ($mode == 3) {
753
            if ($status == 1) {
754
                return img_picto($langs->trans('Enabled'), 'statut4');
755
            }
756
            if ($status == 0) {
757
                return img_picto($langs->trans('Disabled'), 'statut5');
758
            }
759
        }
760
        if ($mode == 4) {
761
            if ($status == 1) {
762
                return img_picto($langs->trans('Enabled'), 'statut4') . ' ' . $langs->trans('Enabled');
763
            }
764
            if ($status == 0) {
765
                return img_picto($langs->trans('Disabled'), 'statut5') . ' ' . $langs->trans('Disabled');
766
            }
767
        }
768
        if ($mode == 5) {
769
            if ($status == 1) {
770
                return $langs->trans('Enabled') . ' ' . img_picto($langs->trans('Enabled'), 'statut4');
771
            }
772
            if ($status == 0) {
773
                return $langs->trans('Disabled') . ' ' . img_picto($langs->trans('Disabled'), 'statut5');
774
            }
775
        }
776
777
        return "";
778
    }
779
780
781
    /**
782
     * Initialise object with example values
783
     * Id must be 0 if object instance is a specimen
784
     *
785
     * @return void
786
     */
787
    public function initAsSpecimen()
788
    {
789
        $this->id = 0;
790
791
        $this->idBBC_vols = '';
792
        $this->date = '';
793
        $this->lieuD = '';
794
        $this->lieuA = '';
795
        $this->heureD = '';
796
        $this->heureA = '';
797
        $this->BBC_ballons_idBBC_ballons = '';
798
        $this->nbrPax = '';
799
        $this->remarque = '';
800
        $this->incidents = '';
801
        $this->fk_type = '';
802
        $this->fk_pilot = '';
803
        $this->fk_organisateur = '';
804
        $this->is_facture = '';
805
        $this->kilometers = '';
806
        $this->cost = '';
807
        $this->fk_receiver = '';
808
        $this->justif_kilometers = '';
809
810
811
    }
812
813
    /**
814
     * @return string
815
     */
816
    public function __toString()
817
    {
818
        return $this->idBBC_vols . " " . $this->lieuD . " " . $this->lieuA;
819
    }
820
821
    /**
822
     * @return string
823
     */
824
    public function toString()
825
    {
826
        return "" . $this;
827
    }
828
829
    /**
830
     * @return string
831
     */
832
    public function getStatus()
833
    {
834
        return $this->statut;
835
    }
836
837
    /**
838
     * @return boolean 
839
     */
840
    public function hasFacture(){
841
        return count($this->linkedObjectsIds) > 0;
842
    }
843
844
    /**
845
     * @param int $userId
846
     * 
847
     * @return User
848
     */
849
    private function fetchUser($userId)
850
    {
851
        $user = new User($this->db);
852
        $user->fetch($userId);
853
        
854
        return $user;
855
    }
856
857
    /**
858
     * @return Bbc_ballons
859
     */
860
    private function fetchBalloon()
861
    {
862
        $balloon = new Bbc_ballons($this->db);
863
        $balloon->fetch($this->BBC_ballons_idBBC_ballons);
864
865
        return $balloon;
866
    }
867
868
    /**
869
     * @return Bbc_ballons
870
     */
871
    public function getBalloon()
872
    {
873
        if(!$this->balloon){
874
            $this->balloon = $this->fetchBalloon();
875
        }
876
877
        return $this->balloon;
878
    }
879
880
    /**
881
     * @return User
882
     */
883
    public function getPilot()
884
    {
885
        if(!$this->pilot){
886
            $this->pilot = $this->fetchUser($this->fk_pilot);
887
        }
888
889
        return $this->pilot;
890
    }
891
892
    /**
893
     * @return Bbctypes
894
     */
895
    public function getFlightType(){
896
        $flightType = new Bbctypes($this->db);
897
        $flightType->fetch($this->fk_type);
898
899
        return $flightType;
900
    }
901
902
    /**
903
     * @return string
904
     */
905
    public function getComment()
906
    {
907
        return $this->remarque;
908
    }
909
910
    /**
911
     * @return string
912
     */
913
    public function getIncident()
914
    {
915
        return $this->incidents;
916
    }
917
918
    /**
919
     * Return true if the number of pax is greater than 0
920
     *
921
     * @return boolean
922
     */
923
    public function hasPax()
924
    {
925
        return (int)$this->nbrPax > 0;
926
    }
927
928
    /**
929
     * Regarding the type of the flight give an indication if the flight must have pax to be valid.
930
     * @return boolean
931
     */
932
    public function mustHavePax()
933
    {
934
        return $this->getFlightType()->isPaxRequired();
935
    }
936
937
    /**
938
     * Returns true if the amount requested by the flight is 0.
939
     *
940
     * @return boolean
941
     */
942
    public function isFree()
943
    {
944
        return empty($this->cost);
945
    }
946
947
    /**
948
     * @return boolean
949
     */
950
    public function hasReceiver()
951
    {
952
        return !empty($this->fk_receiver);
953
    }
954
955
}
956
957
/**
958
 * Class BbcvolsLine
959
 */
960
class BbcvolsLine
961
{
962
    /**
963
     * @var int ID
964
     */
965
    public $id;
966
    /**
967
     * @var mixed Sample line property 1
968
     */
969
970
    public $idBBC_vols;
971
    public $date = '';
972
    public $lieuD;
973
    public $lieuA;
974
    public $heureD;
975
    public $heureA;
976
    public $BBC_ballons_idBBC_ballons;
977
    public $nbrPax;
978
    public $remarque;
979
    public $incidents;
980
    public $fk_type;
981
    public $fk_pilot;
982
    public $fk_organisateur;
983
    public $is_facture;
984
    public $kilometers;
985
    public $cost;
986
    public $fk_receiver;
987
    public $justif_kilometers;
988
    public $date_creation;
989
    public $date_update;
990
991
    /**
992
     * @var mixed Sample line property 2
993
     */
994
995
}
996