Passed
Branch develop (027d94)
by
unknown
26:09
created

Hook::LibStatut()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 2
b 0
f 0
nc 4
nop 2
dl 0
loc 19
rs 9.9332
1
<?php
2
/* Copyright (C) 2017  Laurent Destailleur <[email protected]>
3
 * Copyright (C) 2019       Frédéric France     <[email protected]>
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 * \file        htdocs/modulebuilder/template/class/hook.class.php
20
 * \ingroup     zapier
21
 * \brief       This file is a CRUD class file for Hook (Create/Read/Update/Delete)
22
 */
23
24
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
25
26
/**
27
 * Class for Hook
28
 */
29
class Hook extends CommonObject
30
{
31
    /**
32
     * @var string ID to identify managed object
33
     */
34
    public $element = 'hook';
35
36
    /**
37
     * @var string Name of table without prefix where object is stored
38
     */
39
    public $table_element = 'zapier_hook';
40
41
    /**
42
     * @var int  Does hook support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
43
     */
44
    public $ismultientitymanaged = 0;
45
46
    /**
47
     * @var int  Does hook support extrafields ? 0=No, 1=Yes
48
     */
49
    public $isextrafieldmanaged = 1;
50
51
    /**
52
     * @var string String with name of icon for hook. Must be the part after the 'object_' into object_hook.png
53
     */
54
    public $picto = 'hook@zapier';
55
56
57
    const STATUS_DRAFT = 0;
58
    const STATUS_VALIDATED = 1;
59
    const STATUS_DISABLED = -1;
60
61
62
    /**
63
     *  'type' if the field format ('integer', 'integer:Class:pathtoclass', 'varchar(x)', 'double(24,8)', 'text', 'html', 'datetime', 'timestamp', 'float')
64
     *  'label' the translation key.
65
     *  'enabled' is a condition when the field must be managed.
66
     *  '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). Using a negative value means field is not shown by default on list but can be selected for viewing)
67
     *  'noteditable' says if field is not editable (1 or 0)
68
     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
69
     *  'default' is a default value for creation (can still be replaced by the global setup of default values)
70
     *  'index' if we want an index in database.
71
     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
72
     *  'position' is the sort order of field.
73
     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
74
     *  '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).
75
     *  'css' is the CSS style to use on field. For example: 'maxwidth200'
76
     *  'help' is a string visible as a tooltip on field
77
     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
78
     *  'showoncombobox' if value of the field must be visible into the label of the combobox that list record
79
     *  'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
80
     */
81
82
    /**
83
     * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
84
     */
85
    public $fields = array(
86
        'rowid' => array(
87
            'type' => 'integer',
88
            'label' => 'TechnicalID',
89
            'enabled' => 1,
90
            'visible' => -2,
91
            'noteditable' => 1,
92
            'notnull' => 1,
93
            'index' => 1,
94
            'position' => 1,
95
            'comment' => 'Id',
96
        ),
97
        'entity' => array(
98
            'type' => 'integer',
99
            'label' => 'Entity',
100
            'enabled' => 1,
101
            'visible' => 0,
102
            'notnull' => 1,
103
            'default' => 1,
104
            'index' => 1,
105
            'position' => 20,
106
        ),
107
        'fk_user' => array(
108
            'type' => 'integer',
109
            'label' => 'UserOwner',
110
            'enabled' => 1,
111
            'visible' => -2,
112
            'notnull' => 1,
113
            'position' => 510,
114
            'foreignkey' => 'llx_user.rowid',
115
        ),
116
        'url' => array(
117
            'type' => 'varchar(255)',
118
            'label' => 'Url',
119
            'enabled' => 1,
120
            'visible' => 1,
121
            'position' => 30,
122
            'searchall' => 1,
123
            'css' => 'minwidth200',
124
            'help' => 'Hook url',
125
            'showoncombobox' => 1,
126
        ),
127
        'module' => array(
128
            'type' => 'varchar(128)',
129
            'label' => 'Url',
130
            'enabled' => 1,
131
            'visible' => 1,
132
            'position' => 30,
133
            'searchall' => 1,
134
            'css' => 'minwidth200',
135
            'help' => 'Hook module',
136
            'showoncombobox' => 1,
137
        ),
138
        'action' => array(
139
            'type' => 'varchar(128)',
140
            'label' => 'Url',
141
            'enabled' => 1,
142
            'visible' => 1,
143
            'position' => 30,
144
            'searchall' => 1,
145
            'css' => 'minwidth200',
146
            'help' => 'Hook action trigger',
147
            'showoncombobox' => 1,
148
        ),
149
        'event' => array(
150
            'type' => 'varchar(255)',
151
            'label' => 'Event',
152
            'enabled' => 1,
153
            'visible' => 1,
154
            'position' => 30,
155
            'searchall' => 1,
156
            'css' => 'minwidth200',
157
            'help' => 'Event',
158
            'showoncombobox' => 1,
159
        ),
160
        'date_creation' => array(
161
            'type' => 'datetime',
162
            'label' => 'DateCreation',
163
            'enabled' => 1,
164
            'visible' => -2,
165
            'notnull' => 1,
166
            'position' => 500,
167
        ),
168
        'import_key' => array(
169
            'type' => 'varchar(14)',
170
            'label' => 'ImportId',
171
            'enabled' => 1,
172
            'visible' => -2,
173
            'notnull' => -1,
174
            'index' => 0,
175
            'position' => 1000,
176
        ),
177
        'status' => array(
178
            'type' => 'integer',
179
            'label' => 'Status',
180
            'enabled' => 1,
181
            'visible' => 1,
182
            'notnull' => 1,
183
            'default' => 0,
184
            'index' => 1,
185
            'position' => 1000,
186
            'arrayofkeyval' => array(
187
                0 => 'Draft',
188
                1 => 'Active',
189
                -1 => 'Canceled',
190
            ),
191
        ),
192
    );
193
194
    /**
195
     * @var int ID
196
     */
197
    public $rowid;
198
199
    /**
200
     * @var string Ref
201
     */
202
    public $ref;
203
204
    /**
205
     * @var int Entity
206
     */
207
    public $entity;
208
209
    /**
210
     * @var string label
211
     */
212
    public $label;
213
214
    /**
215
     * @var string amount
216
     */
217
    public $amount;
218
219
    /**
220
     * @var int Status
221
     */
222
    public $status;
223
224
    /**
225
     * @var integer|string date_creation
226
     */
227
    public $date_creation;
228
229
    /**
230
     * @var integer tms
231
     */
232
    public $tms;
233
234
    /**
235
     * @var int ID
236
     */
237
    public $fk_user_creat;
238
239
    /**
240
     * @var int ID
241
     */
242
    public $fk_user_modif;
243
244
    /**
245
     * @var string import_key
246
     */
247
    public $import_key;
248
249
250
    // If this object has a subtable with lines
251
252
    /**
253
     * @var int    Name of subtable line
254
     */
255
    //public $table_element_line = 'hookdet';
256
257
    /**
258
     * @var int    Field with ID of parent key if this field has a parent
259
     */
260
    //public $fk_element = 'fk_hook';
261
262
    /**
263
     * @var int    Name of subtable class that manage subtable lines
264
     */
265
    //public $class_element_line = 'MyObjectline';
266
267
    /**
268
     * @var array  Array of child tables (child tables to delete before deleting a record)
269
     */
270
    //protected $childtables=array('hookdet');
271
272
    /**
273
     * @var MyObjectLine[]     Array of subtable lines
274
     */
275
    //public $lines = array();
276
277
278
279
    /**
280
     * Constructor
281
     *
282
     * @param DoliDb $db Database handler
283
     */
284
    public function __construct(DoliDB $db)
285
    {
286
        global $conf, $langs, $user;
287
288
        $this->db = $db;
289
290
        if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
291
            $this->fields['rowid']['visible']=0;
292
        }
293
        if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
294
            $this->fields['entity']['enabled']=0;
295
        }
