ConferenceOrBoothAttendee::getNomUrl()   F
last analyzed

Complexity

Conditions 37
Paths > 20000

Size

Total Lines 117
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 37
eloc 75
nc 149760
nop 5
dl 0
loc 117
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\EventOrganizaction\Classes;
23
24
use Dolibarr\Core\Base\CommonObject;
25
use DoliDB;
26
27
/**
28
 * \file        class/conferenceorboothattendee.class.php
29
 * \ingroup     eventorganization
30
 * \brief       This file is a CRUD class file for ConferenceOrBoothAttendee (Create/Read/Update/Delete)
31
 */
32
33
// Put here all includes required by your class file
34
//use Dolibarr\Code\Societe\Classes\Societe;
35
//
36
/**
37
 * Class for ConferenceOrBoothAttendee
38
 */
39
class ConferenceOrBoothAttendee extends CommonObject
40
{
41
    /**
42
     * @var string ID of module.
43
     */
44
    public $module = 'eventorganization';
45
46
    /**
47
     * @var string ID to identify managed object.
48
     */
49
    public $element = 'conferenceorboothattendee';
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 = 'eventorganization_conferenceorboothattendee';
55
56
    /**
57
     * @var string String with name of icon for conferenceorboothattendee. Must be the part after the 'object_' into object_conferenceorboothattendee.png
58
     */
59
    public $picto = 'contact';
60
61
    public $paid = 0;
62
63
    const STATUS_DRAFT = 0;
64
    const STATUS_VALIDATED = 1;
65
    const STATUS_CANCELED = 9;
66
67
68
    /**
69
     *  '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')
70
     *         Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
71
     *  'label' the translation key.
72
     *  'picto' is code of a picto to show before value in forms
73
     *  'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalString("MY_SETUP_PARAM")')
74
     *  'position' is the sort order of field.
75
     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
76
     *  '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)
77
     *  'noteditable' says if field is not editable (1 or 0)
78
     *  '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.
79
     *  'index' if we want an index in database.
80
     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...).
81
     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
82
     *  '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).
83
     *  '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'
84
     *  'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
85
     *  'showoncombobox' if value of the field must be visible into the label of the combobox that list record
86
     *  '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.
87
     *  'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
88
     *  'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
89
     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
90
     *
91
     *  Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
92
     */
93
94
    // BEGIN MODULEBUILDER PROPERTIES
95
    /**
96
     * @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...
97
     */
98
    public $fields = array(
99
        'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
100
        'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 2, 'index' => 1, 'comment' => "Reference of object"),
101
        //'fk_actioncomm' => array('type'=>'integer:ActionComm:comm/action/class/actioncomm.class.php:1', 'label'=>'ConferenceOrBooth', 'enabled'=>'1', 'position'=>15, 'notnull'=>0, 'visible'=>0, 'index'=>1, 'picto'=>'agenda'),
102
        'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'position' => 20, 'notnull' => 1, 'visible' => 0, 'index' => 1, 'picto' => 'project', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
103
        'email' => array('type' => 'mail', 'label' => 'EmailAttendee', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'index' => 1, 'autofocusoncreate' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax150'),
104
        'firstname' => array('type' => 'varchar(100)', 'label' => 'Firstname', 'enabled' => 1, 'position' => 31, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax125'),
105
        'lastname' => array('type' => 'varchar(100)', 'label' => 'Lastname', 'enabled' => 1, 'position' => 32, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax125'),
106
        'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'enabled' => 'isModEnabled("societe")', 'position' => 40, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'help' => "OrganizationEventLinkToThirdParty", 'picto' => 'company', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
107
        'email_company' => array('type' => 'mail', 'label' => 'EmailCompany', 'enabled' => 1, 'position' => 41, 'notnull' => 0, 'visible' => -2, 'searchall' => 1),
108
        'date_subscription' => array('type' => 'datetime', 'label' => 'DateOfRegistration', 'enabled' => 1, 'position' => 56, 'notnull' => 1, 'visible' => 1, 'showoncombobox' => 1,),
109
        'fk_invoice' => array('type' => 'integer:Facture:compta/facture/class/facture.class.php', 'label' => 'Invoice', 'enabled' => 'isModEnabled("invoice")', 'position' => 57, 'notnull' => 0, 'visible' => 1, 'index' => 0, 'picto' => 'bill', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
110
        'amount' => array('type' => 'price', 'label' => 'AmountPaid', 'enabled' => 1, 'position' => 57, 'notnull' => 0, 'visible' => 1, 'default' => 'null', 'isameasure' => 1, 'help' => "AmountOfRegistrationPaid",),
111
        'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 3,),
112
        'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 3,),
113
        'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'css' => 'nowraponall'),
114
        'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
115
        'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => -1, 'visible' => -2),
116
        'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
117
        'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => 0,),
118
        'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
119
        'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
120
        'ip' => array('type' => 'varchar(250)', 'label' => 'IPAddress', 'enabled' => 1, 'position' => 900, 'notnull' => -1, 'visible' => -2,),
121
        'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'default' => '0', 'notnull' => 1, 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated', '9' => 'Canceled'),),
122
    );
123
    public $rowid;
124
    public $ref;
125
    public $fk_actioncomm;
126
    public $fk_project;
127
    public $email;
128
    public $firstname;
129
    public $lastname;
130
    public $fk_soc;
131
    public $email_company;
132
    public $date_subscription;
133
    public $fk_invoice;
134
    public $amount;
135
    public $note_public;
136
    public $note_private;
137
    public $date_creation;
138
    public $fk_user_creat;
139
    public $fk_user_modif;
140
    public $last_main_doc;
141
    public $import_key;
142
    public $model_pdf;
143
    public $status;
144
    // END MODULEBUILDER PROPERTIES
145
146
147
    // If this object has a subtable with lines
148
149
    // /**
150
    //  * @var string    Name of subtable line
151
    //  */
152
    // public $table_element_line = 'eventorganization_conferenceorboothattendeeline';
153
154
    // /**
155
    //  * @var string    Field with ID of parent key if this object has a parent
156
    //  */
157
    // public $fk_element = 'fk_conferenceorboothattendee';
158
159
    // /**
160
    //  * @var string    Name of subtable class that manage subtable lines
161
    //  */
162
    // public $class_element_line = 'ConferenceOrBoothAttendeeline';
163
164
    // /**
165
    //  * @var array    List of child tables. To test if we can delete object.
166
    //  */
167
    // protected $childtables = array();
168
169
    // /**
170
    //  * @var array    List of child tables. To know object to delete on cascade.
171
    //  *               If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
172
    //  *               call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
173
    //  */
174
    // protected $childtablesoncascade = array('eventorganization_conferenceorboothattendeedet');
175
176
    // /**
177
    //  * @var ConferenceOrBoothAttendeeLine[]     Array of subtable lines
178
    //  */
179
    // public $lines = array();
180
181
182
183
    /**
184
     * Constructor
185
     *
186
     * @param DoliDB $db Database handler
187
     */
188
    public function __construct(DoliDB $db)
189
    {
190
        global $conf, $langs;
191
192
        $this->db = $db;
193
194
        $this->ismultientitymanaged = 'fk_project@projet';
0 ignored issues
show
Documentation Bug introduced by
The property $ismultientitymanaged was declared of type integer, but 'fk_project@projet' is of type string. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
195
        $this->isextrafieldmanaged = 1;
196
197
        if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
198
            $this->fields['rowid']['visible'] = 0;
199
        }
200
        if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
201
            $this->fields['entity']['enabled'] = 0;
202
        }
203
204
        if (getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_CAT')) {
205
            $this->fields['fk_soc']['type'] .= ' AND rowid IN (SELECT DISTINCT c.fk_soc FROM ' . MAIN_DB_PREFIX . 'categorie_societe as c WHERE c.fk_categorie=' . (int) $conf->global->EVENTORGANIZATION_FILTERATTENDEES_CAT . ')';
206
        }
207
        if (
208
            isset($conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE)
209
            && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== ''
210
            && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== '-1'
211
        ) {
212
            $this->fields['fk_soc']['type'] .= ' AND client = ' . ((int) getDolGlobalInt('EVENTORGANIZATION_FILTERATTENDEES_TYPE', 0));
213
        }
214
215
        // Example to show how to set values of fields definition dynamically
216
        /*if ($user->rights->eventorganization->conferenceorboothattendee->read) {
217
            $this->fields['myfield']['visible'] = 1;
218
            $this->fields['myfield']['noteditable'] = 0;
219
        }*/
220
221
        // Unset fields that are disabled
222
        foreach ($this->fields as $key => $val) {
223
            if (isset($val['enabled']) && empty($val['enabled'])) {
224
                unset($this->fields[$key]);
225
            }
226
        }
227
228
        // Translate some data of arrayofkeyval
229
        if (is_object($langs)) {
230
            foreach ($this->fields as $key => $val) {
231
                if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
232
                    foreach ($val['arrayofkeyval'] as $key2 => $val2) {
233
                        $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
234
                    }
235
                }
236
            }
237
        }
238
    }
