Passed
Push — EXTRACT_CLASSES ( ae6b5c...83d77a )
by Rafael
60:14 queued 23:58
created

CTicketCategory::createFromClone()   F

Complexity

Conditions 21
Paths 6912

Size

Total Lines 87
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 21
eloc 45
nc 6912
nop 2
dl 0
loc 87
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* Copyright (C) 2017       Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2024       Frédéric France             <[email protected]>
5
 * Copyright (C) 2024		MDW							<[email protected]>
6
 * Copyright (C) 2024       Rafael San José             <[email protected]>
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 <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Dolibarr\Code\Ticket\Classes;
23
24
use Dolibarr\Core\Base\CommonObject;
25
26
/**
27
 * \file        htdocs/modulebuilder/template/class/myobject.class.php
28
 * \ingroup     mymodule
29
 * \brief       This file is a CRUD class file for MyObject (Create/Read/Update/Delete)
30
 */
31
32
// Put here all includes required by your class file
33
//use Dolibarr\Code\Societe\Classes\Societe;
34
//require_once constant('DOL_DOCUMENT_ROOT') . '/product/class/product.class.php';
35
36
/**
37
 * Class for MyObject
38
 */
39
class CTicketCategory extends CommonObject
40
{
41
    /**
42
     * @var string ID of module.
43
     */
44
    public $module = 'ticket';
45
46
    /**
47
     * @var string ID to identify managed object.
48
     */
49
    public $element = 'cticketcategory';
50
51
    /**
52
     * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
53
     */
54
    public $table_element = 'c_ticket_category';
55
56
    /**
57
     * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
58
     */
59
    public $picto = 'ticket';
60
61
62
    const STATUS_DISABLED = 0;
63
    const STATUS_ENABLED = 1;
64
65
66
    /**
67
     *  'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
68
     *         Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
69
     *  'label' the translation key.
70
     *  'picto' is code of a picto to show before value in forms
71
     *  'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalString('MY_SETUP_PARAM'))
72
     *  'position' is the sort order of field.
73
     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
74
     *  'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
75
     *  'noteditable' says if field is not editable (1 or 0)
76
     *  'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
77
     *  'index' if we want an index in database.
78
     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...).
79
     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
80
     *  'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
81
     *  'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'maxwidth200', 'wordbreak', 'tdoverflowmax200'
82
     *  'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
83
     *  'showoncombobox' if value of the field must be visible into the label of the combobox that list record
84
     *  'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
85
     *  'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
86
     *  'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
87
     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
88
     *
89
     *  Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
90
     */
91
92
    // BEGIN MODULEBUILDER PROPERTIES
93
    /**
94
     * @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}>  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,array{type:...ring>,comment?:string}> at position 16 could not be parsed: Expected '}' at position 16, but found 'int'.
Loading history...
95
     */
96
    public $fields = array(
97
        'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
98
        'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'position' => 15, 'index' => 1),
99
        'code' => array('type' => 'varchar(32)', 'label' => 'Code', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 20),
100
        'pos' => array('type' => 'integer', 'label' => 'Pos', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 25),
101
        'label' => array('type' => 'varchar(128)', 'label' => 'Label', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 30, 'showoncombobox' => 1),
102
        'active' => array('type' => 'integer', 'label' => 'Active', 'enabled' => 1, 'visible' => -1, 'position' => 35),
103
        'use_default' => array('type' => 'integer', 'label' => 'Usedefault', 'enabled' => 1, 'visible' => -1, 'position' => 40),
104
        'description' => array('type' => 'varchar(255)', 'label' => 'Description', 'enabled' => 1, 'visible' => -1, 'position' => 45),
105
        'fk_parent' => array('type' => 'integer', 'label' => 'Fkparent', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 50),
106
        'force_severity' => array('type' => 'varchar(32)', 'label' => 'Forceseverity', 'enabled' => 1, 'visible' => -1, 'position' => 55),
107
        'public' => array('type' => 'integer', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'position' => 60),
108
    );
109
110
    /**
111
     * @var int ID
112
     */
113
    public $rowid;
114
115
    /**
116
     * @var string Ref
117
     */
118
    public $ref;
119
120
    /**
121
     * @var int Entity
122
     */
123
    public $entity;
124
125
    /**
126
     * @var string label
127
     */
128
    public $label;
129
130
    /**
131
     * @var string amount
132
     */
133
    public $amount;
134
135
    /**
136
     * @var int Status
137
     */
138
    public $status;
139
140
    /**
141
     * @var integer|string date_creation
142
     */
143
    public $date_creation;
144
145
    /**
146
     * @var int ID
147
     */
148
    public $fk_user_creat;
149
150
    /**
151
     * @var int ID
152
     */
153
    public $fk_user_modif;
154
155
    /**
156
     * @var string public $last_main_doc
157
     */
158
    public $last_main_doc;
159
160
    /**
161
     * @var string import_key
162
     */
163
    public $import_key;
164
    // END MODULEBUILDER PROPERTIES
165
166
167
168
    /**
169
     * Constructor
170
     *
171
     * @param DoliDB $db Database handler
172
     */
173
    public function __construct(DoliDB $db)
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\Ticket\Classes\DoliDB was not found. Did you mean DoliDB? If so, make sure to prefix the type with \.
Loading history...
174
    {
175
        global $conf, $langs;
176
177
        $this->db = $db;
178
179
        $this->ismultientitymanaged = 0;
180
        $this->isextrafieldmanaged = 0;
181
182
        if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
183
            $this->fields['rowid']['visible'] = 0;
184
        }
185
        if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
186
            $this->fields['entity']['enabled'] = 0;
187
        }
