Passed
Push — EXTRACT_CLASSES ( c25e41...9f3ede )
by Rafael
55:18
created

ConferenceOrBoothAttendee::cancel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

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

616
                            /** @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...
617
                        }
618
                    }
619
                }
620
            }
621
        }
622
623
        // Set new ref and current status
624
        if (!$error) {
625
            $this->ref = $num;
626
            $this->status = self::STATUS_VALIDATED;
627
        }
628
629
        if (!$error) {
630
            $this->db->commit();
631
            return 1;
632
        } else {
633
            $this->db->rollback();
634
            return -1;
635
        }
636
    }
637
638
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
639
    /**
640
     *      Load the project with id $this->fk_project into this->project
641
     *
642
     *      @return     int         Return integer <0 if KO, >=0 if OK
643
     */
644
    public function fetch_projet()
645
    {
646
		// phpcs:enable
647
        include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
648
649
        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

649
        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...
650
            $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

650
            $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...
651
        }
652
        if (empty($this->fk_project)) {
653
            return 0;
654
        }
655
656
        $project = new Project($this->db);
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\EventOrganizaction\Classes\Project was not found. Did you mean Project? If so, make sure to prefix the type with \.
Loading history...
657
        $result = $project->fetch($this->fk_project);
658
659
        $this->projet = $project; // deprecated
0 ignored issues
show
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...
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

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