239
240
    /**
241
     * Create object into database
242
     *
243
     * @param  User $user      User that creates
244
     * @param  int  $notrigger 0=launch triggers after, 1=disable triggers
245
     * @return int             Return integer <0 if KO, Id of created object if OK
246
     */
247
    public function create(User $user, $notrigger = 0)
248
    {
249
        global $langs;
250
251
        if (!isValidEmail($this->email)) {
252
            $langs->load("errors");
253
            $this->errors[] = $langs->trans("ErrorBadEMail", $this->email);
254
            return -1;
255
        }
256
257
        $result = $this->createCommon($user, $notrigger);
258
        if ($result > 0) {
259
            $result = $this->fetch($result);
260
            if ($result > 0) {
261
                $this->ref = (string) $this->id;
262
                $result = $this->update($user);
263
            }
264
        }
265
        return $result;
266
    }
267
268
    /**
269
     * Clone an object into another one
270
     *
271
     * @param   User    $user       User that creates
272
     * @param   int     $fromid     Id of object to clone
273
     * @return  mixed               New object created, <0 if KO
274
     */
275
    public function createFromClone(User $user, $fromid)
276
    {
277
        global $langs, $extrafields;
278
        $error = 0;
279
280
        dol_syslog(__METHOD__, LOG_DEBUG);
281
282
        $object = new self($this->db);
283
284
        $this->db->begin();
285
286
        // Load source object
287
        $result = $object->fetchCommon($fromid);
288
        if ($result > 0 && !empty($object->table_element_line)) {
289
            $object->fetchLines();
290
        }
291
292
        // get lines so they will be clone
293
        //foreach($this->lines as $line)
294
        //  $line->fetch_optionals();
295
296
        // Reset some properties
297
        unset($object->id);
298
        unset($object->fk_user_creat);
299
        unset($object->import_key);
300
301
        // Clear fields
302
        if (property_exists($object, 'ref')) {
303
            $object->ref = empty($this->fields['ref']['default']) ? "(PROV)" : $this->fields['ref']['default'];
304
        }
305
        if (property_exists($object, 'label')) {
306
            $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf") . " " . $object->label : $this->fields['label']['default'];
307
        }
308
        if (property_exists($object, 'status')) {
309
            $object->status = self::STATUS_DRAFT;
310
        }
311
        if (property_exists($object, 'date_creation')) {
312
            $object->date_creation = dol_now();
313
        }
314
        if (property_exists($object, 'date_modification')) {
315
            $object->date_modification = null;
316
        }
317
        // ...
318
        // Clear extrafields that are unique
319
        if (is_array($object->array_options) && count($object->array_options) > 0) {
320
            $extrafields->fetch_name_optionals_label($this->table_element);
321
            foreach ($object->array_options as $key => $option) {
322
                $shortkey = preg_replace('/options_/', '', $key);
323
                if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
324
                    //var_dump($key);
325
                    //var_dump($clonedObj->array_options[$key]); exit;
326
                    unset($object->array_options[$key]);
327
                }
328
            }
329
        }
