Passed
Branch develop (96ac0e)
by
unknown
23:19
created

ConferenceOrBoothAttendee::__construct()   F

Complexity

Conditions 17
Paths 240

Size

Total Lines 41
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 17
eloc 20
nc 240
nop 1
dl 0
loc 41
rs 3.8833
c 1
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* Copyright (C) 2017  Laurent Destailleur <[email protected]>
3
 * Copyright (C) ---Put here your own copyright and developer email---
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
/**
20
 * \file        class/conferenceorboothattendee.class.php
21
 * \ingroup     eventorganization
22
 * \brief       This file is a CRUD class file for ConferenceOrBoothAttendee (Create/Read/Update/Delete)
23
 */
24
25
// Put here all includes required by your class file
26
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29
30
/**
31
 * Class for ConferenceOrBoothAttendee
32
 */
33
class ConferenceOrBoothAttendee extends CommonObject
34
{
35
	/**
36
	 * @var string ID of module.
37
	 */
38
	public $module = 'eventorganization';
39
40
	/**
41
	 * @var string ID to identify managed object.
42
	 */
43
	public $element = 'conferenceorboothattendee';
44
45
	/**
46
	 * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
47
	 */
48
	public $table_element = 'eventorganization_conferenceorboothattendee';
49
50
	/**
51
	 * @var int  Does this object support multicompany module ?
52
	 * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
53
	 */
54
	public $ismultientitymanaged = 0;
55
56
	/**
57
	 * @var int  Does object support extrafields ? 0=No, 1=Yes
58
	 */
59
	public $isextrafieldmanaged = 1;
60
61
	/**
62
	 * @var string String with name of icon for conferenceorboothattendee. Must be the part after the 'object_' into object_conferenceorboothattendee.png
63
	 */
64
	public $picto = 'contact';
65
66
	public $paid = 0;
67
68
	const STATUS_DRAFT = 0;
69
	const STATUS_VALIDATED = 1;
70
	const STATUS_CANCELED = 9;
71
72
73
	/**
74
	 *  'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
75
	 *         Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
76
	 *  'label' the translation key.
77
	 *  'picto' is code of a picto to show before value in forms
78
	 *  'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
79
	 *  'position' is the sort order of field.
80
	 *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
81
	 *  '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)
82
	 *  'noteditable' says if field is not editable (1 or 0)
83
	 *  '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.
84
	 *  'index' if we want an index in database.
85
	 *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
86
	 *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
87
	 *  '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).
88
	 *  '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'
89
	 *  'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
90
	 *  'showoncombobox' if value of the field must be visible into the label of the combobox that list record
91
	 *  '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.
92
	 *  'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
93
	 *  'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
94
	 *  'comment' is not used. You can store here any text of your choice. It is not used by application.
95
	 *
96
	 *  Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
97
	 */
98
99
	// BEGIN MODULEBUILDER PROPERTIES
100
	/**
101
	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
102
	 */
103
	public $fields=array(
104
		'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
105
		'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>2, 'index'=>1, 'comment'=>"Reference of object"),
106
		'fk_actioncomm' => array('type'=>'integer:ActionComm:comm/action/class/actioncomm.class.php:1', 'label'=>'ConferenceOrBooth', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>0, 'index'=>1, 'picto'=>'agenda'),
107
		'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>0, 'index'=>1, 'picto'=>'project', 'css'=>'tdoverflowmax150 maxwidth500'),
108
		'email' => array('type'=>'mail', 'label'=>'EmailAttendee', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'index'=>1,),
109
		'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status = 1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>40, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'help'=>"LinkToThirparty", 'picto'=>'company', 'css'=>'tdoverflowmax150 maxwidth500'),
110
		'date_subscription' => array('type'=>'datetime', 'label'=>'DateOfRegistration', 'enabled'=>'1', 'position'=>56, 'notnull'=>0, 'visible'=>1, 'showoncombobox'=>'1',),
111
		'fk_invoice' => array('type'=>'integer:Facture:compta/facture/class/facture.class.php', 'label'=>'Invoice', 'enabled'=>'1', 'position'=>57, 'notnull'=>0, 'visible'=>-1, 'index'=>0, 'picto'=>'bill', 'css'=>'tdoverflowmax150 maxwidth500'),
112
		'amount' => array('type'=>'price', 'label'=>'AmountPaid', 'enabled'=>'1', 'position'=>57, 'notnull'=>0, 'visible'=>1, 'default'=>'null', 'isameasure'=>'1', 'help'=>"AmountOfSubscriptionPaid",),
113
		'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>3,),
114
		'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>3,),
115
		'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
116
		'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
117
		'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>-1, 'visible'=>-2),
118
		'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
119
		'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,),
120
		'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
121
		'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
122
		'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'default'=>0,'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '9'=>'Canceled'),),
