dolibarr  17.0.3
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
25 require_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', '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  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
133  'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
134  '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')),
135  );
136  public $rowid;
137  public $entity;
138  public $ref;
139  public $fk_recruitmentjobposition;
140  public $description;
141  public $note_public;
142  public $note_private;
143  public $date_creation;
144  public $tms;
145  public $fk_user_creat;
146  public $fk_user_modif;
147  public $lastname;
148  public $firstname;
149  public $email;
150  public $phone;
151  public $date_birth;
152  public $email_msgid;
153  public $email_date;
154  public $remuneration_requested;
155  public $remuneration_proposed;
156  public $fk_recruitment_origin;
157  public $import_key;
158  public $model_pdf;
159  public $status;
160  // END MODULEBUILDER PROPERTIES
161 
162 
168  public function __construct(DoliDB $db)
169  {
170  global $conf, $langs;
171 
172  $this->db = $db;
173 
174  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
175  $this->fields['rowid']['visible'] = 0;
176  }
177  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
178  $this->fields['entity']['enabled'] = 0;
179  }
180 
181  // Example to show how to set values of fields definition dynamically
182  /*if ($user->rights->recruitment->recruitmentcandidature->read) {
183  $this->fields['myfield']['visible'] = 1;
184  $this->fields['myfield']['noteditable'] = 0;
185  }*/
186 
187  // Unset fields that are disabled
188  foreach ($this->fields as $key => $val) {
189  if (isset($val['enabled']) && empty($val['enabled'])) {
190  unset($this->fields[$key]);
191  }
192  }
193 
194  // Translate some data of arrayofkeyval
195  if (is_object($langs)) {
196  foreach ($this->fields as $key => $val) {
197  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
198  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
199  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
200  }
201  }
202  }
203  }
204  }
205 
213  public function create(User $user, $notrigger = false)
214  {
215  return $this->createCommon($user, $notrigger);
216  }
217 
225  public function createFromClone(User $user, $fromid)
226  {
227  global $langs, $extrafields;
228  $error = 0;
229 
230  dol_syslog(__METHOD__, LOG_DEBUG);
231 
232  $object = new self($this->db);
233 
234  $this->db->begin();
235 
236  // Load source object
237  $result = $object->fetchCommon($fromid);
238  if ($result > 0 && !empty($object->table_element_line)) {
239  $object->fetchLines();
240  }
241 
242  // get lines so they will be clone
243  //foreach($this->lines as $line)
244  // $line->fetch_optionals();
245 
246  // Reset some properties
247  unset($object->id);
248  unset($object->fk_user_creat);
249  unset($object->import_key);
250 
251  // Clear fields
252  if (property_exists($object, 'ref')) {
253  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
254  }
255  if (property_exists($object, 'label')) {
256  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
257  }
258  if (property_exists($object, 'status')) {
259  $object->status = self::STATUS_DRAFT;
260  }
261  if (property_exists($object, 'date_creation')) {
262  $object->date_creation = dol_now();
263  }
264  if (property_exists($object, 'date_modification')) {
265  $object->date_modification = null;
266  }
267 
268  // ...
269  // Clear extrafields that are unique
270  if (is_array($object->array_options) && count($object->array_options) > 0) {
271  $extrafields->fetch_name_optionals_label($this->table_element);
272  foreach ($object->array_options as $key => $option) {
273  $shortkey = preg_replace('/options_/', '', $key);
274  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
275  //var_dump($key);
276  //var_dump($clonedObj->array_options[$key]); exit;
277  unset($object->array_options[$key]);
278  }
279  }
280  }
281 
282  // Create clone
283  $object->context['createfromclone'] = 'createfromclone';
284  $result = $object->createCommon($user);
285  if ($result < 0) {
286  $error++;
287  $this->error = $object->error;
288  $this->errors = $object->errors;
289  }
290 
291  if (!$error) {
292  // copy internal contacts
293  if ($this->copy_linked_contact($object, 'internal') < 0) {
294  $error++;
295  }
296  }
297 
298  if (!$error) {
299  // copy external contacts if same company
300  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
301  if ($this->copy_linked_contact($object, 'external') < 0) {
302  $error++;
303  }
304  }
305  }
306 
307  unset($object->context['createfromclone']);
308 
309  // End
310  if (!$error) {
311  $this->db->commit();
312  return $object;
313  } else {
314  $this->db->rollback();
315  return -1;
316  }
317  }
318 
327  public function fetch($id, $ref = null, $email_msgid = '')
328  {
329  $morewhere = '';
330  if ($email_msgid) {
331  $morewhere = " AND email_msgid = '".$this->db->escape($email_msgid)."'";
332  }
333  $result = $this->fetchCommon($id, $ref, $morewhere);
334  if ($result > 0 && !empty($this->table_element_line)) {
335  $this->fetchLines();
336  }
337  return $result;
338  }
339 
345  public function fetchLines()
346  {
347  $this->lines = array();
348 
349  $result = $this->fetchLinesCommon();
350  return $result;
351  }
352 
353 
365  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
366  {
367  global $conf;
368 
369  dol_syslog(__METHOD__, LOG_DEBUG);
370 
371  $records = array();
372 
373  $sql = 'SELECT ';
374  $sql .= $this->getFieldList();
375  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
376  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
377  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
378  } else {
379  $sql .= ' WHERE 1 = 1';
380  }
381  // Manage filter
382  $sqlwhere = array();
383  if (count($filter) > 0) {
384  foreach ($filter as $key => $value) {
385  if ($key == 't.rowid') {
386  $sqlwhere[] = $key." = ".((int) $value);
387  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
388  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
389  } elseif ($key == 'customsql') {
390  $sqlwhere[] = $value;
391  } elseif (strpos($value, '%') === false) {
392  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
393  } else {
394  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
395  }
396  }
397  }
398  if (count($sqlwhere) > 0) {
399  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
400  }
401 
402  if (!empty($sortfield)) {
403  $sql .= $this->db->order($sortfield, $sortorder);
404  }
405  if (!empty($limit)) {
406  $sql .= $this->db->plimit($limit, $offset);
407  }
408 
409  $resql = $this->db->query($sql);
410  if ($resql) {
411  $num = $this->db->num_rows($resql);
412  $i = 0;
413  while ($i < ($limit ? min($limit, $num) : $num)) {
414  $obj = $this->db->fetch_object($resql);
415 
416  $record = new self($this->db);
417  $record->setVarsFromFetchObj($obj);
418 
419  $records[$record->id] = $record;
420 
421  $i++;
422  }
423  $this->db->free($resql);
424 
425  return $records;
426  } else {
427  $this->errors[] = 'Error '.$this->db->lasterror();
428  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
429 
430  return -1;
431  }
432  }
433 
441  public function update(User $user, $notrigger = false)
442  {
443  return $this->updateCommon($user, $notrigger);
444  }
445 
453  public function delete(User $user, $notrigger = false)
454  {
455  return $this->deleteCommon($user, $notrigger);
456  //return $this->deleteCommon($user, $notrigger, 1);
457  }
458 
467  public function deleteLine(User $user, $idline, $notrigger = false)
468  {
469  if ($this->status < 0) {
470  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
471  return -2;
472  }
473 
474  return $this->deleteLineCommon($user, $idline, $notrigger);
475  }
476 
477 
485  public function validate($user, $notrigger = 0)
486  {
487  global $conf, $langs;
488 
489  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
490 
491  $error = 0;
492 
493  // Protection
494  if ($this->status == self::STATUS_VALIDATED) {
495  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
496  return 0;
497  }
498 
499  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitmentcandidature->write))
500  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitmentcandidature->recruitmentcandidature_advance->validate))))
501  {
502  $this->error='NotEnoughPermissions';
503  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
504  return -1;
505  }*/
506 
507  $now = dol_now();
508 
509  $this->db->begin();
510 
511  // Define new ref
512  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
513  $num = $this->getNextNumRef();
514  } else {
515  $num = $this->ref;
516  }
517  $this->newref = $num;
518 
519  if (!empty($num)) {
520  // Validate
521  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
522  $sql .= " SET ref = '".$this->db->escape($num)."',";
523  $sql .= " status = ".self::STATUS_VALIDATED;
524  if (!empty($this->fields['date_validation'])) {
525  $sql .= ", date_validation = '".$this->db->idate($now)."',";
526  }
527  if (!empty($this->fields['fk_user_valid'])) {
528  $sql .= ", fk_user_valid = ".$user->id;
529  }
530  $sql .= " WHERE rowid = ".((int) $this->id);
531 
532  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
533  $resql = $this->db->query($sql);
534  if (!$resql) {
535  dol_print_error($this->db);
536  $this->error = $this->db->lasterror();
537  $error++;
538  }
539 
540  if (!$error && !$notrigger) {
541  // Call trigger
542  $result = $this->call_trigger('RECRUITMENTCANDIDATURE_VALIDATE', $user);
543  if ($result < 0) {
544  $error++;
545  }
546  // End call triggers
547  }
548  }
549 
550  if (!$error) {
551  $this->oldref = $this->ref;
552 
553  // Rename directory if dir was a temporary ref
554  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
555  // Now we rename also files into index
556  $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)."'";
557  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentcandidature/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
558  $resql = $this->db->query($sql);
559  if (!$resql) {
560  $error++; $this->error = $this->db->lasterror();
561  }
562 
563  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
564  $oldref = dol_sanitizeFileName($this->ref);
565  $newref = dol_sanitizeFileName($num);
566  $dirsource = $conf->recruitment->dir_output.'/recruitmentcandidature/'.$oldref;
567  $dirdest = $conf->recruitment->dir_output.'/recruitmentcandidature/'.$newref;
568  if (!$error && file_exists($dirsource)) {
569  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
570 
571  if (@rename($dirsource, $dirdest)) {
572  dol_syslog("Rename ok");
573  // Rename docs starting with $oldref with $newref
574  $listoffiles = dol_dir_list($conf->recruitment->dir_output.'/recruitmentcandidature/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
575  foreach ($listoffiles as $fileentry) {
576  $dirsource = $fileentry['name'];
577  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
578  $dirsource = $fileentry['path'].'/'.$dirsource;
579  $dirdest = $fileentry['path'].'/'.$dirdest;
580  @rename($dirsource, $dirdest);
581  }
582  }
583  }
584  }
585  }
586 
587  // Set new ref and current status
588  if (!$error) {
589  $this->ref = $num;
590  $this->status = self::STATUS_VALIDATED;
591  }
592 
593  if (!$error) {
594  $this->db->commit();
595  return 1;
596  } else {
597  $this->db->rollback();
598  return -1;
599  }
600  }
601 
602 
610  public function setDraft($user, $notrigger = 0)
611  {
612  // Protection
613  if ($this->status <= self::STATUS_DRAFT) {
614  return 0;
615  }
616 
617  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
618  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
619  {
620  $this->error='Permission denied';
621  return -1;
622  }*/
623 
624  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'RECRUITMENTCANDIDATURE_UNVALIDATE');
625  }
626 
634  public function cancel($user, $notrigger = 0)
635  {
636  // Protection
637  if ($this->status != self::STATUS_VALIDATED) {
638  return 0;
639  }
640 
641  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
642  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
643  {
644  $this->error='Permission denied';
645  return -1;
646  }*/
647 
648  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'RECRUITMENTCANDIDATURE_CLOSE');
649  }
650 
658  public function reopen($user, $notrigger = 0)
659  {
660  // Protection
661  if ($this->status != self::STATUS_REFUSED && $this->status != self::STATUS_CANCELED && $this->status != self::STATUS_CONTRACT_REFUSED) {
662  return 0;
663  }
664 
665  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
666  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
667  {
668  $this->error='Permission denied';
669  return -1;
670  }*/
671 
672  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'RECRUITMENTCANDIDATURE_REOPEN');
673  }
674 
685  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
686  {
687  global $conf, $langs, $hookmanager;
688 
689  if (!empty($conf->dol_no_mouse_hover)) {
690  $notooltip = 1; // Force disable tooltips
691  }
692 
693  $result = '';
694 
695  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("RecruitmentCandidature").'</u>';
696  if (isset($this->status)) {
697  $label .= ' '.$this->getLibStatut(5);
698  }
699  $label .= '<br>';
700  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
701  $label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email;
702  $label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
703 
704  $url = dol_buildpath('/recruitment/recruitmentcandidature_card.php', 1).'?id='.$this->id;
705 
706  if ($option != 'nolink') {
707  // Add param to save lastsearch_values or not
708  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
709  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
710  $add_save_lastsearch_values = 1;
711  }
712  if ($add_save_lastsearch_values) {
713  $url .= '&save_lastsearch_values=1';
714  }
715  }
716 
717  $linkclose = '';
718  if (empty($notooltip)) {
719  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
720  $label = $langs->trans("ShowRecruitmentCandidature");
721  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
722  }
723  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
724  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
725  } else {
726  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
727  }
728 
729  $linkstart = '<a href="'.$url.'"';
730  $linkstart .= $linkclose.'>';
731  $linkend = '</a>';
732 
733  $result .= $linkstart;
734 
735  if (empty($this->showphoto_on_popup)) {
736  if ($withpicto) {
737  $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);
738  }
739  } else {
740  if ($withpicto) {
741  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
742 
743  list($class, $module) = explode('@', $this->picto);
744  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
745  $filearray = dol_dir_list($upload_dir, "files");
746  $filename = $filearray[0]['name'];
747  if (!empty($filename)) {
748  $pospoint = strpos($filearray[0]['name'], '.');
749 
750  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
751  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
752  $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>';
753  } else {
754  $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>';
755  }
756 
757  $result .= '</div>';
758  } else {
759  $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);
760  }
761  }
762  }
763 
764  if ($withpicto != 2) {
765  $result .= $this->ref;
766  }
767 
768  $result .= $linkend;
769  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
770 
771  global $action, $hookmanager;
772  $hookmanager->initHooks(array('recruitmentcandidaturedao'));
773  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
774  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
775  if ($reshook > 0) {
776  $result = $hookmanager->resPrint;
777  } else {
778  $result .= $hookmanager->resPrint;
779  }
780 
781  return $result;
782  }
783 
790  public function getLibStatut($mode = 0)
791  {
792  return $this->LibStatut($this->status, $mode);
793  }
794 
795  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
803  public function LibStatut($status, $mode = 0)
804  {
805  // phpcs:enable
806  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
807  global $langs;
808  //$langs->load("recruitment@recruitment");
809  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
810  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Received').' ('.$langs->transnoentitiesnoconv("InterviewToDo").')';
811  $this->labelStatus[self::STATUS_CONTRACT_PROPOSED] = $langs->transnoentitiesnoconv('ContractProposed');
812  $this->labelStatus[self::STATUS_CONTRACT_SIGNED] = $langs->transnoentitiesnoconv('ContractSigned');
813  $this->labelStatus[self::STATUS_CONTRACT_REFUSED] = $langs->transnoentitiesnoconv('ContractRefused');
814  $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
815  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
816  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
817  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Received');
818  $this->labelStatusShort[self::STATUS_CONTRACT_PROPOSED] = $langs->transnoentitiesnoconv('ContractProposed');
819  $this->labelStatusShort[self::STATUS_CONTRACT_SIGNED] = $langs->transnoentitiesnoconv('ContractSigned');
820  $this->labelStatusShort[self::STATUS_CONTRACT_REFUSED] = $langs->transnoentitiesnoconv('ContractRefused');
821  $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
822  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
823  }
824 
825  $statusType = 'status'.$status;
826  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
827  if ($status == self::STATUS_CANCELED) {
828  $statusType = 'status9';
829  }
830  if ($status == self::STATUS_CONTRACT_PROPOSED) {
831  $statusType = 'status4';
832  }
833  if ($status == self::STATUS_CONTRACT_SIGNED) {
834  $statusType = 'status6';
835  }
836  if ($status == self::STATUS_REFUSED) {
837  $statusType = 'status10';
838  }
839 
840  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
841  }
842 
849  public function info($id)
850  {
851  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
852  $sql .= ' fk_user_creat, fk_user_modif';
853  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
854  $sql .= ' WHERE t.rowid = '.((int) $id);
855  $result = $this->db->query($sql);
856  if ($result) {
857  if ($this->db->num_rows($result)) {
858  $obj = $this->db->fetch_object($result);
859  $this->id = $obj->rowid;
860 
861  $this->user_creation_id = $obj->fk_user_creat;
862  $this->user_modification_id = $obj->fk_user_modif;
863  $this->date_creation = $this->db->jdate($obj->datec);
864  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
865  }
866 
867  $this->db->free($result);
868  } else {
869  dol_print_error($this->db);
870  }
871  }
872 
879  public function initAsSpecimen()
880  {
881  $this->initAsSpecimenCommon();
882  }
883 
889  public function getLinesArray()
890  {
891  $this->lines = array();
892 
893  $objectline = new RecruitmentCandidatureLine($this->db);
894  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_recruitmentcandidature = '.((int) $this->id)));
895 
896  if (is_numeric($result)) {
897  $this->error = $objectline->error;
898  $this->errors = $objectline->errors;
899  return $result;
900  } else {
901  $this->lines = $result;
902  return $this->lines;
903  }
904  }
905 
911  public function getNextNumRef()
912  {
913  global $langs, $conf;
914  $langs->load("recruitment@recruitment");
915 
916  if (empty($conf->global->RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON)) {
917  $conf->global->RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON = 'mod_recruitmentcandidature_standard';
918  }
919 
920  if (!empty($conf->global->RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON)) {
921  $mybool = false;
922 
923  $file = $conf->global->RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON.".php";
924  $classname = $conf->global->RECRUITMENT_RECRUITMENTCANDIDATURE_ADDON;
925 
926  // Include file with class
927  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
928  foreach ($dirmodels as $reldir) {
929  $dir = dol_buildpath($reldir."core/modules/recruitment/");
930 
931  // Load file with numbering class (if found)
932  $mybool |= @include_once $dir.$file;
933  }
934 
935  if ($mybool === false) {
936  dol_print_error('', "Failed to include file ".$file);
937  return '';
938  }
939 
940  if (class_exists($classname)) {
941  $obj = new $classname();
942  $numref = $obj->getNextValue($this);
943 
944  if ($numref != '' && $numref != '-1') {
945  return $numref;
946  } else {
947  $this->error = $obj->error;
948  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
949  return "";
950  }
951  } else {
952  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
953  return "";
954  }
955  } else {
956  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
957  return "";
958  }
959  }
960 
972  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
973  {
974  global $conf, $langs;
975 
976  $result = 0;
977  $includedocgeneration = 0;
978 
979  $langs->load("recruitment@recruitment");
980 
981  if (!dol_strlen($modele)) {
982  if (!empty($conf->global->RECRUITMENTCANDIDATURE_ADDON_PDF)) {
983  $modele = $conf->global->RECRUITMENTCANDIDATURE_ADDON_PDF;
984  } else {
985  $modele = ''; // No default value. For job application, we allow to disable all PDF generation
986  }
987  }
988 
989  $modelpath = "core/modules/recruitment/doc/";
990 
991  if ($includedocgeneration && !empty($modele)) {
992  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
993  }
994 
995  return $result;
996  }
997 
1005  public function doScheduledJob()
1006  {
1007  global $conf, $langs;
1008 
1009  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1010 
1011  $error = 0;
1012  $this->output = '';
1013  $this->error = '';
1014 
1015  dol_syslog(__METHOD__, LOG_DEBUG);
1016 
1017  $now = dol_now();
1018 
1019  $this->db->begin();
1020 
1021  // ...
1022 
1023  $this->db->commit();
1024 
1025  return $error;
1026  }
1027 }
1028 
1029 
1030 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1031 
1036 {
1037  // To complete with content of an object RecruitmentCandidatureLine
1038  // We should have a field rowid, fk_recruitmentcandidature and position
1039 
1045  public function __construct(DoliDB $db)
1046  {
1047  $this->db = $db;
1048  }
1049 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9573
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9851
db
$conf db
API class for accounts.
Definition: inc.php:41
RecruitmentCandidature\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: recruitmentcandidature.class.php:972
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9363
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1236
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
RecruitmentCandidature\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: recruitmentcandidature.class.php:610
RecruitmentCandidature\info
info($id)
Load the info information in the object.
Definition: recruitmentcandidature.class.php:849
RecruitmentCandidature\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: recruitmentcandidature.class.php:911
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
ref
$object ref
Definition: info.php:78
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1061
dol_dir_list
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:61
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9419
RecruitmentCandidature\fetch
fetch($id, $ref=null, $email_msgid='')
Load object in memory from the database.
Definition: recruitmentcandidature.class.php:327
CommonObjectLine
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Definition: commonobjectline.class.php:32
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
RecruitmentCandidature\__construct
__construct(DoliDB $db)
Constructor.
Definition: recruitmentcandidature.class.php:168
CommonObject\getFullName
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
Definition: commonobject.class.php:717
RecruitmentCandidature\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: recruitmentcandidature.class.php:685
RecruitmentCandidature\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: recruitmentcandidature.class.php:879
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4024
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9191
RecruitmentCandidature\update
update(User $user, $notrigger=false)
Update object into database.
Definition: recruitmentcandidature.class.php:441
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
RecruitmentCandidature\create
create(User $user, $notrigger=false)
Create object into database.
Definition: recruitmentcandidature.class.php:213
RecruitmentCandidature
Class for RecruitmentCandidature.
Definition: recruitmentcandidature.class.php:32
RecruitmentCandidature\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: recruitmentcandidature.class.php:365
RecruitmentCandidature\getLibStatut
getLibStatut($mode=0)
Return label of the status.
Definition: recruitmentcandidature.class.php:790
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9469
RecruitmentCandidature\validate
validate($user, $notrigger=0)
Validate object.
Definition: recruitmentcandidature.class.php:485
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3887
RecruitmentCandidature\getLinesArray
getLinesArray()
Create an array of lines.
Definition: recruitmentcandidature.class.php:889
RecruitmentCandidature\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: recruitmentcandidature.class.php:1005
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
User
Class to manage Dolibarr users.
Definition: user.class.php:46
RecruitmentCandidature\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: recruitmentcandidature.class.php:345
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10744
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4360
RecruitmentCandidature\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: recruitmentcandidature.class.php:634
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
RecruitmentCandidature\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: recruitmentcandidature.class.php:658
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9789
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5818
RecruitmentCandidature\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: recruitmentcandidature.class.php:225
RecruitmentCandidature\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: recruitmentcandidature.class.php:467
RecruitmentCandidatureLine
Class RecruitmentCandidatureLine.
Definition: recruitmentcandidature.class.php:1035
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9143
RecruitmentCandidatureLine\__construct
__construct(DoliDB $db)
Constructor.
Definition: recruitmentcandidature.class.php:1045
RecruitmentCandidature\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: recruitmentcandidature.class.php:803