Passed
Branch develop (59f205)
by
unknown
29:12
created

ConferenceOrBooth::info()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 18
nc 4
nop 1
dl 0
loc 24
rs 9.6666
c 1
b 0
f 0
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/conferenceorbooth.class.php
21
 * \ingroup     eventorganization
22
 * \brief       This file is a CRUD class file for ConferenceOrBooth (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 . '/comm/action/class/actioncomm.class.php';
28
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29
30
/**
31
 * Class for ConferenceOrBooth
32
 */
33
class ConferenceOrBooth extends ActionComm
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 = 'conferenceorbooth';
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 = 'actioncomm';
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 = 1;
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 conferenceorbooth. Must be the part after the 'object_' into object_conferenceorbooth.png
63
	 */
64
	public $picto = 'conferenceorbooth@eventorganization';
65
66
67
	const STATUS_DRAFT = 0;
68
	const STATUS_SUGGESTED = 1;
69
	const STATUS_CONFIRMED = 2;
70
	const STATUS_NOT_QUALIFIED = 3;
71
	const STATUS_DONE = 4;
72
	const STATUS_CANCELED = -1;
73
74
75
	/**
76
	 *  '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')
77
	 *         Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
78
	 *  'label' the translation key.
79
	 *  'picto' is code of a picto to show before value in forms
80
	 *  'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
81
	 *  'position' is the sort order of field.
82
	 *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
83
	 *  '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)
84
	 *  'noteditable' says if field is not editable (1 or 0)
85
	 *  '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.
86
	 *  'index' if we want an index in database.
87
	 *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
88
	 *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
89
	 *  '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).
90
	 *  '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'
91
	 *  'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
92
	 *  'showoncombobox' if value of the field must be visible into the label of the combobox that list record
93
	 *  '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.
94
	 *  'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
95
	 *  'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
96
	 *  'comment' is not used. You can store here any text of your choice. It is not used by application.
97
	 *
98
	 *  Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
99
	 */
100
101
	// BEGIN MODULEBUILDER PROPERTIES
102
	/**
103
	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
104
	 */
105
	public $fields=array(
106
		'id' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
107
		'ref' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
108
		'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'help'=>"Help text", 'showoncombobox'=>'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'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'help'=>"LinkToThirparty",),
110
		'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'1', 'position'=>52, 'notnull'=>-1, 'visible'=>-1, 'index'=>1,),
111
		'note' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>1,),
112
		'fk_action' => array('type'=>'sellist:c_actioncomm:label:rowid::module LIKE (\'conference\',\'booth\'))', 'label'=>'Format', 'enabled'=>'1', 'position'=>60, 'notnull'=>1, 'visible'=>1,),
113
		'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
114
		'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
115
		'fk_user_author' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
116
		'fk_user_mod' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
117
		'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
118
		'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Valid&eacute;', '9'=>'Annul&eacute;'),),
119
	);
120
	public $rowid;
121
	public $id;
122
	public $label;
123
	public $fk_soc;
124
	public $fk_project;
125
	public $note;
126
	public $fk_action;
127
	public $datec;
128
	public $tms;
129
	public $fk_user_author;
130
	public $fk_user_mod;
131
	public $import_key;
132
	public $status;
133
	// END MODULEBUILDER PROPERTIES
134
135
	/**
136
	 * Constructor
137
	 *
138
	 * @param DoliDb $db Database handler
139
	 */
140
	public function __construct(DoliDB $db)
141
	{
142
		global $conf, $langs;
143
144
		$this->db = $db;
145
146
		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
147
			$this->fields['id']['visible'] = 0;
148
		}
149
		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
150
			$this->fields['entity']['enabled'] = 0;
151
		}
152
153
		// Example to show how to set values of fields definition dynamically
154
		/*if ($user->rights->eventorganization->conferenceorbooth->read) {
155
			$this->fields['myfield']['visible'] = 1;
156
			$this->fields['myfield']['noteditable'] = 0;
157
		}*/