123
	);
124
	public $rowid;
125
	public $ref;
126
	public $fk_soc;
127
	public $fk_actioncomm;
128
	public $email;
129
	public $date_subscription;
130
	public $fk_invoice;
131
	public $amount;
132
	public $note_public;
133
	public $note_private;
134
	public $date_creation;
135
	public $tms;
136
	public $fk_user_creat;
137
	public $fk_user_modif;
138
	public $last_main_doc;
139
	public $import_key;
140
	public $model_pdf;
141
	public $status;
142
	// END MODULEBUILDER PROPERTIES
143
144
145
	// If this object has a subtable with lines
146
147
	// /**
148
	//  * @var string    Name of subtable line
149
	//  */
150
	// public $table_element_line = 'eventorganization_conferenceorboothattendeeline';
151
152
	// /**
153
	//  * @var string    Field with ID of parent key if this object has a parent
154
	//  */
155
	// public $fk_element = 'fk_conferenceorboothattendee';
156
157
	// /**
158
	//  * @var string    Name of subtable class that manage subtable lines
159
	//  */
160
	// public $class_element_line = 'ConferenceOrBoothAttendeeline';
161
162
	// /**
163
	//  * @var array	List of child tables. To test if we can delete object.
164
	//  */
165
	// protected $childtables = array();
166
167
	// /**
168
	//  * @var array    List of child tables. To know object to delete on cascade.
169
	//  *               If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
170
	//  *               call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
171
	//  */
172
	// protected $childtablesoncascade = array('eventorganization_conferenceorboothattendeedet');
173
174
	// /**
175
	//  * @var ConferenceOrBoothAttendeeLine[]     Array of subtable lines
176
	//  */
177
	// public $lines = array();
178
179
180
181
	/**
182
	 * Constructor
183
	 *
184
	 * @param DoliDb $db Database handler
185
	 */
186
	public function __construct(DoliDB $db)
187
	{
188
		global $conf, $langs;
189
190
		$this->db = $db;
191
192
		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
193
			$this->fields['rowid']['visible'] = 0;
194
		}
195
		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
196
			$this->fields['entity']['enabled'] = 0;
197
		}
198
199
		if (!empty($conf->global->EVENTORGANIZATION_FILTERATTENDEES_CAT)) {
200
			$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.')';
201
		}
202
		if (isset($conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE)
203
			&& $conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE !== ''
204
			&& $conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE !== '-1') {
205
			$this->fields['fk_soc']['type'] .= ' AND client = '.(int) $conf->global->EVENTORGANIZATION_FILTERATTENDEES_TYPE;
206
		}
207
208
		// Example to show how to set values of fields definition dynamically
209
		/*if ($user->rights->eventorganization->conferenceorboothattendee->read) {
210
			$this->fields['myfield']['visible'] = 1;
211
			$this->fields['myfield']['noteditable'] = 0;
212
		}*/
213
214
		// Unset fields that are disabled
215
		foreach ($this->fields as $key => $val) {
216
			if (isset($val['enabled']) && empty($val['enabled'])) {
217
				unset($this->fields[$key]);
218
			}
219
		}
220
221
		// Translate some data of arrayofkeyval
222
		if (is_object($langs)) {
223
			foreach ($this->fields as $key => $val) {
224
				if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
225
					foreach ($val['arrayofkeyval'] as $key2 => $val2) {
226
						$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
227
					}
228
				}
229
			}
230
		}
231
	}
232
233
	/**
234
	 * Create object into database
235
	 *
236
	 * @param  User $user      User that creates
237
	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
238
	 * @return int             <0 if KO, Id of created object if OK
239
	 */
240
	public function create(User $user, $notrigger = false)
241
	{
242
		global $langs;
243
244
		if (!isValidEMail($this->email)) {
245
			$langs->load("errors");
246
			$this->errors[] = $langs->trans("ErrorBadEMail", $this->email);
247
			return -1;
248
		}
249
250
		$result = $this->createCommon($user, $notrigger);
251
		if ($result>0) {
252
			$result =$this->fetch($result);
253
			if ($result>0) {
254
				$this->ref = $this->id;
255
				$result = $this->update($user);
256
			}
257
		}
258
		return $result;
259
	}
260
261
	/**
262
	 * Clone an object into another one
263
	 *
264
	 * @param  	User 	$user      	User that creates
265
	 * @param  	int 	$fromid     Id of object to clone
266
	 * @return 	mixed 				New object created, <0 if KO
267
	 */
268
	public function createFromClone(User $user, $fromid)
