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