296
297
        // Unset fields that are disabled
298
        foreach($this->fields as $key => $val) {
299
            if (isset($val['enabled']) && empty($val['enabled'])) {
300
                unset($this->fields[$key]);
301
            }
302
        }
303
304
        // Translate some data of arrayofkeyval
305
        foreach($this->fields as $key => $val) {
306
            if (is_array($this->fields['status']['arrayofkeyval'])) {
307
                foreach($this->fields['status']['arrayofkeyval'] as $key2 => $val2) {
308
                    $this->fields['status']['arrayofkeyval'][$key2]=$langs->trans($val2);
309
                }
310
            }
311
        }
312
    }
313
314
    /**
315
     * Create object into database
316
     *
317
     * @param  User $user      User that creates
318
     * @param  bool $notrigger false=launch triggers after, true=disable triggers
319
     * @return int             <0 if KO, Id of created object if OK
320
     */
321
    public function create(User $user, $notrigger = false)
322
    {
323
        return $this->createCommon($user, $notrigger);
324
    }
325
326
    /**
327
     * Clone an object into another one
328
     *
329
     * @param   User    $user       User that creates
330
     * @param   int     $fromid     Id of object to clone
331
     * @return  mixed               New object created, <0 if KO
332
     */
333
    public function createFromClone(User $user, $fromid)