269
	{
270
		global $langs, $extrafields;
271
		$error = 0;
272
273
		dol_syslog(__METHOD__, LOG_DEBUG);
274
275
		$object = new self($this->db);
276
277
		$this->db->begin();
278
279
		// Load source object
280
		$result = $object->fetchCommon($fromid);
281
		if ($result > 0 && !empty($object->table_element_line)) {
282
			$object->fetchLines();
283
		}
284
285
		// get lines so they will be clone
286
		//foreach($this->lines as $line)
287
		//	$line->fetch_optionals();
288
289
		// Reset some properties
290
		unset($object->id);
291
		unset($object->fk_user_creat);
292
		unset($object->import_key);
293
294
		// Clear fields
295
		if (property_exists($object, 'ref')) {
296
			$object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
297
		}
298
		if (property_exists($object, 'label')) {
299
			$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
300
		}
301
		if (property_exists($object, 'status')) {
302
			$object->status = self::STATUS_DRAFT;
303
		}
304
		if (property_exists($object, 'date_creation')) {
305
			$object->date_creation = dol_now();
306
		}
307
		if (property_exists($object, 'date_modification')) {
308
			$object->date_modification = null;
309
		}
310
		// ...
311
		// Clear extrafields that are unique
312
		if (is_array($object->array_options) && count($object->array_options) > 0) {
313
			$extrafields->fetch_name_optionals_label($this->table_element);
314
			foreach ($object->array_options as $key => $option) {
315
				$shortkey = preg_replace('/options_/', '', $key);
316
				if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
317
					//var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
318
					unset($object->array_options[$key]);
319
				}
320
			}
321
		}
322
323
		// Create clone
324
		$object->context['createfromclone'] = 'createfromclone';
325
		$result = $object->createCommon($user);
326
		if ($result < 0) {
327
			$error++;
328
			$this->error = $object->error;
329
			$this->errors = $object->errors;
330
		}
331
332
		if (!$error) {
333
			// copy internal contacts
334
			if ($this->copy_linked_contact($object, 'internal') < 0) {
335
				$error++;
336
			}
337
		}
338
339
		if (!$error) {
340
			// copy external contacts if same company
341
			if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
342
				if ($this->copy_linked_contact($object, 'external') < 0) {
343
					$error++;
344
				}
345
			}
346
		}
347
348
		unset($object->context['createfromclone']);
349
350
		// End
351
		if (!$error) {
352
			$this->db->commit();
353
			return $object;
354
		} else {
355
			$this->db->rollback();
356
			return -1;
357
		}
358
	}
359
360
	/**
361
	 * Load object in memory from the database
362
	 *
363
	 * @param int    $id   Id object
364
	 * @param string $ref  Ref
365
	 * @return int         <0 if KO, 0 if not found, >0 if OK
366
	 */
367
	public function fetch($id, $ref = null)
368
	{
369
		$result = $this->fetchCommon($id, $ref);
370
		if ($result > 0 && !empty($this->table_element_line)) {
371
			$this->fetchLines();
372
		}
373
		return $result;
374
	}
375
376
	/**
377
	 * Load object lines in memory from the database
378
	 *
379
	 * @return int         <0 if KO, 0 if not found, >0 if OK
380
	 */
381
	public function fetchLines()
382
	{
383
		$this->lines = array();
384
385
		$result = $this->fetchLinesCommon();
386
		return $result;
387
	}
388
389
390
	/**
391
	 * Load list of objects in memory from the database.
392
	 *
393
	 * @param  string      $sortorder    Sort Order
394
	 * @param  string      $sortfield    Sort field
395
	 * @param  int         $limit        limit
396
	 * @param  int         $offset       Offset
397
	 * @param  array       $filter       Filter array. Example array('field'=>'valueforlike', 'customurl'=>...). WARNING: customerurl must be a sanitized SQL string.
398
	 * @param  string      $filtermode   Filter mode (AND or OR)
399
	 * @return array|int                 int <0 if KO, array of pages if OK
400
	 */
401
	public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
402
	{
403
		global $conf;
404
405
		dol_syslog(__METHOD__, LOG_DEBUG);
406
407
		$records = array();
408
409
		$sql = 'SELECT ';
410
		$sql .= $this->getFieldList('t');
411
		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
412
		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm as a on a.id = t.fk_actioncomm";
413
		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
414
			$sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
415
		} else {
416
			$sql .= ' WHERE 1 = 1';
417
		}
418
		// Manage filter
419
		$sqlwhere = array();
