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

Bbctypes::isPaxRequired()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 10
rs 9.4285
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
//TODO refactor to match the table
23
24
/**
25
 * \file    flightlog/bbctypes.class.php
26
 * \ingroup flightlog
27
 * \brief   This file is an example for a CRUD class file (Create/Read/Update/Delete)
28
 *          Put some comments here
29
 */
30
31
// Put here all includes required by your class file
32
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
33
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
34
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
35
36
/**
37
 * Class Bbctypes
38
 *
39
 * Put here description of your class
40
 * @see CommonObject
41
 */
42
class Bbctypes extends CommonObject
43
{
44
	/**
45
	 * @var string Id to identify managed objects
46
	 */
47
	public $element = 'bbctypes';
48
	/**
49
	 * @var string Name of table without prefix where object is stored
50
	 */
51
	public $table_element = 'bbc_types';
52
53
	/**
54
	 * @var BbctypesLine[] Lines
55
	 */
56
	public $lines = array();
57
58
	/**
59
	 */
60
	
61
	public $idType;
62
	public $numero;
63
	public $nom;
64
	public $active;
65
	public $fkService;
66
67
    /**
68
     * @var Product
69
     */
70
	public $service;
71
72
	/**
73
	 * Constructor
74
	 *
75
	 * @param DoliDb $db Database handler
76
	 */
77
	public function __construct(DoliDB $db)
78
	{
79
		$this->db = $db;
80
	}
81
82
	/**
83
	 * Create object into database
84
	 *
85
	 * @param  User $user      User that creates
86
	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
87
	 *
88
	 * @return int <0 if KO, Id of created object if OK
89
	 */
90
	public function create(User $user, $notrigger = false)
91
	{
92
		dol_syslog(__METHOD__, LOG_DEBUG);
93
94
		$error = 0;
95
96
		// Clean parameters
97
		
98
		if (isset($this->idType)) {
99
			 $this->idType = trim($this->idType);
100
		}
101
		if (isset($this->numero)) {
102
			 $this->numero = trim($this->numero);
103
		}
104
		if (isset($this->nom)) {
105
			 $this->nom = trim($this->nom);
106
		}
107
		if (isset($this->active)) {
108
			 $this->active = trim($this->active);
109
		}
110
		if (isset($this->fkService)) {
111
			 $this->fkService = trim($this->fkService);
112
		}
113
114
115
116
		// Check parameters
117
		// Put here code to add control on parameters values
118
119
		// Insert request
120
		$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
121
		
122
		$sql.= 'numero,';
123
		$sql.= 'nom,';
124
		$sql.= 'fkService,';
125
		$sql.= 'active';
126
127
		
128
		$sql .= ') VALUES (';
129
		
130
		$sql .= ' '.(! isset($this->numero)?'NULL':$this->numero).',';
131
		$sql .= ' '.(! isset($this->nom)?'NULL':"'".$this->db->escape($this->nom)."'").',';
132
		$sql .= ' '.(! isset($this->fkService)?'NULL':"'".$this->db->escape($this->fkService)."'").',';
133
		$sql .= ' '.(! isset($this->active)?'NULL':$this->active);
134
135
		
136
		$sql .= ')';
137
138
		$this->db->begin();
139
140
		$resql = $this->db->query($sql);
141
		if (!$resql) {
142
			$error ++;
143
			$this->errors[] = 'Error ' . $this->db->lasterror();
144
			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
145
		}
146
147 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...
148
			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
149
150
			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...
151
				// Uncomment this and change MYOBJECT to your own tag if you
152
				// want this action to call a trigger.
153
154
				//// Call triggers
155
				//$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...
156
				//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...
157
				//// End call triggers
158
			}
159
		}
160
161
		// Commit or rollback
162
		if ($error) {
163
			$this->db->rollback();
164
165
			return - 1 * $error;
166
		} else {
167
			$this->db->commit();
168
169
			return $this->id;
170
		}
171
	}
172
173
	/**
174
	 * Load object in memory from the database
175
	 *
176
	 * @param int    $id  Id object
177
	 * @param string $ref Ref
178
	 *
179
	 * @return int <0 if KO, 0 if not found, >0 if OK
180
	 */