158
159
		// Unset fields that are disabled
160
		foreach ($this->fields as $key => $val) {
161
			if (isset($val['enabled']) && empty($val['enabled'])) {
162
				unset($this->fields[$key]);
163
			}
164
		}
165
166
		// Translate some data of arrayofkeyval
167
		if (is_object($langs)) {
168
			foreach ($this->fields as $key => $val) {
169
				if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
170
					foreach ($val['arrayofkeyval'] as $key2 => $val2) {
171
						$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
172
					}
173
				}
174
			}
175
		}
176
	}
177
178
	/**
179
	 * Create object into database
180
	 *
181
	 * @param  User $user      User that creates
182
	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
183
	 * @return int             <0 if KO, Id of created object if OK
184
	 */
185
	public function create(User $user, $notrigger = false)
186
	{
187
		$this->setPercentageFromStatus();
188
		return parent::create($user, $notrigger);
189
	}
190
191
	/**
192
	 * Set Percentage from status
193
	 */
194
	public function setPercentageFromStatus()
195
	{
196
		if ($this->status==self::STATUS_DONE) {
197
			$this->percentage=100;
198
		}
199
		if ($this->status==self::STATUS_DRAFT) {
200
			$this->percentage=0;
201
		}
202
	}
203
204
	/**
205
	 * Load object in memory from the database
206
	 *
207
	 * @param int    $id   Id object
208
	 * @param string $ref  Ref
209
	 * @return int         <0 if KO, 0 if not found, >0 if OK
210
	 */
211
	public function fetch($id, $ref = null)
212
	{
213
		$result = parent::fetch($id, $ref);
214
		return $result;
215
	}
216
217
	/**
218
	 * Load list of objects in memory from the database.
219
	 *
220
	 * @param  string      $sortorder    Sort Order
221
	 * @param  string      $sortfield    Sort field
222
	 * @param  int         $limit        limit
223
	 * @param  int         $offset       Offset
224
	 * @param  array       $filter       Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
225
	 * @param  string      $filtermode   Filter mode (AND or OR)
226
	 * @return array|int                 int <0 if KO, array of pages if OK
227
	 */
228
	public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
229
	{
230
231
		//TODO set percent according status
232
		global $conf;
233
234
		dol_syslog(__METHOD__, LOG_DEBUG);
235
236
		$records = array();
237
238
		$sql = 'SELECT ';
239
		$sql .= $this->getFieldList();
240
		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
241
		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
242
			$sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
243
		} else {
244
			$sql .= ' WHERE 1 = 1';
245
		}
246
		// Manage filter
247
		$sqlwhere = array();
248
		if (count($filter) > 0) {
249
			foreach ($filter as $key => $value) {
250
				if ($key == 't.id') {
251
					$sqlwhere[] = $key.'='.$value;
252
				} elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
253
					$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
254
				} elseif ($key == 'customsql') {
255
					$sqlwhere[] = $value;
256
				} elseif (strpos($value, '%') === false) {
257
					$sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
258
				} else {
259
					$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
260
				}
261
			}
262
		}
263
		if (count($sqlwhere) > 0) {
264
			$sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
265
		}
266
267
		if (!empty($sortfield)) {
268
			$sql .= $this->db->order($sortfield, $sortorder);
269
		}
270
		if (!empty($limit)) {
271
			$sql .= ' '.$this->db->plimit($limit, $offset);
272
		}
273
274
		$resql = $this->db->query($sql);
275
		if ($resql) {
276
			$num = $this->db->num_rows($resql);
277
			$i = 0;
278
			while ($i < ($limit ? min($limit, $num) : $num)) {
279
				$obj = $this->db->fetch_object($resql);
280
281
				$record = new self($this->db);
282
				$record->setVarsFromFetchObj($obj);
283
284
				$records[$record->id] = $record;
285
286
				$i++;
287
			}
288
			$this->db->free($resql);
289
290
			return $records;
291
		} else {
292
			$this->errors[] = 'Error '.$this->db->lasterror();
293
			dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
294
295
			return -1;
296
		}