420
		if (count($filter) > 0) {
421
			foreach ($filter as $key => $value) {
422
				if ($key == 't.rowid' || $key == 't.fk_soc' || $key == 't.fk_project' || $key == 't.fk_actioncomm') {
423
					$sqlwhere[] = $key.'='.((int) $value);
424
				} elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
425
					$sqlwhere[] = $key." = '".$this->db->idate($value)."'";
426
				} elseif ($key == 'customsql') {
427
					$sqlwhere[] = $value;
428
				} elseif (strpos($value, '%') === false) {
429
					$sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
430
				} else {
431
					$sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
432
				}
433
			}
434
		}
435
		if (count($sqlwhere) > 0) {
436
			$sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
437
		}
438
439
		if (!empty($sortfield)) {
440
			$sql .= $this->db->order($sortfield, $sortorder);
441
		}
442
		if (!empty($limit)) {
443
			$sql .= $this->db->plimit($limit, $offset);
444
		}
445
446
		$resql = $this->db->query($sql);
447
		if ($resql) {
448
			$num = $this->db->num_rows($resql);
449
			$i = 0;
450
			while ($i < ($limit ? min($limit, $num) : $num)) {
451
				$obj = $this->db->fetch_object($resql);
452
453
				$record = new self($this->db);
454
				$record->setVarsFromFetchObj($obj);
455
456
				$records[$record->id] = $record;
457
458
				$i++;
459
			}
460
			$this->db->free($resql);
461
462
			return $records;
463
		} else {
464
			$this->errors[] = 'Error '.$this->db->lasterror();
465
			dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
466
467
			return -1;
468
		}
469
	}
470
471
	/**
472
	 * Update object into database
473
	 *
474
	 * @param  User $user      User that modifies
475
	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
476
	 * @return int             <0 if KO, >0 if OK
477
	 */
478
	public function update(User $user, $notrigger = false)
479
	{
480
		return $this->updateCommon($user, $notrigger);
481
	}
482
483
	/**
484
	 * Delete object in database
485
	 *
486
	 * @param User $user       User that deletes
487
	 * @param bool $notrigger  false=launch triggers after, true=disable triggers
488
	 * @return int             <0 if KO, >0 if OK
489
	 */
490
	public function delete(User $user, $notrigger = false)
491
	{
492
		return $this->deleteCommon($user, $notrigger);
493
		//return $this->deleteCommon($user, $notrigger, 1);
494
	}
495
496
	/**
497
	 *  Delete a line of object in database
498
	 *
499
	 *	@param  User	$user       User that delete
500
	 *  @param	int		$idline		Id of line to delete
501
	 *  @param 	bool 	$notrigger  false=launch triggers after, true=disable triggers
502
	 *  @return int         		>0 if OK, <0 if KO
503
	 */
504
	public function deleteLine(User $user, $idline, $notrigger = false)
505
	{
506
		if ($this->status < 0) {
507
			$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
508
			return -2;
509
		}
510
511
		return $this->deleteLineCommon($user, $idline, $notrigger);
512
	}
513
514
515
	/**
516
	 *	Validate object
517
	 *
518
	 *	@param		User	$user     		User making status change
519
	 *  @param		int		$notrigger		1=Does not execute triggers, 0= execute triggers
520
	 *	@return  	int						<=0 if OK, 0=Nothing done, >0 if KO
521
	 */
522
	public function validate($user, $notrigger = 0)
523
	{
524
		global $conf, $langs;
525
526
		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
527
528
		$error = 0;
529
530
		// Protection
531
		if ($this->status == self::STATUS_VALIDATED) {
532
			dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
533
			return 0;
534
		}
535
536
		/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->conferenceorboothattendee->write))
537
		 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->conferenceorboothattendee->conferenceorboothattendee_advance->validate))))
538
		 {
539
		 $this->error='NotEnoughPermissions';
540
		 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
541
		 return -1;
542
		 }*/
543
544
		$now = dol_now();
545
546
		$this->db->begin();
547
548
		// Define new ref
549
		if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
550
			$num = $this->getNextNumRef();
551
		} else {
552
			$num = $this->ref;
553
		}
554
		$this->newref = $num;
555
556
		if (!empty($num)) {
557
			// Validate
558
			$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
559
			$sql .= " SET ref = '".$this->db->escape($num)."',";
560
			$sql .= " status = ".self::STATUS_VALIDATED;
561
			if (!empty($this->fields['date_validation'])) {
562
				$sql .= ", date_validation = '".$this->db->idate($now)."'";
563
			}
564
			if (!empty($this->fields['fk_user_valid'])) {
565
				$sql .= ", fk_user_valid = ".$user->id;
566
			}
567
			$sql .= " WHERE rowid = ".((int) $this->id);
568
569
			dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
570
			$resql = $this->db->query($sql);
571
			if (!$resql) {
572
				dol_print_error($this->db);
573
				$this->error = $this->db->lasterror();
574
				$error++;
575
			}
576
577
			if (!$error && !$notrigger) {
578
				// Call trigger
579
				$result = $this->call_trigger('CONFERENCEORBOOTHATTENDEE_VALIDATE', $user);
580
				if ($result < 0) {
581
					$error++;
582
				}
583
				// End call triggers
584
			}
585
		}