188
189
        // Unset fields that are disabled
190
        foreach ($this->fields as $key => $val) {
191
            if (isset($val['enabled']) && empty($val['enabled'])) {
192
                unset($this->fields[$key]);
193
            }
194
        }
195
196
        // Translate some data of arrayofkeyval
197
        if (is_object($langs)) {
198
            foreach ($this->fields as $key => $val) {
199
                if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
200
                    foreach ($val['arrayofkeyval'] as $key2 => $val2) {
201
                        $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
202
                    }
203
                }
204
            }
205
        }
206
    }
207
208
    /**
209
     * Create object into database
210
     *
211
     * @param  User $user      User that creates
212
     * @param  int  $notrigger 0=launch triggers after, 1=disable triggers
213
     * @return int             Return integer <0 if KO, Id of created object if OK
214
     */
215
    public function create(User $user, $notrigger = 0)
216
    {
217
        $resultcreate = $this->createCommon($user, $notrigger);
218
219
        //$resultvalidate = $this->validate($user, $notrigger);
220
221
        return $resultcreate;
222
    }
223
224
    /**
225
     * Clone an object into another one
226
     *
227
     * @param   User    $user       User that creates
228
     * @param   int     $fromid     Id of object to clone
229
     * @return  mixed               New object created, <0 if KO
230
     */
231
    public function createFromClone(User $user, $fromid)
232
    {
233
        global $langs, $extrafields;
234
        $error = 0;
235
236
        dol_syslog(__METHOD__, LOG_DEBUG);
237
238
        $object = new self($this->db);
239
240
        $this->db->begin();
241
242
        // Load source object
243
        $result = $object->fetchCommon($fromid);
244
        if ($result > 0 && !empty($object->table_element_line)) {
245
            $object->fetchLines();
246
        }
247
248
        // get lines so they will be clone
249
        //foreach($this->lines as $line)
250
        //  $line->fetch_optionals();
251
252
        // Reset some properties
253
        unset($object->id);
254
        unset($object->fk_user_creat);
255
        unset($object->import_key);
256
257
        // Clear fields
258
        if (property_exists($object, 'ref')) {
259
            $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_" . $object->ref : $this->fields['ref']['default'];
260
        }
261
        if (property_exists($object, 'label')) {
262
            $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf") . " " . $object->label : $this->fields['label']['default'];
263
        }
264
        if (property_exists($object, 'date_creation')) {
265
            $object->date_creation = dol_now();
266
        }
267
        if (property_exists($object, 'date_modification')) {
268
            $object->date_modification = null;
269
        }
270
        // ...
271
        // Clear extrafields that are unique
272
        if (is_array($object->array_options) && count($object->array_options) > 0) {
273
            $extrafields->fetch_name_optionals_label($this->table_element);
274
            foreach ($object->array_options as $key => $option) {
275
                $shortkey = preg_replace('/options_/', '', $key);
276
                if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
277
                    //var_dump($key);
278
                    //var_dump($clonedObj->array_options[$key]); exit;
279
                    unset($object->array_options[$key]);
280
                }
281
            }
282
        }
283
284
        // Create clone
285
        $object->context['createfromclone'] = 'createfromclone';
286
        $result = $object->createCommon($user);
287
        if ($result < 0) {
288
            $error++;
289
            $this->error = $object->error;
290
            $this->errors = $object->errors;
291
        }
292
293
        if (!$error) {
294
            // copy internal contacts
295
            if ($this->copy_linked_contact($object, 'internal') < 0) {
296
                $error++;
297
            }
298
        }
299
300
        if (!$error) {
301
            // copy external contacts if same company
302
            if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
303
                if ($this->copy_linked_contact($object, 'external') < 0) {
304
                    $error++;
305
                }
306
            }