330
331
        // Create clone
332
        $object->context['createfromclone'] = 'createfromclone';
333
        $result = $object->createCommon($user);
334
        if ($result < 0) {
335
            $error++;
336
            $this->setErrorsFromObject($object);
337
        } else {
338
            $object->ref = (string) $object->id;
339
            $result = $object->update($user);
340
        }
341
342
        if (!$error) {
343
            // copy internal contacts
344
            if ($this->copy_linked_contact($object, 'internal') < 0) {
345
                $error++;
346
            }
347
        }
348
349
        if (!$error) {
350
            // copy external contacts if same company
351
            if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
352
                if ($this->copy_linked_contact($object, 'external') < 0) {
353
                    $error++;
354
                }
355
            }
356
        }
357
358
        unset($object->context['createfromclone']);
359
360
        // End
361
        if (!$error) {
362
            $this->db->commit();
363
            return $object;
364
        } else {
365
            $this->db->rollback();
366
            return -1;
367
        }
368
    }
369
370
    /**
371
     * Load object in memory from the database
372
     *
373
     * @param int    $id   Id object
374
     * @param string $ref  Ref
375
     * @return int         Return integer <0 if KO, 0 if not found, >0 if OK
376
     */
377
    public function fetch($id, $ref = null)
378
    {
379
        $result = $this->fetchCommon($id, $ref);
380
        if ($result > 0 && !empty($this->table_element_line)) {
381
            $this->fetchLines();
382
        }
383
        return $result;
384
    }
385
386
    /**
387
     * Load object lines in memory from the database
388
     *
389
     * @return int         Return integer <0 if KO, 0 if not found, >0 if OK
390
     */
391
    public function fetchLines()
392
    {
393
        $this->lines = array();
394
395
        $result = $this->fetchLinesCommon();
396
        return $result;
397
    }
398
399
400
    /**
401
     * Load list of objects in memory from the database.
402
     *
403
     * @param  string       $sortorder      Sort Order
404
     * @param  string       $sortfield      Sort field
405
     * @param  int          $limit          limit
406
     * @param  int          $offset         Offset
407
     * @param  string       $filter         Filter as an Universal Search string.
408
     *                                      Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')'
409
     * @param  string       $filtermode     No more used
410
     * @return array|int                    int <0 if KO, array of pages if OK
411
     */
412
    public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