586
587
		if (!$error) {
588
			$this->oldref = $this->ref;
589
590
			// Rename directory if dir was a temporary ref
591
			if (preg_match('/^[\(]?PROV/i', $this->ref)) {
592
				// Now we rename also files into index
593
				$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)."'";
594
				$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'conferenceorboothattendee/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
595
				$resql = $this->db->query($sql);
596
				if (!$resql) {
597
					$error++; $this->error = $this->db->lasterror();
598
				}
599
600
				// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
601
				$oldref = dol_sanitizeFileName($this->ref);
602
				$newref = dol_sanitizeFileName($num);
603
				$dirsource = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$oldref;
604
				$dirdest = $conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref;
605
				if (!$error && file_exists($dirsource)) {
606
					dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
607
608
					if (@rename($dirsource, $dirdest)) {
609
						dol_syslog("Rename ok");
610
						// Rename docs starting with $oldref with $newref
611
						$listoffiles = dol_dir_list($conf->eventorganization->dir_output.'/conferenceorboothattendee/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
612
						foreach ($listoffiles as $fileentry) {
613
							$dirsource = $fileentry['name'];
614
							$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
615
							$dirsource = $fileentry['path'].'/'.$dirsource;
616
							$dirdest = $fileentry['path'].'/'.$dirdest;
617
							@rename($dirsource, $dirdest);
618
						}
619
					}
620
				}
621
			}
622
		}
623
624
		// Set new ref and current status
625
		if (!$error) {
626
			$this->ref = $num;
627
			$this->status = self::STATUS_VALIDATED;
628
		}
629
630
		if (!$error) {
631
			$this->db->commit();
632
			return 1;
633
		} else {
634
			$this->db->rollback();
635
			return -1;
636
		}
637
	}
638
639
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
640
	/**
641
	 *		Load the project with id $this->fk_project into this->project
642
	 *
643
	 *		@return		int			<0 if KO, >=0 if OK
644
	 */
645
	public function fetch_projet()
646
	{
647
		// phpcs:enable
648
		include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
649
650
		if (empty($this->fk_project) && !empty($this->fk_projet)) {
0 ignored issues
show
Bug introduced by
The property fk_projet does not exist on ConferenceOrBoothAttendee. Did you mean projet?
Loading history...
651
			$this->fk_project = $this->fk_projet; // For backward compatibility
652
		}
653
		if (empty($this->fk_project)) {
654
			return 0;
655
		}
656
657
		$project = new Project($this->db);
658
		$result = $project->fetch($this->fk_project);
659
660
		$this->projet = $project; // deprecated
661
		$this->project = $project;
662
		return $result;
663
	}
664
665
	/**
666
	 *	Set draft status
667
	 *
668
	 *	@param	User	$user			Object user that modify
669
	 *  @param	int		$notrigger		1=Does not execute triggers, 0=Execute triggers
670
	 *	@return	int						<0 if KO, >0 if OK
671
	 */
672
	public function setDraft($user, $notrigger = 0)
673
	{
674
		// Protection
675
		if ($this->status <= self::STATUS_DRAFT) {
676
			return 0;
677
		}
678
679
		/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
680
		 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
681
		 {
682
		 $this->error='Permission denied';
683
		 return -1;
684
		 }*/
685
686
		return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTHATTENDEE_UNVALIDATE');
687
	}
688
689
	/**
690
	 *	Set cancel status
691
	 *
692
	 *	@param	User	$user			Object user that modify
693
	 *  @param	int		$notrigger		1=Does not execute triggers, 0=Execute triggers
694
	 *	@return	int						<0 if KO, 0=Nothing done, >0 if OK
695
	 */
696
	public function cancel($user, $notrigger = 0)
697
	{
698
		// Protection
699
		if ($this->status != self::STATUS_VALIDATED) {
700
			return 0;
701
		}
702
703
		/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
704
		 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
705
		 {
706
		 $this->error='Permission denied';
707
		 return -1;
708
		 }*/
709
710
		return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_CANCEL');
711
	}
712
713
	/**
714
	 *	Set back to validated status
715
	 *
716
	 *	@param	User	$user			Object user that modify
717
	 *  @param	int		$notrigger		1=Does not execute triggers, 0=Execute triggers
718
	 *	@return	int						<0 if KO, 0=Nothing done, >0 if OK
719
	 */
