eventproduct.class.php.back 40 KB

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