knowledgerecord.class.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/knowledgemanagement/class/knowledgerecord.class.php
  19. * \ingroup knowledgemanagement
  20. * \brief This file is a CRUD class file for KnowledgeRecord (Create/Read/Update/Delete)
  21. */
  22. // Put here all includes required by your class file
  23. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  24. //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  25. //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  26. /**
  27. * Class for KnowledgeRecord
  28. */
  29. class KnowledgeRecord extends CommonObject
  30. {
  31. /**
  32. * @var string ID of module.
  33. */
  34. public $module = 'knowledgemanagement';
  35. /**
  36. * @var string ID to identify managed object.
  37. */
  38. public $element = 'knowledgerecord';
  39. /**
  40. * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
  41. */
  42. public $table_element = 'knowledgemanagement_knowledgerecord';
  43. /**
  44. * @var int Does this object support multicompany module ?
  45. * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
  46. */
  47. public $ismultientitymanaged = 1;
  48. /**
  49. * @var int Does object support extrafields ? 0=No, 1=Yes
  50. */
  51. public $isextrafieldmanaged = 1;
  52. /**
  53. * @var string String with name of icon for knowledgerecord. Must be the part after the 'object_' into object_knowledgerecord.png
  54. */
  55. public $picto = 'knowledgemanagement';
  56. const STATUS_DRAFT = 0;
  57. const STATUS_VALIDATED = 1;
  58. const STATUS_CANCELED = 9;
  59. /**
  60. * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:SortField]]]', '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 '$conf->global->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. * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
  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. * 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value)
  82. *
  83. * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
  84. */
  85. // BEGIN MODULEBUILDER PROPERTIES
  86. /**
  87. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  88. */
  89. public $fields=array(
  90. 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
  91. 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'visible'=>5, 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object", "csslist"=>"nowraponall", "showoncombobox"=>1),
  92. 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>20, 'index'=>1),
  93. 'question' => array('type'=>'text', 'label'=>'Question', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'csslist'=>'tdoverflowmax300', 'copytoclipboard'=>1, 'tdcss'=>'titlefieldcreate nowraponall'),
  94. 'lang' => array('type'=>'varchar(6)', 'label'=>'Language', 'enabled'=>'1', 'position'=>40, 'notnull'=>0, 'visible'=>1, 'tdcss'=>'titlefieldcreate nowraponall', "csslist"=>"tdoverflowmax100"),
  95. 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
  96. 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>2,),
  97. 'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,),
  98. 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserCreation', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
  99. 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
  100. 'fk_user_valid' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserValidation', 'enabled'=>'1', 'position'=>512, 'notnull'=>0, 'visible'=>-2,),
  101. 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
  102. 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
  103. //'url' => array('type'=>'varchar(255)', 'label'=>'URL', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>-1, 'csslist'=>'tdoverflow200', 'help'=>'UrlForInfoPage'),
  104. 'fk_c_ticket_category' => array('type'=>'integer:CTicketCategory:ticket/class/cticketcategory.class.php:0:(t.active:=:1):pos', 'label'=>'SuggestedForTicketsInGroup', 'enabled'=>'isModEnabled("ticket")', 'position'=>520, 'notnull'=>0, 'visible'=>-1, 'help'=>'YouCanLinkArticleToATicketCategory', 'csslist'=>'minwidth200 tdoverflowmax250'),
  105. 'answer' => array('type'=>'html', 'label'=>'Solution', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>3, 'searchall'=>1, 'csslist'=>'tdoverflowmax300', 'copytoclipboard'=>1, 'tdcss'=>'titlefieldcreate nowraponall'),
  106. 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>5, 'default'=>0, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '9'=>'Obsolete'),),
  107. );
  108. public $rowid;
  109. public $ref;
  110. public $entity;
  111. public $date_creation;
  112. public $tms;
  113. public $last_main_doc;
  114. public $fk_user_creat;
  115. public $fk_user_modif;
  116. public $fk_user_valid;
  117. public $import_key;
  118. public $model_pdf;
  119. /**
  120. * @var string question asked
  121. */
  122. public $question;
  123. /**
  124. * @var string answer to question
  125. */
  126. public $answer;
  127. public $url;
  128. public $status;
  129. public $lang;
  130. // END MODULEBUILDER PROPERTIES
  131. // If this object has a subtable with lines
  132. // /**
  133. // * @var string Name of subtable line
  134. // */
  135. // public $table_element_line = 'knowledgemanagement_knowledgerecordline';
  136. // /**
  137. // * @var string Field with ID of parent key if this object has a parent
  138. // */
  139. // public $fk_element = 'fk_knowledgerecord';
  140. // /**
  141. // * @var string Name of subtable class that manage subtable lines
  142. // */
  143. // public $class_element_line = 'KnowledgeRecordline';
  144. // /**
  145. // * @var array List of child tables. To test if we can delete object.
  146. // */
  147. // protected $childtables = array();
  148. // /**
  149. // * @var array List of child tables. To know object to delete on cascade.
  150. // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
  151. // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
  152. // */
  153. // protected $childtablesoncascade = array('knowledgemanagement_knowledgerecorddet');
  154. // /**
  155. // * @var KnowledgeRecordLine[] Array of subtable lines
  156. // */
  157. // public $lines = array();
  158. /**
  159. * Constructor
  160. *
  161. * @param DoliDb $db Database handler
  162. */
  163. public function __construct(DoliDB $db)
  164. {
  165. global $conf, $langs;
  166. $this->db = $db;
  167. if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
  168. $this->fields['rowid']['visible'] = 0;
  169. }
  170. if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
  171. $this->fields['entity']['enabled'] = 0;
  172. }
  173. // Example to show how to set values of fields definition dynamically
  174. /*if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
  175. $this->fields['myfield']['visible'] = 1;
  176. $this->fields['myfield']['noteditable'] = 0;
  177. }*/
  178. // Unset fields that are disabled
  179. foreach ($this->fields as $key => $val) {
  180. if (isset($val['enabled']) && empty($val['enabled'])) {
  181. unset($this->fields[$key]);
  182. }
  183. }
  184. // Translate some data of arrayofkeyval
  185. if (is_object($langs)) {
  186. foreach ($this->fields as $key => $val) {
  187. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  188. foreach ($val['arrayofkeyval'] as $key2 => $val2) {
  189. $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
  190. }
  191. }
  192. }
  193. }
  194. }
  195. /**
  196. * Create object into database
  197. *
  198. * @param User $user User that creates
  199. * @param bool $notrigger false=launch triggers after, true=disable triggers
  200. * @return int <0 if KO, Id of created object if OK
  201. */
  202. public function create(User $user, $notrigger = false)
  203. {
  204. return $this->createCommon($user, $notrigger);
  205. }
  206. /**
  207. * Clone an object into another one
  208. *
  209. * @param User $user User that creates
  210. * @param int $fromid Id of object to clone
  211. * @return mixed New object created, <0 if KO
  212. */
  213. public function createFromClone(User $user, $fromid)
  214. {
  215. global $langs, $extrafields;
  216. $error = 0;
  217. dol_syslog(__METHOD__, LOG_DEBUG);
  218. $object = new self($this->db);
  219. $this->db->begin();
  220. // Load source object
  221. $result = $object->fetchCommon($fromid);
  222. if ($result > 0 && !empty($object->table_element_line)) {
  223. $object->fetchLines();
  224. }
  225. // get lines so they will be clone
  226. //foreach($this->lines as $line)
  227. // $line->fetch_optionals();
  228. // Reset some properties
  229. unset($object->id);
  230. unset($object->fk_user_creat);
  231. unset($object->import_key);
  232. // Clear fields
  233. if (property_exists($object, 'ref')) {
  234. $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
  235. }
  236. if (property_exists($object, 'question')) {
  237. $object->question = empty($this->fields['question']['default']) ? $langs->trans("CopyOf")." ".$object->question : $this->fields['question']['default'];
  238. }
  239. if (property_exists($object, 'status')) {
  240. $object->status = self::STATUS_DRAFT;
  241. }
  242. if (property_exists($object, 'date_creation')) {
  243. $object->date_creation = dol_now();
  244. }
  245. if (property_exists($object, 'date_modification')) {
  246. $object->date_modification = null;
  247. }
  248. // ...
  249. // Clear extrafields that are unique
  250. if (is_array($object->array_options) && count($object->array_options) > 0) {
  251. $extrafields->fetch_name_optionals_label($this->table_element);
  252. foreach ($object->array_options as $key => $option) {
  253. $shortkey = preg_replace('/options_/', '', $key);
  254. if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
  255. //var_dump($key);
  256. //var_dump($clonedObj->array_options[$key]); exit;
  257. unset($object->array_options[$key]);
  258. }
  259. }
  260. }
  261. // Create clone
  262. $object->context['createfromclone'] = 'createfromclone';
  263. $result = $object->createCommon($user);
  264. if ($result < 0) {
  265. $error++;
  266. $this->error = $object->error;
  267. $this->errors = $object->errors;
  268. }
  269. if (!$error) {
  270. // copy internal contacts
  271. if ($this->copy_linked_contact($object, 'internal') < 0) {
  272. $error++;
  273. }
  274. }
  275. if (!$error) {
  276. // copy external contacts if same company
  277. if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
  278. if ($this->copy_linked_contact($object, 'external') < 0) {
  279. $error++;
  280. }
  281. }
  282. }
  283. unset($object->context['createfromclone']);
  284. // End
  285. if (!$error) {
  286. $this->db->commit();
  287. return $object;
  288. } else {
  289. $this->db->rollback();
  290. return -1;
  291. }
  292. }
  293. /**
  294. * Load object in memory from the database
  295. *
  296. * @param int $id Id object
  297. * @param string $ref Ref
  298. * @return int <0 if KO, 0 if not found, >0 if OK
  299. */
  300. public function fetch($id, $ref = null)
  301. {
  302. $result = $this->fetchCommon($id, $ref);
  303. if ($result > 0 && !empty($this->table_element_line)) {
  304. $this->fetchLines();
  305. }
  306. return $result;
  307. }
  308. /**
  309. * Load object lines in memory from the database
  310. *
  311. * @return int <0 if KO, 0 if not found, >0 if OK
  312. */
  313. public function fetchLines()
  314. {
  315. $this->lines = array();
  316. $result = $this->fetchLinesCommon();
  317. return $result;
  318. }
  319. /**
  320. * Load list of objects in memory from the database.
  321. *
  322. * @param string $sortorder Sort Order
  323. * @param string $sortfield Sort field
  324. * @param int $limit limit
  325. * @param int $offset Offset
  326. * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
  327. * @param string $filtermode Filter mode (AND or OR)
  328. * @return array|int int <0 if KO, array of pages if OK
  329. */
  330. public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
  331. {
  332. global $conf;
  333. dol_syslog(__METHOD__, LOG_DEBUG);
  334. $records = array();
  335. $sql = 'SELECT ';
  336. $sql .= $this->getFieldList('t');
  337. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  338. if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
  339. $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
  340. } else {
  341. $sql .= ' WHERE 1 = 1';
  342. }
  343. // Manage filter
  344. $sqlwhere = array();
  345. if (count($filter) > 0) {
  346. foreach ($filter as $key => $value) {
  347. if ($key == 't.rowid') {
  348. $sqlwhere[] = $key." = ".((int) $value);
  349. } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
  350. $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
  351. } elseif ($key == 'customsql') {
  352. $sqlwhere[] = $value;
  353. } elseif (strpos($value, '%') === false) {
  354. $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
  355. } else {
  356. $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
  357. }
  358. }
  359. }
  360. if (count($sqlwhere) > 0) {
  361. $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
  362. }
  363. if (!empty($sortfield)) {
  364. $sql .= $this->db->order($sortfield, $sortorder);
  365. }
  366. if (!empty($limit)) {
  367. $sql .= $this->db->plimit($limit, $offset);
  368. }
  369. $resql = $this->db->query($sql);
  370. if ($resql) {
  371. $num = $this->db->num_rows($resql);
  372. $i = 0;
  373. while ($i < ($limit ? min($limit, $num) : $num)) {
  374. $obj = $this->db->fetch_object($resql);
  375. $record = new self($this->db);
  376. $record->setVarsFromFetchObj($obj);
  377. $records[$record->id] = $record;
  378. $i++;
  379. }
  380. $this->db->free($resql);
  381. return $records;
  382. } else {
  383. $this->errors[] = 'Error '.$this->db->lasterror();
  384. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  385. return -1;
  386. }
  387. }
  388. /**
  389. * Update object into database
  390. *
  391. * @param User $user User that modifies
  392. * @param bool $notrigger false=launch triggers after, true=disable triggers
  393. * @return int <0 if KO, >0 if OK
  394. */
  395. public function update(User $user, $notrigger = false)
  396. {
  397. return $this->updateCommon($user, $notrigger);
  398. }
  399. /**
  400. * Delete object in database
  401. *
  402. * @param User $user User that deletes
  403. * @param bool $notrigger false=launch triggers after, true=disable triggers
  404. * @return int <0 if KO, >0 if OK
  405. */
  406. public function delete(User $user, $notrigger = false)
  407. {
  408. $error = 0;
  409. $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_knowledgemanagement WHERE fk_knowledgemanagement = ".((int) $this->id);
  410. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  411. $resql = $this->db->query($sql);
  412. if (!$resql) {
  413. $error++;
  414. $this->error .= $this->db->lasterror();
  415. $errorflag = -1;
  416. }
  417. // Delete all child tables
  418. if (!$error) {
  419. $elements = array('categorie_knowledgemanagement');
  420. foreach ($elements as $table) {
  421. if (!$error) {
  422. $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
  423. $sql .= " WHERE fk_knowledgemanagement = ".(int) $this->id;
  424. $result = $this->db->query($sql);
  425. if (!$result) {
  426. $error++;
  427. $this->errors[] = $this->db->lasterror();
  428. }
  429. }
  430. }
  431. }
  432. return $this->deleteCommon($user, $notrigger);
  433. //return $this->deleteCommon($user, $notrigger, 1);
  434. }
  435. /**
  436. * Delete a line of object in database
  437. *
  438. * @param User $user User that delete
  439. * @param int $idline Id of line to delete
  440. * @param bool $notrigger false=launch triggers after, true=disable triggers
  441. * @return int >0 if OK, <0 if KO
  442. */
  443. public function deleteLine(User $user, $idline, $notrigger = false)
  444. {
  445. if ($this->status < 0) {
  446. $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
  447. return -2;
  448. }
  449. return $this->deleteLineCommon($user, $idline, $notrigger);
  450. }
  451. /**
  452. * Validate object
  453. *
  454. * @param User $user User making status change
  455. * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
  456. * @return int <=0 if OK, 0=Nothing done, >0 if KO
  457. */
  458. public function validate($user, $notrigger = 0)
  459. {
  460. global $conf, $langs;
  461. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  462. $error = 0;
  463. // Protection
  464. if ($this->status == self::STATUS_VALIDATED) {
  465. dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
  466. return 0;
  467. }
  468. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight('knowledgemanagement', 'knowledgerecord', 'write'))
  469. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->knowledgemanagement->knowledgerecord->knowledgerecord_advance->validate))))
  470. {
  471. $this->error='NotEnoughPermissions';
  472. dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
  473. return -1;
  474. }*/
  475. $now = dol_now();
  476. $this->db->begin();
  477. // Define new ref
  478. if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
  479. $num = $this->getNextNumRef();
  480. } else {
  481. $num = $this->ref;
  482. }
  483. $this->newref = $num;
  484. if (!empty($num)) {
  485. // Validate
  486. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  487. $sql .= " SET ref = '".$this->db->escape($num)."',";
  488. $sql .= " status = ".self::STATUS_VALIDATED;
  489. if (!empty($this->fields['date_validation'])) {
  490. $sql .= ", date_validation = '".$this->db->idate($now)."'";
  491. }
  492. if (!empty($this->fields['fk_user_valid'])) {
  493. $sql .= ", fk_user_valid = ".((int) $user->id);
  494. }
  495. $sql .= " WHERE rowid = ".((int) $this->id);
  496. dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
  497. $resql = $this->db->query($sql);
  498. if (!$resql) {
  499. dol_print_error($this->db);
  500. $this->error = $this->db->lasterror();
  501. $error++;
  502. }
  503. if (!$error && !$notrigger) {
  504. // Call trigger
  505. $result = $this->call_trigger('KNOWLEDGERECORD_VALIDATE', $user);
  506. if ($result < 0) {
  507. $error++;
  508. }
  509. // End call triggers
  510. }
  511. }
  512. if (!$error) {
  513. $this->oldref = $this->ref;
  514. // Rename directory if dir was a temporary ref
  515. if (preg_match('/^[\(]?PROV/i', $this->ref)) {
  516. // Now we rename also files into index
  517. $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'knowledgerecord/".$this->db->escape($this->newref)."'";
  518. $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'knowledgerecord/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
  519. $resql = $this->db->query($sql);
  520. if (!$resql) {
  521. $error++; $this->error = $this->db->lasterror();
  522. }
  523. // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
  524. $oldref = dol_sanitizeFileName($this->ref);
  525. $newref = dol_sanitizeFileName($num);
  526. $dirsource = $conf->knowledgemanagement->dir_output.'/knowledgerecord/'.$oldref;
  527. $dirdest = $conf->knowledgemanagement->dir_output.'/knowledgerecord/'.$newref;
  528. if (!$error && file_exists($dirsource)) {
  529. dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
  530. if (@rename($dirsource, $dirdest)) {
  531. dol_syslog("Rename ok");
  532. // Rename docs starting with $oldref with $newref
  533. $listoffiles = dol_dir_list($conf->knowledgemanagement->dir_output.'/knowledgerecord/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
  534. foreach ($listoffiles as $fileentry) {
  535. $dirsource = $fileentry['name'];
  536. $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
  537. $dirsource = $fileentry['path'].'/'.$dirsource;
  538. $dirdest = $fileentry['path'].'/'.$dirdest;
  539. @rename($dirsource, $dirdest);
  540. }
  541. }
  542. }
  543. }
  544. }
  545. // Set new ref and current status
  546. if (!$error) {
  547. $this->ref = $num;
  548. $this->status = self::STATUS_VALIDATED;
  549. }
  550. if (!$error) {
  551. $this->db->commit();
  552. return 1;
  553. } else {
  554. $this->db->rollback();
  555. return -1;
  556. }
  557. }
  558. /**
  559. * Set draft status
  560. *
  561. * @param User $user Object user that modify
  562. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  563. * @return int <0 if KO, >0 if OK
  564. */
  565. public function setDraft($user, $notrigger = 0)
  566. {
  567. // Protection
  568. if ($this->status <= self::STATUS_DRAFT) {
  569. return 0;
  570. }
  571. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->knowledgemanagement->write))
  572. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->knowledgemanagement->knowledgemanagement_advance->validate))))
  573. {
  574. $this->error='Permission denied';
  575. return -1;
  576. }*/
  577. return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'KNOWLEDGERECORD_UNVALIDATE');
  578. }
  579. /**
  580. * Set cancel status
  581. *
  582. * @param User $user Object user that modify
  583. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  584. * @return int <0 if KO, 0=Nothing done, >0 if OK
  585. */
  586. public function cancel($user, $notrigger = 0)
  587. {
  588. // Protection
  589. if ($this->status != self::STATUS_VALIDATED) {
  590. return 0;
  591. }
  592. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->knowledgemanagement->write))
  593. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->knowledgemanagement->knowledgemanagement_advance->validate))))
  594. {
  595. $this->error='Permission denied';
  596. return -1;
  597. }*/
  598. return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'KNOWLEDGERECORD_CANCEL');
  599. }
  600. /**
  601. * Set back to validated status
  602. *
  603. * @param User $user Object user that modify
  604. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  605. * @return int <0 if KO, 0=Nothing done, >0 if OK
  606. */
  607. public function reopen($user, $notrigger = 0)
  608. {
  609. // Protection
  610. if ($this->status != self::STATUS_CANCELED) {
  611. return 0;
  612. }
  613. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->knowledgemanagement->write))
  614. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->knowledgemanagement->knowledgemanagement_advance->validate))))
  615. {
  616. $this->error='Permission denied';
  617. return -1;
  618. }*/
  619. return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'KNOWLEDGERECORD_REOPEN');
  620. }
  621. /**
  622. * getTooltipContentArray
  623. *
  624. * @param array $params ex option, infologin
  625. * @since v18
  626. * @return array
  627. */
  628. public function getTooltipContentArray($params)
  629. {
  630. global $conf, $langs;
  631. $langs->loadLangs(['knowledgemanagement', 'languages']);
  632. $datas = array();
  633. $nofetch = !empty($params['nofetch']);
  634. $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("KnowledgeRecord").'</u>';
  635. if (isset($this->statut)) {
  636. $datas['picto'] .= ' '.$this->getLibStatut(5);
  637. }
  638. $datas['label'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
  639. $datas['question'] = '<br><b>'.$langs->trans('Question').':</b> '.$this->question;
  640. $labellang = ($this->lang ? $langs->trans('Language_'.$this->lang) : '');
  641. $datas['lang'] = '<br><b>'.$langs->trans('Language').':</b> ' . picto_from_langcode($this->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang;
  642. // show categories for this record only in ajax to not overload lists
  643. if (isModEnabled('categorie') && !$nofetch) {
  644. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  645. $form = new Form($this->db);
  646. $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_KNOWLEDGEMANAGEMENT, 1);
  647. }
  648. return $datas;
  649. }
  650. /**
  651. * Return a link to the object card (with optionaly the picto)
  652. *
  653. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  654. * @param string $option On what the link point to ('nolink', ...)
  655. * @param int $notooltip 1=Disable tooltip
  656. * @param string $morecss Add more css on link
  657. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  658. * @return string String with URL
  659. */
  660. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  661. {
  662. global $conf, $langs, $hookmanager;
  663. if (!empty($conf->dol_no_mouse_hover)) {
  664. $notooltip = 1; // Force disable tooltips
  665. }
  666. $result = '';
  667. $params = [
  668. 'id' => $this->id,
  669. 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
  670. 'option' => $option,
  671. 'nofetch' => 1,
  672. ];
  673. $classfortooltip = 'classfortooltip';
  674. $dataparams = '';
  675. if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
  676. $classfortooltip = 'classforajaxtooltip';
  677. $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
  678. $label = '';
  679. } else {
  680. $label = implode($this->getTooltipContentArray($params));
  681. }
  682. $url = dol_buildpath('/knowledgemanagement/knowledgerecord_card.php', 1).'?id='.$this->id;
  683. if ($option != 'nolink') {
  684. // Add param to save lastsearch_values or not
  685. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  686. if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  687. $add_save_lastsearch_values = 1;
  688. }
  689. if ($add_save_lastsearch_values) {
  690. $url .= '&save_lastsearch_values=1';
  691. }
  692. }
  693. $linkclose = '';
  694. if (empty($notooltip)) {
  695. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  696. $label = $langs->trans("ShowKnowledgeRecord");
  697. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  698. }
  699. $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
  700. $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
  701. } else {
  702. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  703. }
  704. if ($option == 'nolink') {
  705. $linkstart = '<span';
  706. } else {
  707. $linkstart = '<a href="'.$url.'"';
  708. }
  709. $linkstart .= $linkclose.'>';
  710. if ($option == 'nolink') {
  711. $linkend = '</span>';
  712. } else {
  713. $linkend = '</a>';
  714. }
  715. $result .= $linkstart;
  716. if (empty($this->showphoto_on_popup)) {
  717. if ($withpicto) {
  718. $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
  719. }
  720. } else {
  721. if ($withpicto) {
  722. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  723. list($class, $module) = explode('@', $this->picto);
  724. $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
  725. $filearray = dol_dir_list($upload_dir, "files");
  726. $filename = $filearray[0]['name'];
  727. if (!empty($filename)) {
  728. $pospoint = strpos($filearray[0]['name'], '.');
  729. $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
  730. if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
  731. $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
  732. } else {
  733. $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
  734. }
  735. $result .= '</div>';
  736. } else {
  737. $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
  738. }
  739. }
  740. }
  741. if ($withpicto != 2) {
  742. $result .= $this->ref;
  743. }
  744. $result .= $linkend;
  745. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  746. global $action, $hookmanager;
  747. $hookmanager->initHooks(array('knowledgerecorddao'));
  748. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  749. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  750. if ($reshook > 0) {
  751. $result = $hookmanager->resPrint;
  752. } else {
  753. $result .= $hookmanager->resPrint;
  754. }
  755. return $result;
  756. }
  757. /**
  758. * Return the label of the status
  759. *
  760. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  761. * @return string Label of status
  762. */
  763. public function getLibStatut($mode = 0)
  764. {
  765. return $this->LibStatut($this->status, $mode);
  766. }
  767. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  768. /**
  769. * Return the status
  770. *
  771. * @param int $status Id status
  772. * @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
  773. * @return string Label of status
  774. */
  775. public function LibStatut($status, $mode = 0)
  776. {
  777. // phpcs:enable
  778. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  779. global $langs;
  780. //$langs->load("knowledgemanagement");
  781. $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  782. $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
  783. $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Obsolete');
  784. $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  785. $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
  786. $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Obsolete');
  787. }
  788. $statusType = 'status'.$status;
  789. if ($status == self::STATUS_VALIDATED) $statusType = 'status4';
  790. if ($status == self::STATUS_CANCELED) {
  791. $statusType = 'status6';
  792. }
  793. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  794. }
  795. /**
  796. * Load the info information in the object
  797. *
  798. * @param int $id Id of object
  799. * @return void
  800. */
  801. public function info($id)
  802. {
  803. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  804. $sql .= ' fk_user_creat, fk_user_modif';
  805. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  806. $sql .= ' WHERE t.rowid = '.((int) $id);
  807. $result = $this->db->query($sql);
  808. if ($result) {
  809. if ($this->db->num_rows($result)) {
  810. $obj = $this->db->fetch_object($result);
  811. $this->id = $obj->rowid;
  812. $this->user_creation_id = $obj->fk_user_creat;
  813. $this->user_modification_id = $obj->fk_user_modif;
  814. $this->date_creation = $this->db->jdate($obj->datec);
  815. $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
  816. }
  817. $this->db->free($result);
  818. } else {
  819. dol_print_error($this->db);
  820. }
  821. }
  822. /**
  823. * Initialise object with example values
  824. * Id must be 0 if object instance is a specimen
  825. *
  826. * @return void
  827. */
  828. public function initAsSpecimen()
  829. {
  830. $this->question = "ABCD";
  831. $this->initAsSpecimenCommon();
  832. }
  833. /**
  834. * Create an array of lines
  835. *
  836. * @return array|int array of lines if OK, <0 if KO
  837. */
  838. public function getLinesArray()
  839. {
  840. $this->lines = array();
  841. $objectline = new KnowledgeRecordLine($this->db);
  842. $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_knowledgerecord = '.((int) $this->id)));
  843. if (is_numeric($result)) {
  844. $this->error = $objectline->error;
  845. $this->errors = $objectline->errors;
  846. return $result;
  847. } else {
  848. $this->lines = $result;
  849. return $this->lines;
  850. }
  851. }
  852. /**
  853. * Returns the reference to the following non used object depending on the active numbering module.
  854. *
  855. * @return string Object free reference
  856. */
  857. public function getNextNumRef()
  858. {
  859. global $langs, $conf;
  860. $langs->load("knowledgemanagement");
  861. if (empty($conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON)) {
  862. $conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON = 'mod_knowledgerecord_standard';
  863. }
  864. if (!empty($conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON)) {
  865. $mybool = false;
  866. $file = getDolGlobalString('KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON') . ".php";
  867. $classname = $conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON;
  868. // Include file with class
  869. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  870. foreach ($dirmodels as $reldir) {
  871. $dir = dol_buildpath($reldir."core/modules/knowledgemanagement/");
  872. // Load file with numbering class (if found)
  873. $mybool |= @include_once $dir.$file;
  874. }
  875. if ($mybool === false) {
  876. dol_print_error('', "Failed to include file ".$file);
  877. return '';
  878. }
  879. if (class_exists($classname)) {
  880. $obj = new $classname();
  881. $numref = $obj->getNextValue($this);
  882. if ($numref != '' && $numref != '-1') {
  883. return $numref;
  884. } else {
  885. $this->error = $obj->error;
  886. //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
  887. return "";
  888. }
  889. } else {
  890. print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
  891. return "";
  892. }
  893. } else {
  894. print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
  895. return "";
  896. }
  897. }
  898. /**
  899. * Create a document onto disk according to template module.
  900. *
  901. * @param string $modele Force template to use ('' to not force)
  902. * @param Translate $outputlangs objet lang a utiliser pour traduction
  903. * @param int $hidedetails Hide details of lines
  904. * @param int $hidedesc Hide description
  905. * @param int $hideref Hide ref
  906. * @param null|array $moreparams Array to provide more information
  907. * @return int 0 if KO, 1 if OK
  908. */
  909. public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
  910. {
  911. global $conf, $langs;
  912. $result = 0;
  913. $includedocgeneration = 0;
  914. $langs->load("knowledgemanagement");
  915. if (!dol_strlen($modele)) {
  916. $modele = 'standard_knowledgerecord';
  917. if (!empty($this->model_pdf)) {
  918. $modele = $this->model_pdf;
  919. } elseif (!empty($conf->global->KNOWLEDGERECORD_ADDON_PDF)) {
  920. $modele = $conf->global->KNOWLEDGERECORD_ADDON_PDF;
  921. }
  922. }
  923. $modelpath = "core/modules/knowledgemanagement/doc/";
  924. if ($includedocgeneration && !empty($modele)) {
  925. $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
  926. }
  927. return $result;
  928. }
  929. /**
  930. * Action executed by scheduler
  931. * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
  932. * Use public function doScheduledJob($param1, $param2, ...) to get parameters
  933. *
  934. * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
  935. */
  936. public function doScheduledJob()
  937. {
  938. global $conf, $langs;
  939. //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
  940. $error = 0;
  941. $this->output = '';
  942. $this->error = '';
  943. dol_syslog(__METHOD__, LOG_DEBUG);
  944. $now = dol_now();
  945. $this->db->begin();
  946. // ...
  947. $this->db->commit();
  948. return $error;
  949. }
  950. /**
  951. * Sets object to supplied categories.
  952. *
  953. * Deletes object from existing categories not supplied.
  954. * Adds it to non existing supplied categories.
  955. * Existing categories are left untouch.
  956. *
  957. * @param int[]|int $categories Category or categories IDs
  958. * @return int <0 if KO, >0 if OK
  959. */
  960. public function setCategories($categories)
  961. {
  962. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  963. return parent::setCategoriesCommon($categories, Categorie::TYPE_KNOWLEDGEMANAGEMENT);
  964. }
  965. /**
  966. * Return clicable link of object (with eventually picto)
  967. *
  968. * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
  969. * @param array $arraydata Array of data
  970. * @return string HTML Code for Kanban thumb.
  971. */
  972. public function getKanbanView($option = '', $arraydata = null)
  973. {
  974. $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
  975. $return = '<div class="box-flex-item box-flex-grow-zero">';
  976. $return .= '<div class="info-box info-box-sm">';
  977. $return .= '<span class="info-box-icon bg-infobox-action">';
  978. $return .= img_picto('', $this->picto);
  979. $return .= '</span>';
  980. $return .= '<div class="info-box-content">';
  981. $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
  982. $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
  983. if (property_exists($this, 'lang') && !empty($this->lang)) {
  984. //$return .= '<br><span class="opacitymedium">'.$langs->trans("Language").'</span> : <span class="info-box-label" title="'.$langs->trans("Language_".$this->lang).'">'.$langs->trans("Language_".$this->lang, '', '', '', '', 12).'</span>';
  985. $return .= '<br>'.picto_from_langcode($this->lang, 'class="paddingrightonly saturatemedium opacitylow paddingrightonly"');
  986. }
  987. if (property_exists($this, 'question')) {
  988. $return .= '<span class="info-box-label">'.dolGetFirstLineOfText($this->question).'</span>';
  989. }
  990. if (method_exists($this, 'getLibStatut')) {
  991. $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
  992. }
  993. $return .= '</div>';
  994. $return .= '</div>';
  995. $return .= '</div>';
  996. return $return;
  997. }
  998. }
  999. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
  1000. /**
  1001. * Class KnowledgeRecordLine. You can also remove this and generate a CRUD class for lines objects.
  1002. */
  1003. class KnowledgeRecordLine extends CommonObjectLine
  1004. {
  1005. // To complete with content of an object KnowledgeRecordLine
  1006. // We should have a field rowid, fk_knowledgerecord and position
  1007. /**
  1008. * @var int Does object support extrafields ? 0=No, 1=Yes
  1009. */
  1010. public $isextrafieldmanaged = 0;
  1011. /**
  1012. * Constructor
  1013. *
  1014. * @param DoliDb $db Database handler
  1015. */
  1016. public function __construct(DoliDB $db)
  1017. {
  1018. $this->db = $db;
  1019. }
  1020. }