ConferenceOrBooth   F
last analyzed

Complexity

Total Complexity 104

Size/Duplication

Total Lines 776
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 299
dl 0
loc 776
rs 2
c 0
b 0
f 0
wmc 104

21 Methods

Rating   Name   Duplication   Size   Complexity  
A getLibStatut() 0 3 1
A setActionCommFields() 0 7 1
A create() 0 5 1
A initAsSpecimen() 0 3 1
A generateDocument() 0 26 6
A setDraft() 0 15 2
C __construct() 0 29 13
A LibStatutEvent() 0 27 4
A doScheduledJob() 0 21 1
B fetchAll() 0 57 9
A cancel() 0 15 2
A delete() 0 4 1
A info() 0 22 4
A reopen() 0 15 2
B validate() 0 51 8
A setPercentageFromStatus() 0 7 3
A fetch() 0 16 1
C getKanbanView() 0 34 10
F getNomUrl() 0 96 32
A update() 0 5 1
A getActionCommFields() 0 5 1

How to fix   Complexity   

Complex Class

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

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

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

1
<?php
2
3
/* Copyright (C) 2017       Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2024       Frédéric France             <[email protected]>
5
 * Copyright (C) 2024		MDW							<[email protected]>
6
 * Copyright (C) 2024       Rafael San José             <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Dolibarr\Code\EventOrganizaction\Classes;
23
24
use Dolibarr\Code\Comm\Classes\ActionComm;
25
use Dolibarr\Code\Core\Classes\Translate;
26
use Dolibarr\Code\User\Classes\User;
27
use DoliDB;
28
29
/**
30
 * \file        class/conferenceorbooth.class.php
31
 * \ingroup     eventorganization
32
 * \brief       This file is a CRUD class file for ConferenceOrBooth (Create/Read/Update/Delete)
33
 */
34
35
// Put here all includes required by your class file
36
//
37
/**
38
 * Class for ConferenceOrBooth
39
 */
40
class ConferenceOrBooth extends ActionComm
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 = 'conferenceorbooth';
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 = 'actioncomm';
56
57
    /**
58
     * @var string String with name of icon for conferenceorbooth. Must be the part after the 'object_' into object_conferenceorbooth.png
59
     */
60
    public $picto = 'conferenceorbooth';
61
62
63
    const STATUS_DRAFT = 0;
64
    const STATUS_SUGGESTED = 1;
65
    const STATUS_CONFIRMED = 2;
66
    const STATUS_NOT_QUALIFIED = 3;
67
    const STATUS_DONE = 4;
68
    const STATUS_CANCELED = 9;
69
70
71
    /**
72
     *  'type' field format:
73
     *      'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',
74
     *      'select' (list of values are in 'options'),
75
     *      'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:CategoryIdType[:CategoryIdList[:SortField]]]]]]',
76
     *      'chkbxlst:...',
77
     *      'varchar(x)',
78
     *      'text', 'text:none', 'html',
79
     *      'double(24,8)', 'real', 'price',
80
     *      'date', 'datetime', 'timestamp', 'duration',
81
     *      'boolean', 'checkbox', 'radio', 'array',
82
     *      'mail', 'phone', 'url', 'password', 'ip'
83
     *      Note: Filter must be a Dolibarr Universal Filter syntax string. Example: "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.status:!=:0) or (t.nature:is:NULL)"
84
     *  'label' the translation key.
85
     *  'picto' is code of a picto to show before value in forms
86
     *  'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalString("MY_SETUP_PARAM")'
87
     *  'position' is the sort order of field.
88
     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
89
     *  '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)
90
     *  'noteditable' says if field is not editable (1 or 0)
91
     *  '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.
92
     *  'index' if we want an index in database.
93
     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...).
94
     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
95
     *  '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).
96
     *  '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'
97
     *  'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
98
     *  'showoncombobox' if value of the field must be visible into the label of the combobox that list record
99
     *  '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.
100
     *  'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
101
     *  'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
102
     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
103
     *
104
     *  Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
105
     */
106
107
    // BEGIN MODULEBUILDER PROPERTIES
108
    /**
109
     * @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...
110
     */
111
    public $fields = array(
112
        'id' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'csslist' => 'left', 'comment' => "Id"),