297
	}
298
299
	/**
300
	 * Update object into database
301
	 *
302
	 * @param  User $user      User that modifies
303
	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
304
	 * @return int             <0 if KO, >0 if OK
305
	 */
306
	public function update(User $user, $notrigger = false)
307
	{
308
		$this->setPercentageFromStatus();
309
		return parent::update($user, $notrigger);
310
	}
311
312
	/**
313
	 * Delete object in database
314
	 *
315
	 * @param User $user       User that deletes
316
	 * @param bool $notrigger  false=launch triggers after, true=disable triggers
317
	 * @return int             <0 if KO, >0 if OK
318
	 */
319
	public function delete(User $user, $notrigger = false)
320
	{
321
		//TODO delete attendees and subscription
322
		return parent::delete($notrigger);
323
	}
324
325
	/**
326
	 *	Validate object
327
	 *
328
	 *	@param		User	$user     		User making status change
329
	 *  @param		int		$notrigger		1=Does not execute triggers, 0= execute triggers
330
	 *	@return  	int						<=0 if OK, 0=Nothing done, >0 if KO
331
	 */
332
	public function validate($user, $notrigger = 0)
333
	{
334
		global $conf, $langs;
335
336
		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
337
338
		$error = 0;
339
340
		// Protection
341
		if ($this->status == self::STATUS_VALIDATED) {
0 ignored issues
show
Bug introduced by
The constant ConferenceOrBooth::STATUS_VALIDATED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
342
			dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
343
			return 0;
344
		}
345
346
		$now = dol_now();
347
348
		$this->db->begin();
349
350
		// Validate
351
		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
352
		$sql .= " status = ".self::STATUS_CONFIRMED;
353
		$sql .= " WHERE id = ".$this->id;
354
355
		dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
356
		$resql = $this->db->query($sql);
357
		if (!$resql) {
358
			dol_print_error($this->db);
359
			$this->error = $this->db->lasterror();
360
			$error++;
361
		}
362
363
		if (!$error && !$notrigger) {
364
			// Call trigger
365
			$result = $this->call_trigger('CONFERENCEORBOOTH_VALIDATE', $user);
366
			if ($result < 0) $error++;
367
			// End call triggers
368
		}
369
370
		if (!$error) {
371
			$this->oldref = $this->ref;
372
373
			// Rename directory if dir was a temporary ref
374
			if (preg_match('/^[\(]?PROV/i', $this->ref)) {
375
				// Now we rename also files into index
376
				$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'conferenceorbooth/".$this->db->escape($this->newref)."'";
377
				$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'conferenceorbooth/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
378
				$resql = $this->db->query($sql);
379
				if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
380
381
				// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
382
				$oldref = dol_sanitizeFileName($this->ref);
383
				$newref = dol_sanitizeFileName($num);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $num seems to be never defined.
Loading history...
384
				$dirsource = $conf->eventorganization->dir_output.'/conferenceorbooth/'.$oldref;
385
				$dirdest = $conf->eventorganization->dir_output.'/conferenceorbooth/'.$newref;
386
				if (!$error && file_exists($dirsource)) {
387
					dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
388
389
					if (@rename($dirsource, $dirdest)) {
390
						dol_syslog("Rename ok");
391
						// Rename docs starting with $oldref with $newref
392
						$listoffiles = dol_dir_list($conf->eventorganization->dir_output.'/conferenceorbooth/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
393
						foreach ($listoffiles as $fileentry) {
394
							$dirsource = $fileentry['name'];
395
							$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
396
							$dirsource = $fileentry['path'].'/'.$dirsource;
397
							$dirdest = $fileentry['path'].'/'.$dirdest;
398
							@rename($dirsource, $dirdest);
399
						}
400
					}
401
				}
402
			}
403
		}
404
405
		// Set new ref and current status
406
		if (!$error) {
407
			$this->ref = $num;
408
			$this->status = self::STATUS_CONFIRMED;
409
		}
410
411
		if (!$error) {
412
			$this->db->commit();
413
			return 1;
414
		} else {
415
			$this->db->rollback();
416
			return -1;
417
		}
418
	}
419
420
421
	/**
422
	 *	Set draft status
423
	 *
424
	 *	@param	User	$user			Object user that modify
425
	 *  @param	int		$notrigger		1=Does not execute triggers, 0=Execute triggers
426
	 *	@return	int						<0 if KO, >0 if OK
427
	 */
428
	public function setDraft($user, $notrigger = 0)
429
	{
430
		// Protection
431
		if ($this->status <= self::STATUS_DRAFT) {
432
			return 0;
433
		}
434
435
		/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
436
		 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
437
		 {
438
		 $this->error='Permission denied';
439
		 return -1;
440
		 }*/
441
442
		return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CONFERENCEORBOOTH_UNVALIDATE');
443
	}
444
445
	/**
446
	 *	Set cancel status
447
	 *
448
	 *	@param	User	$user			Object user that modify
449
	 *  @param	int		$notrigger		1=Does not execute triggers, 0=Execute triggers
450
	 *	@return	int						<0 if KO, 0=Nothing done, >0 if OK
451
	 */
452
	public function cancel($user, $notrigger = 0)
453
	{
454
		// Protection
455
		if ($this->status != self::STATUS_CONFIRMED) {
456
			return 0;
457
		}
458
459
		/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
460
		 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
461
		 {
462
		 $this->error='Permission denied';
463
		 return -1;
464
		 }*/
465
466
		return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CONFERENCEORBOOTH_CANCEL');
467
	}
468
469
	/**
470
	 *	Set back to validated status
471
	 *
472
	 *	@param	User	$user			Object user that modify
473
	 *  @param	int		$notrigger		1=Does not execute triggers, 0=Execute triggers
474
	 *	@return	int						<0 if KO, 0=Nothing done, >0 if OK
475
	 */
476
	public function reopen($user, $notrigger = 0)
477
	{
478
		// Protection
479
		if ($this->status != self::STATUS_CANCELED) {
480
			return 0;
481
		}
482
483
		/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->write))
