recruitmentjobposition.class.php 39 KB

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