113
        'ref' => array('type' => 'integer', 'label' => 'Ref', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 2, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'csslist' => 'left', 'comment' => "Id"),
114
        'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'csslist' => 'tdoverflowmax150', 'help' => "OrganizationEvenLabelName", 'showoncombobox' => 1, 'autofocusoncreate' => 1),
115
        'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1:(t.usage_organize_event:=:1)', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'position' => 52, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'picto' => 'project', 'css' => 'maxwidth500', 'csslist' => 'tdoverflowmax100'),
116
        'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'enabled' => '$conf->societe->enabled', 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'help' => "OrganizationEventLinkToThirdParty", 'picto' => 'company', 'csslist' => 'tdoverflowmax100', 'css' => 'maxwidth500'),
117
        'note' => array('type' => 'html', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 3),
118
        'fk_action' => array('type' => "sellist:c_actioncomm:libelle:id::(module:LIKE:'%@eventorganization')", 'label' => 'ConferenceOrBoothFormat', 'enabled' => 1, 'position' => 60, 'notnull' => 1, 'visible' => 1, 'css' => 'width200', 'csslist' => 'tdoverflowmax100'),
119
        'datep' => array('type' => 'datetime', 'label' => 'DateStart', 'enabled' => 1, 'position' => 70, 'notnull' => 0, 'visible' => 1, 'showoncombobox' => '2',),
120
        'datep2' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'position' => 71, 'notnull' => 0, 'visible' => 1, 'showoncombobox' => '3',),
121
        'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'csslist' => 'nowraponall'),
122
        'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2, 'csslist' => 'nowraponall'),
123
        'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid', 'csslist' => 'tdoverflowmax100'),
124
        'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2, 'csslist' => 'tdoverflowmax100'),
125
        'num_vote' => array('type' => 'smallint', 'label' => 'NbVotes', 'enabled' => 1, 'position' => 800, 'notnull' => -1, 'visible' => 5, 'default' => '0', 'index' => 0),
126
        'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
127
        'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'visible' => 1, 'default' => '0', 'index' => 1, 'arrayofkeyval' => array('0' => 'EvntOrgDraft', '1' => 'EvntOrgSuggested', '2' => 'EvntOrgConfirmed', '3' => 'EvntOrgNotQualified', '4' => 'EvntOrgDone', '9' => 'EvntOrgCancelled'),),
128
    );
129
    public $rowid;
130
    public $id;
131
    public $label;
132
    public $fk_soc;
133
    public $fk_project;
134
    public $note;
135
    public $fk_action;
136
    public $datec;
137
138
    public $fk_user_author;
139
    public $fk_user_mod;
140
    public $import_key;
141
    public $status;
142
    // END MODULEBUILDER PROPERTIES
143
144
    //public $pubregister;
145
146
147
    /**
148
     * Constructor
149
     *
150
     * @param DoliDB $db Database handler
151
     */
152
    public function __construct(DoliDB $db)
153
    {
154
        global $conf, $langs;
155
156
        $this->db = $db;
157
158
        $this->ismultientitymanaged = 1;
159
        $this->isextrafieldmanaged = 1;
160
161
        if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
162
            $this->fields['id']['visible'] = 0;
163
        }
164
        if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
165
            $this->fields['entity']['enabled'] = 0;
166
        }
167
168
        // Unset fields that are disabled
169
        foreach ($this->fields as $key => $val) {
170
            if (isset($val['enabled']) && empty($val['enabled'])) {
171
                unset($this->fields[$key]);
172
            }
173
        }
174
175
        // Translate some data of arrayofkeyval
176
        if (is_object($langs)) {
177
            foreach ($this->fields as $key => $val) {
178
                if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
179
                    foreach ($val['arrayofkeyval'] as $key2 => $val2) {
180
                        $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
181
                    }
182
                }
183
            }
184
        }
185
    }
186
187
    /**
188
     * Create object into database
189
     *
190
     * @param  User $user      User that creates
191
     * @param  int  $notrigger 0=launch triggers after, 1=disable triggers
192
     * @return int             Return integer <0 if KO, Id of created object if OK
193
     */
194
    public function create(User $user, $notrigger = 0)
