dolibarr 19.0.4
recruitmentcandidature.class.php
Go to the documentation of this file.
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
24// Put here all includes required by your class file
25require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
26//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
27//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
28
33{
37 public $module = 'recruitment';
38
42 public $element = 'recruitmentcandidature';
43
47 public $table_element = 'recruitment_recruitmentcandidature';
48
53 public $ismultientitymanaged = 1;
54
58 public $isextrafieldmanaged = 1;
59
63 public $picto = 'recruitmentcandidature';
64
68 public $email_fields_no_propagate_in_actioncomm;
69
70
71 const STATUS_DRAFT = 0;
72 const STATUS_VALIDATED = 1;
73 //const STATUS_INTERVIEW_SCHEDULED = 2;
74 const STATUS_CONTRACT_PROPOSED = 3;
75 const STATUS_CONTRACT_SIGNED = 5;
76 const STATUS_CONTRACT_REFUSED = 6;
77 const STATUS_REFUSED = 8;
78 const STATUS_CANCELED = 9;
79
80
106 // BEGIN MODULEBUILDER PROPERTIES
110 public $fields = array(
111 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'comment'=>"Id"),
112 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1),
113 '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'),
114 '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'),
115 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
116 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
117 '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'),
118 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2, 'csslist'=>'tdoverflowmax100'),
119 'lastname' => array('type'=>'varchar(128)', 'label'=>'Lastname', 'enabled'=>'1', 'position'=>20, 'notnull'=>0, 'visible'=>1, 'csslist'=>'tdoverflowmax150'),
120 'firstname' => array('type'=>'varchar(128)', 'label'=>'Firstname', 'enabled'=>'1', 'position'=>21, 'notnull'=>0, 'visible'=>1, 'csslist'=>'tdoverflowmax150'),
121 'email' => array('type'=>'email', 'label'=>'EMail', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'picto'=>'email', 'csslist'=>'tdoverflowmax150'),
122 'phone' => array('type'=>'phone', 'label'=>'Phone', 'enabled'=>'1', 'position'=>31, 'notnull'=>0, 'visible'=>1, 'picto'=>'phone', 'csslist'=>'tdoverflowmax150'),
123 'date_birth' => array('type'=>'date', 'label'=>'DateOfBirth', 'enabled'=>'1', 'position'=>70, 'visible'=>-1,),
124 'email_msgid' => array('type'=>'varchar(255)', 'label'=>'EmailMsgID', 'visible'=>-2, 'enabled'=>1, 'position'=>540, 'notnull'=>-1, 'help'=>'EmailMsgIDDesc'),
125 'email_date' => array('type'=>'datetime', 'label'=>'EmailDate', 'visible'=>-2, 'enabled'=>1, 'position'=>541),
126 //'fk_recruitment_origin' => array('type'=>'integer:CRecruitmentOrigin:recruitment/class/crecruitmentorigin.class.php', 'label'=>'Origin', 'enabled'=>'1', 'position'=>45, 'visible'=>1, 'index'=>1),
127 'remuneration_requested' => array('type'=>'integer', 'label'=>'RequestedRemuneration', 'enabled'=>'1', 'position'=>80, 'notnull'=>0, 'visible'=>-1,),
128 'remuneration_proposed' => array('type'=>'integer', 'label'=>'ProposedRemuneration', 'enabled'=>'1', 'position'=>81, 'notnull'=>0, 'visible'=>-1,),
129 'description' => array('type'=>'html', 'label'=>'Description', 'enabled'=>'1', 'position'=>300, 'notnull'=>0, 'visible'=>3, 'cssview'=>'wordbreak'),
130 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-4, 'csslist'=>'nowraponall'),
131 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2, 'csslist'=>'nowraponall'),
132 'fk_user' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'LinkedToDolibarrUser', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>-1, 'csslist'=>'tdoverflowmax100'),
133 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
134 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
135 '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')),
136 );
137 public $rowid;
138 public $entity;
139 public $ref;
140 public $fk_recruitmentjobposition;
141 public $description;
142 public $note_public;
143 public $note_private;
144 public $date_creation;
145 public $tms;
146 public $fk_user_creat;
147 public $fk_user_modif;
148 public $fk_user;
149 public $lastname;
150 public $firstname;
151 public $email;
152 public $phone;
153 public $date_birth;
154 public $email_msgid;
155 public $email_date;
156 public $remuneration_requested;
157 public $remuneration_proposed;
158 public $fk_recruitment_origin;
159 public $import_key;
160 public $model_pdf;
161 public $status;
162 // END MODULEBUILDER PROPERTIES
163
164
170 public function __construct(DoliDB $db)
171 {
172 global $conf, $langs;
173
174 $this->db = $db;
175
176 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
177 $this->fields['rowid']['visible'] = 0;
178 }
179 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
180 $this->fields['entity']['enabled'] = 0;
181 }
182
183 // Example to show how to set values of fields definition dynamically
184 /*if ($user->rights->recruitment->recruitmentcandidature->read) {
185 $this->fields['myfield']['visible'] = 1;
186 $this->fields['myfield']['noteditable'] = 0;
187 }*/
188
189 // Unset fields that are disabled
190 foreach ($this->fields as $key => $val) {
191 if (isset($val['enabled']) && empty($val['enabled'])) {
192 unset($this->fields[$key]);
193 }
194 }
195
196 // Translate some data of arrayofkeyval
197 if (is_object($langs)) {
198 foreach ($this->fields as $key => $val) {
199 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
200 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
201 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
202 }
203 }
204 }
205 }
206
207 if (GETPOST("action", "aZ09") == 'create') {
208 $reg = array();
209 preg_match('/^(integer|link):(.*):(.*):(.*):(.*)/i', $this->fields['fk_recruitmentjobposition']['type'], $reg);
210 if (!empty($reg)) {
211 $this->fields['fk_recruitmentjobposition']['type'] .= " AND (t.status:=:1)";
212 } else {
213 $this->fields['fk_recruitmentjobposition']['type'] .= ":(t.status:=:1)";
214 }
215 }
216 }
217
225 public function create(User $user, $notrigger = false)
226 {
227 return $this->createCommon($user, $notrigger);
228 }
229
237 public function createFromClone(User $user, $fromid)
238 {
239 global $langs, $extrafields;
240 $error = 0;
241
242 dol_syslog(__METHOD__, LOG_DEBUG);
243
244 $object = new self($this->db);
245
246 $this->db->begin();
247
248 // Load source object
249 $result = $object->fetchCommon($fromid);
250 if ($result > 0 && !empty($object->table_element_line)) {
251 $object->fetchLines();
252 }
253
254 // get lines so they will be clone
255 //foreach($this->lines as $line)
256 // $line->fetch_optionals();
257
258 // Reset some properties
259 unset($object->id);
260 unset($object->fk_user_creat);
261 unset($object->import_key);
262
263 // Clear fields
264 if (property_exists($object, 'ref')) {
265 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
266 }
267 if (property_exists($object, 'label')) {
268 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
269 }
270 if (property_exists($object, 'status')) {
271 $object->status = self::STATUS_DRAFT;
272 }
273 if (property_exists($object, 'date_creation')) {
274 $object->date_creation = dol_now();
275 }
276 if (property_exists($object, 'date_modification')) {
277 $object->date_modification = null;
278 }
279
280 // ...
281 // Clear extrafields that are unique
282 if (is_array($object->array_options) && count($object->array_options) > 0) {
283 $extrafields->fetch_name_optionals_label($this->table_element);
284 foreach ($object->array_options as $key => $option) {
285 $shortkey = preg_replace('/options_/', '', $key);
286 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
287 //var_dump($key);
288 //var_dump($clonedObj->array_options[$key]); exit;
289 unset($object->array_options[$key]);
290 }
291 }
292 }
293
294 // Create clone
295 $object->context['createfromclone'] = 'createfromclone';
296 $result = $object->createCommon($user);
297 if ($result < 0) {
298 $error++;
299 $this->error = $object->error;
300 $this->errors = $object->errors;
301 }
302
303 if (!$error) {
304 // copy internal contacts
305 if ($this->copy_linked_contact($object, 'internal') < 0) {
306 $error++;
307 }
308 }
309
310 if (!$error) {
311 // copy external contacts if same company
312 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
313 if ($this->copy_linked_contact($object, 'external') < 0) {
314 $error++;
315 }
316 }
317 }
318
319 unset($object->context['createfromclone']);
320
321 // End
322 if (!$error) {
323 $this->db->commit();
324 return $object;
325 } else {
326 $this->db->rollback();
327 return -1;
328 }
329 }
330
339 public function fetch($id, $ref = null, $email_msgid = '')
340 {
341 $morewhere = '';
342 if ($email_msgid) {
343 $morewhere = " AND email_msgid = '".$this->db->escape($email_msgid)."'";
344 }
345 $result = $this->fetchCommon($id, $ref, $morewhere);
346 if ($result > 0 && !empty($this->table_element_line)) {
347 $this->fetchLines();
348 }
349 return $result;
350 }
351
357 public function fetchLines()
358 {
359 $this->lines = array();
360
361 $result = $this->fetchLinesCommon();
362 return $result;
363 }
364
365
377 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
378 {
379 dol_syslog(__METHOD__, LOG_DEBUG);
380
381 $records = array();
382
383 $sql = 'SELECT ';
384 $sql .= $this->getFieldList();
385 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
386 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
387 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
388 } else {
389 $sql .= ' WHERE 1 = 1';
390 }
391 // Manage filter
392 $sqlwhere = array();
393 if (count($filter) > 0) {
394 foreach ($filter as $key => $value) {
395 if ($key == 't.rowid') {
396 $sqlwhere[] = $key." = ".((int) $value);
397 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
398 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
399 } elseif ($key == 'customsql') {
400 $sqlwhere[] = $value;
401 } elseif (strpos($value, '%') === false) {
402 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
403 } else {
404 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
405 }
406 }
407 }
408 if (count($sqlwhere) > 0) {
409 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
410 }
411
412 if (!empty($sortfield)) {
413 $sql .= $this->db->order($sortfield, $sortorder);
414 }
415 if (!empty($limit)) {
416 $sql .= $this->db->plimit($limit, $offset);
417 }
418
419 $resql = $this->db->query($sql);
420 if ($resql) {
421 $num = $this->db->num_rows($resql);
422 $i = 0;
423 while ($i < ($limit ? min($limit, $num) : $num)) {
424 $obj = $this->db->fetch_object($resql);
425
426 $record = new self($this->db);
427 $record->setVarsFromFetchObj($obj);
428
429 $records[$record->id] = $record;
430
431 $i++;
432 }
433 $this->db->free($resql);
434
435 return $records;
436 } else {
437 $this->errors[] = 'Error '.$this->db->lasterror();
438 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
439
440 return -1;
441 }
442 }
443
451 public function update(User $user, $notrigger = false)
452 {
453 return $this->updateCommon($user, $notrigger);
454 }
455
463 public function delete(User $user, $notrigger = false)
464 {
465 return $this->deleteCommon($user, $notrigger);
466 //return $this->deleteCommon($user, $notrigger, 1);
467 }
468
477 public function deleteLine(User $user, $idline, $notrigger = false)
478 {
479 if ($this->status < 0) {
480 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
481 return -2;
482 }
483
484 return $this->deleteLineCommon($user, $idline, $notrigger);
485 }
486
487
495 public function validate($user, $notrigger = 0)
496 {
497 global $conf, $langs;
498
499 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
500
501 $error = 0;
502
503 // Protection
504 if ($this->status == self::STATUS_VALIDATED) {
505 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
506 return 0;
507 }
508
509 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitmentcandidature->write))
510 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitmentcandidature->recruitmentcandidature_advance->validate))))
511 {
512 $this->error='NotEnoughPermissions';
513 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
514 return -1;
515 }*/
516
517 $now = dol_now();
518
519 $this->db->begin();
520
521 // Define new ref
522 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
523 $num = $this->getNextNumRef();
524 } else {
525 $num = $this->ref;
526 }
527 $this->newref = $num;
528
529 if (!empty($num)) {
530 // Validate
531 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
532 $sql .= " SET ref = '".$this->db->escape($num)."',";
533 $sql .= " status = ".self::STATUS_VALIDATED;
534 if (!empty($this->fields['date_validation'])) {
535 $sql .= ", date_validation = '".$this->db->idate($now)."',";
536 }
537 if (!empty($this->fields['fk_user_valid'])) {
538 $sql .= ", fk_user_valid = ".$user->id;
539 }
540 $sql .= " WHERE rowid = ".((int) $this->id);
541
542 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
543 $resql = $this->db->query($sql);
544 if (!$resql) {
545 dol_print_error($this->db);
546 $this->error = $this->db->lasterror();
547 $error++;
548 }
549
550 if (!$error && !$notrigger) {
551 // Call trigger
552 $result = $this->call_trigger('RECRUITMENTCANDIDATURE_VALIDATE', $user);
553 if ($result < 0) {
554 $error++;
555 }
556 // End call triggers
557 }
558 }
559
560 if (!$error) {
561 $this->oldref = $this->ref;
562
563 // Rename directory if dir was a temporary ref
564 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
565 // Now we rename also files into index
566 $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)."'";
567 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
568 $resql = $this->db->query($sql);
569 if (!$resql) {
570 $error++;
571 $this->error = $this->db->lasterror();
572 }
573 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'recruitmentcandidature/".$this->db->escape($this->newref)."'";
574 $sql .= " WHERE filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
575 $resql = $this->db->query($sql);
576 if (!$resql) {
577 $error++;
578 $this->error = $this->db->lasterror();
579 }
580
581 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
582 $oldref = dol_sanitizeFileName($this->ref);
583 $newref = dol_sanitizeFileName($num);
584 $dirsource = $conf->recruitment->dir_output.'/recruitmentcandidature/'.$oldref;
585 $dirdest = $conf->recruitment->dir_output.'/recruitmentcandidature/'.$newref;
586 if (!$error && file_exists($dirsource)) {
587 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
588
589 if (@rename($dirsource, $dirdest)) {
590 dol_syslog("Rename ok");
591 // Rename docs starting with $oldref with $newref
592 $listoffiles = dol_dir_list($conf->recruitment->dir_output.'/recruitmentcandidature/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
593 foreach ($listoffiles as $fileentry) {
594 $dirsource = $fileentry['name'];
595 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
596 $dirsource = $fileentry['path'].'/'.$dirsource;
597 $dirdest = $fileentry['path'].'/'.$dirdest;
598 @rename($dirsource, $dirdest);
599 }
600 }
601 }
602 }
603 }
604
605 // Set new ref and current status
606 if (!$error) {
607 $this->ref = $num;
608 $this->status = self::STATUS_VALIDATED;
609 }
610
611 if (!$error) {
612 $this->db->commit();
613 return 1;
614 } else {
615 $this->db->rollback();
616 return -1;
617 }
618 }
619
620
628 public function setDraft($user, $notrigger = 0)
629 {
630 // Protection
631 if ($this->status <= self::STATUS_DRAFT) {
632 return 0;
633 }
634
635 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
636 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
637 {
638 $this->error='Permission denied';
639 return -1;
640 }*/
641
642 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'RECRUITMENTCANDIDATURE_UNVALIDATE');
643 }
644
652 public function cancel($user, $notrigger = 0)
653 {
654 // Protection
655 if ($this->status != self::STATUS_VALIDATED) {
656 return 0;
657 }
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
666 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'RECRUITMENTCANDIDATURE_CLOSE');
667 }
668
676 public function reopen($user, $notrigger = 0)
677 {
678 // Protection
679 if ($this->status != self::STATUS_REFUSED && $this->status != self::STATUS_CANCELED && $this->status != self::STATUS_CONTRACT_REFUSED) {
680 return 0;
681 }
682
683 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
684 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
685 {
686 $this->error='Permission denied';
687 return -1;
688 }*/
689
690 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'RECRUITMENTCANDIDATURE_REOPEN');
691 }
692
702 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
703 {
704 $lastname = $this->lastname;
705 $firstname = $this->firstname;
706 if (empty($lastname)) {
707 $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 : '')))));
708 }
709
710 $ret = '';
711
712 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
713
714 return dol_trunc($ret, $maxlen);
715 }
716
727 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
728 {
729 global $conf, $langs, $hookmanager;
730
731 if (!empty($conf->dol_no_mouse_hover)) {
732 $notooltip = 1; // Force disable tooltips
733 }
734
735 $result = '';
736
737 $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("RecruitmentCandidature").'</u>';
738 if (isset($this->status)) {
739 $label .= ' '.$this->getLibStatut(5);
740 }
741 $label .= '<br>';
742 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
743 $label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email;
744 $label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
745
746 $url = dol_buildpath('/recruitment/recruitmentcandidature_card.php', 1).'?id='.$this->id;
747
748 if ($option != 'nolink') {
749 // Add param to save lastsearch_values or not
750 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
751 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
752 $add_save_lastsearch_values = 1;
753 }
754 if ($add_save_lastsearch_values) {
755 $url .= '&save_lastsearch_values=1';
756 }
757 }
758
759 $linkclose = '';
760 if (empty($notooltip)) {
761 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
762 $label = $langs->trans("ShowRecruitmentCandidature");
763 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
764 }
765 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
766 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
767 } else {
768 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
769 }
770
771 $linkstart = '<a href="'.$url.'"';
772 $linkstart .= $linkclose.'>';
773 $linkend = '</a>';
774
775 $result .= $linkstart;
776
777 if (empty($this->showphoto_on_popup)) {
778 if ($withpicto) {
779 $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);
780 }
781 } else {
782 if ($withpicto) {
783 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
784
785 list($class, $module) = explode('@', $this->picto);
786 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
787 $filearray = dol_dir_list($upload_dir, "files");
788 $filename = $filearray[0]['name'];
789 if (!empty($filename)) {
790 $pospoint = strpos($filearray[0]['name'], '.');
791
792 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
793 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
794 $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>';
795 } else {
796 $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>';
797 }
798
799 $result .= '</div>';
800 } else {
801 $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);
802 }
803 }
804 }
805
806 if ($withpicto != 2) {
807 $result .= $this->ref;
808 }
809
810 $result .= $linkend;
811 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
812
813 global $action, $hookmanager;
814 $hookmanager->initHooks(array('recruitmentcandidaturedao'));
815 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
816 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
817 if ($reshook > 0) {
818 $result = $hookmanager->resPrint;
819 } else {
820 $result .= $hookmanager->resPrint;
821 }
822
823 return $result;
824 }
825
832 public function getLibStatut($mode = 0)
833 {
834 return $this->LibStatut($this->status, $mode);
835 }
836
837 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
845 public function LibStatut($status, $mode = 0)
846 {
847 // phpcs:enable
848 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
849 global $langs;
850 //$langs->load("recruitment@recruitment");
851 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
852 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Received').' ('.$langs->transnoentitiesnoconv("InterviewToDo").')';
853 $this->labelStatus[self::STATUS_CONTRACT_PROPOSED] = $langs->transnoentitiesnoconv('ContractProposed');
854 $this->labelStatus[self::STATUS_CONTRACT_SIGNED] = $langs->transnoentitiesnoconv('ContractSigned');
855 $this->labelStatus[self::STATUS_CONTRACT_REFUSED] = $langs->transnoentitiesnoconv('ContractRefused');
856 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
857 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
858 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
859 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Received');
860 $this->labelStatusShort[self::STATUS_CONTRACT_PROPOSED] = $langs->transnoentitiesnoconv('ContractProposed');
861 $this->labelStatusShort[self::STATUS_CONTRACT_SIGNED] = $langs->transnoentitiesnoconv('ContractSigned');
862 $this->labelStatusShort[self::STATUS_CONTRACT_REFUSED] = $langs->transnoentitiesnoconv('ContractRefused');
863 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
864 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
865 }
866
867 $statusType = 'status'.$status;
868 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
869 if ($status == self::STATUS_CANCELED) {
870 $statusType = 'status9';
871 }
872 if ($status == self::STATUS_CONTRACT_PROPOSED) {
873 $statusType = 'status4';
874 }
875 if ($status == self::STATUS_CONTRACT_SIGNED) {
876 $statusType = 'status6';
877 }
878 if ($status == self::STATUS_REFUSED) {
879 $statusType = 'status10';
880 }
881
882 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
883 }
884
891 public function info($id)
892 {
893 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
894 $sql .= ' fk_user_creat, fk_user_modif';
895 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
896 $sql .= ' WHERE t.rowid = '.((int) $id);
897 $result = $this->db->query($sql);
898 if ($result) {
899 if ($this->db->num_rows($result)) {
900 $obj = $this->db->fetch_object($result);
901
902 $this->id = $obj->rowid;
903
904 $this->user_creation_id = $obj->fk_user_creat;
905 $this->user_modification_id = $obj->fk_user_modif;
906 $this->date_creation = $this->db->jdate($obj->datec);
907 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
908 }
909
910 $this->db->free($result);
911 } else {
912 dol_print_error($this->db);
913 }
914 }
915
922 public function initAsSpecimen()
923 {
924 $this->initAsSpecimenCommon();
925 }
926
932 public function getLinesArray()
933 {
934 $this->lines = array();
935
936 $objectline = new RecruitmentCandidatureLine($this->db);
937 $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_recruitmentcandidature = '.((int) $this->id)));
938
939 if (is_numeric($result)) {
940 $this->error = $objectline->error;
941 $this->errors = $objectline->errors;
942 return $result;
943 } else {
944 $this->lines = $result;
945 return $this->lines;
946 }
947 }
948
954 public function getNextNumRef()
955 {
956 global $langs, $conf;
957 $langs->load("recruitment@recruitment");
958
959 if (!getDolGlobalString('RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON')) {
960 $conf->global->RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON = 'mod_recruitmentcandidature_standard';
961 }
962
963 if (getDolGlobalString('RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON')) {
964 $mybool = false;
965
966 $file = getDolGlobalString('RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON') . ".php";
967 $classname = $conf->global->RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON;
968
969 // Include file with class
970 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
971 foreach ($dirmodels as $reldir) {
972 $dir = dol_buildpath($reldir."core/modules/recruitment/");
973
974 // Load file with numbering class (if found)
975 $mybool |= @include_once $dir.$file;
976 }
977
978 if ($mybool === false) {
979 dol_print_error('', "Failed to include file ".$file);
980 return '';
981 }
982
983 if (class_exists($classname)) {
984 $obj = new $classname();
985 $numref = $obj->getNextValue($this);
986
987 if ($numref != '' && $numref != '-1') {
988 return $numref;
989 } else {
990 $this->error = $obj->error;
991 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
992 return "";
993 }
994 } else {
995 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
996 return "";
997 }
998 } else {
999 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1000 return "";
1001 }
1002 }
1003
1015 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1016 {
1017 global $conf, $langs;
1018
1019 $result = 0;
1020 $includedocgeneration = 0;
1021
1022 $langs->load("recruitment@recruitment");
1023
1024 if (!dol_strlen($modele)) {
1025 if (getDolGlobalString('RECRUITMENTCANDIDATURE_ADDON_PDF')) {
1026 $modele = $conf->global->RECRUITMENTCANDIDATURE_ADDON_PDF;
1027 } else {
1028 $modele = ''; // No default value. For job application, we allow to disable all PDF generation
1029 }
1030 }
1031
1032 $modelpath = "core/modules/recruitment/doc/";
1033
1034 if ($includedocgeneration && !empty($modele)) {
1035 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1036 }
1037
1038 return $result;
1039 }
1040
1048 public function doScheduledJob()
1049 {
1050 global $conf, $langs;
1051
1052 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1053
1054 $error = 0;
1055 $this->output = '';
1056 $this->error = '';
1057
1058 dol_syslog(__METHOD__, LOG_DEBUG);
1059
1060 $now = dol_now();
1061
1062 $this->db->begin();
1063
1064 // ...
1065
1066 $this->db->commit();
1067
1068 return $error;
1069 }
1070
1078 public function getKanbanView($option = '', $arraydata = null)
1079 {
1080 global $langs;
1081
1082 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1083
1084 $return = '<div class="box-flex-item box-flex-grow-zero">';
1085 $return .= '<div class="info-box info-box-sm">';
1086 $return .= '<span class="info-box-icon bg-infobox-action">';
1087 $return .= img_picto('', $this->picto);
1088 $return .= '</span>';
1089 $return .= '<div class="info-box-content">';
1090 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1091 if ($selected >= 0) {
1092 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1093 }
1094 if (property_exists($this, 'fk_recruitmentjobposition')) {
1095 $return .= '<br>';
1096 //$return .= '<span class="opacitymedium">';
1097 //$return .= $langs->trans('Job').'</span> : ';
1098 $return .= '<span class="info-box-label">';
1099 $tmpjob = new RecruitmentJobPosition($this->db);
1100 $tmpjob->fetch($this->fk_recruitmentjobposition);
1101 //$return .= $this->fk_recruitmentjobposition;
1102 $return .= $tmpjob->label;
1103 $return .= '</span>';
1104 }
1105 if (property_exists($this, 'phone') && $this->phone) {
1106 $return .= '<br><span class="info-box-label opacitymedium small">'.img_picto('', 'phone').' '.$this->phone.'</span>';
1107 }
1108 if (property_exists($this, 'email') && $this->email) {
1109 $return .= '<br><span class="info-box-label opacitymedium small">'.img_picto('', 'email').' '.$this->email.'</span>';
1110 }
1111 if (method_exists($this, 'getLibStatut')) {
1112 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1113 }
1114 $return .= '</div>';
1115 $return .= '</div>';
1116 $return .= '</div>';
1117 return $return;
1118 }
1119}
1120
1121
1122require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1123
1128{
1129 // To complete with content of an object RecruitmentCandidatureLine
1130 // We should have a field rowid, fk_recruitmentcandidature and position
1131
1137 public function __construct(DoliDB $db)
1138 {
1139 $this->db = $db;
1140 }
1141}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
create(User $user, $notrigger=false)
Create object into database.
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 clicable 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 optionaly the picto)
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
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.
update(User $user, $notrigger=false)
Update object into database.
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.
validate($user, $notrigger=0)
Validate object.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
LibStatut($status, $mode=0)
Return the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $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.
info($id)
Load the info information in the object.
Class RecruitmentCandidatureLine.
Class for RecruitmentJobPosition.
Class to manage Dolibarr users.
dol_dir_list($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:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124