myobject.class.php 39 KB

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