recruitmentjobposition.class.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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'=>-2,),
  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); var_dump($clonedObj->array_options[$key]); exit;
  249. unset($object->array_options[$key]);
  250. }
  251. }
  252. }
  253. // Create clone
  254. $object->context['createfromclone'] = 'createfromclone';
  255. $result = $object->createCommon($user);
  256. if ($result < 0) {
  257. $error++;
  258. $this->error = $object->error;
  259. $this->errors = $object->errors;
  260. }
  261. if (!$error) {
  262. // copy internal contacts
  263. if ($this->copy_linked_contact($object, 'internal') < 0) {
  264. $error++;
  265. }
  266. }
  267. if (!$error) {
  268. // copy external contacts if same company
  269. if (property_exists($this, 'socid') && $this->socid == $object->socid) {
  270. if ($this->copy_linked_contact($object, 'external') < 0) {
  271. $error++;
  272. }
  273. }
  274. }
  275. unset($object->context['createfromclone']);
  276. // End
  277. if (!$error) {
  278. $this->db->commit();
  279. return $object;
  280. } else {
  281. $this->db->rollback();
  282. return -1;
  283. }
  284. }
  285. /**
  286. * Load object in memory from the database
  287. *
  288. * @param int $id Id object
  289. * @param string $ref Ref
  290. * @return int <0 if KO, 0 if not found, >0 if OK
  291. */
  292. public function fetch($id, $ref = null)
  293. {
  294. $result = $this->fetchCommon($id, $ref);
  295. if ($result > 0 && !empty($this->table_element_line)) {
  296. $this->fetchLines();
  297. }
  298. return $result;
  299. }
  300. /**
  301. * Load object lines in memory from the database
  302. *
  303. * @return int <0 if KO, 0 if not found, >0 if OK
  304. */
  305. public function fetchLines()
  306. {
  307. $this->lines = array();
  308. $result = $this->fetchLinesCommon();
  309. return $result;
  310. }
  311. /**
  312. * Load list of objects in memory from the database.
  313. *
  314. * @param string $sortorder Sort Order
  315. * @param string $sortfield Sort field
  316. * @param int $limit limit
  317. * @param int $offset Offset
  318. * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
  319. * @param string $filtermode Filter mode (AND or OR)
  320. * @return array|int int <0 if KO, array of pages if OK
  321. */
  322. public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
  323. {
  324. global $conf;
  325. dol_syslog(__METHOD__, LOG_DEBUG);
  326. $records = array();
  327. $sql = 'SELECT ';
  328. $sql .= $this->getFieldList();
  329. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  330. if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
  331. $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
  332. } else {
  333. $sql .= ' WHERE 1 = 1';
  334. }
  335. // Manage filter
  336. $sqlwhere = array();
  337. if (count($filter) > 0) {
  338. foreach ($filter as $key => $value) {
  339. if ($key == 't.rowid') {
  340. $sqlwhere[] = $key." = ".((int) $value);
  341. } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
  342. $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
  343. } elseif ($key == 'customsql') {
  344. $sqlwhere[] = $value;
  345. } elseif (strpos($value, '%') === false) {
  346. $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
  347. } else {
  348. $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
  349. }
  350. }
  351. }
  352. if (count($sqlwhere) > 0) {
  353. $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
  354. }
  355. if (!empty($sortfield)) {
  356. $sql .= $this->db->order($sortfield, $sortorder);
  357. }
  358. if (!empty($limit)) {
  359. $sql .= $this->db->plimit($limit, $offset);
  360. }
  361. $resql = $this->db->query($sql);
  362. if ($resql) {
  363. $num = $this->db->num_rows($resql);
  364. $i = 0;
  365. while ($i < ($limit ? min($limit, $num) : $num)) {
  366. $obj = $this->db->fetch_object($resql);
  367. $record = new self($this->db);
  368. $record->setVarsFromFetchObj($obj);
  369. $records[$record->id] = $record;
  370. $i++;
  371. }
  372. $this->db->free($resql);
  373. return $records;
  374. } else {
  375. $this->errors[] = 'Error '.$this->db->lasterror();
  376. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  377. return -1;
  378. }
  379. }
  380. /**
  381. * Update object into database
  382. *
  383. * @param User $user User that modifies
  384. * @param bool $notrigger false=launch triggers after, true=disable triggers
  385. * @return int <0 if KO, >0 if OK
  386. */
  387. public function update(User $user, $notrigger = false)
  388. {
  389. return $this->updateCommon($user, $notrigger);
  390. }
  391. /**
  392. * Delete object in database
  393. *
  394. * @param User $user User that deletes
  395. * @param bool $notrigger false=launch triggers after, true=disable triggers
  396. * @return int <0 if KO, >0 if OK
  397. */
  398. public function delete(User $user, $notrigger = false)
  399. {
  400. return $this->deleteCommon($user, $notrigger);
  401. //return $this->deleteCommon($user, $notrigger, 1);
  402. }
  403. /**
  404. * Delete a line of object in database
  405. *
  406. * @param User $user User that delete
  407. * @param int $idline Id of line to delete
  408. * @param bool $notrigger false=launch triggers after, true=disable triggers
  409. * @return int >0 if OK, <0 if KO
  410. */
  411. public function deleteLine(User $user, $idline, $notrigger = false)
  412. {
  413. if ($this->status < 0) {
  414. $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
  415. return -2;
  416. }
  417. return $this->deleteLineCommon($user, $idline, $notrigger);
  418. }
  419. /**
  420. * Validate object
  421. *
  422. * @param User $user User making status change
  423. * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
  424. * @return int <=0 if OK, 0=Nothing done, >0 if KO
  425. */
  426. public function validate($user, $notrigger = 0)
  427. {
  428. global $conf, $langs;
  429. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  430. $error = 0;
  431. // Protection
  432. if ($this->status == self::STATUS_VALIDATED) {
  433. dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
  434. return 0;
  435. }
  436. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitmentjobposition->create))
  437. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitmentjobposition->recruitmentjobposition_advance->validate))))
  438. {
  439. $this->error='NotEnoughPermissions';
  440. dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
  441. return -1;
  442. }*/
  443. $now = dol_now();
  444. $this->db->begin();
  445. // Define new ref
  446. if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
  447. $num = $this->getNextNumRef();
  448. } else {
  449. $num = $this->ref;
  450. }
  451. $this->newref = $num;
  452. if (!empty($num)) {
  453. // Validate
  454. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  455. $sql .= " SET ref = '".$this->db->escape($num)."',";
  456. $sql .= " status = ".self::STATUS_VALIDATED;
  457. if (!empty($this->fields['date_validation'])) {
  458. $sql .= ", date_validation = '".$this->db->idate($now)."',";
  459. }
  460. if (!empty($this->fields['fk_user_valid'])) {
  461. $sql .= ", fk_user_valid = ".$user->id;
  462. }
  463. $sql .= " WHERE rowid = ".((int) $this->id);
  464. dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
  465. $resql = $this->db->query($sql);
  466. if (!$resql) {
  467. dol_print_error($this->db);
  468. $this->error = $this->db->lasterror();
  469. $error++;
  470. }
  471. if (!$error && !$notrigger) {
  472. // Call trigger
  473. $result = $this->call_trigger('RECRUITMENTJOBPOSITION_VALIDATE', $user);
  474. if ($result < 0) {
  475. $error++;
  476. }
  477. // End call triggers
  478. }
  479. }
  480. if (!$error) {
  481. $this->oldref = $this->ref;
  482. // Rename directory if dir was a temporary ref
  483. if (preg_match('/^[\(]?PROV/i', $this->ref)) {
  484. // Now we rename also files into index
  485. $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)."'";
  486. $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentjobposition/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
  487. $resql = $this->db->query($sql);
  488. if (!$resql) {
  489. $error++; $this->error = $this->db->lasterror();
  490. }
  491. // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
  492. $oldref = dol_sanitizeFileName($this->ref);
  493. $newref = dol_sanitizeFileName($num);
  494. $dirsource = $conf->recruitment->dir_output.'/recruitmentjobposition/'.$oldref;
  495. $dirdest = $conf->recruitment->dir_output.'/recruitmentjobposition/'.$newref;
  496. if (!$error && file_exists($dirsource)) {
  497. dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
  498. if (@rename($dirsource, $dirdest)) {
  499. dol_syslog("Rename ok");
  500. // Rename docs starting with $oldref with $newref
  501. $listoffiles = dol_dir_list($conf->recruitment->dir_output.'/recruitmentjobposition/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
  502. foreach ($listoffiles as $fileentry) {
  503. $dirsource = $fileentry['name'];
  504. $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
  505. $dirsource = $fileentry['path'].'/'.$dirsource;
  506. $dirdest = $fileentry['path'].'/'.$dirdest;
  507. @rename($dirsource, $dirdest);
  508. }
  509. }
  510. }
  511. }
  512. }
  513. // Set new ref and current status
  514. if (!$error) {
  515. $this->ref = $num;
  516. $this->status = self::STATUS_VALIDATED;
  517. }
  518. if (!$error) {
  519. $this->db->commit();
  520. return 1;
  521. } else {
  522. $this->db->rollback();
  523. return -1;
  524. }
  525. }
  526. /**
  527. * Set draft status
  528. *
  529. * @param User $user Object user that modify
  530. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  531. * @return int <0 if KO, >0 if OK
  532. */
  533. public function setDraft($user, $notrigger = 0)
  534. {
  535. // Protection
  536. if ($this->status <= self::STATUS_DRAFT) {
  537. return 0;
  538. }
  539. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
  540. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
  541. {
  542. $this->error='Permission denied';
  543. return -1;
  544. }*/
  545. return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'RECRUITMENTJOBPOSITION_UNVALIDATE');
  546. }
  547. /**
  548. * Set cancel status
  549. *
  550. * @param User $user Object user that modify
  551. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  552. * @return int <0 if KO, 0=Nothing done, >0 if OK
  553. */
  554. public function cancel($user, $notrigger = 0)
  555. {
  556. // Protection
  557. if ($this->status != self::STATUS_VALIDATED) {
  558. return 0;
  559. }
  560. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
  561. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
  562. {
  563. $this->error='Permission denied';
  564. return -1;
  565. }*/
  566. return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'RECRUITMENTJOBPOSITION_CLOSE');
  567. }
  568. /**
  569. * Close the commercial proposal
  570. *
  571. * @param User $user Object user that close
  572. * @param int $status Statut
  573. * @param string $note Complete private note with this note
  574. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  575. * @return int <0 if KO, >0 if OK
  576. */
  577. public function cloture($user, $status, $note = "", $notrigger = 0)
  578. {
  579. global $langs, $conf;
  580. $error = 0;
  581. $now = dol_now();
  582. $this->db->begin();
  583. $newprivatenote = dol_concatdesc($this->note_private, $note);
  584. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  585. $sql .= " SET status = ".((int) $status).", note_private = '".$this->db->escape($newprivatenote)."'";
  586. //$sql .= ", date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
  587. $sql .= " WHERE rowid = ".((int) $this->id);
  588. $resql = $this->db->query($sql);
  589. if ($resql) {
  590. $modelpdf = $this->model_pdf;
  591. $triggerName = 'RECRUITMENTJOB_CLOSE_REFUSED';
  592. if ($status == self::STATUS_RECRUITED) {
  593. $triggerName = 'RECRUITMENTJOB_CLOSE_RECRUITED';
  594. $modelpdf = $this->model_pdf;
  595. if ($result < 0) {
  596. $this->error = $this->db->lasterror();
  597. $this->db->rollback();
  598. return -2;
  599. }
  600. }
  601. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  602. // Define output language
  603. $outputlangs = $langs;
  604. if (!empty($conf->global->MAIN_MULTILANGS)) {
  605. $outputlangs = new Translate("", $conf);
  606. $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang);
  607. $outputlangs->setDefaultLang($newlang);
  608. }
  609. // PDF
  610. $hidedetails = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
  611. $hidedesc = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
  612. $hideref = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
  613. //$ret=$object->fetch($id); // Reload to get new records
  614. $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  615. }
  616. if (!$error) {
  617. $this->oldcopy = clone $this;
  618. $this->status = $status;
  619. $this->date_cloture = $now;
  620. $this->note_private = $newprivatenote;
  621. }
  622. if (!$notrigger && empty($error)) {
  623. // Call trigger
  624. $result = $this->call_trigger($triggerName, $user);
  625. if ($result < 0) {
  626. $error++;
  627. }
  628. // End call triggers
  629. }
  630. if (!$error) {
  631. $this->db->commit();
  632. return 1;
  633. } else {
  634. $this->status = $this->oldcopy->status;
  635. $this->date_cloture = $this->oldcopy->date_cloture;
  636. $this->note_private = $this->oldcopy->note_private;
  637. $this->db->rollback();
  638. return -1;
  639. }
  640. } else {
  641. $this->error = $this->db->lasterror();
  642. $this->db->rollback();
  643. return -1;
  644. }
  645. }
  646. /**
  647. * Set back to validated status
  648. *
  649. * @param User $user Object user that modify
  650. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  651. * @return int <0 if KO, 0=Nothing done, >0 if OK
  652. */
  653. public function reopen($user, $notrigger = 0)
  654. {
  655. // Protection
  656. if ($this->status != self::STATUS_CANCELED) {
  657. return 0;
  658. }
  659. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
  660. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
  661. {
  662. $this->error='Permission denied';
  663. return -1;
  664. }*/
  665. return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'RECRUITMENTJOBPOSITION_REOPEN');
  666. }
  667. /**
  668. * Return a link to the object card (with optionaly the picto)
  669. *
  670. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  671. * @param string $option On what the link point to ('nolink', ...)
  672. * @param int $notooltip 1=Disable tooltip
  673. * @param string $morecss Add more css on link
  674. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  675. * @return string String with URL
  676. */
  677. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  678. {
  679. global $conf, $langs, $hookmanager;
  680. if (!empty($conf->dol_no_mouse_hover)) {
  681. $notooltip = 1; // Force disable tooltips
  682. }
  683. $result = '';
  684. $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("PositionToBeFilled").'</u>';
  685. if (isset($this->status)) {
  686. $label .= ' '.$this->getLibStatut(5);
  687. }
  688. $label .= '<br>';
  689. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  690. $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
  691. $url = dol_buildpath('/recruitment/recruitmentjobposition_card.php', 1).'?id='.$this->id;
  692. if ($option != 'nolink') {
  693. // Add param to save lastsearch_values or not
  694. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  695. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  696. $add_save_lastsearch_values = 1;
  697. }
  698. if ($add_save_lastsearch_values) {
  699. $url .= '&save_lastsearch_values=1';
  700. }
  701. }
  702. $linkclose = '';
  703. if (empty($notooltip)) {
  704. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  705. $label = $langs->trans("ShowRecruitmentJobPosition");
  706. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  707. }
  708. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  709. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  710. } else {
  711. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  712. }
  713. $linkstart = '<a href="'.$url.'"';
  714. $linkstart .= $linkclose.'>';
  715. $linkend = '</a>';
  716. $result .= $linkstart;
  717. if (empty($this->showphoto_on_popup)) {
  718. if ($withpicto) {
  719. $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);
  720. }
  721. } else {
  722. if ($withpicto) {
  723. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  724. list($class, $module) = explode('@', $this->picto);
  725. $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
  726. $filearray = dol_dir_list($upload_dir, "files");
  727. $filename = $filearray[0]['name'];
  728. if (!empty($filename)) {
  729. $pospoint = strpos($filearray[0]['name'], '.');
  730. $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
  731. if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
  732. $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>';
  733. } else {
  734. $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>';
  735. }
  736. $result .= '</div>';
  737. } else {
  738. $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);
  739. }
  740. }
  741. }
  742. if ($withpicto != 2) {
  743. $result .= $this->ref;
  744. }
  745. $result .= $linkend;
  746. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  747. global $action, $hookmanager;
  748. $hookmanager->initHooks(array('recruitmentjobpositiondao'));
  749. $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
  750. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  751. if ($reshook > 0) {
  752. $result = $hookmanager->resPrint;
  753. } else {
  754. $result .= $hookmanager->resPrint;
  755. }
  756. return $result;
  757. }
  758. /**
  759. * Return label of the status
  760. *
  761. * @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
  762. * @return string Label of status
  763. */
  764. public function getLibStatut($mode = 0)
  765. {
  766. return $this->LibStatut($this->status, $mode);
  767. }
  768. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  769. /**
  770. * Return the status
  771. *
  772. * @param int $status Id status
  773. * @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
  774. * @return string Label of status
  775. */
  776. public function LibStatut($status, $mode = 0)
  777. {
  778. // phpcs:enable
  779. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  780. global $langs;
  781. //$langs->load("recruitment");
  782. $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  783. $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
  784. $this->labelStatus[self::STATUS_RECRUITED] = $langs->transnoentitiesnoconv('Recruited');
  785. $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
  786. $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  787. $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
  788. $this->labelStatusShort[self::STATUS_RECRUITED] = $langs->transnoentitiesnoconv('Recruited');
  789. $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
  790. }
  791. $statusType = 'status'.$status;
  792. if ($status == self::STATUS_VALIDATED) {
  793. $statusType = 'status4';
  794. }
  795. if ($status == self::STATUS_RECRUITED) {
  796. $statusType = 'status6';
  797. }
  798. if ($status == self::STATUS_CANCELED) {
  799. $statusType = 'status9';
  800. }
  801. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  802. }
  803. /**
  804. * Load the info information in the object
  805. *
  806. * @param int $id Id of object
  807. * @return void
  808. */
  809. public function info($id)
  810. {
  811. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  812. $sql .= ' fk_user_creat, fk_user_modif';
  813. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  814. $sql .= ' WHERE t.rowid = '.((int) $id);
  815. $result = $this->db->query($sql);
  816. if ($result) {
  817. if ($this->db->num_rows($result)) {
  818. $obj = $this->db->fetch_object($result);
  819. $this->id = $obj->rowid;
  820. if ($obj->fk_user_author) {
  821. $cuser = new User($this->db);
  822. $cuser->fetch($obj->fk_user_author);
  823. $this->user_creation = $cuser;
  824. }
  825. if ($obj->fk_user_valid) {
  826. $vuser = new User($this->db);
  827. $vuser->fetch($obj->fk_user_valid);
  828. $this->user_validation = $vuser;
  829. }
  830. if ($obj->fk_user_cloture) {
  831. $cluser = new User($this->db);
  832. $cluser->fetch($obj->fk_user_cloture);
  833. $this->user_cloture = $cluser;
  834. }
  835. $this->date_creation = $this->db->jdate($obj->datec);
  836. $this->date_modification = $this->db->jdate($obj->datem);
  837. $this->date_validation = $this->db->jdate($obj->datev);
  838. }
  839. $this->db->free($result);
  840. } else {
  841. dol_print_error($this->db);
  842. }
  843. }
  844. /**
  845. * Initialise object with example values
  846. * Id must be 0 if object instance is a specimen
  847. *
  848. * @return void
  849. */
  850. public function initAsSpecimen()
  851. {
  852. $this->initAsSpecimenCommon();
  853. }
  854. /**
  855. * Create an array of lines
  856. *
  857. * @return array|int array of lines if OK, <0 if KO
  858. */
  859. public function getLinesArray()
  860. {
  861. $this->lines = array();
  862. return $this->lines;
  863. }
  864. /**
  865. * Returns the reference to the following non used object depending on the active numbering module.
  866. *
  867. * @return string Object free reference
  868. */
  869. public function getNextNumRef()
  870. {
  871. global $langs, $conf;
  872. $langs->load("recruitment");
  873. if (empty($conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON)) {
  874. $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON = 'mod_recruitmentjobposition_standard';
  875. }
  876. if (!empty($conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON)) {
  877. $mybool = false;
  878. $file = $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON.".php";
  879. $classname = $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON;
  880. // Include file with class
  881. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  882. foreach ($dirmodels as $reldir) {
  883. $dir = dol_buildpath($reldir."core/modules/recruitment/");
  884. // Load file with numbering class (if found)
  885. $mybool |= @include_once $dir.$file;
  886. }
  887. if ($mybool === false) {
  888. dol_print_error('', "Failed to include file ".$file);
  889. return '';
  890. }
  891. if (class_exists($classname)) {
  892. $obj = new $classname();
  893. $numref = $obj->getNextValue($this);
  894. if ($numref != '' && $numref != '-1') {
  895. return $numref;
  896. } else {
  897. $this->error = $obj->error;
  898. //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
  899. return "";
  900. }
  901. } else {
  902. print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
  903. return "";
  904. }
  905. } else {
  906. print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
  907. return "";
  908. }
  909. }
  910. /**
  911. * Create a document onto disk according to template module.
  912. *
  913. * @param string $modele Force template to use ('' to not force)
  914. * @param Translate $outputlangs objet lang a utiliser pour traduction
  915. * @param int $hidedetails Hide details of lines
  916. * @param int $hidedesc Hide description
  917. * @param int $hideref Hide ref
  918. * @param null|array $moreparams Array to provide more information
  919. * @return int 0 if KO, 1 if OK
  920. */
  921. public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
  922. {
  923. global $conf, $langs;
  924. $result = 0;
  925. $includedocgeneration = 1;
  926. $langs->load("recruitment");
  927. if (!dol_strlen($modele)) {
  928. if (!empty($conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF)) {
  929. $modele = $conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF;
  930. } else {
  931. $modele = ''; // No default value. For job position, we allow to disable all PDF generation
  932. }
  933. }
  934. $modelpath = "core/modules/recruitment/doc/";
  935. if ($includedocgeneration && !empty($modele)) {
  936. $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
  937. }
  938. return $result;
  939. }
  940. /**
  941. * Action executed by scheduler
  942. * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
  943. * Use public function doScheduledJob($param1, $param2, ...) to get parameters
  944. *
  945. * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
  946. */
  947. public function doScheduledJob()
  948. {
  949. global $conf, $langs;
  950. //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
  951. $error = 0;
  952. $this->output = '';
  953. $this->error = '';
  954. dol_syslog(__METHOD__, LOG_DEBUG);
  955. $now = dol_now();
  956. $this->db->begin();
  957. // ...
  958. $this->db->commit();
  959. return $error;
  960. }
  961. }