334
    {
335
        global $langs, $hookmanager, $extrafields;
336
        $error = 0;
337
338
        dol_syslog(__METHOD__, LOG_DEBUG);
339
340
        $object = new self($this->db);
341
342
        $this->db->begin();
343
344
        // Load source object
345
        $object->fetchCommon($fromid);
346
        // Reset some properties
347
        unset($object->id);
348
        unset($object->fk_user_creat);
349
        unset($object->import_key);
350
351
        // Clear fields
352
        $object->ref = "copy_of_".$object->ref;
353
        $object->title = $langs->trans("CopyOf")." ".$object->title;
354
        // ...
355
        // Clear extrafields that are unique
356
        if (is_array($object->array_options) && count($object->array_options) > 0) {
357
            $extrafields->fetch_name_optionals_label($this->element);
358
            foreach($object->array_options as $key => $option) {
359
                $shortkey = preg_replace('/options_/', '', $key);
360
                if (! empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
361
                    // var_dump($key);
362
                    // var_dump($clonedObj->array_options[$key]);
363
                    // exit;
364
                    unset($object->array_options[$key]);
365
                }
366
            }
367
        }
368
369
        // Create clone
370
        $object->context['createfromclone'] = 'createfromclone';
371
        $result = $object->createCommon($user);
372
        if ($result < 0) {
373
            $error++;
374
            $this->error = $object->error;
375
            $this->errors = $object->errors;
376
        }
377
378
        unset($object->context['createfromclone']);
379
380
        // End
381
        if (!$error) {
382
            $this->db->commit();
383
            return $object;
384
        } else {
385
            $this->db->rollback();
386
            return -1;
387
        }
388
    }
389
390
    /**
391
     * Load object in memory from the database
392
     *
393
     * @param int    $id   Id object
394
     * @param string $ref  Ref
395
     * @return int         <0 if KO, 0 if not found, >0 if OK
396
     */
397
    public function fetch($id, $ref = null)
398
    {
399
        $result = $this->fetchCommon($id, $ref);
400
        if ($result > 0 && ! empty($this->table_element_line)) {
401
            $this->fetchLines();
0 ignored issues
show
Bug introduced by
The method fetchLines() does not exist on Hook. Did you maybe mean fetchLinesCommon()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

401
            $this->/** @scrutinizer ignore-call */ 
402
                   fetchLines();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
402
        }
403
        return $result;
404
    }
405
406
    /**
407
     * Load object lines in memory from the database
408
     *
409
     * @return int         <0 if KO, 0 if not found, >0 if OK
410
     */
411
    /*public function fetchLines()
412
    {
413
        $this->lines=array();
414
415
        // Load lines with object MyObjectLine
416
417
        return count($this->lines)?1:0;
418
    }*/
419
420
    /**
421
     * Load list of objects in memory from the database.
422
     *
423
     * @param  string      $sortorder    Sort Order
424
     * @param  string      $sortfield    Sort field
425
     * @param  int         $limit        limit
426
     * @param  int         $offset       Offset
427
     * @param  array       $filter       Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
428
     * @param  string      $filtermode   Filter mode (AND or OR)
429
     * @return array|int                 int <0 if KO, array of pages if OK
430
     */
431
    public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