720
	public function reopen($user, $notrigger = 0)
721
	{
722
		// Protection
723
		if ($this->status != self::STATUS_CANCELED) {
724
			return 0;
725
		}
726
727
		/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
728
		 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
729
		 {
730
		 $this->error='Permission denied';
731
		 return -1;
732
		 }*/
733
734
		return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CONFERENCEORBOOTHATTENDEE_REOPEN');
735
	}
736
737
	/**
738
	 *  Return a link to the object card (with optionaly the picto)
739
	 *
740
	 *  @param  int     $withpicto                  Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
741
	 *  @param  string  $option                     On what the link point to ('nolink', ...)
742
	 *  @param  int     $notooltip                  1=Disable tooltip
743
	 *  @param  string  $morecss                    Add more css on link
744
	 *  @param  int     $save_lastsearch_value      -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
745
	 *  @return	string                              String with URL
746
	 */
747
	public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
748
	{
749
		global $conf, $langs, $hookmanager;
750
751
		if (!empty($conf->dol_no_mouse_hover)) {
752
			$notooltip = 1; // Force disable tooltips
753
		}
754
755
		$result = '';
756
757
		$label = img_picto('', $this->picto).' <u>'.$langs->trans("ConferenceOrBoothAttendee").'</u>';
758
		if (isset($this->status)) {
759
			$label .= ' '.$this->getLibStatut(5);
760
		}
761
		$label .= '<br>';
762
		$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
763
		$label .= '<br><b>'.$langs->trans('DateOfRegistration').':</b> '.dol_print_date($this->date_subscription, 'dayhour');
764
		$label .= '<br><b>'.$langs->trans('AmountPaid').':</b> '.$this->amount;
765
766
		$url = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.$this->id;
767
768
		if ($option != 'nolink') {
769
			// Add param to save lastsearch_values or not
770
			$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
771
			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
772
				$add_save_lastsearch_values = 1;
773
			}
774
			if ($add_save_lastsearch_values) {
775
				$url .= '&save_lastsearch_values=1';
776
			}
777
778
			if ($option == 'conforboothid') {
779
				$url .= '&conforboothid='.((int) $this->fk_actioncomm);
780
			}
781
782
			if ($option == 'projectid') {
783
				$url .= '&fk_project='.((int) $this->fk_project).'&withproject=1';
784
			}
785
786
			if ($option == 'conforboothidproject') {
787
				$url .= '&conforboothid='.((int) $this->fk_actioncomm).'&withproject=1' ;
788
			}
789
		}
790
791
		$linkclose = '';
792
		if (empty($notooltip)) {
793
			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
794
				$label = $langs->trans("ShowConferenceOrBoothAttendee");
795
				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
796
			}
797
			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
798
			$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
799
		} else {
800
			$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
801
		}
802
803
		if ($option == 'nolink') {
804
			$linkstart = '<span';
805
		} else {
806
			$linkstart = '<a href="'.$url.'"';
807
		}
808
		$linkstart .= $linkclose.'>';
809
		if ($option == 'nolink') {
810
			$linkend = '</span>';
811
		} else {
812
			$linkend = '</a>';
813
		}
814
815
		$result .= $linkstart;
816
817
		if (empty($this->showphoto_on_popup)) {
818
			if ($withpicto) {
819
				$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
820
			}
821
		} else {
822
			if ($withpicto) {
823
				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
824
825
				list($class, $module) = explode('@', $this->picto);
826
				$upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
827
				$filearray = dol_dir_list($upload_dir, "files");
828
				$filename = $filearray[0]['name'];
829
				if (!empty($filename)) {
830
					$pospoint = strpos($filearray[0]['name'], '.');
831
832
					$pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
833
					if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
834
						$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>';
835
					} else {
836
						$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>';
837
					}
838
839
					$result .= '</div>';
840
				} else {
841
					$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);
842
				}
843
			}
844
		}
845
846
		if ($withpicto != 2) {
847
			$result .= $this->ref;
848
		}
849
850
		$result .= $linkend;
851
		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
852
853
		global $action, $hookmanager;
854
		$hookmanager->initHooks(array('conferenceorboothattendeedao'));
855
		$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
856
		$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
857
		if ($reshook > 0) {
858
			$result = $hookmanager->resPrint;
859
		} else {
860
			$result .= $hookmanager->resPrint;
861
		}
862
863
		return $result;
864
	}
865
866
	/**
867
	 *  Return the label of the status
868
	 *
869
	 *  @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
870
	 *  @return	string 			       Label of status
871
	 */
