dolibarr 25.0.0-alpha
recruitmentcandidature.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonpeople.class.php';
29
34{
35 use CommonPeople;
36
40 public $module = 'recruitment';
41
45 public $element = 'recruitmentcandidature';
46
50 public $table_element = 'recruitment_recruitmentcandidature';
51
55 public $picto = 'recruitmentcandidature';
56
60 public $email_fields_no_propagate_in_actioncomm;
61
62
63 const STATUS_DRAFT = 0;
64 const STATUS_VALIDATED = 1;
65 //const STATUS_INTERVIEW_SCHEDULED = 2;
66 const STATUS_CONTRACT_PROPOSED = 3;
67 const STATUS_CONTRACT_SIGNED = 5;
68 const STATUS_CONTRACT_REFUSED = 6;
69 const STATUS_REFUSED = 8;
70 const STATUS_CANCELED = 9;
71
72
98 // BEGIN MODULEBUILDER PROPERTIES
102 public $fields = array(
103 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => "Id"),
104 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'position' => 5, 'notnull' => 1, 'default' => '1', 'index' => 1),
105 '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'),
106 'fk_recruitmentjobposition' => array('type' => 'integer:RecruitmentJobPosition:recruitment/class/recruitmentjobposition.class.php:0', 'label' => 'Job', 'enabled' => '1', 'position' => 15, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'picto' => 'recruitmentjobposition', 'css' => 'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist' => 'minwidth100 nowraponall'),
107 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
108 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
109 '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'),
110 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2, 'csslist' => 'tdoverflowmax100'),
111 'lastname' => array('type' => 'varchar(128)', 'label' => 'Lastname', 'enabled' => 1, 'position' => 20, 'notnull' => 0, 'visible' => 1, 'csslist' => 'tdoverflowmax150'),
112 'firstname' => array('type' => 'varchar(128)', 'label' => 'Firstname', 'enabled' => 1, 'position' => 21, 'notnull' => 0, 'visible' => 1, 'csslist' => 'tdoverflowmax150'),
113 'email' => array('type' => 'email', 'label' => 'EMail', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'picto' => 'email', 'csslist' => 'tdoverflowmax150'),
114 'phone' => array('type' => 'phone', 'label' => 'Phone', 'enabled' => 1, 'position' => 31, 'notnull' => 0, 'visible' => 1, 'picto' => 'phone', 'csslist' => 'tdoverflowmax150'),
115 'date_birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'position' => 70, 'visible' => -1,),
116 'email_msgid' => array('type' => 'varchar(255)', 'label' => 'EmailMsgID', 'visible' => -2, 'enabled' => 1, 'position' => 540, 'notnull' => -1, 'help' => 'EmailMsgIDDesc'),
117 'email_date' => array('type' => 'datetime', 'label' => 'EmailDate', 'visible' => -2, 'enabled' => 1, 'position' => 541),
118 //'fk_recruitment_origin' => array('type'=>'integer:CRecruitmentOrigin:recruitment/class/crecruitmentorigin.class.php', 'label'=>'Origin', 'enabled'=>1, 'position'=>45, 'visible'=>1, 'index'=>1),
119 'remuneration_requested' => array('type' => 'integer', 'label' => 'RequestedRemuneration', 'enabled' => 1, 'position' => 80, 'notnull' => 0, 'visible' => -1,),
120 'remuneration_proposed' => array('type' => 'integer', 'label' => 'ProposedRemuneration', 'enabled' => 1, 'position' => 81, 'notnull' => 0, 'visible' => -1,),
121 'description' => array('type' => 'html', 'label' => 'Description', 'enabled' => 1, 'position' => 300, 'notnull' => 0, 'visible' => 3, 'cssview' => 'wordbreak'),
122 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -4, 'csslist' => 'nowraponall'),
123 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2, 'csslist' => 'nowraponall'),
124 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Employee', 'picto' => 'user', 'help' => 'LinkToUserCreated', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => -1, 'css' => 'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist' => 'tdoverflowmax100'),
125 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
126 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
127 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'visible' => 2, 'index' => 1, 'default' => '0', 'arrayofkeyval' => array(0 => 'Draft', 1 => 'Received', 3 => 'ContractProposed', 5 => 'RecruitmentContractSigned', 8 => 'Refused', 9 => 'Canceled')),
128 "ip" => array("type" => "varchar(250)", "label" => "Ip", "enabled" => 1, 'position' => 700, 'notnull' => 0, "visible" => 0, "comment" => "ip used to create record (for public submission page)"),
129 );
130
134 public $rowid;
135
139 public $ref;
143 public $fk_recruitmentjobposition;
147 public $description;
151 public $fk_user_creat;
155 public $fk_user_modif;
159 public $fk_user;
163 public $lastname;
167 public $firstname;
171 public $email;
175 public $phone;
179 public $date_birth;
183 public $email_msgid;
187 public $email_date;
191 public $remuneration_requested;
195 public $remuneration_proposed;
199 public $fk_recruitment_origin;
203 public $import_key;
207 public $model_pdf;
211 public $status;
215 public $ip;
216 // END MODULEBUILDER PROPERTIES
217
223 public function __construct(DoliDB $db)
224 {
225 global $langs;
226
227 $this->db = $db;
228
229 $this->ismultientitymanaged = 1;
230 $this->isextrafieldmanaged = 1;
231
232 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
233 $this->fields['rowid']['visible'] = 0;
234 }
235 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
236 $this->fields['entity']['enabled'] = 0;
237 }
238
239 // Example to show how to set values of fields definition dynamically
240 /*if ($user->rights->recruitment->recruitmentcandidature->read) {
241 $this->fields['myfield']['visible'] = 1;
242 $this->fields['myfield']['noteditable'] = 0;
243 }*/
244
245 // Unset fields that are disabled
246 foreach ($this->fields as $key => $val) {
247 if (isset($val['enabled']) && empty($val['enabled'])) {
248 unset($this->fields[$key]);
249 }
250 }
251
252 // Translate some data of arrayofkeyval
253 if (is_object($langs)) {
254 foreach ($this->fields as $key => $val) {
255 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
256 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
257 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
258 }
259 }
260 }
261 }
262 }
263
271 public function create(User $user, $notrigger = 0)
272 {
273 return $this->createCommon($user, $notrigger);
274 }
275
283 public function createFromClone(User $user, $fromid)
284 {
285 global $langs, $extrafields;
286 $error = 0;
287
288 dol_syslog(__METHOD__, LOG_DEBUG);
289
290 $object = new self($this->db);
291
292 $this->db->begin();
293
294 // Load source object
295 $result = $object->fetchCommon($fromid);
296 if ($result > 0 && !empty($object->table_element_line)) {
297 $object->fetchLines();
298 }
299
300 // get lines so they will be clone
301 //foreach($this->lines as $line)
302 // $line->fetch_optionals();
303
304 // Reset some properties
305 unset($object->id);
306 unset($object->fk_user_creat);
307 unset($object->import_key);
308
309 // Clear fields
310 if (property_exists($object, 'ref')) {
311 // @phan-suppress-next-line PhanTypeMismatchProperty
312 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
313 }
314
315 $object->status = self::STATUS_DRAFT;
316 $object->date_creation = dol_now();
317 $object->date_modification = null;
318
319 // Clear extrafields that are unique
320 if (is_array($object->array_options) && count($object->array_options) > 0) {
321 $extrafields->fetch_name_optionals_label($this->table_element);
322 foreach ($object->array_options as $key => $option) {
323 $shortkey = preg_replace('/options_/', '', $key);
324 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
325 unset($object->array_options[$key]);
326 }
327 }
328 }
329
330 // Create clone
331 $object->context['createfromclone'] = 'createfromclone';
332 $result = $object->createCommon($user);
333 if ($result < 0) {
334 $error++;
336 }
337
338 if (!$error) {
339 // copy internal contacts
340 if ($this->copy_linked_contact($object, 'internal') < 0) {
341 $error++;
342 }
343 }
344
345 unset($object->context['createfromclone']);
346
347 // End
348 if (!$error) {
349 $this->db->commit();
350 return $object;
351 } else {
352 $this->db->rollback();
353 return -1;
354 }
355 }
356
365 public function fetch($id, $ref = null, $email_msgid = '')
366 {
367 $morewhere = '';
368 if ($email_msgid) {
369 $morewhere = " AND email_msgid = '".$this->db->escape($email_msgid)."'";
370 }
371 $result = $this->fetchCommon($id, $ref, $morewhere);
372 if ($result > 0 && !empty($this->table_element_line)) {
373 $this->fetchLines();
374 }
375 return $result;
376 }
377
383 public function fetchLines()
384 {
385 $this->lines = array();
386
387 $result = $this->fetchLinesCommon();
388 return $result;
389 }
390
391
404 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
405 {
406 dol_syslog(__METHOD__, LOG_DEBUG);
407
408 $records = array();
409
410 $sql = 'SELECT ';
411 $sql .= $this->getFieldList();
412 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
413 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
414 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
415 } else {
416 $sql .= ' WHERE 1 = 1';
417 }
418
419 // Manage filter
420 $errormessage = '';
421 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
422 if ($errormessage) {
423 $this->errors[] = $errormessage;
424 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
425 return -1;
426 }
427
428 if (!empty($sortfield)) {
429 $sql .= $this->db->order($sortfield, $sortorder);
430 }
431 if (!empty($limit)) {
432 $sql .= $this->db->plimit($limit, $offset);
433 }
434
435 $resql = $this->db->query($sql);
436 if ($resql) {
437 $num = $this->db->num_rows($resql);
438 $i = 0;
439 while ($i < ($limit ? min($limit, $num) : $num)) {
440 $obj = $this->db->fetch_object($resql);
441
442 $record = new self($this->db);
443 $record->setVarsFromFetchObj($obj);
444
445 $records[$record->id] = $record;
446
447 $i++;
448 }
449 $this->db->free($resql);
450
451 return $records;
452 } else {
453 $this->errors[] = 'Error '.$this->db->lasterror();
454 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
455
456 return -1;
457 }
458 }
459
467 public function update(User $user, $notrigger = 0)
468 {
469 return $this->updateCommon($user, $notrigger);
470 }
471
479 public function delete(User $user, $notrigger = 0)
480 {
481 return $this->deleteCommon($user, $notrigger);
482 //return $this->deleteCommon($user, $notrigger, 1);
483 }
484
493 public function deleteLine(User $user, $idline, $notrigger = 0)
494 {
495 if ($this->status < 0) {
496 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
497 return -2;
498 }
499
500 return $this->deleteLineCommon($user, $idline, $notrigger);
501 }
502
503
511 public function validate($user, $notrigger = 0)
512 {
513 global $conf, $langs;
514
515 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
516
517 $error = 0;
518
519 // Protection
520 if ($this->status == self::STATUS_VALIDATED) {
521 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
522 return 0;
523 }
524
525 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitmentcandidature->write))
526 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitmentcandidature->recruitmentcandidature_advance->validate))))
527 {
528 $this->error='NotEnoughPermissions';
529 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
530 return -1;
531 }*/
532
533 $now = dol_now();
534
535 $this->db->begin();
536
537 // Define new ref
538 if (/* !$error && */ (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
539 $num = $this->getNextNumRef();
540 } else {
541 $num = (string) $this->ref;
542 }
543 $this->newref = $num;
544
545 if (!empty($num)) {
546 // Validate
547 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
548 $sql .= " SET ref = '".$this->db->escape($num)."',";
549 $sql .= " status = ".self::STATUS_VALIDATED;
550 if (!empty($this->fields['date_validation'])) {
551 $sql .= ", date_validation = '".$this->db->idate($now)."',";
552 }
553 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
554 $sql .= ", fk_user_valid = ".((int) $user->id);
555 }
556 $sql .= " WHERE rowid = ".((int) $this->id);
557
558 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
559 $resql = $this->db->query($sql);
560 if (!$resql) {
561 dol_print_error($this->db);
562 $this->error = $this->db->lasterror();
563 $error++;
564 }
565
566 if (!$error && !$notrigger) {
567 // Call trigger
568 $result = $this->call_trigger('RECRUITMENTCANDIDATURE_VALIDATE', $user);
569 if ($result < 0) {
570 $error++;
571 }
572 // End call triggers
573 }
574 }
575
576 if (!$error) {
577 $this->oldref = $this->ref;
578
579 // Rename directory if dir was a temporary ref
580 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
581 // Now we rename also files into index
582 $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)."'";
583 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
584 $resql = $this->db->query($sql);
585 if (!$resql) {
586 $error++;
587 $this->error = $this->db->lasterror();
588 }
589 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'recruitmentcandidature/".$this->db->escape($this->newref)."'";
590 $sql .= " WHERE filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
591 $resql = $this->db->query($sql);
592 if (!$resql) {
593 $error++;
594 $this->error = $this->db->lasterror();
595 }
596
597 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
598 $oldref = dol_sanitizeFileName($this->ref);
599 $newref = dol_sanitizeFileName($num);
600 $dirsource = $conf->recruitment->dir_output.'/recruitmentcandidature/'.$oldref;
601 $dirdest = $conf->recruitment->dir_output.'/recruitmentcandidature/'.$newref;
602 if (!$error && file_exists($dirsource)) {
603 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
604
605 if (@rename($dirsource, $dirdest)) {
606 dol_syslog("Rename ok");
607 // Rename docs starting with $oldref with $newref
608 $listoffiles = dol_dir_list($conf->recruitment->dir_output.'/recruitmentcandidature/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
609 foreach ($listoffiles as $fileentry) {
610 $dirsource = $fileentry['name'];
611 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
612 $dirsource = $fileentry['path'].'/'.$dirsource;
613 $dirdest = $fileentry['path'].'/'.$dirdest;
614 @rename($dirsource, $dirdest);
615 }
616 }
617 }
618 }
619 }
620
621 // Set new ref and current status
622 if (!$error) {
623 $this->ref = $num;
624 $this->status = self::STATUS_VALIDATED;
625 }
626
627 if (!$error) {
628 $this->db->commit();
629 return 1;
630 } else {
631 $this->db->rollback();
632 return -1;
633 }
634 }
635
636
644 public function setDraft($user, $notrigger = 0)
645 {
646 // Protection
647 if ($this->status <= self::STATUS_DRAFT) {
648 return 0;
649 }
650
651 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
652 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
653 {
654 $this->error='Permission denied';
655 return -1;
656 }*/
657
658 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'RECRUITMENTCANDIDATURE_UNVALIDATE');
659 }
660
668 public function cancel($user, $notrigger = 0)
669 {
670 // Protection
671 if ($this->status != self::STATUS_VALIDATED) {
672 return 0;
673 }
674
675 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
676 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
677 {
678 $this->error='Permission denied';
679 return -1;
680 }*/
681
682 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'RECRUITMENTCANDIDATURE_CLOSE');
683 }
684
692 public function reopen($user, $notrigger = 0)
693 {
694 // Protection
695 if ($this->status != self::STATUS_REFUSED && $this->status != self::STATUS_CANCELED && $this->status != self::STATUS_CONTRACT_REFUSED) {
696 return 0;
697 }
698
699 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
700 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
701 {
702 $this->error='Permission denied';
703 return -1;
704 }*/
705
706 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'RECRUITMENTCANDIDATURE_REOPEN');
707 }
708
718 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
719 {
720 $lastname = $this->lastname;
721 $firstname = $this->firstname;
722
723 $ret = '';
724
725 $ret .= dolGetFirstLastname((string) $firstname, (string) $lastname, $nameorder);
726
727 return dol_trunc($ret, $maxlen);
728 }
729
737 public function getTooltipContentArray($params)
738 {
739 global $langs;
740
741 $langs->load('recruitment');
742
743 $datas = [];
744
745 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
746 return ['optimize' => $langs->trans("ShowRecruitmentCandidature")];
747 }
748 $datas['picto'] = img_picto('', $this->picto) . ' <u class="paddingrightonly">' . $langs->trans("RecruitmentCandidature") . '</u>';
749 if (isset($this->status)) {
750 $datas['picto'] .= ' ' . $this->getLibStatut(5);
751 }
752 if (!empty($this->ref)) {
753 $datas['ref'] = '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
754 }
755 if (!empty($this->email)) {
756 $datas['email'] = '<br>' . $langs->trans('Email') . ':</b> ' . $this->email;
757 }
758 $datas['name'] = '<br>' . $langs->trans('Email') . ':</b> ' . $this->getFullName($langs);
759
760 return $datas;
761 }
762
773 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
774 {
775 global $conf, $langs, $hookmanager;
776
777 if (!empty($conf->dol_no_mouse_hover)) {
778 $notooltip = 1; // Force disable tooltips
779 }
780
781 $result = '';
782 $params = [
783 'id' => (string) $this->id,
784 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
785 'option' => $option,
786 ];
787 $classfortooltip = 'classfortooltip';
788 $dataparams = '';
789 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
790 $classfortooltip = 'classforajaxtooltip';
791 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
792 $label = '';
793 } else {
794 $label = implode($this->getTooltipContentArray($params));
795 }
796
797 $baseurl = DOL_URL_ROOT . '/recruitment/recruitmentcandidature_card.php';
798 $query = ['id' => $this->id];
799 if ($option !== 'nolink') {
800 // Add param to save lastsearch_values or not
801 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
802 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
803 $add_save_lastsearch_values = 1;
804 }
805 if ($add_save_lastsearch_values) {
806 $query += ['save_lastsearch_values' => 1];
807 }
808 }
809 $url = dolBuildUrl($baseurl, $query);
810
811 $linkclose = '';
812 if (empty($notooltip)) {
813 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
814 $label = $langs->trans("ShowRecruitmentCandidature");
815 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
816 }
817 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
818 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
819 } else {
820 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
821 }
822
823 $linkstart = '<a href="'.$url.'"';
824 $linkstart .= $linkclose.'>';
825 $linkend = '</a>';
826
827 $result .= $linkstart;
828
829 if (empty($this->showphoto_on_popup)) {
830 if ($withpicto) {
831 $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);
832 }
833 } else {
834 if ($withpicto) {
835 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
836
837 list($class, $module) = explode('@', $this->picto);
838 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
839 $filearray = dol_dir_list($upload_dir, "files");
840 $filename = $filearray[0]['name'];
841 if (!empty($filename)) {
842 $pospoint = strpos($filearray[0]['name'], '.');
843
844 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.dol_substr($filename, 0, $pospoint).'_mini'.dol_substr($filename, $pospoint);
845 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
846 $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>';
847 } else {
848 $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>';
849 }
850
851 $result .= '</div>';
852 } else {
853 $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);
854 }
855 }
856 }
857
858 if ($withpicto != 2) {
859 $result .= $this->ref;
860 }
861
862 $result .= $linkend;
863 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
864
865 global $action, $hookmanager;
866 $hookmanager->initHooks(array('recruitmentcandidaturedao'));
867 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
868 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
869 if ($reshook > 0) {
870 $result = $hookmanager->resPrint;
871 } else {
872 $result .= $hookmanager->resPrint;
873 }
874
875 return $result;
876 }
877
884 public function getLibStatut($mode = 0)
885 {
886 return $this->LibStatut($this->status, $mode);
887 }
888
889 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
897 public function LibStatut($status, $mode = 0)
898 {
899 // phpcs:enable
900 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
901 global $langs;
902 //$langs->load("recruitment@recruitment");
903 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
904 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Received').' ('.$langs->transnoentitiesnoconv("InterviewToDo").')';
905 $this->labelStatus[self::STATUS_CONTRACT_PROPOSED] = $langs->transnoentitiesnoconv('ContractProposed');
906 $this->labelStatus[self::STATUS_CONTRACT_SIGNED] = $langs->transnoentitiesnoconv('RecruitmentContractSigned');
907 $this->labelStatus[self::STATUS_CONTRACT_REFUSED] = $langs->transnoentitiesnoconv('ContractRefused');
908 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
909 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
910 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
911 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Received');
912 $this->labelStatusShort[self::STATUS_CONTRACT_PROPOSED] = $langs->transnoentitiesnoconv('ContractProposed');
913 $this->labelStatusShort[self::STATUS_CONTRACT_SIGNED] = $langs->transnoentitiesnoconv('RecruitmentContractSigned');
914 $this->labelStatusShort[self::STATUS_CONTRACT_REFUSED] = $langs->transnoentitiesnoconv('ContractRefused');
915 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
916 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
917 }
918
919 $statusType = 'status'.$status;
920 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
921 if ($status == self::STATUS_CANCELED) {
922 $statusType = 'status9';
923 }
924 if ($status == self::STATUS_CONTRACT_PROPOSED) {
925 $statusType = 'status4';
926 }
927 if ($status == self::STATUS_CONTRACT_SIGNED) {
928 $statusType = 'status6';
929 }
930 if ($status == self::STATUS_REFUSED) {
931 $statusType = 'status10';
932 }
933
934 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
935 }
936
943 public function info($id)
944 {
945 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
946 $sql .= ' fk_user_creat, fk_user_modif';
947 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
948 $sql .= ' WHERE t.rowid = '.((int) $id);
949 $result = $this->db->query($sql);
950 if ($result) {
951 if ($this->db->num_rows($result)) {
952 $obj = $this->db->fetch_object($result);
953
954 $this->id = $obj->rowid;
955
956 $this->user_creation_id = $obj->fk_user_creat;
957 $this->user_modification_id = $obj->fk_user_modif;
958 $this->date_creation = $this->db->jdate($obj->datec);
959 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
960 }
961
962 $this->db->free($result);
963 } else {
964 dol_print_error($this->db);
965 }
966 }
967
974 public function initAsSpecimen()
975 {
976 return $this->initAsSpecimenCommon();
977 }
978
984 public function getLinesArray()
985 {
986 $this->lines = array();
987
988 $objectline = new RecruitmentCandidatureLine($this->db);
989 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_recruitmentcandidature:=:'.((int) $this->id).')');
990
991 if (is_numeric($result)) {
992 $this->setErrorsFromObject($objectline);
993 return $result;
994 } else {
995 $this->lines = $result;
996 // @phpstan-ignore-next-line
997 return $result; // @phan-suppress-current-line PhanTypeMismatchReturn
998 }
999 }
1000
1006 public function getNextNumRef()
1007 {
1008 global $langs, $conf;
1009 $langs->load("recruitment@recruitment");
1010
1011 if (!getDolGlobalString('RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON')) {
1012 $conf->global->RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON = 'mod_recruitmentcandidature_standard';
1013 }
1014
1015 if (getDolGlobalString('RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON')) {
1016 $mybool = false;
1017
1018 $file = getDolGlobalString('RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON') . ".php";
1019 $classname = getDolGlobalString('RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON');
1020
1021 // Include file with class
1022 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1023 foreach ($dirmodels as $reldir) {
1024 $dir = dol_buildpath($reldir."core/modules/recruitment/");
1025
1026 // Load file with numbering class (if found)
1027 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1028 }
1029
1030 if (!$mybool) {
1031 dol_print_error(null, "Failed to include file ".$file);
1032 return '';
1033 }
1034
1035 if (class_exists($classname)) {
1036 $obj = new $classname();
1037 '@phan-var-force ModeleNumRefRecruitmentCandidature $obj';
1039 $numref = $obj->getNextValue($this);
1040
1041 if ($numref != '' && $numref != '-1') {
1042 return $numref;
1043 } else {
1044 $this->error = $obj->error;
1045 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1046 return "";
1047 }
1048 } else {
1049 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1050 return "";
1051 }
1052 } else {
1053 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1054 return "";
1055 }
1056 }
1057
1069 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1070 {
1071 global $conf, $langs;
1072
1073 $result = 0;
1074 $includedocgeneration = 0;
1075
1076 $langs->load("recruitment@recruitment");
1077
1078 if (!dol_strlen($modele)) {
1079 if (getDolGlobalString('RECRUITMENTCANDIDATURE_ADDON_PDF')) {
1080 $modele = getDolGlobalString('RECRUITMENTCANDIDATURE_ADDON_PDF');
1081 } else {
1082 $modele = ''; // No default value. For job application, we allow to disable all PDF generation
1083 }
1084 }
1085
1086 $modelpath = "core/modules/recruitment/doc/";
1087
1088 if ($includedocgeneration && !empty($modele)) {
1089 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1090 }
1091
1092 return $result;
1093 }
1094
1102 public function doScheduledJob()
1103 {
1104 global $conf, $langs;
1105
1106 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1107
1108 $error = 0;
1109 $this->output = '';
1110 $this->error = '';
1111
1112 dol_syslog(__METHOD__, LOG_DEBUG);
1113
1114 $now = dol_now();
1115
1116 $this->db->begin();
1117
1118 // ...
1119
1120 $this->db->commit();
1121
1122 return $error;
1123 }
1124
1132 public function getKanbanView($option = '', $arraydata = null)
1133 {
1134 global $mysoc;
1135
1136 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1137
1138 $return = '<div class="box-flex-item box-flex-grow-zero">';
1139 $return .= '<div class="info-box info-box-sm">';
1140 $return .= '<span class="info-box-icon bg-infobox-action">';
1141 $return .= img_picto('', $this->picto);
1142 $return .= '</span>';
1143 $return .= '<div class="info-box-content">';
1144 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1145 if ($selected >= 0) {
1146 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1147 }
1148 if (property_exists($this, 'fk_recruitmentjobposition')) {
1149 $return .= '<br>';
1150 //$return .= '<span class="opacitymedium">';
1151 //$return .= $langs->trans('Job').'</span> : ';
1152 $return .= '<div class="info-box-label tdoverflowmax150">';
1153 $tmpjob = new RecruitmentJobPosition($this->db);
1154 $tmpjob->fetch($this->fk_recruitmentjobposition);
1155 //$return .= $this->fk_recruitmentjobposition;
1156 $return .= dolPrintHTML($tmpjob->label);
1157 $return .= '</div>';
1158 }
1159 if (property_exists($this, 'phone') && $this->phone) {
1160 $return .= '<div class="info-box-label small">'.dol_print_phone($this->phone, $mysoc->country_code, 0, 0, 'AC_TEL', '&nbsp;', 'phone').'</div>';
1161 }
1162 if (property_exists($this, 'email') && $this->email) {
1163 $return .= '<div class="info-box-label small">'.dol_print_email($this->email, 0, 0, 1, 64, 1, 1).'</div>';
1164 }
1165 if (method_exists($this, 'getLibStatut')) {
1166 $return .= '<div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1167 }
1168 $return .= '</div>';
1169 $return .= '</div>';
1170 $return .= '</div>';
1171 return $return;
1172 }
1173}
1174
1175
1176require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1177
1182{
1183 // To complete with content of an object RecruitmentCandidatureLine
1184 // We should have a field rowid, fk_recruitmentcandidature and position
1185
1191 public function __construct(DoliDB $db)
1192 {
1193 $this->db = $db;
1194 }
1195}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for RecruitmentCandidature.
getLinesArray()
Create an array of lines.
createFromClone(User $user, $fromid)
Clone an object into another one.
cancel($user, $notrigger=0)
Set cancel status.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
reopen($user, $notrigger=0)
Set back to validated status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getLibStatut($mode=0)
Return label of the status.
fetch($id, $ref=null, $email_msgid='')
Load object in memory from the database.
fetchLines()
Load object lines in memory from the database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
update(User $user, $notrigger=0)
Update object into database.
validate($user, $notrigger=0)
Validate object.
getTooltipContentArray($params)
getTooltipContentArray
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
LibStatut($status, $mode=0)
Return the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name ('name+' '+lastname)
setDraft($user, $notrigger=0)
Set draft status.
create(User $user, $notrigger=0)
Create object into database.
info($id)
Load the info information in the object.
Class RecruitmentCandidatureLine.
Class for RecruitmentJobPosition.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.