conferenceorboothattendee.class.php 41 KB

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