195
    {
196
        $this->setPercentageFromStatus();
197
        $this->setActionCommFields($user);
198
        return parent::create($user, $notrigger);
199
    }
200
201
    /**
202
     * Set Percentage from status
203
     *
204
     * @return void
205
     */
206
    protected function setPercentageFromStatus()
207
    {
208
        if ($this->status == self::STATUS_DONE) {
209
            $this->percentage = 100;
210
        }
211
        if ($this->status == self::STATUS_DRAFT) {
212
            $this->percentage = 0;
213
        }
214
    }
215
216
    /**
217
     * Set action comm fields
218
     *
219
     * @param User $user User
220
     * @return void
221
     */
222
    protected function setActionCommFields(User $user)
223
    {
224
        $this->userownerid = $user->id;
225
        $this->type_id = $this->fk_action;
226
        $this->socid = $this->fk_soc;
227
        $this->datef = $this->datep2;
228
        $this->note_private = $this->note;
229
    }
230
231
    /**
232
     * Get action comm fields
233
     *
234
     * @return void
235
     */
236
    protected function getActionCommFields()
237
    {
238
        $this->fk_action = $this->type_id;
239
        $this->fk_soc = $this->socid;
240
        $this->datep2 = $this->datef;
241
    }
242
243
    /**
244
     * Load object in memory from the database
245
     *
246
     * @param int    $id   Id object
247
     * @param string $ref  Ref
248
     * @param  string   $ref_ext        Ref ext to get
249
     * @param   string  $email_msgid    Email msgid
250
     * @param int       $loadresources  1=Load also resources
251
     * @return int         Return integer <0 if KO, 0 if not found, >0 if OK
252
     */
253
    public function fetch($id, $ref = null, $ref_ext = '', $email_msgid = '', $loadresources = 1)
254
    {
255
        global $dolibarr_main_url_root, $conf, $langs;
256
257
        $result = parent::fetch($id, $ref, $ref_ext, $email_msgid);
258
259
        $link_subscription = $dolibarr_main_url_root . '/public/eventorganization/attendee_new.php?id=' . urlencode((string) ($id)) . '&type=conf';
260
261
        $encodedsecurekey = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY') . 'conferenceorbooth' . $id, 2);
262
        $link_subscription .= '&securekey=' . urlencode($encodedsecurekey);
263
264
        /*$this->fields['pubregister'] = array('type'=>'url', 'label'=>$langs->trans("PublicAttendeeSubscriptionPage"), 'enabled'=>'1', 'position'=>72, 'notnull'=>0, 'visible'=>1);
265
        $this->pubregister = $link_subscription;*/
266
267
        $this->getActionCommFields();
268
        return $result;
269
    }
270
271
    /**
272
     * Load list of objects in memory from the database.
273
     *
274
     * @param  string       $sortorder      Sort Order
275
     * @param  string       $sortfield      Sort field
276
     * @param  int          $limit          limit
277
     * @param  int          $offset         Offset
278
     * @param  string       $filter         Filter as an Universal Search string.
279
     *                                      Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')'
280
     * @param  string       $filtermode     No more used
281
     * @return array|int                    int <0 if KO, array of pages if OK
282
     */
283
    public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
284
    {
285
        //TODO set percent according status
286
        global $conf;
287
288
        dol_syslog(__METHOD__, LOG_DEBUG);
289
290
        $records = array();
291
292
        $sql = 'SELECT ';
293
        $sql .= $this->getFieldList('t');
294
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
295
        $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_actioncomm as cact ON cact.id=t.fk_action AND cact.module LIKE '%@eventorganization'";
296
        if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
297
            $sql .= ' WHERE t.entity IN (' . getEntity($this->element) . ')';
298
        } else {
299
            $sql .= ' WHERE 1 = 1';
300
        }
301
302
        // Manage filter
303
        $errormessage = '';
304
        $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
305
        if ($errormessage) {
306
            $this->errors[] = $errormessage;
307
            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
308
            return -1;
309
        }
310
311
        if (!empty($sortfield)) {
312
            $sql .= $this->db->order($sortfield, $sortorder);
313
        }
314
        if (!empty($limit)) {
315
            $sql .= $this->db->plimit($limit, $offset);
316
        }
317
318
        $resql = $this->db->query($sql);