307
        }
308
309
        unset($object->context['createfromclone']);
310
311
        // End
312
        if (!$error) {
313
            $this->db->commit();
314
            return $object;
315
        } else {
316
            $this->db->rollback();
317
            return -1;
318
        }
319
    }
320
321
    /**
322
     * Load object in memory from the database
323
     *
324
     * @param int    $id   Id object
325
     * @param string $ref  Ref
326
     * @return int         Return integer <0 if KO, 0 if not found, >0 if OK
327
     */
328
    public function fetch($id, $ref = null)
329
    {
330
        $result = $this->fetchCommon($id, $ref);
331
        if ($result > 0 && !empty($this->table_element_line)) {
332
            $this->fetchLines();
333
        }
334
        return $result;
335
    }
336
337
    /**
338
     * Load object lines in memory from the database
339
     *
340
     * @return int         Return integer <0 if KO, 0 if not found, >0 if OK
341
     */
342
    public function fetchLines()
343
    {
344
        $this->lines = array();
345
346
        $result = $this->fetchLinesCommon();
347
        return $result;
348
    }
349
350
351
    /**
352
     * Load list of objects in memory from the database.
353
     *
354
     * @param  string       $sortorder      Sort Order
355
     * @param  string       $sortfield      Sort field
356
     * @param  int          $limit          limit
357
     * @param  int          $offset         Offset
358
     * @param  string       $filter         Filter as an Universal Search string.
359
     *                                      Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')'
360
     * @param  string       $filtermode     No more used
361
     * @return array|int                    int <0 if KO, array of pages if OK
362
     */
363
    public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
364
    {
365
        dol_syslog(__METHOD__, LOG_DEBUG);
366
367
        $records = array();
368
369
        $sql = 'SELECT ';
370
        $sql .= $this->getFieldList('t');
371
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
372
        if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
373
            $sql .= ' WHERE t.entity IN (' . getEntity($this->element) . ')';
374
        } else {
375
            $sql .= ' WHERE 1 = 1';
376
        }
377
378
        // Manage filter
379
        $errormessage = '';
380
        $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
381
        if ($errormessage) {
382
            $this->errors[] = $errormessage;
383
            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
384
            return -1;
385
        }
386
387
        if (!empty($sortfield)) {
388
            $sql .= $this->db->order($sortfield, $sortorder);
389
        }
390
        if (!empty($limit)) {
391
            $sql .= $this->db->plimit($limit, $offset);
392
        }
393
394
        $resql = $this->db->query($sql);
395
        if ($resql) {
396
            $num = $this->db->num_rows($resql);
397
            $i = 0;
398
            while ($i < ($limit ? min($limit, $num) : $num)) {
399
                $obj = $this->db->fetch_object($resql);
400
401
                $record = new self($this->db);
402
                $record->setVarsFromFetchObj($obj);
403
404
                $records[$record->id] = $record;
405
406
                $i++;
407
            }
408
            $this->db->free($resql);
409
410
            return $records;
411
        } else {
412
            $this->errors[] = 'Error ' . $this->db->lasterror();
413
            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
414
415
            return -1;
416
        }
417
    }
418
419
    /**
420
     * Update object into database
421
     *
422
     * @param  User $user      User that modifies
423
     * @param  int  $notrigger 0=launch triggers after, 1=disable triggers
424
     * @return int             Return integer <0 if KO, >0 if OK
425
     */
426
    public function update(User $user, $notrigger = 0)
427
    {
428
        return $this->updateCommon($user, $notrigger);
429
    }
430
431
    /**
432
     * Delete object in database
433
     *
434
     * @param User $user       User that deletes
435
     * @param int   $notrigger  0=launch triggers after, 1=disable triggers
436
     * @return int             Return integer <0 if KO, >0 if OK
437
     */
438
    public function delete(User $user, $notrigger = 0)
439
    {
440
        return $this->deleteCommon($user, $notrigger);
441
        //return $this->deleteCommon($user, $notrigger, 1);
442
    }
443
444
    /**
445
     *  Delete a line of object in database
446
     *
447
     *  @param  User    $user       User that delete
448
     *  @param  int     $idline     Id of line to delete
449
     *  @param  int     $notrigger  false=launch triggers after, true=disable triggers
450
     *  @return int                 >0 if OK, <0 if KO
451
     */
452
    public function deleteLine(User $user, $idline, $notrigger = 0)
453
    {
454
        if ($this->status < 0) {
455
            $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
456
            return -2;
457
        }
458
459
        return $this->deleteLineCommon($user, $idline, $notrigger);
460
    }