413
    {
414
        dol_syslog(__METHOD__, LOG_DEBUG);
415
416
        $records = array();
417
418
        $sql = 'SELECT ';
419
        $sql .= $this->getFieldList('t');
420
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
421
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "actioncomm as a on a.id = t.fk_actioncomm";
422
        if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
423
            $sql .= ' WHERE t.entity IN (' . getEntity($this->element) . ')';
424
        } else {
425
            $sql .= ' WHERE 1 = 1';
426
        }
427
428
        // Manage filter
429
        $errormessage = '';
430
        $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
431
        if ($errormessage) {
432
            $this->errors[] = $errormessage;
433
            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
434
            return -1;
435
        }
436
437
        if (!empty($sortfield)) {
438
            $sql .= $this->db->order($sortfield, $sortorder);
439
        }
440
        if (!empty($limit)) {
441
            $sql .= $this->db->plimit($limit, $offset);
442
        }
443
444
        $resql = $this->db->query($sql);
445
        if ($resql) {
446
            $num = $this->db->num_rows($resql);
447
            $i = 0;
448
            while ($i < ($limit ? min($limit, $num) : $num)) {
449
                $obj = $this->db->fetch_object($resql);
450
451
                $record = new self($this->db);
452
                $record->setVarsFromFetchObj($obj);
453
454
                $records[$record->id] = $record;
455
456
                $i++;
457
            }
458
            $this->db->free($resql);
459
460
            return $records;
461
        } else {
462
            $this->errors[] = 'Error ' . $this->db->lasterror();
463
            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
464
465
            return -1;
466
        }
467
    }
468
469
    /**
470
     * Update object into database
471
     *
472
     * @param  User $user      User that modifies
473
     * @param  int  $notrigger 0=launch triggers after, 1=disable triggers
474
     * @return int             Return integer <0 if KO, >0 if OK
475
     */
476
    public function update(User $user, $notrigger = 0)
477
    {
478
        return $this->updateCommon($user, $notrigger);
479
    }
480
481
    /**
482
     * Delete object in database
483
     *
484
     * @param User  $user       User that deletes
485
     * @param int   $notrigger  0=launch triggers after, 1=disable triggers
486
     * @return int              Return integer <0 if KO, >0 if OK
487
     */
488
    public function delete(User $user, $notrigger = 0)
489
    {
490
        return $this->deleteCommon($user, $notrigger);
491
        //return $this->deleteCommon($user, $notrigger, 1);
492
    }
493
494
    /**
495
     *  Delete a line of object in database
496
     *
497
     *  @param  User    $user       User that delete
498
     *  @param  int     $idline     Id of line to delete
499
     *  @param  int     $notrigger  0=launch triggers after, 1=disable triggers
500
     *  @return int                 >0 if OK, <0 if KO
501
     */
502
    public function deleteLine(User $user, $idline, $notrigger = 0)
503
    {
504
        if ($this->status < 0) {
505
            $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
506
            return -2;
507
        }
508
509
        return $this->deleteLineCommon($user, $idline, $notrigger);
510
    }
511
512
513
    /**
514
     *  Validate object
515
     *
516
     *  @param      User    $user           User making status change
517
     *  @param      int     $notrigger      1=Does not execute triggers, 0= execute triggers
518
     *  @return     int                     Return integer <=0 if OK, 0=Nothing done, >0 if KO
519
     */
520
    public function validate($user, $notrigger = 0)
521
    {
522
        global $conf;
523
524
        require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
525
526
        $error = 0;
527
528
        // Protection
529
        if ($this->status == self::STATUS_VALIDATED) {
530
            dol_syslog(get_only_class($this) . "::validate action abandoned: already validated", LOG_WARNING);
531
            return 0;
532
        }
533
534
        $now = dol_now();
535
536
        $this->db->begin();
537
538
        // Define new ref
539
        if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
540
            $num = $this->getNextNumRef();
541
        } else {
542
            $num = $this->ref;
543
        }
544
        $this->newref = $num;
545
546
        if (!empty($num)) {
547
            // Validate
548
            $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element;
549
            $sql .= " SET ref = '" . $this->db->escape($num) . "',";
550
            $sql .= " status = " . self::STATUS_VALIDATED;
551
            if (!empty($this->fields['date_validation'])) {
552
                $sql .= ", date_validation = '" . $this->db->idate($now) . "'";
553
            }
554
            if (!empty($this->fields['fk_user_valid'])) {
555
                $sql .= ", fk_user_valid = " . $user->id;
556
            }
557
            $sql .= " WHERE rowid = " . ((int) $this->id);
558
559
            dol_syslog(get_only_class($this) . "::validate()", LOG_DEBUG);
560
            $resql = $this->db->query($sql);
561
            if (!$resql) {
562
                dol_print_error($this->db);
563
                $this->error = $this->db->lasterror();
564
                $error++;
565
            }
566
567
            if (!$error && !$notrigger) {
568
                // Call trigger
569
                $result = $this->call_trigger('CONFERENCEORBOOTHATTENDEE_VALIDATE', $user);
570
                if ($result < 0) {
571
                    $error++;
572
                }
573
                // End call triggers
574
            }
575
        }