484
		 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->eventorganization->eventorganization_advance->validate))))
485
		 {
486
		 $this->error='Permission denied';
487
		 return -1;
488
		 }*/
489
490
		return $this->setStatusCommon($user, self::STATUS_CONFIRMED, $notrigger, 'CONFERENCEORBOOTH_REOPEN');
491
	}
492
493
	/**
494
	 *  Return a link to the object card (with optionaly the picto)
495
	 *
496
	 *  @param  int     $withpicto                  Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
497
	 *  @param  string  $option                     On what the link point to ('nolink', ...)
498
	 *  @param  int     $notooltip                  1=Disable tooltip
499
	 *  @param  string  $morecss                    Add more css on link
500
	 *  @param  int     $save_lastsearch_value      -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
501
	 *  @return	string                              String with URL
502
	 */
503
	public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
504
	{
505
		global $conf, $langs, $hookmanager;
506
507
		if (!empty($conf->dol_no_mouse_hover)) {
508
			$notooltip = 1; // Force disable tooltips
509
		}
510
511
		$result = '';
512
513
		$label = img_picto('', $this->picto).' <u>'.$langs->trans("ConferenceOrBooth").'</u>';
514
		if (isset($this->status)) {
515
			$label .= ' '.$this->getLibStatut(5);
516
		}
517
		$label .= '<br>';
518
		$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->id;
519
520
		$url = dol_buildpath('/eventorganization/conferenceorbooth_card.php', 1).'?id='.$this->id;
521
522
		if ($option != 'nolink') {
523
			// Add param to save lastsearch_values or not
524
			$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
525
			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
526
				$add_save_lastsearch_values = 1;
527
			}
528
			if ($add_save_lastsearch_values) {
529
				$url .= '&save_lastsearch_values=1';
530
			}
531
		}
