recruitmentcandidature.class.php 42 KB

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