319
        if ($resql) {
320
            $num = $this->db->num_rows($resql);
321
            $i = 0;
322
            while ($i < ($limit ? min($limit, $num) : $num)) {
323
                $obj = $this->db->fetch_object($resql);
324
325
                $record = new self($this->db);
326
                $record->setVarsFromFetchObj($obj);
327
328
                $records[$record->id] = $record;
329
330
                $i++;
331
            }
332
            $this->db->free($resql);
333
334
            return $records;
335
        } else {
336
            $this->errors[] = 'Error ' . $this->db->lasterror();
337
            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
338
339
            return -1;
340
        }
341
    }
342
343
    /**
344
     * Update object into database
345
     *
346
     * @param  User $user      User that modifies
347
     * @param  int  $notrigger 0=launch triggers after, 1=disable triggers
348
     * @return int             Return integer <0 if KO, >0 if OK
349
     */
350
    public function update(User $user, $notrigger = 0)
351
    {
352
        $this->setPercentageFromStatus();
353
        $this->setActionCommFields($user);
354
        return parent::update($user, $notrigger);
355
    }
356
357
    /**
358
     * Delete object in database
359
     *
360
     * @param   User    $user       User making the delete
361
     * @param   int     $notrigger  false=launch triggers after, true=disable triggers
362
     * @return  int                 Return integer <0 if KO, >0 if OK
363
     */
364
    public function delete($user, $notrigger = 0)
365
    {
366
        //TODO delete attendees and subscription
367
        return parent::delete($user, $notrigger);
368
    }
369
370
    /**
371
     *  Validate object
372
     *
373
     *  @param      User    $user           User making status change
374
     *  @param      int     $notrigger      1=Does not execute triggers, 0= execute triggers
375
     *  @return     int                     Return integer <=0 if OK, 0=Nothing done, >0 if KO
376
     */
377
    public function validate($user, $notrigger = 0)
378
    {
379
        global $conf, $langs;
380
381
        require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
382
383
        $error = 0;
384
385
        // Protection
386
        if ($this->status == self::STATUS_CONFIRMED) {
387
            dol_syslog(get_only_class($this) . "::validate action abandoned: already validated", LOG_WARNING);
388
            return 0;
389
        }
390
391
        $now = dol_now();
392
393
        $this->db->begin();
394
395
        // Validate
396
        $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element;
397
        $sql .= " status = " . self::STATUS_CONFIRMED;
398
        $sql .= " WHERE id = " . $this->id;
399
400
        dol_syslog(get_only_class($this) . "::validate()", LOG_DEBUG);
401
        $resql = $this->db->query($sql);
402
        if (!$resql) {
403
            dol_print_error($this->db);
404
            $this->error = $this->db->lasterror();
405
            $error++;
406
        }
407
408
        if (!$error && !$notrigger) {
409
            // Call trigger
410
            $result = $this->call_trigger('CONFERENCEORBOOTH_VALIDATE', $user);
411
            if ($result < 0) {
412
                $error++;
413
            }
414
            // End call triggers
415
        }
416
417
        // Set new ref and current status
418
        if (!$error) {
419
            $this->status = self::STATUS_CONFIRMED;
420
        }
421
422
        if (!$error) {
423
            $this->db->commit();
424
            return 1;
425
        } else {
426
            $this->db->rollback();
427
            return -1;
428
        }
429
    }
430
431
432
    /**
433
     *  Set draft status
434
     *
435
     *  @param  User    $user           Object user that modify
436
     *  @param  int     $notrigger      1=Does not execute triggers, 0=Execute triggers
437
     *  @return int                     Return integer <0 if KO, >0 if OK
438
     */
439
    public function setDraft($user, $notrigger = 0)
440
    {
441
        // Protection
442
        if ($this->status <= self::STATUS_DRAFT) {
443
            return 0;
444
        }
445
446
        /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->write))
447
         || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->eventorganization_advance->validate))))
448
         {
449
         $this->error='Permission denied';
450
         return -1;
451
         }*/
452
453
        return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTH_UNVALIDATE');
454
    }
455
456
    /**
457
     *  Set cancel status
458
     *
459
     *  @param  User    $user           Object user that modify
460
     *  @param  int     $notrigger      1=Does not execute triggers, 0=Execute triggers
461
     *  @return int                     Return integer <0 if KO, 0=Nothing done, >0 if OK
462
     */
