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

ConferenceOrBooth::setDraft()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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