532
533
		$linkclose = '';
534
		if (empty($notooltip)) {
535
			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
536
				$label = $langs->trans("ShowConferenceOrBooth");
537
				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
538
			}
539
			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
540
			$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
541
		} else {
542
			$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
543
		}
544
545
		$linkstart = '<a href="'.$url.'"';
546
		$linkstart .= $linkclose.'>';
547
		$linkend = '</a>';
548
549
		$result .= $linkstart;
550
551
		if (empty($this->showphoto_on_popup)) {
552
			if ($withpicto) {
553
				$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);
554
			}
555
		} else {
556
			if ($withpicto) {
557
				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
558
559
				list($class, $module) = explode('@', $this->picto);
560
				$upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
561
				$filearray = dol_dir_list($upload_dir, "files");
562
				$filename = $filearray[0]['name'];
563
				if (!empty($filename)) {
564
					$pospoint = strpos($filearray[0]['name'], '.');
565
566
					$pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
567
					if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
568
						$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>';
569
					} else {
570
						$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>';
571
					}
572
573
					$result .= '</div>';
574
				} else {
575
					$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);
576
				}
577
			}
578
		}
579
580
		if ($withpicto != 2) {
581
			$result .= $this->ref;
582
		}
583
584
		$result .= $linkend;
585
		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
586
587
		global $action, $hookmanager;
588
		$hookmanager->initHooks(array('conferenceorboothdao'));
589
		$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
590
		$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
591
		if ($reshook > 0) {
592
			$result = $hookmanager->resPrint;
593
		} else {
594
			$result .= $hookmanager->resPrint;
595
		}
596
597
		return $result;
598
	}
599
600
	/**
601
	 *  Return the label of the status
602
	 *
603
	 *  @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
604
	 *  @return	string 			       Label of status
605
	 */
606
	public function getLibStatut($mode = 0)
607
	{
608
		return $this->LibStatut($this->status, $mode);
609
	}
610
611
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
612
	/**
613
	 *  Return the status
614
	 *
615
	 *  @param	int		$status        Id status
616
	 *  @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
617
	 *  @return string 			       Label of status
618
	 */
619
	public function LibStatut($status, $mode = 0)
620
	{
621
		// phpcs:enable
622
		if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
623
			global $langs;
624
			//$langs->load("eventorganization@eventorganization");
625
			$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
626
			$this->labelStatus[self::STATUS_SUGGESTED] = $langs->trans('Suggested');
627
			$this->labelStatus[self::STATUS_CONFIRMED] = $langs->trans('Confirmed');
628
			$this->labelStatus[self::STATUS_NOTSELECTED] = $langs->trans('NotSelected');
0 ignored issues
show
Bug introduced by
The constant ConferenceOrBooth::STATUS_NOTSELECTED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
629
			$this->labelStatus[self::STATUS_DONE] = $langs->trans('Done');
630
			$this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Canceled');
631
			$this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
632
			$this->labelStatusShort[self::STATUS_SUGGESTED] = $langs->trans('Suggested');
633
			$this->labelStatusShort[self::STATUS_CONFIRMED] = $langs->trans('Confirmed');
634
			$this->labelStatusShort[self::STATUS_NOTSELECTED] = $langs->trans('NotSelected');
635
			$this->labelStatusShort[self::STATUS_DONE] = $langs->trans('Done');
636
			$this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Canceled');
637
		}
638
639
		$statusType = 'status'.$status;
640
		//if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
641
		if ($status == self::STATUS_CANCELED) {
642
			$statusType = 'status6';
643
		}
644
645
		return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
646
	}
647
648
	/**
649
	 *	Load the info information in the object
650
	 *
651
	 *	@param  int		$id       Id of object
652
	 *	@return	void
653
	 */
654
	public function info($id)