872
	public function getLabelStatus($mode = 0)
873
	{
874
		return $this->LibStatut($this->status, $mode);
875
	}
876
877
	/**
878
	 *  Return the label of the status
879
	 *
880
	 *  @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
881
	 *  @return	string 			       Label of status
882
	 */
883
	public function getLibStatut($mode = 0)
884
	{
885
		return $this->LibStatut($this->status, $mode);
886
	}
887
888
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
889
	/**
890
	 *  Return the status
891
	 *
892
	 *  @param	int		$status        Id status
893
	 *  @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
894
	 *  @return string 			       Label of status
895
	 */
896
	public function LibStatut($status, $mode = 0)
897
	{
898
		// phpcs:enable
899
		global $langs;
900
901
		if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
902
			//$langs->load("eventorganization@eventorganization");
903
			$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
904
			$this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
905
			$this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
906
			$this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
907
			$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
908
			$this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
909
		}
910
911
		$statusType = 'status'.$status;
912
		//if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
913
		if ($status == self::STATUS_CANCELED) {
914
			$statusType = 'status6';
915
		}
916
917
		if ($status == self::STATUS_VALIDATED && $this->date_subscription && $this->amount) {
918
			$statusType = 'status4';
919
			$this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated').' - '.$langs->trans("Paid");
920
		}
921
922
		return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
923
	}
924
925
	/**
926
	 *	Load the info information in the object
927
	 *
928
	 *	@param  int		$id       Id of object
929
	 *	@return	void
930
	 */
931
	public function info($id)
932
	{
933
		$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
934
		$sql .= ' fk_user_creat, fk_user_modif';
935
		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
936
		$sql .= ' WHERE t.rowid = '.((int) $id);
937
		$result = $this->db->query($sql);
938
		if ($result) {
939
			if ($this->db->num_rows($result)) {
940
				$obj = $this->db->fetch_object($result);
941
				$this->id = $obj->rowid;
942
				if ($obj->fk_user_author) {
943
					$cuser = new User($this->db);
944
					$cuser->fetch($obj->fk_user_author);
945
					$this->user_creation = $cuser;
946
				}
947
948
				if ($obj->fk_user_valid) {
949
					$vuser = new User($this->db);
950
					$vuser->fetch($obj->fk_user_valid);
951
					$this->user_validation = $vuser;
952
				}
953
954
				if ($obj->fk_user_cloture) {
955
					$cluser = new User($this->db);
956
					$cluser->fetch($obj->fk_user_cloture);
957
					$this->user_cloture = $cluser;
958
				}
959
960
				$this->date_creation     = $this->db->jdate($obj->datec);
961
				$this->date_modification = $this->db->jdate($obj->datem);
962
				$this->date_validation   = $this->db->jdate($obj->datev);
963
			}
964
965
			$this->db->free($result);
966
		} else {
967
			dol_print_error($this->db);
968
		}
969
	}
970
971
	/**
972
	 * Initialise object with example values
973
	 * Id must be 0 if object instance is a specimen
974
	 *
975
	 * @return void
976
	 */
977
	public function initAsSpecimen()
978
	{
979
		$this->initAsSpecimenCommon();
980
	}
981
982
	/**
983
	 * 	Create an array of lines
984
	 *
985
	 * 	@return array|int		array of lines if OK, <0 if KO
986
	 */
987
	public function getLinesArray()
988
	{
989
		$this->lines = array();
990
991
		$objectline = new ConferenceOrBoothAttendeeLine($this->db);
992
		$result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_conferenceorboothattendee = '.((int) $this->id)));
0 ignored issues
show
Bug introduced by
The method fetchAll() does not exist on ConferenceOrBoothAttendeeLine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

992
		/** @scrutinizer ignore-call */ 
993
  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_conferenceorboothattendee = '.((int) $this->id)));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
993
994
		if (is_numeric($result)) {
995
			$this->error = $this->error;
996
			$this->errors = $this->errors;
997
			return $result;
998
		} else {
999
			$this->lines = $result;
1000
			return $this->lines;
1001
		}
1002
	}
1003
1004
	/**
1005
	 *  Returns the reference to the following non used object depending on the active numbering module.
1006
	 *
1007
	 *  @return string      		Object free reference
1008
	 */
1009
	public function getNextNumRef()
