CTicketCategory   F
last analyzed

Complexity

Total Complexity 77

Size/Duplication

Total Lines 588
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 209
dl 0
loc 588
rs 2.24
c 0
b 0
f 0
wmc 77

14 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 3 1
F createFromClone() 0 87 21
A create() 0 7 1
A fetchLines() 0 6 1
A getLibStatut() 0 3 1
B fetchAll() 0 53 9
A deleteLine() 0 8 2
A LibStatut() 0 19 4
A fetch() 0 7 3
A delete() 0 3 1
F getNomUrl() 0 72 15
A initAsSpecimen() 0 3 1
A info() 0 22 4
C __construct() 0 29 13

How to fix   Complexity   

Complex Class

Complex classes like CTicketCategory often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CTicketCategory, and based on these observations, apply Extract Interface, too.

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