cticketcategory.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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 CTicketCategory extends CommonObject
  31. {
  32. /**
  33. * @var string ID of module.
  34. */
  35. public $module = 'ticket';
  36. /**
  37. * @var string ID to identify managed object.
  38. */
  39. public $element = 'cticketcategory';
  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 = 'c_ticket_category';
  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 = 0;
  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 = 'ticket';
  57. const STATUS_DISABLED = 0;
  58. const STATUS_ENABLED = 1;
  59. /**
  60. * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
  61. * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
  62. * 'label' the translation key.
  63. * 'picto' is code of a picto to show before value in forms
  64. * 'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalString('MY_SETUP_PARAM'))
  65. * 'position' is the sort order of field.
  66. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  67. * '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)
  68. * 'noteditable' says if field is not editable (1 or 0)
  69. * '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.
  70. * 'index' if we want an index in database.
  71. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  72. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  73. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
  74. * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'maxwidth200', 'wordbreak', 'tdoverflowmax200'
  75. * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
  76. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  77. * '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.
  78. * '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'
  79. * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
  80. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  81. *
  82. * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
  83. */
  84. // BEGIN MODULEBUILDER PROPERTIES
  85. /**
  86. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  87. */
  88. public $fields=array(
  89. 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
  90. 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'position'=>15, 'index'=>1),
  91. 'code' =>array('type'=>'varchar(32)', 'label'=>'Code', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20),
  92. 'pos' =>array('type'=>'integer', 'label'=>'Pos', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25),
  93. 'label' =>array('type'=>'varchar(128)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>30, 'showoncombobox'=>1),
  94. 'active' =>array('type'=>'integer', 'label'=>'Active', 'enabled'=>1, 'visible'=>-1, 'position'=>35),
  95. 'use_default' =>array('type'=>'integer', 'label'=>'Usedefault', 'enabled'=>1, 'visible'=>-1, 'position'=>40),
  96. 'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>45),
  97. 'fk_parent' =>array('type'=>'integer', 'label'=>'Fkparent', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>50),
  98. 'force_severity' =>array('type'=>'varchar(32)', 'label'=>'Forceseverity', 'enabled'=>1, 'visible'=>-1, 'position'=>55),
  99. 'public' =>array('type'=>'integer', 'label'=>'Public', 'enabled'=>1, 'visible'=>-1, 'position'=>60),
  100. );
  101. /**
  102. * @var int ID
  103. */
  104. public $rowid;
  105. /**
  106. * @var string Ref
  107. */
  108. public $ref;
  109. /**
  110. * @var int Entity
  111. */
  112. public $entity;
  113. /**
  114. * @var string label
  115. */
  116. public $label;
  117. /**
  118. * @var string amount
  119. */
  120. public $amount;
  121. /**
  122. * @var int Status
  123. */
  124. public $status;
  125. /**
  126. * @var integer|string date_creation
  127. */
  128. public $date_creation;
  129. /**
  130. * @var integer tms
  131. */
  132. public $tms;
  133. /**
  134. * @var int ID
  135. */
  136. public $fk_user_creat;
  137. /**
  138. * @var int ID
  139. */
  140. public $fk_user_modif;
  141. /**
  142. * @var string public $last_main_doc
  143. */
  144. public $last_main_doc;
  145. /**
  146. * @var string import_key
  147. */
  148. public $import_key;
  149. // END MODULEBUILDER PROPERTIES
  150. /**
  151. * Constructor
  152. *
  153. * @param DoliDb $db Database handler
  154. */
  155. public function __construct(DoliDB $db)
  156. {
  157. global $conf, $langs;
  158. $this->db = $db;
  159. if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
  160. $this->fields['rowid']['visible'] = 0;
  161. }
  162. if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
  163. $this->fields['entity']['enabled'] = 0;
  164. }
  165. // Example to show how to set values of fields definition dynamically
  166. /*if ($user->hasRight('mymodule', 'myobject', 'read')) {
  167. $this->fields['myfield']['visible'] = 1;
  168. $this->fields['myfield']['noteditable'] = 0;
  169. }*/
  170. // Unset fields that are disabled
  171. foreach ($this->fields as $key => $val) {
  172. if (isset($val['enabled']) && empty($val['enabled'])) {
  173. unset($this->fields[$key]);
  174. }
  175. }
  176. // Translate some data of arrayofkeyval
  177. if (is_object($langs)) {
  178. foreach ($this->fields as $key => $val) {
  179. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  180. foreach ($val['arrayofkeyval'] as $key2 => $val2) {
  181. $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
  182. }
  183. }
  184. }
  185. }
  186. }
  187. /**
  188. * Create object into database
  189. *
  190. * @param User $user User that creates
  191. * @param bool $notrigger false=launch triggers after, true=disable triggers
  192. * @return int Return integer <0 if KO, Id of created object if OK
  193. */
  194. public function create(User $user, $notrigger = false)
  195. {
  196. $resultcreate = $this->createCommon($user, $notrigger);
  197. //$resultvalidate = $this->validate($user, $notrigger);
  198. return $resultcreate;
  199. }
  200. /**
  201. * Clone an object into another one
  202. *
  203. * @param User $user User that creates
  204. * @param int $fromid Id of object to clone
  205. * @return mixed New object created, <0 if KO
  206. */
  207. public function createFromClone(User $user, $fromid)
  208. {
  209. global $langs, $extrafields;
  210. $error = 0;
  211. dol_syslog(__METHOD__, LOG_DEBUG);
  212. $object = new self($this->db);
  213. $this->db->begin();
  214. // Load source object
  215. $result = $object->fetchCommon($fromid);
  216. if ($result > 0 && !empty($object->table_element_line)) {
  217. $object->fetchLines();
  218. }
  219. // get lines so they will be clone
  220. //foreach($this->lines as $line)
  221. // $line->fetch_optionals();
  222. // Reset some properties
  223. unset($object->id);
  224. unset($object->fk_user_creat);
  225. unset($object->import_key);
  226. // Clear fields
  227. if (property_exists($object, 'ref')) {
  228. $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
  229. }
  230. if (property_exists($object, 'label')) {
  231. $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
  232. }
  233. if (property_exists($object, 'date_creation')) {
  234. $object->date_creation = dol_now();
  235. }
  236. if (property_exists($object, 'date_modification')) {
  237. $object->date_modification = null;
  238. }
  239. // ...
  240. // Clear extrafields that are unique
  241. if (is_array($object->array_options) && count($object->array_options) > 0) {
  242. $extrafields->fetch_name_optionals_label($this->table_element);
  243. foreach ($object->array_options as $key => $option) {
  244. $shortkey = preg_replace('/options_/', '', $key);
  245. if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
  246. //var_dump($key);
  247. //var_dump($clonedObj->array_options[$key]); exit;
  248. unset($object->array_options[$key]);
  249. }
  250. }
  251. }
  252. // Create clone
  253. $object->context['createfromclone'] = 'createfromclone';
  254. $result = $object->createCommon($user);
  255. if ($result < 0) {
  256. $error++;
  257. $this->error = $object->error;
  258. $this->errors = $object->errors;
  259. }
  260. if (!$error) {
  261. // copy internal contacts
  262. if ($this->copy_linked_contact($object, 'internal') < 0) {
  263. $error++;
  264. }
  265. }
  266. if (!$error) {
  267. // copy external contacts if same company
  268. if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
  269. if ($this->copy_linked_contact($object, 'external') < 0) {
  270. $error++;
  271. }
  272. }
  273. }
  274. unset($object->context['createfromclone']);
  275. // End
  276. if (!$error) {
  277. $this->db->commit();
  278. return $object;
  279. } else {
  280. $this->db->rollback();
  281. return -1;
  282. }
  283. }
  284. /**
  285. * Load object in memory from the database
  286. *
  287. * @param int $id Id object
  288. * @param string $ref Ref
  289. * @return int Return integer <0 if KO, 0 if not found, >0 if OK
  290. */
  291. public function fetch($id, $ref = null)
  292. {
  293. $result = $this->fetchCommon($id, $ref);
  294. if ($result > 0 && !empty($this->table_element_line)) {
  295. $this->fetchLines();
  296. }
  297. return $result;
  298. }
  299. /**
  300. * Load object lines in memory from the database
  301. *
  302. * @return int Return integer <0 if KO, 0 if not found, >0 if OK
  303. */
  304. public function fetchLines()
  305. {
  306. $this->lines = array();
  307. $result = $this->fetchLinesCommon();
  308. return $result;
  309. }
  310. /**
  311. * Load list of objects in memory from the database.
  312. *
  313. * @param string $sortorder Sort Order
  314. * @param string $sortfield Sort field
  315. * @param int $limit limit
  316. * @param int $offset Offset
  317. * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
  318. * @param string $filtermode Filter mode (AND or OR)
  319. * @return array|int int <0 if KO, array of pages if OK
  320. */
  321. public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
  322. {
  323. dol_syslog(__METHOD__, LOG_DEBUG);
  324. $records = array();
  325. $sql = 'SELECT ';
  326. $sql .= $this->getFieldList('t');
  327. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  328. if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
  329. $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
  330. } else {
  331. $sql .= ' WHERE 1 = 1';
  332. }
  333. // Manage filter
  334. $sqlwhere = array();
  335. if (count($filter) > 0) {
  336. foreach ($filter as $key => $value) {
  337. if ($key == 't.rowid') {
  338. $sqlwhere[] = $key." = ".((int) $value);
  339. } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
  340. $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
  341. } elseif ($key == 'customsql') {
  342. $sqlwhere[] = $value;
  343. } elseif (strpos($value, '%') === false) {
  344. $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
  345. } else {
  346. $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
  347. }
  348. }
  349. }
  350. if (count($sqlwhere) > 0) {
  351. $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
  352. }
  353. if (!empty($sortfield)) {
  354. $sql .= $this->db->order($sortfield, $sortorder);
  355. }
  356. if (!empty($limit)) {
  357. $sql .= $this->db->plimit($limit, $offset);
  358. }
  359. $resql = $this->db->query($sql);
  360. if ($resql) {
  361. $num = $this->db->num_rows($resql);
  362. $i = 0;
  363. while ($i < ($limit ? min($limit, $num) : $num)) {
  364. $obj = $this->db->fetch_object($resql);
  365. $record = new self($this->db);
  366. $record->setVarsFromFetchObj($obj);
  367. $records[$record->id] = $record;
  368. $i++;
  369. }
  370. $this->db->free($resql);
  371. return $records;
  372. } else {
  373. $this->errors[] = 'Error '.$this->db->lasterror();
  374. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  375. return -1;
  376. }
  377. }
  378. /**
  379. * Update object into database
  380. *
  381. * @param User $user User that modifies
  382. * @param bool $notrigger false=launch triggers after, true=disable triggers
  383. * @return int Return integer <0 if KO, >0 if OK
  384. */
  385. public function update(User $user, $notrigger = false)
  386. {
  387. return $this->updateCommon($user, $notrigger);
  388. }
  389. /**
  390. * Delete object in database
  391. *
  392. * @param User $user User that deletes
  393. * @param bool $notrigger false=launch triggers after, true=disable triggers
  394. * @return int Return integer <0 if KO, >0 if OK
  395. */
  396. public function delete(User $user, $notrigger = false)
  397. {
  398. return $this->deleteCommon($user, $notrigger);
  399. //return $this->deleteCommon($user, $notrigger, 1);
  400. }
  401. /**
  402. * Delete a line of object in database
  403. *
  404. * @param User $user User that delete
  405. * @param int $idline Id of line to delete
  406. * @param bool $notrigger false=launch triggers after, true=disable triggers
  407. * @return int >0 if OK, <0 if KO
  408. */
  409. public function deleteLine(User $user, $idline, $notrigger = false)
  410. {
  411. if ($this->status < 0) {
  412. $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
  413. return -2;
  414. }
  415. return $this->deleteLineCommon($user, $idline, $notrigger);
  416. }
  417. /**
  418. * Return a link to the object card (with optionaly the picto)
  419. *
  420. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  421. * @param string $option On what the link point to ('nolink', ...)
  422. * @param int $notooltip 1=Disable tooltip
  423. * @param string $morecss Add more css on link
  424. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  425. * @return string String with URL
  426. */
  427. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  428. {
  429. global $conf, $langs, $hookmanager;
  430. if (!empty($conf->dol_no_mouse_hover)) {
  431. $notooltip = 1; // Force disable tooltips
  432. }
  433. $result = '';
  434. /*$label = img_picto('', $this->picto).' <u>'.$langs->trans("MyObject").'</u>';
  435. if (isset($this->status)) {
  436. $label .= ' '.$this->getLibStatut(5);
  437. }
  438. $label .= '<br>';
  439. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  440. */
  441. $label = '';
  442. //$url = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$this->id;
  443. $url = '';
  444. if ($option != 'nolink') {
  445. // Add param to save lastsearch_values or not
  446. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  447. if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  448. $add_save_lastsearch_values = 1;
  449. }
  450. if ($add_save_lastsearch_values) {
  451. $url .= '&save_lastsearch_values=1';
  452. }
  453. }
  454. $linkclose = '';
  455. if (empty($notooltip)) {
  456. if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
  457. $label = $langs->trans("ShowMyObject");
  458. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  459. }
  460. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  461. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  462. } else {
  463. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  464. }
  465. if ($option == 'nolink') {
  466. $linkstart = '<span';
  467. } else {
  468. $linkstart = '<a href="'.$url.'"';
  469. }
  470. $linkstart .= $linkclose.'>';
  471. if ($option == 'nolink') {
  472. $linkend = '</span>';
  473. } else {
  474. $linkend = '</a>';
  475. }
  476. //$result .= $linkstart;
  477. $result .= $this->label;
  478. //$result .= $linkend;
  479. global $action, $hookmanager;
  480. $hookmanager->initHooks(array('cticketcategorydao'));
  481. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  482. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  483. if ($reshook > 0) {
  484. $result = $hookmanager->resPrint;
  485. } else {
  486. $result .= $hookmanager->resPrint;
  487. }
  488. return $result;
  489. }
  490. /**
  491. * Return the label of the status
  492. *
  493. * @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
  494. * @return string Label of status
  495. */
  496. public function getLibStatut($mode = 0)
  497. {
  498. return $this->LibStatut($this->status, $mode);
  499. }
  500. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  501. /**
  502. * Return the status
  503. *
  504. * @param int $status Id status
  505. * @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
  506. * @return string Label of status
  507. */
  508. public function LibStatut($status, $mode = 0)
  509. {
  510. // phpcs:enable
  511. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  512. global $langs;
  513. //$langs->load("mymodule@mymodule");
  514. $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
  515. $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
  516. $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
  517. $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
  518. }
  519. $statusType = 'status'.$status;
  520. //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
  521. if ($status == self::STATUS_DISABLED) {
  522. $statusType = 'status6';
  523. }
  524. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  525. }
  526. /**
  527. * Load the info information in the object
  528. *
  529. * @param int $id Id of object
  530. * @return void
  531. */
  532. public function info($id)
  533. {
  534. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  535. $sql .= ' fk_user_creat, fk_user_modif';
  536. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  537. $sql .= ' WHERE t.rowid = '.((int) $id);
  538. $result = $this->db->query($sql);
  539. if ($result) {
  540. if ($this->db->num_rows($result)) {
  541. $obj = $this->db->fetch_object($result);
  542. $this->id = $obj->rowid;
  543. $this->user_creation_id = $obj->fk_user_creat;
  544. $this->user_modification_id = $obj->fk_user_modif;
  545. $this->date_creation = $this->db->jdate($obj->datec);
  546. $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
  547. }
  548. $this->db->free($result);
  549. } else {
  550. dol_print_error($this->db);
  551. }
  552. }
  553. /**
  554. * Initialise object with example values
  555. * Id must be 0 if object instance is a specimen
  556. *
  557. * @return void
  558. */
  559. public function initAsSpecimen()
  560. {
  561. $this->initAsSpecimenCommon();
  562. }
  563. }