dolibarr 22.0.5
conferenceorboothattendee.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
30
35{
39 public $module = 'eventorganization';
40
44 public $element = 'conferenceorboothattendee';
45
49 public $table_element = 'eventorganization_conferenceorboothattendee';
50
54 public $picto = 'contact';
55
56 const STATUS_DRAFT = 0;
57 const STATUS_VALIDATED = 1;
58 const STATUS_USED = 5; // was present, presence confirmed, no more entrances can be done using this ticket
59 const STATUS_CANCELED = 9;
60
87 // BEGIN MODULEBUILDER PROPERTIES
91 public $fields = array(
92 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
93 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 2, 'index' => 1, 'comment' => "Reference of object"),
94 //'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'),
95 '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'),
96 'email' => array('type' => 'mail', 'label' => 'EmailAttendee', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'index' => 1, 'autofocusoncreate' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'csslist' => 'tdoverflowmax150'),
97 'firstname' => array('type' => 'varchar(100)', 'label' => 'Firstname', 'enabled' => 1, 'position' => 31, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax125'),
98 'lastname' => array('type' => 'varchar(100)', 'label' => 'Lastname', 'enabled' => 1, 'position' => 32, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax125'),
99 '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'),
100 'email_company' => array('type' => 'mail', 'label' => 'EmailCompany', 'enabled' => 1, 'position' => 41, 'notnull' => 0, 'visible' => -2, 'searchall' => 1),
101 'date_subscription' => array('type' => 'datetime', 'label' => 'DateOfRegistration', 'enabled' => 1, 'position' => 56, 'notnull' => 1, 'visible' => 1, 'showoncombobox' => 1,),
102 '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'),
103 'amount' => array('type' => 'price', 'label' => 'AmountPaid', 'enabled' => 1, 'position' => 57, 'notnull' => 0, 'visible' => 1, 'default' => 'null', 'isameasure' => 1, 'help' => "AmountOfRegistrationPaid",),
104 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 3,),
105 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 3,),
106 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'css' => 'nowraponall'),
107 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
108 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => -1, 'visible' => -2),
109 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
110 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => 0,),
111 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
112 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
113 'ip' => array('type' => 'varchar(250)', 'label' => 'IPAddress', 'enabled' => 1, 'position' => 900, 'notnull' => -1, 'visible' => -2,),
114 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'default' => '0', 'notnull' => 1, 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Registered', '5' => 'ShowedUp', '9' => 'Canceled'),),
115 );
119 public $rowid;
123 public $ref;
127 public $fk_actioncomm;
131 public $fk_project;
135 public $email;
139 public $firstname;
143 public $lastname;
147 public $fk_soc;
151 public $email_company;
155 public $date_subscription;
159 public $fk_invoice;
163 public $amount;
167 public $note_public;
171 public $note_private;
175 public $fk_user_creat;
179 public $fk_user_modif;
183 public $last_main_doc;
187 public $import_key;
191 public $model_pdf;
195 public $status;
196 // END MODULEBUILDER PROPERTIES
197
198
199 // If this object has a subtable with lines
200
201 // /**
202 // * @var string Name of subtable line
203 // */
204 // public $table_element_line = 'eventorganization_conferenceorboothattendeeline';
205
206 // /**
207 // * @var string Field with ID of parent key if this object has a parent
208 // */
209 // public $fk_element = 'fk_conferenceorboothattendee';
210
211 // /**
212 // * @var string Name of subtable class that manage subtable lines
213 // */
214 // public $class_element_line = 'ConferenceOrBoothAttendeeline';
215
216 // /**
217 // * @var array List of child tables. To test if we can delete object.
218 // */
219 // protected $childtables = array();
220
221 // /**
222 // * @var array List of child tables. To know object to delete on cascade.
223 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
224 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
225 // */
226 // protected $childtablesoncascade = array('eventorganization_conferenceorboothattendeedet');
227
228 // /**
229 // * @var ConferenceOrBoothAttendeeLine[] Array of subtable lines
230 // */
231 // public $lines = array();
232
233
234
240 public function __construct(DoliDB $db)
241 {
242 global $conf, $langs;
243
244 $this->db = $db;
245
246 $this->ismultientitymanaged = 'fk_project@projet';
247 $this->isextrafieldmanaged = 1;
248
249 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
250 $this->fields['rowid']['visible'] = 0;
251 }
252 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
253 $this->fields['entity']['enabled'] = 0;
254 }
255
256 if (getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_CAT')) {
257 $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.')';
258 }
259 if (isset($conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE)
260 && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== ''
261 && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== '-1') {
262 $this->fields['fk_soc']['type'] .= ' AND (client:=:'.((int) getDolGlobalInt('EVENTORGANIZATION_FILTERATTENDEES_TYPE', 0) . ')');
263 }
264
265 // Example to show how to set values of fields definition dynamically
266 /*if ($user->rights->eventorganization->conferenceorboothattendee->read) {
267 $this->fields['myfield']['visible'] = 1;
268 $this->fields['myfield']['noteditable'] = 0;
269 }*/
270
271 // Unset fields that are disabled
272 foreach ($this->fields as $key => $val) {
273 if (isset($val['enabled']) && empty($val['enabled'])) {
274 unset($this->fields[$key]);
275 }
276 }
277
278 // Translate some data of arrayofkeyval
279 if (is_object($langs)) {
280 foreach ($this->fields as $key => $val) {
281 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
282 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
283 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
284 }
285 }
286 }
287 }
288 }
289
297 public function create(User $user, $notrigger = 0)
298 {
299 global $langs;
300
301 if (!isValidEmail($this->email)) {
302 $langs->load("errors");
303 $this->errors[] = $langs->trans("ErrorBadEMail", $this->email);
304 return -1;
305 }
306
307 $result = $this->createCommon($user, $notrigger);
308 if ($result > 0) {
309 $result = $this->fetch($result);
310 if ($result > 0) {
311 $this->ref = (string) $this->id;
312 $result = $this->update($user);
313 }
314 }
315 return $result;
316 }
317
325 public function createFromClone(User $user, $fromid)
326 {
327 global $langs, $extrafields;
328 $error = 0;
329
330 dol_syslog(__METHOD__, LOG_DEBUG);
331
332 $object = new self($this->db);
333
334 $this->db->begin();
335
336 // Load source object
337 $result = $object->fetchCommon($fromid);
338 if ($result > 0 && !empty($object->table_element_line)) {
339 $object->fetchLines();
340 }
341
342 // get lines so they will be clone
343 //foreach($this->lines as $line)
344 // $line->fetch_optionals();
345
346 // Reset some properties
347 unset($object->id);
348 unset($object->fk_user_creat);
349 unset($object->user_creation_id);
350 unset($object->import_key);
351
352 // Clear fields
353 if (property_exists($object, 'ref')) {
354 // @phan-suppress-next-line PhanTypeInvalidDimOffset
355 $object->ref = empty($this->fields['ref']['default']) ? "(PROV)" : $this->fields['ref']['default'];
356 }
357 if (property_exists($object, 'status')) {
358 $object->status = self::STATUS_DRAFT;
359 }
360 if (property_exists($object, 'date_creation')) {
361 $object->date_creation = dol_now();
362 }
363 if (property_exists($object, 'date_modification')) {
364 $object->date_modification = null;
365 }
366 // ...
367 // Clear extrafields that are unique
368 if (is_array($object->array_options) && count($object->array_options) > 0) {
369 $extrafields->fetch_name_optionals_label($this->table_element);
370 foreach ($object->array_options as $key => $option) {
371 $shortkey = preg_replace('/options_/', '', $key);
372 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
373 //var_dump($key);
374 //var_dump($clonedObj->array_options[$key]); exit;
375 unset($object->array_options[$key]);
376 }
377 }
378 }
379
380 // Create clone
381 $object->context['createfromclone'] = 'createfromclone';
382 $result = $object->createCommon($user);
383 if ($result < 0) {
384 $error++;
386 } else {
387 $object->ref = (string) $object->id;
388 $result = $object->update($user);
389 }
390
391 if (!$error) {
392 // copy internal contacts
393 if ($this->copy_linked_contact($object, 'internal') < 0) {
394 $error++;
395 }
396 }
397
398 if (!$error) {
399 // copy external contacts if same company
400 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
401 if ($this->copy_linked_contact($object, 'external') < 0) {
402 $error++;
403 }
404 }
405 }
406
407 unset($object->context['createfromclone']);
408
409 // End
410 if (!$error) {
411 $this->db->commit();
412 return $object;
413 } else {
414 $this->db->rollback();
415 return -1;
416 }
417 }
418
426 public function fetch($id, $ref = null)
427 {
428 $result = $this->fetchCommon($id, $ref, '', 0);
429 if ($result > 0 && !empty($this->table_element_line)) {
430 $this->fetchLines();
431 }
432 return $result;
433 }
434
440 public function fetchLines()
441 {
442 $this->lines = array();
443
444 $result = $this->fetchLinesCommon();
445 return $result;
446 }
447
448
461 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
462 {
463 dol_syslog(__METHOD__, LOG_DEBUG);
464
465 $records = array();
466
467 $sql = 'SELECT ';
468 $sql .= $this->getFieldList('t');
469 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
470 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm as a on a.id = t.fk_actioncomm";
471 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
472 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
473 } else {
474 $sql .= ' WHERE 1 = 1';
475 }
476
477 // Manage filter
478 if (is_array($filter)) { // deprecated, use $filter = USF syntax
479 dol_syslog("You are using a deprecated use of fetchAll. filter parameter must be an USF string now.", LOG_WARNING);
480 $sqlwhere = array();
481 if (count($filter) > 0) {
482 foreach ($filter as $key => $value) {
483 if ($key == 't.rowid' || $key == 't.fk_soc' || $key == 't.fk_project' || $key == 't.fk_actioncomm') {
484 $sqlwhere[] = $this->db->sanitize($key).' = '.((int) $value);
485 } elseif (!empty($this->fields[$key]) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
486 $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
487 } elseif ($key == 'customsql') {
488 $sqlwhere[] = $value;
489 } elseif (strpos($value, '%') === false) {
490 $sqlwhere[] = $this->db->sanitize($key).' IN ('.$this->db->sanitize($this->db->escape($value)).')';
491 } else {
492 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($value)."%'";
493 }
494 }
495 }
496 if (count($sqlwhere) > 0) {
497 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
498 }
499
500 $filter = '';
501 }
502
503 // Manage filter
504 $errormessage = '';
505 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
506 if ($errormessage) {
507 $this->errors[] = $errormessage;
508 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
509 return -1;
510 }
511
512 if (!empty($sortfield)) {
513 $sql .= $this->db->order($sortfield, $sortorder);
514 }
515 if (!empty($limit)) {
516 $sql .= $this->db->plimit($limit, $offset);
517 }
518
519 $resql = $this->db->query($sql);
520 if ($resql) {
521 $num = $this->db->num_rows($resql);
522 $i = 0;
523 while ($i < ($limit ? min($limit, $num) : $num)) {
524 $obj = $this->db->fetch_object($resql);
525
526 $record = new self($this->db);
527 $record->setVarsFromFetchObj($obj);
528
529 $records[$record->id] = $record;
530
531 $i++;
532 }
533 $this->db->free($resql);
534
535 return $records;
536 } else {
537 $this->errors[] = 'Error '.$this->db->lasterror();
538 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
539
540 return -1;
541 }
542 }
543
551 public function update(User $user, $notrigger = 0)
552 {
553 return $this->updateCommon($user, $notrigger);
554 }
555
563 public function delete(User $user, $notrigger = 0)
564 {
565 return $this->deleteCommon($user, $notrigger);
566 //return $this->deleteCommon($user, $notrigger, 1);
567 }
568
577 public function deleteLine(User $user, $idline, $notrigger = 0)
578 {
579 if ($this->status < 0) {
580 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
581 return -2;
582 }
583
584 return $this->deleteLineCommon($user, $idline, $notrigger);
585 }
586
587
595 public function validate($user, $notrigger = 0)
596 {
597 global $conf;
598
599 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
600
601 $error = 0;
602
603 // Protection
604 if ($this->status == self::STATUS_VALIDATED) {
605 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
606 return 0;
607 }
608
609 $now = dol_now();
610
611 $this->db->begin();
612
613 // Define new ref
614 $num = (string) $this->ref;
615 if (!$error && (preg_match('/^[\‍(]?PROV/i', $num) || empty($num))) { // empty should not happened, but when it occurs, the test saves life
616 $num = $this->getNextNumRef();
617 }
618
619 $this->newref = (string) $num;
620
621 if (!empty($num)) {
622 // Validate
623 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
624 $sql .= " SET ref = '".$this->db->escape($num)."',";
625 $sql .= " status = ".self::STATUS_VALIDATED;
626 if (!empty($this->fields['date_validation'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
627 $sql .= ", date_validation = '".$this->db->idate($now)."'";
628 }
629 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
630 $sql .= ", fk_user_valid = ".((int) $user->id);
631 }
632 $sql .= " WHERE rowid = ".((int) $this->id);
633
634 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
635 $resql = $this->db->query($sql);
636 if (!$resql) {
637 dol_print_error($this->db);
638 $this->error = $this->db->lasterror();
639 $error++;
640 }
641
642 if (!$error && !$notrigger) {
643 // Call trigger
644 $result = $this->call_trigger('CONFERENCEORBOOTHATTENDEE_VALIDATE', $user);
645 if ($result < 0) {
646 $error++;
647 }
648 // End call triggers
649 }
650 }
651
652 if (!$error) {
653 $this->oldref = $this->ref;
654
655 // Rename directory if dir was a temporary ref
656 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
657 // Now we rename also files into index
658 $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)."'";
659 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
660 $resql = $this->db->query($sql);
661 if (!$resql) {
662 $error++;
663 $this->error = $this->db->lasterror();
664 }
665 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'conferenceorboothattendee/".$this->db->escape($this->newref)."'";
666 $sql .= " WHERE filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
667 $resql = $this->db->query($sql);
668 if (!$resql) {
669 $error++;
670 $this->error = $this->db->lasterror();
671 }
672
673 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
674 $oldref = dol_sanitizeFileName($this->ref);
675 $newref = dol_sanitizeFileName($num);
676 $dirsource = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$oldref;
677 $dirdest = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref;
678 if (!$error && file_exists($dirsource)) {
679 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
680
681 if (@rename($dirsource, $dirdest)) {
682 dol_syslog("Rename ok");
683 // Rename docs starting with $oldref with $newref
684 $listoffiles = dol_dir_list($conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
685 foreach ($listoffiles as $fileentry) {
686 $dirsource = $fileentry['name'];
687 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
688 $dirsource = $fileentry['path'].'/'.$dirsource;
689 $dirdest = $fileentry['path'].'/'.$dirdest;
690 @rename($dirsource, $dirdest);
691 }
692 }
693 }
694 }
695 }
696
697 // Set new ref and current status
698 if (!$error) {
699 $this->ref = $num;
700 $this->status = self::STATUS_VALIDATED;
701 }
702
703 if (!$error) {
704 $this->db->commit();
705 return 1;
706 } else {
707 $this->db->rollback();
708 return -1;
709 }
710 }
711
712 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
718 public function fetch_projet()
719 {
720 // phpcs:enable
721 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
722
723 if (empty($this->fk_project) && !empty($this->fk_projet)) {
724 $this->fk_project = $this->fk_projet; // For backward compatibility
725 }
726 if (empty($this->fk_project)) {
727 return 0;
728 }
729
730 $project = new Project($this->db);
731 $result = $project->fetch($this->fk_project);
732
733 $this->projet = $project; // deprecated
734 $this->project = $project;
735 return $result;
736 }
737
745 public function setDraft($user, $notrigger = 0)
746 {
747 // Protection
748 if ($this->status <= self::STATUS_DRAFT) {
749 return 0;
750 }
751
752 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTHATTENDEE_UNVALIDATE');
753 }
754
762 public function cancel($user, $notrigger = 0)
763 {
764 // Protection
765 if ($this->status != self::STATUS_VALIDATED) {
766 return 0;
767 }
768
769 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_CANCEL');
770 }
771
779 public function reopen($user, $notrigger = 0)
780 {
781 // Protection
782 if ($this->status != self::STATUS_CANCELED) {
783 return 0;
784 }
785
786 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_REOPEN');
787 }
788
799 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
800 {
801 global $conf, $langs, $hookmanager;
802
803 if (!empty($conf->dol_no_mouse_hover)) {
804 $notooltip = 1; // Force disable tooltips
805 }
806
807 $result = '';
808
809 $label = img_picto('', $this->picto).' <u>'.$langs->trans("ConferenceOrBoothAttendee").'</u>';
810 if (isset($this->status)) {
811 $label .= ' '.$this->getLibStatut(5);
812 }
813 $label .= '<br>';
814 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
815 $label .= '<br><b>'.$langs->trans('DateOfRegistration').':</b> '.dol_print_date($this->date_subscription, 'dayhour');
816 $label .= '<br><b>'.$langs->trans('AmountPaid').':</b> '.$this->amount;
817
818 $url = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.$this->id;
819
820 if ($option != 'nolink') {
821 // Add param to save lastsearch_values or not
822 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
823 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
824 $add_save_lastsearch_values = 1;
825 }
826 if ($add_save_lastsearch_values) {
827 $url .= '&save_lastsearch_values=1';
828 }
829
830 if ($option == 'conforboothid') {
831 $url .= '&conforboothid='.((int) $this->fk_actioncomm);
832 }
833
834 if ($option == 'projectid') {
835 $url .= '&fk_project='.((int) $this->fk_project).'&withproject=1';
836 }
837
838 if ($option == 'conforboothidproject') {
839 $url .= '&conforboothid='.((int) $this->fk_actioncomm).'&withproject=1';
840 }
841 }
842
843 $linkclose = '';
844 if (empty($notooltip)) {
845 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
846 $label = $langs->trans("ShowConferenceOrBoothAttendee");
847 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
848 }
849 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
850 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
851 } else {
852 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
853 }
854
855 if ($option == 'nolink') {
856 $linkstart = '<span';
857 } else {
858 $linkstart = '<a href="'.$url.'"';
859 }
860 $linkstart .= $linkclose.'>';
861 if ($option == 'nolink') {
862 $linkend = '</span>';
863 } else {
864 $linkend = '</a>';
865 }
866
867 $result .= $linkstart;
868
869 if (empty($this->showphoto_on_popup)) {
870 if ($withpicto) {
871 $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);
872 }
873 } else {
874 if ($withpicto) {
875 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
876
877 list($class, $module) = explode('@', $this->picto);
878 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
879 $filearray = dol_dir_list($upload_dir, "files");
880 $filename = $filearray[0]['name'];
881 if (!empty($filename)) {
882 $pospoint = strpos($filearray[0]['name'], '.');
883
884 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
885 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
886 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
887 } else {
888 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
889 }
890
891 $result .= '</div>';
892 } else {
893 $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);
894 }
895 }
896 }
897
898 if ($withpicto != 2) {
899 $result .= $this->ref;
900 }
901
902 $result .= $linkend;
903 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
904
905 global $action, $hookmanager;
906 $hookmanager->initHooks(array('conferenceorboothattendeedao'));
907 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
908 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
909 if ($reshook > 0) {
910 $result = $hookmanager->resPrint;
911 } else {
912 $result .= $hookmanager->resPrint;
913 }
914
915 return $result;
916 }
917
924 public function getLabelStatus($mode = 0)
925 {
926 return $this->LibStatut($this->status, $mode);
927 }
928
935 public function getLibStatut($mode = 0)
936 {
937 return $this->LibStatut($this->status, $mode);
938 }
939
940 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
948 public function LibStatut($status, $mode = 0)
949 {
950 // phpcs:enable
951 global $langs;
952
953 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
954 //$langs->load("eventorganization@eventorganization");
955 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
956 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Registered');
957 $this->labelStatus[self::STATUS_USED] = $langs->trans('ShowedUp');
958 $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
959 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
960 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Registered');
961 $this->labelStatusShort[self::STATUS_USED] = $langs->trans('ShowedUp');
962 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
963 }
964
965 $labelStatus = $this->labelStatus[$status];
966 $labelStatusShort = $this->labelStatusShort[$status];
967
968 $statusType = 'status'.$status;
969 if ($status == self::STATUS_VALIDATED) {
970 $statusType = 'status2';
971 }
972 if ($status == self::STATUS_CANCELED) {
973 $statusType = 'status9';
974 }
975
976 if ($status == self::STATUS_VALIDATED && $this->date_subscription && $this->amount) {
977 $statusType = 'status4';
978 $labelStatus .= ' - '.$langs->trans("Paid");
979 }
980
981 if ($status == self::STATUS_USED) {
982 $statusType = 'status6';
983 }
984
985 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
986 }
987
994 public function info($id)
995 {
996 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
997 $sql .= ' fk_user_creat, fk_user_modif';
998 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
999 $sql .= ' WHERE t.rowid = '.((int) $id);
1000 $result = $this->db->query($sql);
1001 if ($result) {
1002 if ($this->db->num_rows($result)) {
1003 $obj = $this->db->fetch_object($result);
1004
1005 $this->id = $obj->rowid;
1006
1007 $this->user_creation_id = $obj->fk_user_creat;
1008 $this->user_modification_id = $obj->fk_user_modif;
1009 $this->date_creation = $this->db->jdate($obj->datec);
1010 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1011 }
1012
1013 $this->db->free($result);
1014 } else {
1015 dol_print_error($this->db);
1016 }
1017 }
1018
1025 public function initAsSpecimen()
1026 {
1027 return $this->initAsSpecimenCommon();
1028 }
1029
1035 public function getNextNumRef()
1036 {
1037 global $langs, $conf;
1038 $langs->load("eventorganization@eventorganization");
1039
1040 if (!getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
1041 $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON = 'mod_conferenceorboothattendee_standard';
1042 }
1043
1044 if (getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
1045 $mybool = false;
1046
1047 $file = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON') . ".php";
1048 $classname = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON');
1049
1050 // Include file with class
1051 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1052 foreach ($dirmodels as $reldir) {
1053 $dir = dol_buildpath($reldir."core/modules/eventorganization/");
1054
1055 // Load file with numbering class (if found)
1056 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1057 }
1058
1059 if (!$mybool) {
1060 dol_print_error(null, "Failed to include file ".$file);
1061 return '';
1062 }
1063
1064 if (class_exists($classname)) {
1065 $obj = new $classname();
1066 '@phan-var-force CommonNumRefGenerator $obj';
1067 $numref = $obj->getNextValue($this);
1068
1069 if ($numref != '' && $numref != '-1') {
1070 return $numref;
1071 } else {
1072 $this->error = $obj->error;
1073 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1074 return "";
1075 }
1076 } else {
1077 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1078 return "";
1079 }
1080 } else {
1081 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1082 return "";
1083 }
1084 }
1085
1097 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1098 {
1099 global $conf, $langs;
1100
1101 $result = 0;
1102 $includedocgeneration = 0;
1103
1104 $langs->load("eventorganization@eventorganization");
1105
1106 if (!dol_strlen($modele)) {
1107 $modele = 'standard_conferenceorboothattendee';
1108
1109 if (!empty($this->model_pdf)) {
1110 $modele = $this->model_pdf;
1111 } elseif (getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF')) {
1112 $modele = getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF');
1113 }
1114 }
1115
1116 $modelpath = "core/modules/eventorganization/doc/";
1117
1118 if ($includedocgeneration && !empty($modele)) {
1119 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1120 }
1121
1122 return $result;
1123 }
1124
1132 public function doScheduledJob()
1133 {
1134 global $conf, $langs;
1135
1136 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1137
1138 $error = 0;
1139 $this->output = '';
1140 $this->error = '';
1141
1142 dol_syslog(__METHOD__, LOG_DEBUG);
1143
1144 $now = dol_now();
1145
1146 $this->db->begin();
1147
1148 // ...
1149
1150 $this->db->commit();
1151
1152 return $error;
1153 }
1154
1163 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1164 {
1165 $tables = array(
1166 'eventorganization_conferenceorboothattendee'
1167 );
1168
1169 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1170 }
1171
1181 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
1182 {
1183 $lastname = $this->lastname;
1184 $firstname = $this->firstname;
1185 if (empty($lastname)) {
1186 $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 : '')))));
1187 }
1188
1189 $ret = '';
1190
1191 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
1192
1193 return dol_trunc($ret, $maxlen);
1194 }
1195}
1196
1197
1198require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1199
1204{
1205 // To complete with content of an object ConferenceOrBoothAttendeeLine
1206 // We should have a field rowid, fk_conferenceorboothattendee and position
1207
1213 public function __construct(DoliDB $db)
1214 {
1215 $this->db = $db;
1216
1217 $this->isextrafieldmanaged = 0;
1218 }
1219}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class for ConferenceOrBoothAttendee.
cancel($user, $notrigger=0)
Set cancel status.
createFromClone(User $user, $fromid)
Clone an object into another one.
getLibStatut($mode=0)
Return the label of the status.
info($id)
Load the info information in the object.
fetch($id, $ref=null)
Load object in memory from the database.
getLabelStatus($mode=0)
Return the label of the status.
create(User $user, $notrigger=0)
Create object into database.
fetchLines()
Load object lines in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
LibStatut($status, $mode=0)
Return the status.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
fetch_projet()
Load the project with id $this->fk_project into this->project.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name ('name+' '+lastname)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
update(User $user, $notrigger=0)
Update object into database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
reopen($user, $notrigger=0)
Set back to validated status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
setDraft($user, $notrigger=0)
Set draft status.
validate($user, $notrigger=0)
Validate object.
Class ConferenceOrBoothAttendeeLine.
Class to manage Dolibarr database access.
Class to manage projects.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161