576
577
        if (!$error) {
578
            $this->oldref = $this->ref;
579
580
            // Rename directory if dir was a temporary ref
581
            if (preg_match('/^[\(]?PROV/i', $this->ref)) {
582
                // Now we rename also files into index
583
                $sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filename = CONCAT('" . $this->db->escape($this->newref) . "', SUBSTR(filename, " . (strlen($this->ref) + 1) . ")), filepath = 'conferenceorboothattendee/" . $this->db->escape($this->newref) . "'";
584
                $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'conferenceorboothattendee/" . $this->db->escape($this->ref) . "' and entity = " . $conf->entity;
585
                $resql = $this->db->query($sql);
586
                if (!$resql) {
587
                    $error++;
588
                    $this->error = $this->db->lasterror();
589
                }
590
                $sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filepath = 'conferenceorboothattendee/" . $this->db->escape($this->newref) . "'";
591
                $sql .= " WHERE filepath = 'conferenceorboothattendee/" . $this->db->escape($this->ref) . "' and entity = " . $conf->entity;
592
                $resql = $this->db->query($sql);
593
                if (!$resql) {
594
                    $error++;
595
                    $this->error = $this->db->lasterror();
596
                }
597
598
                // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
599
                $oldref = dol_sanitizeFileName($this->ref);
600
                $newref = dol_sanitizeFileName($num);
601
                $dirsource = $conf->eventorganization->dir_output . '/conferenceorboothattendee/' . $oldref;
602
                $dirdest = $conf->eventorganization->dir_output . '/conferenceorboothattendee/' . $newref;
603
                if (!$error && file_exists($dirsource)) {
604
                    dol_syslog(get_only_class($this) . "::validate() rename dir " . $dirsource . " into " . $dirdest);
605
606
                    if (@rename($dirsource, $dirdest)) {
607
                        dol_syslog("Rename ok");
608
                        // Rename docs starting with $oldref with $newref
609
                        $listoffiles = dol_dir_list($conf->eventorganization->dir_output . '/conferenceorboothattendee/' . $newref, 'files', 1, '^' . preg_quote($oldref, '/'));
610
                        foreach ($listoffiles as $fileentry) {
611
                            $dirsource = $fileentry['name'];
612
                            $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
613
                            $dirsource = $fileentry['path'] . '/' . $dirsource;
614
                            $dirdest = $fileentry['path'] . '/' . $dirdest;
615
                            @rename($dirsource, $dirdest);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for rename(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

615
                            /** @scrutinizer ignore-unhandled */ @rename($dirsource, $dirdest);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
616
                        }
617
                    }
618
                }
619
            }
620
        }
621
622
        // Set new ref and current status
623
        if (!$error) {
624
            $this->ref = $num;
625
            $this->status = self::STATUS_VALIDATED;
626
        }
627
628
        if (!$error) {
629
            $this->db->commit();
630
            return 1;
631
        } else {
632
            $this->db->rollback();
633
            return -1;
634
        }
635
    }
636
637
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
638
    /**
639
     *      Load the project with id $this->fk_project into this->project
640
     *
641
     *      @return     int         Return integer <0 if KO, >=0 if OK
642
     */
643
    public function fetch_projet()
644
    {
645
		// phpcs:enable
646
647
        if (empty($this->fk_project) && !empty($this->fk_projet)) {
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$fk_projet has been deprecated: Use $fk_project instead. ( Ignorable by Annotation )

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

647
        if (empty($this->fk_project) && !empty(/** @scrutinizer ignore-deprecated */ $this->fk_projet)) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
648
            $this->fk_project = $this->fk_projet; // For backward compatibility
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$fk_projet has been deprecated: Use $fk_project instead. ( Ignorable by Annotation )

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

648
            $this->fk_project = /** @scrutinizer ignore-deprecated */ $this->fk_projet; // For backward compatibility

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
649
        }
650
        if (empty($this->fk_project)) {
651
            return 0;
652
        }
653
654
        $project = new Project($this->db);
655
        $result = $project->fetch($this->fk_project);
656
657
        $this->projet = $project; // deprecated
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$projet has been deprecated: Use $project instead. ( Ignorable by Annotation )

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

657
        /** @scrutinizer ignore-deprecated */ $this->projet = $project; // deprecated

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Bug Best Practice introduced by
The property $projet is declared private in Dolibarr\Core\Base\CommonObject. Since you implement __set, consider adding a @property or @property-write.
Loading history...
658
        $this->project = $project;
659
        return $result;
660
    }