181
	public function fetch($id, $ref = null)
182
	{
183
		dol_syslog(__METHOD__, LOG_DEBUG);
184
185
		$sql = 'SELECT';
186
		$sql .= ' t.idType,';
187
		
188
		$sql .= " t.numero,";
189
		$sql .= " t.nom,";
190
		$sql .= " t.fkService,";
191
		$sql .= " t.active";
192
193
		
194
		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
195 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...
196
			$sql .= ' WHERE t.ref = ' . '\'' . $ref . '\'';
197
		} else {
198
			$sql .= ' WHERE t.idType = ' . $id;
199
		}
200
201
		$resql = $this->db->query($sql);
202
		if ($resql) {
203
			$numrows = $this->db->num_rows($resql);
204
			if ($numrows) {
205
				$obj = $this->db->fetch_object($resql);
206
207
				$this->id = $obj->idType;
208
				
209
				$this->idType = $obj->idType;
210
				$this->numero = $obj->numero;
211
				$this->nom = $obj->nom;
212
				$this->fkService = $obj->fkService;
213
				$this->active = $obj->active;
214
215
				if($this->fkService){
216
                    $this->service = new Product($this->db);
217
                    $this->service->fetch($this->fkService);
218
                }
219
			}
220
			$this->db->free($resql);
221
222
			if ($numrows) {
223
				return 1;
224
			} else {
225
				return 0;
226
			}
227 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...
228
			$this->errors[] = 'Error ' . $this->db->lasterror();
229
			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
230
231
			return - 1;
232
		}
233
	}
234
235
	/**
236
	 * Load object in memory from the database
237
	 *
238
	 * @param string $sortorder Sort Order
239
	 * @param string $sortfield Sort field
240
	 * @param int    $limit     offset limit
241
	 * @param int    $offset    offset limit
242
	 * @param array  $filter    filter array
243
	 * @param string $filtermode filter mode (AND or OR)
244
	 *
245
	 * @return int <0 if KO, >0 if OK
246
	 */
247
	public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
248
	{
249
		dol_syslog(__METHOD__, LOG_DEBUG);
250
251
		$sql = 'SELECT';
252
		$sql .= " t.idType,";
253
		$sql .= " t.numero,";
254
		$sql .= " t.nom,";
255
		$sql .= " t.fkService,";
256
		$sql .= " t.active";
257
258
		
259
		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
260
261
		// Manage filter
262
		$sqlwhere = array();
263
264
		foreach ($filter as $key => $value) {
265
		    if(is_string($value)){
266
                $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
267
                continue;
268
            }
269
270
            if(is_int($value)){
271
                $sqlwhere [] = $key . ' = ' .(int)$value;
272
                continue;
273
            }
274
        }
275
276 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...
277
			$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
278
		}
279
		
280
		if (!empty($sortfield)) {
281
			$sql .= $this->db->order($sortfield,$sortorder);
282
		}
283
		if (!empty($limit)) {
284
		 $sql .=  ' ' . $this->db->plimit($limit + 1, $offset);
285
		}
286
		$this->lines = array();
287
288
		$resql = $this->db->query($sql);
289
		if ($resql) {
290
			$num = $this->db->num_rows($resql);
291
292
			while ($obj = $this->db->fetch_object($resql)) {
293
				$line = new BbctypesLine();
294
295
				$line->id = $obj->idType;
296
				$line->idType = $obj->idType;
297
				$line->numero = $obj->numero;
298
				$line->nom = $obj->nom;
299
				$line->fkService = $obj->fkService;
300
				$line->active = $obj->active;
301
302
				$this->lines[$line->id] = $line;
303
			}
304
			$this->db->free($resql);
305
306
			return $num;
307 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...
308
			$this->errors[] = 'Error ' . $this->db->lasterror();
309
			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
310
311
			return - 1;
312
		}
313
	}
314
315
	/**
316
	 * Update object into database
317
	 *
318
	 * @param  User $user      User that modifies
319
	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
320
	 *
321
	 * @return int <0 if KO, >0 if OK
322
	 */
323
	public function update(User $user, $notrigger = false)