463
    public function cancel($user, $notrigger = 0)
464
    {
465
        // Protection
466
        if ($this->status != self::STATUS_CONFIRMED) {
467
            return 0;
468
        }
469
470
        /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->write))
471
         || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->eventorganization_advance->validate))))
472
         {
473
         $this->error='Permission denied';
474
         return -1;
475
         }*/
476
477
        return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTH_CANCEL');
478
    }
479
480
    /**
481
     *  Set back to validated status
482
     *
483
     *  @param  User    $user           Object user that modify
484
     *  @param  int     $notrigger      1=Does not execute triggers, 0=Execute triggers
485
     *  @return int                     Return integer <0 if KO, 0=Nothing done, >0 if OK
486
     */
487
    public function reopen($user, $notrigger = 0)
488
    {
489
        // Protection
490
        if ($this->status != self::STATUS_CANCELED) {
491
            return 0;
492
        }
493
494
        /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->write))
495
         || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->eventorganization->eventorganization_advance->validate))))
496
         {
497
         $this->error='Permission denied';
498
         return -1;
499
         }*/
500
501
        return $this->setStatusCommon($user, self::STATUS_CONFIRMED, $notrigger, 'CONFERENCEORBOOTH_REOPEN');
502
    }
503
504
    /**
505
     *  Return a link to the object card (with optionally the picto)
506
     *
507
     *  @param  int     $withpicto                  Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
508
     *  @param  int     $maxlength                  Not use here just for declaration method compatibility with parent classes
509
     *  @param  string  $classname                  Not use here just for declaration method compatibility with parent classes
510
     *  @param  string  $option                     On what the link point to ('nolink', ...)
511
     *  @param  int     $overwritepicto             Not use here just for declaration method compatibility with parent classes
512
     *  @param  int     $notooltip                  1=Disable tooltip
513
     *  @param  int     $save_lastsearch_value      -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
514
     *  @param  string  $morecss                    Add more css on link
515
     *  @return string                              String with URL
516
     */
517
    public function getNomUrl($withpicto = 0, $maxlength = 0, $classname = '', $option = '', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1, $morecss = '')
518
    {
519
        global $conf, $langs, $hookmanager;
520
521
        if (!empty($conf->dol_no_mouse_hover)) {
522
            $notooltip = 1; // Force disable tooltips
523
        }
524
525
        $result = '';
526
527
        $label = img_picto('', $this->picto) . ' <u>' . $langs->trans("ConferenceOrBooth") . '</u>';
528
        if (isset($this->status)) {
529
            $label .= ' ' . $this->getLibStatut(5);
530
        }
531
        $label .= '<br>';
532
        $label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->id;
533
534
        $url = constant('BASE_URL') . '/eventorganization/conferenceorbooth_card.php?id=' . $this->id;
535
536
        if ($option != 'nolink') {
537
            // Add param to save lastsearch_values or not
538
            $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
539
            if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
540
                $add_save_lastsearch_values = 1;
541
            }
542
            if ($add_save_lastsearch_values) {
543
                $url .= '&save_lastsearch_values=1';
544
            }
545
            if ($option == 'withproject') {
546
                $url .= '&withproject=1';
547
            }
548
        }
549
550
        $linkclose = '';
551
        if (empty($notooltip)) {
552
            if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
553
                $label = $langs->trans("ShowConferenceOrBooth");
554
                $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
555
            }
556
            //$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
557
            $linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
558
        } else {
559
            $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
560
        }
561
562
        $linkstart = '<a href="' . $url . '"';
563
        $linkstart .= $linkclose . '>';
564
        $linkend = '</a>';
565
566
        $result .= $linkstart;
