dolibarr 21.0.0-alpha
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) ---Put here your own copyright and developer email---
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31
36{
40 public $module = 'eventorganization';
41
45 public $element = 'conferenceorboothattendee';
46
50 public $table_element = 'eventorganization_conferenceorboothattendee';
51
55 public $picto = 'contact';
56
60 public $paid = 0;
61
62 const STATUS_DRAFT = 0;
63 const STATUS_VALIDATED = 1;
64 const STATUS_CANCELED = 9;
65
66
93 // BEGIN MODULEBUILDER PROPERTIES
97 public $fields = array(
98 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
99 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 2, 'index' => 1, 'comment' => "Reference of object"),
100 //'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'),
101 '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'),
102 'email' => array('type' => 'mail', 'label' => 'EmailAttendee', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'index' => 1, 'autofocusoncreate' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax150'),
103 'firstname' => array('type' => 'varchar(100)', 'label' => 'Firstname', 'enabled' => 1, 'position' => 31, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax125'),
104 'lastname' => array('type' => 'varchar(100)', 'label' => 'Lastname', 'enabled' => 1, 'position' => 32, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'searchall' => 1, 'csslist' => 'tdoverflowmax125'),
105 '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'),
106 'email_company' => array('type' => 'mail', 'label' => 'EmailCompany', 'enabled' => 1, 'position' => 41, 'notnull' => 0, 'visible' => -2, 'searchall' => 1),
107 'date_subscription' => array('type' => 'datetime', 'label' => 'DateOfRegistration', 'enabled' => 1, 'position' => 56, 'notnull' => 1, 'visible' => 1, 'showoncombobox' => 1,),
108 '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'),
109 'amount' => array('type' => 'price', 'label' => 'AmountPaid', 'enabled' => 1, 'position' => 57, 'notnull' => 0, 'visible' => 1, 'default' => 'null', 'isameasure' => 1, 'help' => "AmountOfRegistrationPaid",),
110 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 3,),
111 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 3,),
112 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'css' => 'nowraponall'),
113 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
114 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => -1, 'visible' => -2),
115 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
116 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => 0,),
117 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
118 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
119 'ip' => array('type' => 'varchar(250)', 'label' => 'IPAddress', 'enabled' => 1, 'position' => 900, 'notnull' => -1, 'visible' => -2,),
120 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'default' => '0', 'notnull' => 1, 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated', '9' => 'Canceled'),),
121 );
125 public $rowid;
129 public $ref;
133 public $fk_actioncomm;
137 public $fk_project;
141 public $email;
145 public $firstname;
149 public $lastname;
153 public $fk_soc;
157 public $email_company;
161 public $date_subscription;
165 public $fk_invoice;
169 public $amount;
173 public $note_public;
177 public $note_private;
181 public $fk_user_creat;
185 public $fk_user_modif;
189 public $last_main_doc;
193 public $import_key;
197 public $model_pdf;
201 public $status;
202 // END MODULEBUILDER PROPERTIES
203
204
205 // If this object has a subtable with lines
206
207 // /**
208 // * @var string Name of subtable line
209 // */
210 // public $table_element_line = 'eventorganization_conferenceorboothattendeeline';
211
212 // /**
213 // * @var string Field with ID of parent key if this object has a parent
214 // */
215 // public $fk_element = 'fk_conferenceorboothattendee';
216
217 // /**
218 // * @var string Name of subtable class that manage subtable lines
219 // */
220 // public $class_element_line = 'ConferenceOrBoothAttendeeline';
221
222 // /**
223 // * @var array List of child tables. To test if we can delete object.
224 // */
225 // protected $childtables = array();
226
227 // /**
228 // * @var array List of child tables. To know object to delete on cascade.
229 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
230 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
231 // */
232 // protected $childtablesoncascade = array('eventorganization_conferenceorboothattendeedet');
233
234 // /**
235 // * @var ConferenceOrBoothAttendeeLine[] Array of subtable lines
236 // */
237 // public $lines = array();
238
239
240
246 public function __construct(DoliDB $db)
247 {
248 global $conf, $langs;
249
250 $this->db = $db;
251
252 $this->ismultientitymanaged = 'fk_project@projet';
253 $this->isextrafieldmanaged = 1;
254
255 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
256 $this->fields['rowid']['visible'] = 0;
257 }
258 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
259 $this->fields['entity']['enabled'] = 0;
260 }
261
262 if (getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_CAT')) {
263 $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.')';
264 }
265 if (isset($conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE)
266 && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== ''
267 && getDolGlobalString('EVENTORGANIZATION_FILTERATTENDEES_TYPE') !== '-1') {
268 $this->fields['fk_soc']['type'] .= ' AND client = '.((int) getDolGlobalInt('EVENTORGANIZATION_FILTERATTENDEES_TYPE', 0));
269 }
270
271 // Example to show how to set values of fields definition dynamically
272 /*if ($user->rights->eventorganization->conferenceorboothattendee->read) {
273 $this->fields['myfield']['visible'] = 1;
274 $this->fields['myfield']['noteditable'] = 0;
275 }*/
276
277 // Unset fields that are disabled
278 foreach ($this->fields as $key => $val) {
279 if (isset($val['enabled']) && empty($val['enabled'])) {
280 unset($this->fields[$key]);
281 }
282 }
283
284 // Translate some data of arrayofkeyval
285 if (is_object($langs)) {
286 foreach ($this->fields as $key => $val) {
287 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
288 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
289 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
290 }
291 }
292 }
293 }
294 }
295
303 public function create(User $user, $notrigger = 0)
304 {
305 global $langs;
306
307 if (!isValidEmail($this->email)) {
308 $langs->load("errors");
309 $this->errors[] = $langs->trans("ErrorBadEMail", $this->email);
310 return -1;
311 }
312
313 $result = $this->createCommon($user, $notrigger);
314 if ($result > 0) {
315 $result = $this->fetch($result);
316 if ($result > 0) {
317 $this->ref = (string) $this->id;
318 $result = $this->update($user);
319 }
320 }
321 return $result;
322 }
323
331 public function createFromClone(User $user, $fromid)
332 {
333 global $langs, $extrafields;
334 $error = 0;
335
336 dol_syslog(__METHOD__, LOG_DEBUG);
337
338 $object = new self($this->db);
339
340 $this->db->begin();
341
342 // Load source object
343 $result = $object->fetchCommon($fromid);
344 if ($result > 0 && !empty($object->table_element_line)) {
345 $object->fetchLines();
346 }
347
348 // get lines so they will be clone
349 //foreach($this->lines as $line)
350 // $line->fetch_optionals();
351
352 // Reset some properties
353 unset($object->id);
354 unset($object->fk_user_creat);
355 unset($object->import_key);
356
357 // Clear fields
358 if (property_exists($object, 'ref')) {
359 // @phan-suppress-next-line PhanTypeInvalidDimOffset
360 $object->ref = empty($this->fields['ref']['default']) ? "(PROV)" : $this->fields['ref']['default'];
361 }
362 if (property_exists($object, 'label')) {
363 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
364 }
365 if (property_exists($object, 'status')) {
366 $object->status = self::STATUS_DRAFT;
367 }
368 if (property_exists($object, 'date_creation')) {
369 $object->date_creation = dol_now();
370 }
371 if (property_exists($object, 'date_modification')) {
372 $object->date_modification = null;
373 }
374 // ...
375 // Clear extrafields that are unique
376 if (is_array($object->array_options) && count($object->array_options) > 0) {
377 $extrafields->fetch_name_optionals_label($this->table_element);
378 foreach ($object->array_options as $key => $option) {
379 $shortkey = preg_replace('/options_/', '', $key);
380 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
381 //var_dump($key);
382 //var_dump($clonedObj->array_options[$key]); exit;
383 unset($object->array_options[$key]);
384 }
385 }
386 }
387
388 // Create clone
389 $object->context['createfromclone'] = 'createfromclone';
390 $result = $object->createCommon($user);
391 if ($result < 0) {
392 $error++;
394 } else {
395 $object->ref = (string) $object->id;
396 $result = $object->update($user);
397 }
398
399 if (!$error) {
400 // copy internal contacts
401 if ($this->copy_linked_contact($object, 'internal') < 0) {
402 $error++;
403 }
404 }
405
406 if (!$error) {
407 // copy external contacts if same company
408 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
409 if ($this->copy_linked_contact($object, 'external') < 0) {
410 $error++;
411 }
412 }
413 }
414
415 unset($object->context['createfromclone']);
416
417 // End
418 if (!$error) {
419 $this->db->commit();
420 return $object;
421 } else {
422 $this->db->rollback();
423 return -1;
424 }
425 }
426
434 public function fetch($id, $ref = null)
435 {
436 $result = $this->fetchCommon($id, $ref);
437 if ($result > 0 && !empty($this->table_element_line)) {
438 $this->fetchLines();
439 }
440 return $result;
441 }
442
448 public function fetchLines()
449 {
450 $this->lines = array();
451
452 $result = $this->fetchLinesCommon();
453 return $result;
454 }
455
456
469 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
470 {
471 dol_syslog(__METHOD__, LOG_DEBUG);
472
473 $records = array();
474
475 $sql = 'SELECT ';
476 $sql .= $this->getFieldList('t');
477 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
478 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm as a on a.id = t.fk_actioncomm";
479 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
480 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
481 } else {
482 $sql .= ' WHERE 1 = 1';
483 }
484
485 // Manage filter
486 if (is_array($filter)) { // deprecated, use $filter = USF syntax
487 dol_syslog("You are using a deprecated use of fetchAll. filter parameter mus be an USF string now.", LOG_WARNING);
488 $sqlwhere = array();
489 if (count($filter) > 0) {
490 foreach ($filter as $key => $value) {
491 if ($key == 't.rowid' || $key == 't.fk_soc' || $key == 't.fk_project' || $key == 't.fk_actioncomm') {
492 $sqlwhere[] = $key.'='.((int) $value);
493 } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
494 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
495 } elseif ($key == 'customsql') {
496 $sqlwhere[] = $value;
497 } elseif (strpos($value, '%') === false) {
498 $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
499 } else {
500 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
501 }
502 }
503 }
504 if (count($sqlwhere) > 0) {
505 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
506 }
507
508 $filter = '';
509 }
510
511 // Manage filter
512 $errormessage = '';
513 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
514 if ($errormessage) {
515 $this->errors[] = $errormessage;
516 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
517 return -1;
518 }
519
520 if (!empty($sortfield)) {
521 $sql .= $this->db->order($sortfield, $sortorder);
522 }
523 if (!empty($limit)) {
524 $sql .= $this->db->plimit($limit, $offset);
525 }
526
527 $resql = $this->db->query($sql);
528 if ($resql) {
529 $num = $this->db->num_rows($resql);
530 $i = 0;
531 while ($i < ($limit ? min($limit, $num) : $num)) {
532 $obj = $this->db->fetch_object($resql);
533
534 $record = new self($this->db);
535 $record->setVarsFromFetchObj($obj);
536
537 $records[$record->id] = $record;
538
539 $i++;
540 }
541 $this->db->free($resql);
542
543 return $records;
544 } else {
545 $this->errors[] = 'Error '.$this->db->lasterror();
546 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
547
548 return -1;
549 }
550 }
551
559 public function update(User $user, $notrigger = 0)
560 {
561 return $this->updateCommon($user, $notrigger);
562 }
563
571 public function delete(User $user, $notrigger = 0)
572 {
573 return $this->deleteCommon($user, $notrigger);
574 //return $this->deleteCommon($user, $notrigger, 1);
575 }
576
585 public function deleteLine(User $user, $idline, $notrigger = 0)
586 {
587 if ($this->status < 0) {
588 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
589 return -2;
590 }
591
592 return $this->deleteLineCommon($user, $idline, $notrigger);
593 }
594
595
603 public function validate($user, $notrigger = 0)
604 {
605 global $conf;
606
607 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
608
609 $error = 0;
610
611 // Protection
612 if ($this->status == self::STATUS_VALIDATED) {
613 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
614 return 0;
615 }
616
617 $now = dol_now();
618
619 $this->db->begin();
620
621 // Define new ref
622 $num = (string) $this->ref;
623 if (!$error && (preg_match('/^[\‍(]?PROV/i', $num) || empty($num))) { // empty should not happened, but when it occurs, the test saves life
624 $num = $this->getNextNumRef();
625 }
626
627 $this->newref = (string) $num;
628
629 if (!empty($num)) {
630 // Validate
631 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
632 $sql .= " SET ref = '".$this->db->escape($num)."',";
633 $sql .= " status = ".self::STATUS_VALIDATED;
634 if (!empty($this->fields['date_validation'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
635 $sql .= ", date_validation = '".$this->db->idate($now)."'";
636 }
637 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
638 $sql .= ", fk_user_valid = ".((int) $user->id);
639 }
640 $sql .= " WHERE rowid = ".((int) $this->id);
641
642 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
643 $resql = $this->db->query($sql);
644 if (!$resql) {
645 dol_print_error($this->db);
646 $this->error = $this->db->lasterror();
647 $error++;
648 }
649
650 if (!$error && !$notrigger) {
651 // Call trigger
652 $result = $this->call_trigger('CONFERENCEORBOOTHATTENDEE_VALIDATE', $user);
653 if ($result < 0) {
654 $error++;
655 }
656 // End call triggers
657 }
658 }
659
660 if (!$error) {
661 $this->oldref = $this->ref;
662
663 // Rename directory if dir was a temporary ref
664 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
665 // Now we rename also files into index
666 $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)."'";
667 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
668 $resql = $this->db->query($sql);
669 if (!$resql) {
670 $error++;
671 $this->error = $this->db->lasterror();
672 }
673 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'conferenceorboothattendee/".$this->db->escape($this->newref)."'";
674 $sql .= " WHERE filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
675 $resql = $this->db->query($sql);
676 if (!$resql) {
677 $error++;
678 $this->error = $this->db->lasterror();
679 }
680
681 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
682 $oldref = dol_sanitizeFileName($this->ref);
683 $newref = dol_sanitizeFileName($num);
684 $dirsource = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$oldref;
685 $dirdest = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref;
686 if (!$error && file_exists($dirsource)) {
687 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
688
689 if (@rename($dirsource, $dirdest)) {
690 dol_syslog("Rename ok");
691 // Rename docs starting with $oldref with $newref
692 $listoffiles = dol_dir_list($conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
693 foreach ($listoffiles as $fileentry) {
694 $dirsource = $fileentry['name'];
695 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
696 $dirsource = $fileentry['path'].'/'.$dirsource;
697 $dirdest = $fileentry['path'].'/'.$dirdest;
698 @rename($dirsource, $dirdest);
699 }
700 }
701 }
702 }
703 }
704
705 // Set new ref and current status
706 if (!$error) {
707 $this->ref = $num;
708 $this->status = self::STATUS_VALIDATED;
709 }
710
711 if (!$error) {
712 $this->db->commit();
713 return 1;
714 } else {
715 $this->db->rollback();
716 return -1;
717 }
718 }
719
720 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
726 public function fetch_projet()
727 {
728 // phpcs:enable
729 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
730
731 if (empty($this->fk_project) && !empty($this->fk_projet)) {
732 $this->fk_project = $this->fk_projet; // For backward compatibility
733 }
734 if (empty($this->fk_project)) {
735 return 0;
736 }
737
738 $project = new Project($this->db);
739 $result = $project->fetch($this->fk_project);
740
741 $this->projet = $project; // deprecated
742 $this->project = $project;
743 return $result;
744 }
745
753 public function setDraft($user, $notrigger = 0)
754 {
755 // Protection
756 if ($this->status <= self::STATUS_DRAFT) {
757 return 0;
758 }
759
760 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTHATTENDEE_UNVALIDATE');
761 }
762
770 public function cancel($user, $notrigger = 0)
771 {
772 // Protection
773 if ($this->status != self::STATUS_VALIDATED) {
774 return 0;
775 }
776
777 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_CANCEL');
778 }
779
787 public function reopen($user, $notrigger = 0)
788 {
789 // Protection
790 if ($this->status != self::STATUS_CANCELED) {
791 return 0;
792 }
793
794 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_REOPEN');
795 }
796
807 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
808 {
809 global $conf, $langs, $hookmanager;
810
811 if (!empty($conf->dol_no_mouse_hover)) {
812 $notooltip = 1; // Force disable tooltips
813 }
814
815 $result = '';
816
817 $label = img_picto('', $this->picto).' <u>'.$langs->trans("ConferenceOrBoothAttendee").'</u>';
818 if (isset($this->status)) {
819 $label .= ' '.$this->getLibStatut(5);
820 }
821 $label .= '<br>';
822 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
823 $label .= '<br><b>'.$langs->trans('DateOfRegistration').':</b> '.dol_print_date($this->date_subscription, 'dayhour');
824 $label .= '<br><b>'.$langs->trans('AmountPaid').':</b> '.$this->amount;
825
826 $url = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.$this->id;
827
828 if ($option != 'nolink') {
829 // Add param to save lastsearch_values or not
830 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
831 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
832 $add_save_lastsearch_values = 1;
833 }
834 if ($add_save_lastsearch_values) {
835 $url .= '&save_lastsearch_values=1';
836 }
837
838 if ($option == 'conforboothid') {
839 $url .= '&conforboothid='.((int) $this->fk_actioncomm);
840 }
841
842 if ($option == 'projectid') {
843 $url .= '&fk_project='.((int) $this->fk_project).'&withproject=1';
844 }
845
846 if ($option == 'conforboothidproject') {
847 $url .= '&conforboothid='.((int) $this->fk_actioncomm).'&withproject=1';
848 }
849 }
850
851 $linkclose = '';
852 if (empty($notooltip)) {
853 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
854 $label = $langs->trans("ShowConferenceOrBoothAttendee");
855 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
856 }
857 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
858 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
859 } else {
860 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
861 }
862
863 if ($option == 'nolink') {
864 $linkstart = '<span';
865 } else {
866 $linkstart = '<a href="'.$url.'"';
867 }
868 $linkstart .= $linkclose.'>';
869 if ($option == 'nolink') {
870 $linkend = '</span>';
871 } else {
872 $linkend = '</a>';
873 }
874
875 $result .= $linkstart;
876
877 if (empty($this->showphoto_on_popup)) {
878 if ($withpicto) {
879 $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);
880 }
881 } else {
882 if ($withpicto) {
883 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
884
885 list($class, $module) = explode('@', $this->picto);
886 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
887 $filearray = dol_dir_list($upload_dir, "files");
888 $filename = $filearray[0]['name'];
889 if (!empty($filename)) {
890 $pospoint = strpos($filearray[0]['name'], '.');
891
892 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
893 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
894 $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>';
895 } else {
896 $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>';
897 }
898
899 $result .= '</div>';
900 } else {
901 $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);
902 }
903 }
904 }
905
906 if ($withpicto != 2) {
907 $result .= $this->ref;
908 }
909
910 $result .= $linkend;
911 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
912
913 global $action, $hookmanager;
914 $hookmanager->initHooks(array('conferenceorboothattendeedao'));
915 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
916 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
917 if ($reshook > 0) {
918 $result = $hookmanager->resPrint;
919 } else {
920 $result .= $hookmanager->resPrint;
921 }
922
923 return $result;
924 }
925
932 public function getLabelStatus($mode = 0)
933 {
934 return $this->LibStatut($this->status, $mode);
935 }
936
943 public function getLibStatut($mode = 0)
944 {
945 return $this->LibStatut($this->status, $mode);
946 }
947
948 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
956 public function LibStatut($status, $mode = 0)
957 {
958 // phpcs:enable
959 global $langs;
960
961 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
962 //$langs->load("eventorganization@eventorganization");
963 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
964 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
965 $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
966 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
967 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
968 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
969 }
970
971 $statusType = 'status'.$status;
972 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
973 if ($status == self::STATUS_CANCELED) {
974 $statusType = 'status6';
975 }
976
977 if ($status == self::STATUS_VALIDATED && $this->date_subscription && $this->amount) {
978 $statusType = 'status4';
979 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated').' - '.$langs->trans("Paid");
980 }
981
982 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
983 }
984
991 public function info($id)
992 {
993 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
994 $sql .= ' fk_user_creat, fk_user_modif';
995 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
996 $sql .= ' WHERE t.rowid = '.((int) $id);
997 $result = $this->db->query($sql);
998 if ($result) {
999 if ($this->db->num_rows($result)) {
1000 $obj = $this->db->fetch_object($result);
1001
1002 $this->id = $obj->rowid;
1003
1004 $this->user_creation_id = $obj->fk_user_creat;
1005 $this->user_modification_id = $obj->fk_user_modif;
1006 $this->date_creation = $this->db->jdate($obj->datec);
1007 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1008 }
1009
1010 $this->db->free($result);
1011 } else {
1012 dol_print_error($this->db);
1013 }
1014 }
1015
1022 public function initAsSpecimen()
1023 {
1024 return $this->initAsSpecimenCommon();
1025 }
1026
1032 public function getNextNumRef()
1033 {
1034 global $langs, $conf;
1035 $langs->load("eventorganization@eventorganization");
1036
1037 if (!getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
1038 $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON = 'mod_conferenceorboothattendee_standard';
1039 }
1040
1041 if (getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON')) {
1042 $mybool = false;
1043
1044 $file = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON') . ".php";
1045 $classname = getDolGlobalString('EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON');
1046
1047 // Include file with class
1048 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1049 foreach ($dirmodels as $reldir) {
1050 $dir = dol_buildpath($reldir."core/modules/eventorganization/");
1051
1052 // Load file with numbering class (if found)
1053 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1054 }
1055
1056 if (!$mybool) {
1057 dol_print_error(null, "Failed to include file ".$file);
1058 return '';
1059 }
1060
1061 if (class_exists($classname)) {
1062 $obj = new $classname();
1063 '@phan-var-force CommonNumRefGenerator $obj';
1064 $numref = $obj->getNextValue($this);
1065
1066 if ($numref != '' && $numref != '-1') {
1067 return $numref;
1068 } else {
1069 $this->error = $obj->error;
1070 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1071 return "";
1072 }
1073 } else {
1074 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1075 return "";
1076 }
1077 } else {
1078 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1079 return "";
1080 }
1081 }
1082
1094 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1095 {
1096 global $conf, $langs;
1097
1098 $result = 0;
1099 $includedocgeneration = 0;
1100
1101 $langs->load("eventorganization@eventorganization");
1102
1103 if (!dol_strlen($modele)) {
1104 $modele = 'standard_conferenceorboothattendee';
1105
1106 if (!empty($this->model_pdf)) {
1107 $modele = $this->model_pdf;
1108 } elseif (getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF')) {
1109 $modele = getDolGlobalString('CONFERENCEORBOOTHATTENDEE_ADDON_PDF');
1110 }
1111 }
1112
1113 $modelpath = "core/modules/eventorganization/doc/";
1114
1115 if ($includedocgeneration && !empty($modele)) {
1116 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1117 }
1118
1119 return $result;
1120 }
1121
1129 public function doScheduledJob()
1130 {
1131 global $conf, $langs;
1132
1133 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1134
1135 $error = 0;
1136 $this->output = '';
1137 $this->error = '';
1138
1139 dol_syslog(__METHOD__, LOG_DEBUG);
1140
1141 $now = dol_now();
1142
1143 $this->db->begin();
1144
1145 // ...
1146
1147 $this->db->commit();
1148
1149 return $error;
1150 }
1151
1160 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1161 {
1162 $tables = array(
1163 'eventorganization_conferenceorboothattendee'
1164 );
1165
1166 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1167 }
1168
1178 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
1179 {
1180 $lastname = $this->lastname;
1181 $firstname = $this->firstname;
1182 if (empty($lastname)) {
1183 $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 : '')))));
1184 }
1185
1186 $ret = '';
1187
1188 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
1189
1190 return dol_trunc($ret, $maxlen);
1191 }
1192}
1193
1194
1195require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1196
1201{
1202 // To complete with content of an object ConferenceOrBoothAttendeeLine
1203 // We should have a field rowid, fk_conferenceorboothattendee and position
1204
1210 public function __construct(DoliDB $db)
1211 {
1212 $this->db = $db;
1213
1214 $this->isextrafieldmanaged = 0;
1215 }
1216}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
$object ref
Definition info.php:79
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:162
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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140