324
	{
325
		$error = 0;
326
327
		dol_syslog(__METHOD__, LOG_DEBUG);
328
329
		// Clean parameters
330
		
331
		if (isset($this->idType)) {
332
			 $this->idType = trim($this->idType);
333
		}
334
		if (isset($this->numero)) {
335
			 $this->numero = trim($this->numero);
336
		}
337
		if (isset($this->nom)) {
338
			 $this->nom = trim($this->nom);
339
		}
340
		if (isset($this->fkService)) {
341
			 $this->fkService = trim($this->fkService);
342
		}
343
		if (isset($this->active)) {
344
			 $this->active = trim($this->active);
345
		}
346
347
		
348
349
		// Check parameters
350
		// Put here code to add a control on parameters values
351
352
		// Update request
353
		$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
354
		
355
		$sql .= ' numero = '.(isset($this->numero)?$this->numero:"null").',';
356
		$sql .= ' nom = '.(isset($this->nom)?"'".$this->db->escape($this->nom)."'":"null").',';
357
		$sql .= ' fkService = '.(isset($this->fkService)?"'".$this->db->escape($this->fkService)."'":"null").',';
358
		$sql .= ' active = '.(isset($this->active)?$this->active:"null");
359
360
        
361
		$sql .= ' WHERE idType=' . $this->id;
362
363
		$this->db->begin();
364
365
		$resql = $this->db->query($sql);
366
		if (!$resql) {
367
			$error ++;
368
			$this->errors[] = 'Error ' . $this->db->lasterror();
369
			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
370
		}
371
372
		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...
373
			// Uncomment this and change MYOBJECT to your own tag if you
374
			// want this action calls a trigger.
375
376
			//// Call triggers
377
			//$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...
378
			//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...
379
			//// End call triggers
380
		}
381
382
		// Commit or rollback
383
		if ($error) {
384
			$this->db->rollback();
385
386
			return - 1 * $error;
387
		} else {
388
			$this->db->commit();
389
390
			return 1;
391
		}
392
	}
393
394
	/**
395
	 * Delete object in database
396
	 *
397
	 * @param User $user      User that deletes
398
	 * @param bool $notrigger false=launch triggers after, true=disable triggers
399
	 *
400
	 * @return int <0 if KO, >0 if OK
401
	 */
402 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...
403
	{
404
		dol_syslog(__METHOD__, LOG_DEBUG);
405
406
		$error = 0;
407
408
		$this->db->begin();
409
410
		if (!$error) {
411
			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...
412
				// Uncomment this and change MYOBJECT to your own tag if you
413
				// want this action calls a trigger.
414
415
				//// Call triggers
416
				//$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...
417
				//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...
418
				//// End call triggers
419
			}
420
		}
421
422
		if (!$error) {
423
			$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
424
			$sql .= ' WHERE idType=' . $this->id;
425
426
			$resql = $this->db->query($sql);
427
			if (!$resql) {
428
				$error ++;
429
				$this->errors[] = 'Error ' . $this->db->lasterror();
430
				dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
431
			}
432
		}
433
434
		// Commit or rollback
435
		if ($error) {
436
			$this->db->rollback();
437
438
			return - 1 * $error;
439
		} else {
440
			$this->db->commit();
441
442
			return 1;
443
		}
444
	}
445
446
	/**
447
	 * Load an object from its id and create a new one in database
448
	 *
449
	 * @param int $fromid Id of object to clone
450
	 *
451
	 * @return int New id of clone
452
	 */
453
	public function createFromClone($fromid)
454
	{
455
		dol_syslog(__METHOD__, LOG_DEBUG);
456
457
		global $user;
458
		$error = 0;
459
		$object = new Bbctypes($this->db);
460
461
		$this->db->begin();
462
463
		// Load source object
464
		$object->fetch($fromid);
465
		// Reset object
466
		$object->id = 0;
467
468
		// Clear fields
469
		// ...
470
471
		// Create clone
472
		$result = $object->create($user);
473
474
		// Other options
475
		if ($result < 0) {
476
			$error ++;
477
			$this->errors = $object->errors;
478
			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
479
		}
480
481
		// End
482
		if (!$error) {
483
			$this->db->commit();
484
485
			return $object->id;
486
		} else {
487
			$this->db->rollback();
488
489
			return - 1;
490
		}
491
	}