432
    {
433
        global $conf;
434
435
        dol_syslog(__METHOD__, LOG_DEBUG);
436
437
        $records=array();
438
439
        $sql = 'SELECT';
440
        $sql .= ' t.rowid';
441
        // TODO Get all fields
442
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
443
        $sql .= ' WHERE t.entity = '.$conf->entity;
444
        // Manage filter
445
        $sqlwhere = array();
446
        if (count($filter) > 0) {
447
            foreach ($filter as $key => $value) {
448
                if ($key=='t.rowid') {
449
                    $sqlwhere[] = $key . '='. $value;
450
                } elseif (strpos($key, 'date') !== false) {
451
                    $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
452
                } elseif ($key=='customsql') {
453
                    $sqlwhere[] = $value;
454
                } else {
455
                    $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
456
                }
457
            }
458
        }
459
        if (count($sqlwhere) > 0) {
460
            $sql .= ' AND (' . implode(' '.$filtermode.' ', $sqlwhere).')';
461
        }
462
463
        if (!empty($sortfield)) {
464
            $sql .= $this->db->order($sortfield, $sortorder);
465
        }
466
        if (!empty($limit)) {
467
            $sql .=  ' ' . $this->db->plimit($limit, $offset);
468
        }
469
470
        $resql = $this->db->query($sql);
471
        if ($resql) {
472
            $num = $this->db->num_rows($resql);
473
474
            while ($obj = $this->db->fetch_object($resql)) {
475
                $record = new self($this->db);
476
477
                $record->id = $obj->rowid;
478
                // TODO Get other fields
479
480
                //var_dump($record->id);
481
                $records[$record->id] = $record;
482
            }
483
            $this->db->free($resql);
484
485
            return $records;
486
        } else {
487
            $this->errors[] = 'Error ' . $this->db->lasterror();
488
            dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
489
490
            return -1;
491
        }
492
    }
493
494
    /**
495
     * Update object into database
496
     *
497
     * @param  User $user      User that modifies
498
     * @param  bool $notrigger false=launch triggers after, true=disable triggers
499
     * @return int             <0 if KO, >0 if OK
500
     */
501
    public function update(User $user, $notrigger = false)
502
    {
503
        return $this->updateCommon($user, $notrigger);
504
    }
505
506
    /**
507
     *  Delete object in database
508
     *
509
     * @param User $user       User that deletes
510
     * @param bool $notrigger  false=launch triggers after, true=disable triggers
511
     * @return int             <0 if KO, >0 if OK
512
     */
513
    public function delete(User $user, $notrigger = false)
514
    {
515
        return $this->deleteCommon($user, $notrigger);
516
        //return $this->deleteCommon($user, $notrigger, 1);
517
    }
518
519
    /**
520
     *  Return a link to the object card (with optionaly the picto)
521
     *
522
     *  @param  int     $withpicto                  Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
523
     *  @param  string  $option                     On what the link point to ('nolink', ...)
524
     *  @param  int     $notooltip                  1=Disable tooltip
525
     *  @param  string  $morecss                    Add more css on link
526
     *  @param  int     $save_lastsearch_value      -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
527
     *  @return	string                              String with URL
528
     */
529
    public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
530
    {
531
        global $db, $conf, $langs, $hookmanager, $action;
532
        global $dolibarr_main_authentication, $dolibarr_main_demo;
533
        global $menumanager;
534
535
        if (! empty($conf->dol_no_mouse_hover)) {
536
            // Force disable tooltips
537
            $notooltip=1;
538
        }
539
540
        $result = '';
541
542
        $label = '<u>' . $langs->trans("Hook") . '</u>';
543
        $label.= '<br>';
544
        $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
545
546
        $url = dol_buildpath('/zapier/hook_card.php', 1).'?id='.$this->id;
547
548
        if ($option != 'nolink') {
549
            // Add param to save lastsearch_values or not
550
            $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
551
            if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
552
                $add_save_lastsearch_values=1;
553
            }
554
            if ($add_save_lastsearch_values) {
555
                $url.='&save_lastsearch_values=1';
556
            }
557
        }
558
559
        $linkclose='';
560
        if (empty($notooltip)) {
561
            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
562
                $label=$langs->trans("ShowMyObject");
563
                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
564
            }
565
            $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
566
            $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
567
568
            /*
569
             $hookmanager->initHooks(array('hookdao'));
570
             $parameters=array('id'=>$this->id);
571
             $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
572
             if ($reshook > 0) $linkclose = $hookmanager->resPrint;
573
             */
574
        } else {
575
            $linkclose = ($morecss?' class="'.$morecss.'"':'');
576
        }
577
578
        $linkstart = '<a href="'.$url.'"';
579
        $linkstart.=$linkclose.'>';
580
        $linkend='</a>';
581
582
        $result .= $linkstart;
583
        if ($withpicto) {
584
            $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
585
        }
586
        if ($withpicto != 2) {
587
            $result.= $this->ref;
588
        }
589
        $result .= $linkend;
590
        //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
591
592
        $hookmanager->initHooks(array('hookdao'));
593
        $parameters = array(
594
            'id' => $this->id,
595
            'getnomurl' => $result,
596
        );