655
	{
656
		$sql = 'SELECT rowid, datec as datec, tms as datem,';
657
		$sql .= ' fk_user_author, fk_user_mod';
658
		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
659
		$sql .= ' WHERE t.id = '.$id;
660
		$result = $this->db->query($sql);
661
		if ($result) {
662
			if ($this->db->num_rows($result)) {
663
				$obj = $this->db->fetch_object($result);
664
				$this->id = $obj->rowid;
665
				if ($obj->fk_user_author) {
666
					$cuser = new User($this->db);
667
					$cuser->fetch($obj->fk_user_author);
668
					$this->user_creation = $cuser;
669
				}
670
671
				$this->date_creation     = $this->db->jdate($obj->datec);
672
				$this->date_modification = $this->db->jdate($obj->datem);
673
			}
674
675
			$this->db->free($result);
676
		} else {
677
			dol_print_error($this->db);
678
		}
679
	}
680
681
	/**
682
	 * Initialise object with example values
683
	 * Id must be 0 if object instance is a specimen
684
	 *
685
	 * @return void
686
	 */
687
	public function initAsSpecimen()
688
	{
689
		$this->initAsSpecimenCommon();
690
	}
691
692
	/**
693
	 * 	Create an array of lines
694
	 *
695
	 * 	@return array|int		array of lines if OK, <0 if KO
696
	 */
697
	public function getLinesArray()
698
	{
699
		$this->lines = array();
700
701
		$objectline = new ConferenceOrBoothLine($this->db);
0 ignored issues
show
Bug introduced by
The type ConferenceOrBoothLine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
702
		$result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_conferenceorbooth = '.$this->id));
703
704
		if (is_numeric($result)) {
705
			$this->error = $this->error;
706
			$this->errors = $this->errors;
707
			return $result;
708
		} else {
709
			$this->lines = $result;
710
			return $this->lines;
711
		}
712
	}
713
714
	/**
715
	 *  Create a document onto disk according to template module.
716
	 *
717
	 *  @param	    string		$modele			Force template to use ('' to not force)
718
	 *  @param		Translate	$outputlangs	objet lang a utiliser pour traduction
719
	 *  @param      int			$hidedetails    Hide details of lines
720
	 *  @param      int			$hidedesc       Hide description
721
	 *  @param      int			$hideref        Hide ref
722
	 *  @param      null|array  $moreparams     Array to provide more information
723
	 *  @return     int         				0 if KO, 1 if OK
724
	 */
725
	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
726
	{
727
		global $conf, $langs;
728
729
		$result = 0;
730
		$includedocgeneration = 0;
731
732
		$langs->load("eventorganization@eventorganization");
733
734
		if (!dol_strlen($modele)) {
735
			$modele = 'standard_conferenceorbooth';
736
737
			if (!empty($this->model_pdf)) {
738
				$modele = $this->model_pdf;
739
			} elseif (!empty($conf->global->CONFERENCEORBOOTH_ADDON_PDF)) {
740
				$modele = $conf->global->CONFERENCEORBOOTH_ADDON_PDF;
741
			}
742
		}
743
744
		$modelpath = "core/modules/eventorganization/doc/";
745
746
		if ($includedocgeneration && !empty($modele)) {
747
			$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
748
		}
749
750
		return $result;
751
	}
752
753
	/**
754
	 * Action executed by scheduler
755
	 * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
756
	 * Use public function doScheduledJob($param1, $param2, ...) to get parameters
757
	 *
758
	 * @return	int			0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
759
	 */
760
	public function doScheduledJob()
761
	{
762
		global $conf, $langs;
763
764
		//$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
765
766
		$error = 0;
767
		$this->output = '';
768
		$this->error = '';
769
770
		dol_syslog(__METHOD__, LOG_DEBUG);
771
772
		$now = dol_now();
773
774
		$this->db->begin();
775
776
		// ...
777
778
		$this->db->commit();
779
780
		return $error;
781
	}
782
}
783