recruitmentjobposition.class.php 39 KB

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