492
493
	/**
494
	 *  Return a link to the user card (with optionaly the picto)
495
	 * 	Use this->id,this->lastname, this->firstname
496
	 *
497
	 *	@param	int		$withpicto			Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
498
	 *	@param	string	$option				On what the link point to
499
     *  @param	integer	$notooltip			1=Disable tooltip
500
     *  @param	int		$maxlen				Max length of visible user name
501
     *  @param  string  $morecss            Add more css on link
502
	 *	@return	string						String with URL
503
	 */
504
	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...
505
	{
506
		global $langs, $conf, $db;
507
        global $dolibarr_main_authentication, $dolibarr_main_demo;
508
        global $menumanager;
509
510
511
        $result = '';
512
        $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...
513
514
        $label = '<u>' . $langs->trans("MyModule") . '</u>';
515
        $label.= '<div width="100%">';
516
        $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
517
518
        $link = '<a href="'.DOL_URL_ROOT.'/flightlog/card.php?id='.$this->id.'"';
519
        $link.= ($notooltip?'':' title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip'.($morecss?' '.$morecss:'').'"');
520
        $link.= '>';
521
		$linkend='</a>';
522
523 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...
524
        {
525
            $result.=($link.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend);
526
            if ($withpicto != 2) $result.=' ';
527
		}
528
		$result.= $link . $this->ref . $linkend;
529
		return $result;
530
	}
531
	
532
	/**
533
	 *  Retourne le libelle du status d'un user (actif, inactif)
534
	 *
535
	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
536
	 *  @return	string 			       Label of status
537
	 */
538
	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...
539
	{
540
		return $this->LibStatut($this->status,$mode);
541
	}
542
543
	/**
544
	 *  Renvoi le libelle d'un status donne
545
	 *
546
	 *  @param	int		$status        	Id status
547
	 *  @param  int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
548
	 *  @return string 			       	Label of status
549
	 */
550 View Code Duplication
	function LibStatut($status,$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...
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...
551
	{
552
		global $langs;
553
554
		if ($mode == 0)
555
		{
556
			$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...
557
			if ($status == 1) return $langs->trans('Enabled');
558
			if ($status == 0) return $langs->trans('Disabled');
559
		}
560
		if ($mode == 1)
561
		{
562
			if ($status == 1) return $langs->trans('Enabled');
563
			if ($status == 0) return $langs->trans('Disabled');
564
		}
565
		if ($mode == 2)
566
		{
567
			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
568
			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
569
		}
570
		if ($mode == 3)
571
		{
572
			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
573
			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
574
		}
575
		if ($mode == 4)
576
		{
577
			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
578
			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
579
		}
580
		if ($mode == 5)
581
		{
582
			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
583
			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
584
		}
585
586
		return "";
587
	}
588
	
589
	
590
	/**
591
	 * Initialise object with example values
592
	 * Id must be 0 if object instance is a specimen
593
	 *
594
	 * @return void
595
	 */
596
	public function initAsSpecimen()
597
	{
598
		$this->id = 0;
599
		
600
		$this->idType = '';
601
		$this->numero = '';
602
		$this->nom = '';
603
		$this->fkService = null;
604
		$this->active = '';
605
606
		
607
	}
608
609
    /**
610
     * @return boolean
611
     */
612
    public function isPaxRequired()
613
    {
614
        switch((int)$this->idType){
615
            case 1:
616
            case 2:
617
                return true;
618
            default:
619
                return false;
620
        }
621
    }
622
623
    /**
624
     * Return true if this type of flight requires money.
625
     *
626
     * @return boolean
627
     */
628
    public function isBillingRequired()
629
    {
630
        return (int)$this->idType === 2;
631
    }
632
633
}
634
635
/**
636
 * Class BbctypesLine
637
 */
638
class BbctypesLine
639
{
640
	/**
641
	 * @var int ID
642
	 */
643
	public $id;
644
645
	public $idType;
646
	public $numero;
647
	public $nom;
648
	public $fkService;
649
	public $active;
650
}
651