661
662
    /**
663
     *  Set draft status
664
     *
665
     *  @param  User    $user           Object user that modify
666
     *  @param  int     $notrigger      1=Does not execute triggers, 0=Execute triggers
667
     *  @return int                     Return integer <0 if KO, >0 if OK
668
     */
669
    public function setDraft($user, $notrigger = 0)
670
    {
671
        // Protection
672
        if ($this->status <= self::STATUS_DRAFT) {
673
            return 0;
674
        }
675
676
        return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTHATTENDEE_UNVALIDATE');
677
    }
678
679
    /**
680
     *  Set cancel status
681
     *
682
     *  @param  User    $user           Object user that modify
683
     *  @param  int     $notrigger      1=Does not execute triggers, 0=Execute triggers
684
     *  @return int                     Return integer <0 if KO, 0=Nothing done, >0 if OK
685
     */
686
    public function cancel($user, $notrigger = 0)
687
    {
688
        // Protection
689
        if ($this->status != self::STATUS_VALIDATED) {
690
            return 0;
691
        }
692
693
        return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_CANCEL');
694
    }
695
696
    /**
697
     *  Set back to validated status
698
     *
699
     *  @param  User    $user           Object user that modify
700
     *  @param  int     $notrigger      1=Does not execute triggers, 0=Execute triggers
701
     *  @return int                     Return integer <0 if KO, 0=Nothing done, >0 if OK
702
     */
703
    public function reopen($user, $notrigger = 0)
704
    {
705
        // Protection
706
        if ($this->status != self::STATUS_CANCELED) {
707
            return 0;
708
        }
709
710
        return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_REOPEN');
711
    }
712
713
    /**
714
     *  Return a link to the object card (with optionally the picto)
715
     *
716
     *  @param  int     $withpicto                  Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
717
     *  @param  string  $option                     On what the link point to ('nolink', ...)
718
     *  @param  int     $notooltip                  1=Disable tooltip
719
     *  @param  string  $morecss                    Add more css on link
720
     *  @param  int     $save_lastsearch_value      -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
721
     *  @return string                              String with URL
722
     */
723
    public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
724
    {
725
        global $conf, $langs, $hookmanager;
726
727
        if (!empty($conf->dol_no_mouse_hover)) {
728
            $notooltip = 1; // Force disable tooltips
729
        }
730
731
        $result = '';
732
733
        $label = img_picto('', $this->picto) . ' <u>' . $langs->trans("ConferenceOrBoothAttendee") . '</u>';
734
        if (isset($this->status)) {
735
            $label .= ' ' . $this->getLibStatut(5);
736
        }
737
        $label .= '<br>';
738
        $label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
739
        $label .= '<br><b>' . $langs->trans('DateOfRegistration') . ':</b> ' . dol_print_date($this->date_subscription, 'dayhour');
740
        $label .= '<br><b>' . $langs->trans('AmountPaid') . ':</b> ' . $this->amount;
741
742
        $url = constant('BASE_URL') . '/eventorganization/conferenceorboothattendee_card.php?id=' . $this->id;
743
744
        if ($option != 'nolink') {
745
            // Add param to save lastsearch_values or not
746
            $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
747
            if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
748
                $add_save_lastsearch_values = 1;
749
            }
750
            if ($add_save_lastsearch_values) {
751
                $url .= '&save_lastsearch_values=1';
752
            }
753
754
            if ($option == 'conforboothid') {
755
                $url .= '&conforboothid=' . ((int) $this->fk_actioncomm);
756
            }
757
758
            if ($option == 'projectid') {
759
                $url .= '&fk_project=' . ((int) $this->fk_project) . '&withproject=1';
760
            }
761
762
            if ($option == 'conforboothidproject') {
763
                $url .= '&conforboothid=' . ((int) $this->fk_actioncomm) . '&withproject=1';
764
            }
765
        }
766
767
        $linkclose = '';
768
        if (empty($notooltip)) {
769
            if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
770
                $label = $langs->trans("ShowConferenceOrBoothAttendee");
771
                $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
772
            }
773
            $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"';
774
            $linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
775
        } else {
776
            $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
777
        }
778
779
        if ($option == 'nolink') {
780
            $linkstart = '<span';
781
        } else {
782
            $linkstart = '<a href="' . $url . '"';
783
        }
784
        $linkstart .= $linkclose . '>';
785
        if ($option == 'nolink') {
786
            $linkend = '</span>';
787
        } else {
788
            $linkend = '</a>';
789
        }
790
791
        $result .= $linkstart;
792
793
        if (empty($this->showphoto_on_popup)) {
794
            if ($withpicto) {
795
                $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);
796
            }