567
568
        if (empty($this->showphoto_on_popup)) {
569
            if ($withpicto) {
570
                $picto = img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
571
                //              var_dump($picto);
572
                $result .= $picto;
573
            }
574
        } else {
575
            if ($withpicto) {
576
                require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
577
578
                //list($class, $module) = explode('@', $this->picto);
579
                $upload_dir = $conf->eventorganisation->multidir_output[$conf->entity] . "/" . dol_sanitizeFileName($this->ref);
580
                $filearray = dol_dir_list($upload_dir, "files");
581
                $filename = $filearray[0]['name'];
582
                if (!empty($filename)) {
583
                    $pospoint = strpos($filearray[0]['name'], '.');
584
585
                    $pathtophoto = '/' . $this->ref . '/thumbs/' . substr($filename, 0, $pospoint) . '_mini' . substr($filename, $pospoint);
586
                    $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="' . constant('BASE_URL') . '/viewimage.php?modulepart=eventorganisation&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div>';
587
588
                    $result .= '</div>';
589
                } else {
590
                    $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);
591
                }
592
            }
593
        }
594
595
        if ($withpicto != 2) {
596
            $result .= $this->ref;
597
        }
598
599
        $result .= $linkend;
600
        //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
601
602
        global $action, $hookmanager;
603
        $hookmanager->initHooks(array('conferenceorboothdao'));
604
        $parameters = array('id' => $this->id, 'getnomurl' => &$result);
605
        $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
606
        if ($reshook > 0) {
607
            $result = $hookmanager->resPrint;
608
        } else {
609
            $result .= $hookmanager->resPrint;
610
        }
611
612
        return $result;
613
    }
614
615
    /**
616
     *  Return the label of the status
617
     *
618
     *  @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
619
     *  @param  int     $hidenastatus   Not use here just for declaration method compatibility with parent classes
620
     *  @return string                 Label of status
621
     */
622
    public function getLibStatut($mode = 0, $hidenastatus = 0)
623
    {
624
        return $this->LibStatutEvent($this->status, $mode);
625
    }
626
627
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
628
    /**
629
     *  Return the status
630
     *
631
     *  @param  int     $status        Id status
632
     *  @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
633
     *  @return string                 Label of status
634
     */
635
    public function LibStatutEvent($status, $mode = 0)
636
    {
637
		// phpcs:enable
638
        if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
639
            global $langs;
640
            //$langs->load("eventorganization@eventorganization");
641
            $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
642
            $this->labelStatus[self::STATUS_SUGGESTED] = $langs->transnoentitiesnoconv('Suggested');
643
            $this->labelStatus[self::STATUS_CONFIRMED] = $langs->transnoentitiesnoconv('Confirmed');
644
            $this->labelStatus[self::STATUS_NOT_QUALIFIED] = $langs->transnoentitiesnoconv('NotSelected');
645
            $this->labelStatus[self::STATUS_DONE] = $langs->transnoentitiesnoconv('Done');
646
            $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
647
            $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
648
            $this->labelStatusShort[self::STATUS_SUGGESTED] = $langs->transnoentitiesnoconv('Suggested');
649
            $this->labelStatusShort[self::STATUS_CONFIRMED] = $langs->transnoentitiesnoconv('Confirmed');
650
            $this->labelStatusShort[self::STATUS_NOT_QUALIFIED] = $langs->transnoentitiesnoconv('NotSelected');
651
            $this->labelStatusShort[self::STATUS_DONE] = $langs->transnoentitiesnoconv('Done');
652
            $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
653
        }
654
655
        $statusType = 'status' . $status;
656
        //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
657
        if ($status == self::STATUS_CANCELED) {
658
            $statusType = 'status6';
659
        }
660
661
        return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
662
    }
663
664
    /**
665
     *  Return a thumb for kanban views
666
     *
667
     *  @param      string      $option                 Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
668
     *  @param      array       $arraydata              Array of data
669
     *  @return     string                              HTML Code for Kanban thumb.
670
     */
671
    public function getKanbanView($option = '', $arraydata = null)
672
    {
673
        global $conf, $langs;
674
675
        $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
676
677
        $return = '<div class="box-flex-item box-flex-grow-zero">';
678
        $return .= '<div class="info-box info-box-sm">';
679
        $return .= '<span class="info-box-icon bg-infobox-action">';
680
        $return .= img_picto('', $this->picto);
681
        $return .= '</span>';
682
        $return .= '<div class="info-box-content">';
683
        $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . (method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref) . '</span>';
684
        if ($selected >= 0) {
685
            $return .= '<input id="cb' . $this->id . '" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
686
        }
687
        if (property_exists($this, 'label')) {
688
            $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">' . $this->label . '</div>';
689
        }
690
        if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
691
            $return .= '<br><div class="info-box-ref tdoverflowmax150">' . $this->thirdparty->getNomUrl(1) . '</div>';
692
        }
