conferenceorboothattendee.class.php 41 KB

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