461
462
463
    /**
464
     *  Return a link to the object card (with optionally the picto)
465
     *
466
     *  @param  int     $withpicto                  Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
467
     *  @param  string  $option                     On what the link point to ('nolink', ...)
468
     *  @param  int     $notooltip                  1=Disable tooltip
469
     *  @param  string  $morecss                    Add more css on link
470
     *  @param  int     $save_lastsearch_value      -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
471
     *  @return string                              String with URL
472
     */
473
    public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
474
    {
475
        global $conf, $langs, $hookmanager;
476
477
        if (!empty($conf->dol_no_mouse_hover)) {
478
            $notooltip = 1; // Force disable tooltips
479
        }
480
481
        $result = '';
482
483
        /*$label = img_picto('', $this->picto).' <u>'.$langs->trans("MyObject").'</u>';
484
        if (isset($this->status)) {
485
            $label .= ' '.$this->getLibStatut(5);
486
        }
487
        $label .= '<br>';
488
        $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
489
        */
490
        $label = '';
491
492
        //$url = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$this->id;
493
        $url = '';
494
495
        if ($option != 'nolink') {
496
            // Add param to save lastsearch_values or not
497
            $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
498
            if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
499
                $add_save_lastsearch_values = 1;
500
            }
501
            if ($add_save_lastsearch_values) {
502
                $url .= '&save_lastsearch_values=1';
503
            }
504
        }
505
506
        $linkclose = '';
507
        if (empty($notooltip)) {
508
            if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
509
                $label = $langs->trans("ShowMyObject");
510
                $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
511
            }
512
            $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"';
513
            $linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
514
        } else {
515
            $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
516
        }
517
518
        if ($option == 'nolink') {
519
            $linkstart = '<span';
520
        } else {
521
            $linkstart = '<a href="' . $url . '"';
522
        }
523
        $linkstart .= $linkclose . '>';
524
        if ($option == 'nolink') {
525
            $linkend = '</span>';
526
        } else {
527
            $linkend = '</a>';
528
        }
529
530
        //$result .= $linkstart;
531
        $result .= $this->label;
532
        //$result .= $linkend;
533
534
        global $action, $hookmanager;
535
        $hookmanager->initHooks(array('cticketcategorydao'));
536
        $parameters = array('id' => $this->id, 'getnomurl' => &$result);
537
        $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
538
        if ($reshook > 0) {
539
            $result = $hookmanager->resPrint;
540
        } else {
541
            $result .= $hookmanager->resPrint;
542
        }
543
544
        return $result;
545
    }
546
547
    /**
548
     *  Return the label of the status
549
     *
550
     *  @param  int     $mode          0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
551
     *  @return string                 Label of status
552
     */
553
    public function getLibStatut($mode = 0)
554
    {
555
        return $this->LibStatut($this->status, $mode);
556
    }
557
558
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
559
    /**
560
     *  Return the status
561
     *
562
     *  @param  int     $status        Id status
563
     *  @param  int     $mode          0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
564
     *  @return string                 Label of status
565
     */
566
    public function LibStatut($status, $mode = 0)
567
    {
568
		// phpcs:enable
569
        if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
570
            global $langs;
571
            //$langs->load("mymodule@mymodule");
572
            $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
573
            $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
574
            $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
575
            $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
576
        }
577
578
        $statusType = 'status' . $status;
579
        //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
580
        if ($status == self::STATUS_DISABLED) {
581
            $statusType = 'status6';
582
        }
583
584
        return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
585
    }
586
587
    /**
588
     *  Load the info information in the object
589
     *
590
     *  @param  int     $id       Id of object
591
     *  @return void
592
     */
593
    public function info($id)
594
    {
595
        $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
596
        $sql .= ' fk_user_creat, fk_user_modif';
597
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
598
        $sql .= ' WHERE t.rowid = ' . ((int) $id);
599
        $result = $this->db->query($sql);
600
        if ($result) {
601
            if ($this->db->num_rows($result)) {
602
                $obj = $this->db->fetch_object($result);
603
604
                $this->id = $obj->rowid;
605
606
                $this->user_creation_id = $obj->fk_user_creat;
607
                $this->user_modification_id = $obj->fk_user_modif;
608
                $this->date_creation     = $this->db->jdate($obj->datec);
609
                $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
610
            }
611
612
            $this->db->free($result);
613
        } else {
614
            dol_print_error($this->db);
615
        }
616
    }
617
618
    /**
619
     * Initialise object with example values
620
     * Id must be 0 if object instance is a specimen
621
     *
622
     * @return int
623
     */
624
    public function initAsSpecimen()
625
    {
626
        return $this->initAsSpecimenCommon();
627
    }
628
}
629