693
        if (property_exists($this, 'amount')) {
694
            $return .= '<br>';
695
            $return .= '<span class="info-box-label amount">' . price($this->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span>';
0 ignored issues
show
Bug Best Practice introduced by
The property amount does not exist on Dolibarr\Code\EventOrgan...asses\ConferenceOrBooth. Since you implemented __get, consider adding a @property annotation.
Loading history...
696
        }
697
        if (method_exists($this, 'getLibStatut')) {
698
            $return .= '<br><div class="info-box-status">' . $this->getLibStatut(3) . '</div>';
699
        }
700
        $return .= '</div>';
701
        $return .= '</div>';
702
        $return .= '</div>';
703
704
        return $return;
705
    }
706
707
    /**
708
     *  Load the info information in the object
709
     *
710
     *  @param  int     $id       Id of object
711
     *  @return void
712
     */
713
    public function info($id)
714
    {
715
        $sql = 'SELECT rowid, datec as datec, tms as datem,';
716
        $sql .= ' fk_user_author, fk_user_mod';
717
        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
718
        $sql .= ' WHERE t.id = ' . ((int) $id);
719
        $result = $this->db->query($sql);
720
        if ($result) {
721
            if ($this->db->num_rows($result)) {
722
                $obj = $this->db->fetch_object($result);
723
724
                $this->id = $obj->rowid;
725
726
                $this->user_creation_id = $obj->fk_user_creat;
727
                $this->user_modification_id = $obj->fk_user_modif;
728
                $this->date_creation     = $this->db->jdate($obj->datec);
729
                $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
730
            }
731
732
            $this->db->free($result);
733
        } else {
734
            dol_print_error($this->db);
735
        }
736
    }
737
738
    /**
739
     * Initialise object with example values
740
     * Id must be 0 if object instance is a specimen
741
     *
742
     * @return int
743
     */
744
    public function initAsSpecimen()
745
    {
746
        return $this->initAsSpecimenCommon();
747
    }
748
749
    /**
750
     *  Create a document onto disk according to template module.
751
     *
752
     *  @param      string      $modele         Force template to use ('' to not force)
753
     *  @param      Translate   $outputlangs    object lang a utiliser pour traduction
754
     *  @param      int         $hidedetails    Hide details of lines
755
     *  @param      int         $hidedesc       Hide description
756
     *  @param      int         $hideref        Hide ref
757
     *  @param      null|array  $moreparams     Array to provide more information
758
     *  @return     int                         0 if KO, 1 if OK
759
     */
760
    public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
761
    {
762
        global $conf, $langs;
763
764
        $result = 0;
765
        $includedocgeneration = 0;
766
767
        $langs->load("eventorganization@eventorganization");
768
769
        if (!dol_strlen($modele)) {
770
            $modele = 'standard_conferenceorbooth';
771
772
            if (!empty($this->model_pdf)) {
773
                $modele = $this->model_pdf;
774
            } elseif (getDolGlobalString('CONFERENCEORBOOTH_ADDON_PDF')) {
775
                $modele = getDolGlobalString('CONFERENCEORBOOTH_ADDON_PDF');
776
            }
777
        }
778
779
        $modelpath = "core/modules/eventorganization/doc/";
780
781
        if ($includedocgeneration && !empty($modele)) {
782
            $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
783
        }
784
785
        return $result;
786
    }
787
788
    /**
789
     * Action executed by scheduler
790
     * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
791
     * Use public function doScheduledJob($param1, $param2, ...) to get parameters
792
     *
793
     * @return  int         0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
794
     */
795
    public function doScheduledJob()
796
    {
797
        global $conf, $langs;
798
799
        //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
800
801
        $error = 0;
802
        $this->output = '';
803
        $this->error = '';
804
805
        dol_syslog(__METHOD__, LOG_DEBUG);
806
807
        $now = dol_now();
808
809
        $this->db->begin();
810
811
        // ...
812
813
        $this->db->commit();
814
815
        return $error;
816
    }
817
}
818