797
        } else {
798
            if ($withpicto) {
799
                require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
800
801
                list($class, $module) = explode('@', $this->picto);
802
                $upload_dir = $conf->$module->multidir_output[$conf->entity] . "/$class/" . dol_sanitizeFileName($this->ref);
803
                $filearray = dol_dir_list($upload_dir, "files");
804
                $filename = $filearray[0]['name'];
805
                if (!empty($filename)) {
806
                    $pospoint = strpos($filearray[0]['name'], '.');
807
808
                    $pathtophoto = $class . '/' . $this->ref . '/thumbs/' . substr($filename, 0, $pospoint) . '_mini' . substr($filename, $pospoint);
809
                    if (!getDolGlobalString(strtoupper($module . '_' . $class) . '_FORMATLISTPHOTOSASUSERS')) {
810
                        $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo' . $module . '" alt="No photo" border="0" src="' . constant('BASE_URL') . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div></div>';
811
                    } else {
812
                        $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="' . constant('BASE_URL') . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div>';
813
                    }
814
815
                    $result .= '</div>';
816
                } else {
817
                    $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);
818
                }
819
            }
820
        }
821
822
        if ($withpicto != 2) {
823
            $result .= $this->ref;
824
        }
825
826
        $result .= $linkend;
827
        //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
828
829
        global $action, $hookmanager;
830
        $hookmanager->initHooks(array('conferenceorboothattendeedao'));
831
        $parameters = array('id' => $this->id, 'getnomurl' => &$result);
832
        $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
833
        if ($reshook > 0) {
834
            $result = $hookmanager->resPrint;
835
        } else {
836
            $result .= $hookmanager->resPrint;
837
        }
838
839
        return $result;
840
    }
841
842
    /**
843
     *  Return the label of the status
844
     *
845
     *  @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
846
     *  @return string                 Label of status
847
     */
848
    public function getLabelStatus($mode = 0)
849
    {
850
        return $this->LibStatut($this->status, $mode);
851
    }
852
853
    /**
854
     *  Return the label of the status
855
     *
856
     *  @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
857
     *  @return string                 Label of status
858
     */
859
    public function getLibStatut($mode = 0)
860
    {
861
        return $this->LibStatut($this->status, $mode);
862
    }
863
864
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
865
    /**
866
     *  Return the status
867
     *
868
     *  @param  int     $status        Id status
869
     *  @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
870
     *  @return string                 Label of status
871
     */
872
    public function LibStatut($status, $mode = 0)
873
    {
874
		// phpcs:enable
875
        global $langs;
876
877
        if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
878
            //$langs->load("eventorganization@eventorganization");
879
            $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
880
            $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
881
            $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
882
            $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
883
            $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
884
            $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
885
        }
886
887
        $statusType = 'status' . $status;
888
        //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
889
        if ($status == self::STATUS_CANCELED) {
890
            $statusType = 'status6';
891
        }
892
893
        if ($status == self::STATUS_VALIDATED && $this->date_subscription && $this->amount) {
894
            $statusType = 'status4';
895
            $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated') . ' - ' . $langs->trans("Paid");
896
        }
897
898
        return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
899
    }
900
901
    /**
902
     *  Load the info information in the object
903
     *
904
     *  @param  int     $id       Id of object
905
     *  @return void
906
     */
907
    public function info($id)
908
    {
909
        $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
910
        $sql .= ' fk_user_creat, fk_user_modif';
911
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
912
        $sql .= ' WHERE t.rowid = ' . ((int) $id);
913
        $result = $this->db->query($sql);
914
        if ($result) {
915
            if ($this->db->num_rows($result)) {
916
                $obj = $this->db->fetch_object($result);
917
918
                $this->id = $obj->rowid;
919
920
                $this->user_creation_id = $obj->fk_user_creat;
921
                $this->user_modification_id = $obj->fk_user_modif;
922
                $this->date_creation     = $this->db->jdate($obj->datec);
923
                $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
924
            }
925
926
            $this->db->free($result);
927
        } else {
928
            dol_print_error($this->db);
929
        }
930
    }
931
932
    /**
933
     * Initialise object with example values
934
     * Id must be 0 if object instance is a specimen
935
     *
936
     * @return int
937
     */
938
    public function initAsSpecimen()
939
    {
940
        return $this->initAsSpecimenCommon();
941
    }
942
943
    /**
944
     *  Returns the reference to the following non used object depending on the active numbering module.
945
     *
946
     *  @return string              Object free reference
947
     */
948
    public function getNextNumRef()