1010
	{
1011
		global $langs, $conf;
1012
		$langs->load("eventorganization@eventorganization");
1013
1014
		if (empty($conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON)) {
1015
			$conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON = 'mod_conferenceorboothattendee_standard';
1016
		}
1017
1018
		if (!empty($conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON)) {
1019
			$mybool = false;
1020
1021
			$file = $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON.".php";
1022
			$classname = $conf->global->EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_ADDON;
1023
1024
			// Include file with class
1025
			$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1026
			foreach ($dirmodels as $reldir) {
1027
				$dir = dol_buildpath($reldir."core/modules/eventorganization/");
1028
1029
				// Load file with numbering class (if found)
1030
				$mybool |= @include_once $dir.$file;
1031
			}
1032
1033
			if ($mybool === false) {
1034
				dol_print_error('', "Failed to include file ".$file);
1035
				return '';
1036
			}
1037
1038
			if (class_exists($classname)) {
1039
				$obj = new $classname();
1040
				$numref = $obj->getNextValue($this);
1041
1042
				if ($numref != '' && $numref != '-1') {
1043
					return $numref;
1044
				} else {
1045
					$this->error = $obj->error;
1046
					//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1047
					return "";
1048
				}
1049
			} else {
1050
				print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1051
				return "";
1052
			}
1053
		} else {
1054
			print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1055
			return "";
1056
		}
1057
	}
1058
1059
	/**
1060
	 *  Create a document onto disk according to template module.
1061
	 *
1062
	 *  @param	    string		$modele			Force template to use ('' to not force)
1063
	 *  @param		Translate	$outputlangs	objet lang a utiliser pour traduction
1064
	 *  @param      int			$hidedetails    Hide details of lines
1065
	 *  @param      int			$hidedesc       Hide description
1066
	 *  @param      int			$hideref        Hide ref
1067
	 *  @param      null|array  $moreparams     Array to provide more information
1068
	 *  @return     int         				0 if KO, 1 if OK
1069
	 */
1070
	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1071
	{
1072
		global $conf, $langs;
1073
1074
		$result = 0;
1075
		$includedocgeneration = 0;
1076
1077
		$langs->load("eventorganization@eventorganization");
1078
1079
		if (!dol_strlen($modele)) {
1080
			$modele = 'standard_conferenceorboothattendee';
1081
1082
			if (!empty($this->model_pdf)) {
1083
				$modele = $this->model_pdf;
1084
			} elseif (!empty($conf->global->CONFERENCEORBOOTHATTENDEE_ADDON_PDF)) {
1085
				$modele = $conf->global->CONFERENCEORBOOTHATTENDEE_ADDON_PDF;
1086
			}
1087
		}
1088
1089
		$modelpath = "core/modules/eventorganization/doc/";
1090
1091
		if ($includedocgeneration && !empty($modele)) {
1092
			$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1093
		}
1094
1095
		return $result;
1096
	}
1097
1098
	/**
1099
	 * Action executed by scheduler
1100
	 * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
1101
	 * Use public function doScheduledJob($param1, $param2, ...) to get parameters
1102
	 *
1103
	 * @return	int			0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
1104
	 */
1105
	public function doScheduledJob()
1106
	{
1107
		global $conf, $langs;
1108
1109
		//$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1110
1111
		$error = 0;
1112
		$this->output = '';
1113
		$this->error = '';
1114
1115
		dol_syslog(__METHOD__, LOG_DEBUG);
1116
1117
		$now = dol_now();
1118
1119
		$this->db->begin();
1120
1121
		// ...
1122
1123
		$this->db->commit();
1124
1125
		return $error;
1126
	}
1127
1128
	/**
1129
	 * Function used to replace a thirdparty id with another one.
1130
	 *
1131
	 * @param DoliDB $db Database handler
1132
	 * @param int $origin_id Old thirdparty id
1133
	 * @param int $dest_id New thirdparty id
1134
	 * @return bool
1135
	 */
1136
	public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1137
	{
1138
		$tables = array(
1139
			'eventorganization_conferenceorboothattendee'
1140
		);
1141
1142
		return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1143
	}
1144
}
1145
1146
1147
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1148
1149
/**
1150
 * Class ConferenceOrBoothAttendeeLine. You can also remove this and generate a CRUD class for lines objects.
1151
 */
1152
class ConferenceOrBoothAttendeeLine extends CommonObjectLine
1153
{
1154
	// To complete with content of an object ConferenceOrBoothAttendeeLine
1155
	// We should have a field rowid, fk_conferenceorboothattendee and position
1156
1157
	/**
1158
	 * @var int  Does object support extrafields ? 0=No, 1=Yes
1159
	 */
1160
	public $isextrafieldmanaged = 0;
1161
1162
	/**
1163
	 * Constructor
1164
	 *
1165
	 * @param DoliDb $db Database handler
1166
	 */
1167
	public function __construct(DoliDB $db)
1168
	{
1169
		$this->db = $db;
1170
	}
1171
}
1172