597
        // Note that $action and $object may have been modified by some hooks
598
        $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action);
599
        if ($reshook > 0) {
600
            $result = $hookmanager->resPrint;
601
        } else {
602
            $result .= $hookmanager->resPrint;
603
        }
604
605
        return $result;
606
    }
607
608
    /**
609
     *  Return label of the status
610
     *
611
     *  @param  int     $mode       0 = long label
612
     *                              1 = short label
613
     *                              2 = Picto + short label
614
     *                              3 = Picto, 4=Picto + long label
615
     *                              5 = Short label + Picto
616
     *                              6 = Long label + Picto
617
     *  @return	string              Label of status
618
     */
619
    public function getLibStatut($mode = 0)
620
    {
621
        return $this->LibStatut($this->status, $mode);
622
    }
623
624
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
625
    /**
626
     *  Return the status
627
     *
628
     *  @param  int     $status     Id status
629
     *  @param  int     $mode       0 = long label,
630
     *                              1 = short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
631
     *  @return string              Label of status
632
     */
633
    public function LibStatut($status, $mode = 0)
634
    {
635
        // phpcs:enable
636
    	global $langs;
637
638
    	if (empty($this->labelStatus) || empty($this->labelStatusShort))
639
    	{
640
    		global $langs;
641
    		//$langs->load("mymodule");
642
    		$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Disabled');
643
    		$this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
644
    		$this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Disabled');
645
    		$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
646
    	}
647
648
    	$statusType = 'status5';
649
    	if ($status == self::STATUS_VALIDATED) $statusType = 'status4';
650
651
    	return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
652
    }
653
654
    /**
655
     *  Load the info information in the object
656
     *
657
     *  @param  int     $id       Id of object
658
     *  @return	void
659
     */
660
    public function info($id)
661
    {
662
        $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
663
        $sql.= ' fk_user_creat, fk_user_modif';
664
        $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
665
        $sql.= ' WHERE t.rowid = '.$id;
666
        $result=$this->db->query($sql);
667
        if ($result) {
668
            if ($this->db->num_rows($result)) {
669
                $obj = $this->db->fetch_object($result);
670
                $this->id = $obj->rowid;
671
                if ($obj->fk_user_author) {
672
                    $cuser = new User($this->db);
673
                    $cuser->fetch($obj->fk_user_author);
674
                    $this->user_creation   = $cuser;
675
                }
676
677
                if ($obj->fk_user_valid) {
678
                    $vuser = new User($this->db);
679
                    $vuser->fetch($obj->fk_user_valid);
680
                    $this->user_validation = $vuser;
681
                }
682
683
                if ($obj->fk_user_cloture) {
684
                    $cluser = new User($this->db);
685
                    $cluser->fetch($obj->fk_user_cloture);
686
                    $this->user_cloture   = $cluser;
687
                }
688
689
                $this->date_creation = $this->db->jdate($obj->datec);
690
                $this->date_modification = $this->db->jdate($obj->datem);
691
                $this->date_validation = $this->db->jdate($obj->datev);
692
            }
693
694
            $this->db->free($result);
695
        } else {
696
            dol_print_error($this->db);
697
        }
698
    }
699
700
    /**
701
     * Initialise object with example values
702
     * Id must be 0 if object instance is a specimen
703
     *
704
     * @return void
705
     */
706
    public function initAsSpecimen()
707
    {
708
        $this->initAsSpecimenCommon();
709
    }
710
711
712
    /**
713
     * Action executed by scheduler
714
     * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
715
     *
716
     * @return  int         0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
717
     */
718
    //public function doScheduledJob($param1, $param2, ...)
719
    public function doScheduledJob()
720
    {
721
        global $conf, $langs;
722
723
        //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
724
725
        $error = 0;
726
        $this->output = '';
727
        $this->error='';
728
729
        dol_syslog(__METHOD__, LOG_DEBUG);
730
731
        $now = dol_now();
732
733
        $this->db->begin();
734
735
        // ...
736
737
        $this->db->commit();
738
739
        return $error;
740
    }
741
}
742
743
/**
744
 * Class MyObjectLine. You can also remove this and generate a CRUD class for lines objects.
745
 */
746
/*
747
class MyObjectLine
748
{
749
    // @var int ID
750
    public $id;
751
    // @var mixed Sample line property 1
752
    public $prop1;
753
    // @var mixed Sample line property 2
754
    public $prop2;
755
}
756
*/
757