949
    {
950
        global $langs, $conf;
951
        $langs->load("eventorganization@eventorganization");
952
953
        if (!getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
954
            $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON = 'mod_conferenceorboothattendee_standard';
955
        }
956
957
        if (getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
958
            $mybool = false;
959
960
            $file = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON') . ".php";
961
            $classname = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON');
962
963
            // Include file with class
964
            $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
965
            foreach ($dirmodels as $reldir) {
966
                $dir = dol_buildpath($reldir . "core/modules/eventorganization/");
967
968
                // Load file with numbering class (if found)
969
                $mybool = ((bool) @include_once $dir . $file) || $mybool;
970
            }
971
972
            if ($mybool === false) {
973
                dol_print_error(null, "Failed to include file " . $file);
974
                return '';
975
            }
976
977
            if (class_exists($classname)) {
978
                $obj = new $classname();
979
                $numref = $obj->getNextValue($this);
980
981
                if ($numref != '' && $numref != '-1') {
982
                    return $numref;
983
                } else {
984
                    $this->error = $obj->error;
985
                    //dol_print_error($this->db,get_only_class($this)."::getNextNumRef ".$obj->error);
986
                    return "";
987
                }
988
            } else {
989
                print $langs->trans("Error") . " " . $langs->trans("ClassNotFound") . ' ' . $classname;
990
                return "";
991
            }
992
        } else {
993
            print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
994
            return "";
995
        }
996
    }
997
998
    /**
999
     *  Create a document onto disk according to template module.
1000
     *
1001
     *  @param      string      $modele         Force template to use ('' to not force)
1002
     *  @param      Translate   $outputlangs    object lang a utiliser pour traduction
1003
     *  @param      int         $hidedetails    Hide details of lines
1004
     *  @param      int         $hidedesc       Hide description
1005
     *  @param      int         $hideref        Hide ref
1006
     *  @param      null|array  $moreparams     Array to provide more information
1007
     *  @return     int                         0 if KO, 1 if OK
1008
     */
1009
    public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1010
    {
1011
        global $conf, $langs;
1012
1013
        $result = 0;
1014
        $includedocgeneration = 0;
1015
1016
        $langs->load("eventorganization@eventorganization");
1017
1018
        if (!dol_strlen($modele)) {
1019
            $modele = 'standard_conferenceorboothattendee';
1020
1021
            if (!empty($this->model_pdf)) {
1022
                $modele = $this->model_pdf;
1023
            } elseif (getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF')) {
1024
                $modele = getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF');
1025
            }
1026
        }
1027
1028
        $modelpath = "core/modules/eventorganization/doc/";
1029
1030
        if ($includedocgeneration && !empty($modele)) {
1031
            $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1032
        }
1033
1034
        return $result;
1035
    }
1036
1037
    /**
1038
     * Action executed by scheduler
1039
     * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
1040
     * Use public function doScheduledJob($param1, $param2, ...) to get parameters
1041
     *
1042
     * @return  int         0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
1043
     */
1044
    public function doScheduledJob()
1045
    {
1046
        global $conf, $langs;
1047
1048
        //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1049
1050
        $error = 0;
1051
        $this->output = '';
1052
        $this->error = '';
1053
1054
        dol_syslog(__METHOD__, LOG_DEBUG);
1055
1056
        $now = dol_now();
1057
1058
        $this->db->begin();
1059
1060
        // ...
1061
1062
        $this->db->commit();
1063
1064
        return $error;
1065
    }
1066
1067
    /**
1068
     * Function used to replace a thirdparty id with another one.
1069
     *
1070
     * @param   DoliDB  $dbs        Database handler, because function is static we name it $dbs not $db to avoid breaking coding test
1071
     * @param   int     $origin_id  Old thirdparty id
1072
     * @param   int     $dest_id    New thirdparty id
1073
     * @return  bool
1074
     */
1075
    public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1076
    {
1077
        $tables = array(
1078
            'eventorganization_conferenceorboothattendee'
1079
        );
1080
1081
        return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1082
    }
1083
1084
    /**
1085
     *  Return full name ('name+' '+lastname)
1086
     *
1087
     *  @param  Translate   $langs          Language object for translation of civility (used only if option is 1)
1088
     *  @param  int         $option         0=No option
1089
     *  @param  int         $nameorder      -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname, 3=Firstname if defined else lastname, 4=Lastname, 5=Lastname if defined else firstname
1090
     *  @param  int         $maxlen         Maximum length
1091
     *  @return string                      String with full name
1092
     */
1093
    public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
1094
    {
1095
        $lastname = $this->lastname;
1096
        $firstname = $this->firstname;
1097
        if (empty($lastname)) {
1098
            $lastname = (isset($this->lastname) ? $this->lastname : (isset($this->name) ? $this->name : (isset($this->nom) ? $this->nom : (isset($this->societe) ? $this->societe : (isset($this->company) ? $this->company : '')))));
0 ignored issues
show
Bug Best Practice introduced by
The property nom does not exist on Dolibarr\Code\EventOrgan...nferenceOrBoothAttendee. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property societe does not exist on Dolibarr\Code\EventOrgan...nferenceOrBoothAttendee. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property company does not exist on Dolibarr\Code\EventOrgan...nferenceOrBoothAttendee. Since you implemented __get, consider adding a @property annotation.
Loading history...
1099
        }
1100
1101
        $ret = '';
1102
1103
        $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
1104
1105
        return dol_trunc($ret, $maxlen);
1106
    }
1107
}
1108