dolibarr  18.0.6
recruitmentjobposition.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 /* Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Put here all includes required by your class file
26 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29 
34 {
38  public $module = 'recruitment';
39 
43  public $element = 'recruitmentjobposition';
44 
48  public $table_element = 'recruitment_recruitmentjobposition';
49 
54  public $ismultientitymanaged = 1;
55 
59  public $isextrafieldmanaged = 1;
60 
64  public $picto = 'recruitmentjobposition';
65 
69  const STATUS_DRAFT = 0;
70 
74  const STATUS_VALIDATED = 1;
75 
79  const STATUS_RECRUITED = 3;
80 
84  const STATUS_CANCELED = 9;
85 
86 
112  // BEGIN MODULEBUILDER PROPERTIES
116  public $fields = array(
117  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'comment'=>"Id"),
118  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1),
119  'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object", 'css'=>'nowraponall'),
120  'label' => array('type'=>'varchar(255)', 'label'=>'JobLabel', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth500', 'csslist'=>'tdoverflowmax300', 'showoncombobox'=>'2', 'autofocusoncreate'=>1),
121  'qty' => array('type'=>'integer', 'label'=>'NbOfEmployeesExpected', 'enabled'=>'1', 'position'=>45, 'notnull'=>1, 'visible'=>1, 'default'=>'1', 'isameasure'=>'1', 'css'=>'maxwidth75imp'),
122  'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'$conf->project->enabled', 'position'=>52, 'notnull'=>-1, 'visible'=>-1, 'index'=>1, 'css'=>'maxwidth500', 'picto'=>'project'),
123  'fk_user_recruiter' => array('type'=>'integer:User:user/class/user.class.php:1:(statut:=:1)', 'label'=>'ResponsibleOfRecruitement', 'enabled'=>'1', 'position'=>54, 'notnull'=>1, 'visible'=>1, 'foreignkey'=>'user.rowid', 'css'=>'maxwidth500', 'csslist'=>'tdoverflowmax150', 'picto'=>'user'),
124  'email_recruiter' => array('type'=>'varchar(255)', 'label'=>'EmailRecruiter', 'enabled'=>'1', 'position'=>54, 'notnull'=>0, 'visible'=>-1, 'help'=>'ToUseAGenericEmail', 'picto'=>'email'),
125  'fk_user_supervisor' => array('type'=>'integer:User:user/class/user.class.php:1:(statut:=:1)', 'label'=>'FutureManager', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>-1, 'foreignkey'=>'user.rowid', 'css'=>'maxwidth500', 'csslist'=>'tdoverflowmax150', 'picto'=>'user'),
126  'fk_establishment' => array('type'=>'integer:Establishment:hrm/class/establishment.class.php', 'label'=>'Establishment', 'enabled'=>'$conf->hrm->enabled', 'position'=>56, 'notnull'=>0, 'visible'=>-1, 'foreignkey'=>'establishment.rowid',),
127  'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label'=>'WorkPlace', 'enabled'=>'isModEnabled("societe")', 'position'=>57, 'notnull'=>-1, 'visible'=>-1, 'css'=>'maxwidth500', 'index'=>1, 'help'=>"IfJobIsLocatedAtAPartner", 'picto'=>'company'),
128  'date_planned' => array('type'=>'date', 'label'=>'DateExpected', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>1,),
129  'remuneration_suggested' => array('type'=>'varchar(255)', 'label'=>'Remuneration', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>1,),
130  'description' => array('type'=>'html', 'label'=>'Description', 'enabled'=>'1', 'position'=>65, 'notnull'=>0, 'visible'=>3,),
131  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>101, 'notnull'=>0, 'visible'=>0,),
132  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>102, 'notnull'=>0, 'visible'=>0,),
133  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-4,),
134  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
135  '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',),
136  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
137  'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>900, 'notnull'=>0, 'visible'=>0,),
138  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
139  'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
140  'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>5, 'default'=>'0', 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '3'=>'Recruited', '9'=>'Canceled'),),
141  );
142  public $rowid;
143 
147  public $ref;
148  public $entity;
149 
153  public $label;
154  public $qty;
155  public $fk_soc;
156  public $fk_project;
157  public $fk_user_recruiter;
158 
162  public $email_recruiter;
163 
167  public $remuneration_suggested;
168 
169  public $fk_user_supervisor;
170  public $fk_establishment;
171  public $date_planned;
172  public $description;
173  public $note_public;
174  public $note_private;
175  public $date_creation;
176  public $tms;
177  public $fk_user_creat;
178  public $fk_user_modif;
179  public $last_main_doc;
180  public $import_key;
181  public $model_pdf;
182  public $status;
183  // END MODULEBUILDER PROPERTIES
184 
185 
191  public function __construct(DoliDB $db)
192  {
193  global $conf, $langs;
194 
195  $this->db = $db;
196 
197  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
198  $this->fields['rowid']['visible'] = 0;
199  }
200  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
201  $this->fields['entity']['enabled'] = 0;
202  }
203 
204  // Example to show how to set values of fields definition dynamically
205  /*if ($user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
206  $this->fields['myfield']['visible'] = 1;
207  $this->fields['myfield']['noteditable'] = 0;
208  }*/
209 
210  // Unset fields that are disabled
211  foreach ($this->fields as $key => $val) {
212  if (isset($val['enabled']) && empty($val['enabled'])) {
213  unset($this->fields[$key]);
214  }
215  }
216 
217  // Translate some data of arrayofkeyval
218  if (is_object($langs)) {
219  foreach ($this->fields as $key => $val) {
220  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
221  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
222  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
223  }
224  }
225  }
226  }
227  }
228 
236  public function create(User $user, $notrigger = false)
237  {
238  return $this->createCommon($user, $notrigger);
239  }
240 
248  public function createFromClone(User $user, $fromid)
249  {
250  global $langs, $extrafields;
251  $error = 0;
252 
253  dol_syslog(__METHOD__, LOG_DEBUG);
254 
255  $object = new self($this->db);
256 
257  $this->db->begin();
258 
259  // Load source object
260  $result = $object->fetchCommon($fromid);
261  if ($result > 0 && !empty($object->table_element_line)) {
262  $object->fetchLines();
263  }
264 
265  // get lines so they will be clone
266  //foreach($this->lines as $line)
267  // $line->fetch_optionals();
268 
269  // Reset some properties
270  unset($object->id);
271  unset($object->fk_user_creat);
272  $object->import_key = null;
273 
274  // Clear fields
275  if (property_exists($object, 'ref')) {
276  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
277  }
278  if (property_exists($object, 'label')) {
279  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
280  }
281  if (property_exists($object, 'status')) {
282  $object->status = self::STATUS_DRAFT;
283  }
284  if (property_exists($object, 'date_creation')) {
285  $object->date_creation = dol_now();
286  }
287  if (property_exists($object, 'date_modification')) {
288  $object->date_modification = null;
289  }
290  // ...
291  // Clear extrafields that are unique
292  if (is_array($object->array_options) && count($object->array_options) > 0) {
293  $extrafields->fetch_name_optionals_label($this->table_element);
294  foreach ($object->array_options as $key => $option) {
295  $shortkey = preg_replace('/options_/', '', $key);
296  if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
297  //var_dump($key);
298  //var_dump($clonedObj->array_options[$key]); exit;
299  unset($object->array_options[$key]);
300  }
301  }
302  }
303 
304  // Create clone
305  $object->context['createfromclone'] = 'createfromclone';
306  $result = $object->createCommon($user);
307  if ($result < 0) {
308  $error++;
309  $this->error = $object->error;
310  $this->errors = $object->errors;
311  }
312 
313  if (!$error) {
314  // copy internal contacts
315  if ($this->copy_linked_contact($object, 'internal') < 0) {
316  $error++;
317  }
318  }
319 
320  if (!$error) {
321  // copy external contacts if same company
322  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
323  if ($this->copy_linked_contact($object, 'external') < 0) {
324  $error++;
325  }
326  }
327  }
328 
329  unset($object->context['createfromclone']);
330 
331  // End
332  if (!$error) {
333  $this->db->commit();
334  return $object;
335  } else {
336  $this->db->rollback();
337  return -1;
338  }
339  }
340 
348  public function fetch($id, $ref = null)
349  {
350  $result = $this->fetchCommon($id, $ref);
351  if ($result > 0 && !empty($this->table_element_line)) {
352  $this->fetchLines();
353  }
354  return $result;
355  }
356 
362  public function fetchLines()
363  {
364  $this->lines = array();
365 
366  $result = $this->fetchLinesCommon();
367  return $result;
368  }
369 
370 
382  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
383  {
384  dol_syslog(__METHOD__, LOG_DEBUG);
385 
386  $records = array();
387 
388  $sql = 'SELECT ';
389  $sql .= $this->getFieldList();
390  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
391  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
392  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
393  } else {
394  $sql .= ' WHERE 1 = 1';
395  }
396  // Manage filter
397  $sqlwhere = array();
398  if (count($filter) > 0) {
399  foreach ($filter as $key => $value) {
400  if ($key == 't.rowid') {
401  $sqlwhere[] = $key." = ".((int) $value);
402  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
403  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
404  } elseif ($key == 'customsql') {
405  $sqlwhere[] = $value;
406  } elseif (strpos($value, '%') === false) {
407  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
408  } else {
409  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
410  }
411  }
412  }
413  if (count($sqlwhere) > 0) {
414  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
415  }
416 
417  if (!empty($sortfield)) {
418  $sql .= $this->db->order($sortfield, $sortorder);
419  }
420  if (!empty($limit)) {
421  $sql .= $this->db->plimit($limit, $offset);
422  }
423 
424  $resql = $this->db->query($sql);
425  if ($resql) {
426  $num = $this->db->num_rows($resql);
427  $i = 0;
428  while ($i < ($limit ? min($limit, $num) : $num)) {
429  $obj = $this->db->fetch_object($resql);
430 
431  $record = new self($this->db);
432  $record->setVarsFromFetchObj($obj);
433 
434  $records[$record->id] = $record;
435 
436  $i++;
437  }
438  $this->db->free($resql);
439 
440  return $records;
441  } else {
442  $this->errors[] = 'Error '.$this->db->lasterror();
443  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
444 
445  return -1;
446  }
447  }
448 
456  public function update(User $user, $notrigger = false)
457  {
458  return $this->updateCommon($user, $notrigger);
459  }
460 
468  public function delete(User $user, $notrigger = false)
469  {
470  return $this->deleteCommon($user, $notrigger);
471  //return $this->deleteCommon($user, $notrigger, 1);
472  }
473 
482  public function deleteLine(User $user, $idline, $notrigger = false)
483  {
484  if ($this->status < 0) {
485  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
486  return -2;
487  }
488 
489  return $this->deleteLineCommon($user, $idline, $notrigger);
490  }
491 
492 
500  public function validate($user, $notrigger = 0)
501  {
502  global $conf;
503 
504  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
505 
506  $error = 0;
507 
508  // Protection
509  if ($this->status == self::STATUS_VALIDATED) {
510  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
511  return 0;
512  }
513 
514  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitmentjobposition->create))
515  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitmentjobposition->recruitmentjobposition_advance->validate))))
516  {
517  $this->error='NotEnoughPermissions';
518  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
519  return -1;
520  }*/
521 
522  $now = dol_now();
523 
524  $this->db->begin();
525 
526  // Define new ref
527  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
528  $num = $this->getNextNumRef();
529  } else {
530  $num = $this->ref;
531  }
532  $this->newref = $num;
533 
534  if (!empty($num)) {
535  // Validate
536  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
537  $sql .= " SET ref = '".$this->db->escape($num)."',";
538  $sql .= " status = ".self::STATUS_VALIDATED;
539  if (!empty($this->fields['date_validation'])) {
540  $sql .= ", date_validation = '".$this->db->idate($now)."',";
541  }
542  if (!empty($this->fields['fk_user_valid'])) {
543  $sql .= ", fk_user_valid = ".$user->id;
544  }
545  $sql .= " WHERE rowid = ".((int) $this->id);
546 
547  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
548  $resql = $this->db->query($sql);
549  if (!$resql) {
550  dol_print_error($this->db);
551  $this->error = $this->db->lasterror();
552  $error++;
553  }
554 
555  if (!$error && !$notrigger) {
556  // Call trigger
557  $result = $this->call_trigger('RECRUITMENTJOBPOSITION_VALIDATE', $user);
558  if ($result < 0) {
559  $error++;
560  }
561  // End call triggers
562  }
563  }
564 
565  if (!$error) {
566  $this->oldref = $this->ref;
567 
568  // Rename directory if dir was a temporary ref
569  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
570  // Now we rename also files into index
571  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'recruitmentjobposition/".$this->db->escape($this->newref)."'";
572  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentjobposition/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
573  $resql = $this->db->query($sql);
574  if (!$resql) {
575  $error++; $this->error = $this->db->lasterror();
576  }
577  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'recruitmentjobposition/".$this->db->escape($this->newref)."'";
578  $sql .= " WHERE filepath = 'recruitmentjobposition/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
579  $resql = $this->db->query($sql);
580  if (!$resql) {
581  $error++; $this->error = $this->db->lasterror();
582  }
583 
584  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
585  $oldref = dol_sanitizeFileName($this->ref);
586  $newref = dol_sanitizeFileName($num);
587  $dirsource = $conf->recruitment->dir_output.'/recruitmentjobposition/'.$oldref;
588  $dirdest = $conf->recruitment->dir_output.'/recruitmentjobposition/'.$newref;
589  if (!$error && file_exists($dirsource)) {
590  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
591 
592  if (@rename($dirsource, $dirdest)) {
593  dol_syslog("Rename ok");
594  // Rename docs starting with $oldref with $newref
595  $listoffiles = dol_dir_list($conf->recruitment->dir_output.'/recruitmentjobposition/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
596  foreach ($listoffiles as $fileentry) {
597  $dirsource = $fileentry['name'];
598  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
599  $dirsource = $fileentry['path'].'/'.$dirsource;
600  $dirdest = $fileentry['path'].'/'.$dirdest;
601  @rename($dirsource, $dirdest);
602  }
603  }
604  }
605  }
606  }
607 
608  // Set new ref and current status
609  if (!$error) {
610  $this->ref = $num;
611  $this->status = self::STATUS_VALIDATED;
612  }
613 
614  if (!$error) {
615  $this->db->commit();
616  return 1;
617  } else {
618  $this->db->rollback();
619  return -1;
620  }
621  }
622 
623 
631  public function setDraft($user, $notrigger = 0)
632  {
633  // Protection
634  if ($this->status <= self::STATUS_DRAFT) {
635  return 0;
636  }
637 
638  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
639  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
640  {
641  $this->error='Permission denied';
642  return -1;
643  }*/
644 
645  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'RECRUITMENTJOBPOSITION_UNVALIDATE');
646  }
647 
655  public function cancel($user, $notrigger = 0)
656  {
657  // Protection
658  if ($this->status != self::STATUS_VALIDATED) {
659  return 0;
660  }
661 
662  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
663  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
664  {
665  $this->error='Permission denied';
666  return -1;
667  }*/
668 
669  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'RECRUITMENTJOBPOSITION_CLOSE');
670  }
671 
681  public function cloture($user, $status, $note = "", $notrigger = 0)
682  {
683  global $langs, $conf;
684 
685  $error = 0;
686  $now = dol_now();
687 
688  $this->db->begin();
689 
690  $newprivatenote = dol_concatdesc($this->note_private, $note);
691 
692  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
693  $sql .= " SET status = ".((int) $status).", note_private = '".$this->db->escape($newprivatenote)."'";
694  //$sql .= ", date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
695  $sql .= " WHERE rowid = ".((int) $this->id);
696 
697  $resql = $this->db->query($sql);
698  if ($resql) {
699  $modelpdf = $this->model_pdf;
700  $triggerName = 'RECRUITMENTJOB_CLOSE_REFUSED';
701 
702  if ($status == self::STATUS_RECRUITED) {
703  $triggerName = 'RECRUITMENTJOB_CLOSE_RECRUITED';
704  $modelpdf = $this->model_pdf;
705  }
706 
707  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
708  // Define output language
709  $outputlangs = $langs;
710  if (getDolGlobalInt('MAIN_MULTILANGS')) {
711  $outputlangs = new Translate("", $conf);
712  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang);
713  $outputlangs->setDefaultLang($newlang);
714  }
715 
716  // PDF
717  $hidedetails = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
718  $hidedesc = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
719  $hideref = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
720 
721  //$ret=$object->fetch($id); // Reload to get new records
722  $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
723  }
724 
725  if (!$error) {
726  $this->oldcopy = clone $this;
727  $this->status = $status;
728  $this->date_cloture = $now;
729  $this->note_private = $newprivatenote;
730  }
731 
732  if (!$notrigger && empty($error)) {
733  // Call trigger
734  $result = $this->call_trigger($triggerName, $user);
735  if ($result < 0) {
736  $error++;
737  }
738  // End call triggers
739  }
740 
741  if (!$error) {
742  $this->db->commit();
743  return 1;
744  } else {
745  $this->status = $this->oldcopy->status;
746  $this->date_cloture = $this->oldcopy->date_cloture;
747  $this->note_private = $this->oldcopy->note_private;
748 
749  $this->db->rollback();
750  return -1;
751  }
752  } else {
753  $this->error = $this->db->lasterror();
754  $this->db->rollback();
755  return -1;
756  }
757  }
758 
766  public function reopen($user, $notrigger = 0)
767  {
768  // Protection
769  if ($this->status != self::STATUS_CANCELED) {
770  return 0;
771  }
772 
773  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->write))
774  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->recruitment->recruitment_advance->validate))))
775  {
776  $this->error='Permission denied';
777  return -1;
778  }*/
779 
780  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'RECRUITMENTJOBPOSITION_REOPEN');
781  }
782 
793  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
794  {
795  global $conf, $langs, $hookmanager;
796 
797  if (!empty($conf->dol_no_mouse_hover)) {
798  $notooltip = 1; // Force disable tooltips
799  }
800 
801  $result = '';
802 
803  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("PositionToBeFilled").'</u>';
804  if (isset($this->status)) {
805  $label .= ' '.$this->getLibStatut(5);
806  }
807  $label .= '<br>';
808  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
809  $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
810 
811  $url = dol_buildpath('/recruitment/recruitmentjobposition_card.php', 1).'?id='.$this->id;
812 
813  if ($option != 'nolink') {
814  // Add param to save lastsearch_values or not
815  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
816  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
817  $add_save_lastsearch_values = 1;
818  }
819  if ($add_save_lastsearch_values) {
820  $url .= '&save_lastsearch_values=1';
821  }
822  }
823 
824  $linkclose = '';
825  if (empty($notooltip)) {
826  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
827  $label = $langs->trans("ShowRecruitmentJobPosition");
828  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
829  }
830  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
831  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
832  } else {
833  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
834  }
835 
836  $linkstart = '<a href="'.$url.'"';
837  $linkstart .= $linkclose.'>';
838  $linkend = '</a>';
839 
840  $result .= $linkstart;
841 
842  if (empty($this->showphoto_on_popup)) {
843  if ($withpicto) {
844  $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);
845  }
846  } else {
847  if ($withpicto) {
848  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
849 
850  list($class, $module) = explode('@', $this->picto);
851  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
852  $filearray = dol_dir_list($upload_dir, "files");
853  $filename = $filearray[0]['name'];
854  if (!empty($filename)) {
855  $pospoint = strpos($filearray[0]['name'], '.');
856 
857  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
858  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
859  $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>';
860  } else {
861  $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>';
862  }
863 
864  $result .= '</div>';
865  } else {
866  $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);
867  }
868  }
869  }
870 
871  if ($withpicto != 2) {
872  $result .= $this->ref;
873  }
874 
875  $result .= $linkend;
876  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
877 
878  global $action, $hookmanager;
879  $hookmanager->initHooks(array('recruitmentjobpositiondao'));
880  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
881  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
882  if ($reshook > 0) {
883  $result = $hookmanager->resPrint;
884  } else {
885  $result .= $hookmanager->resPrint;
886  }
887 
888  return $result;
889  }
890 
897  public function getLibStatut($mode = 0)
898  {
899  return $this->LibStatut($this->status, $mode);
900  }
901 
902  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
910  public function LibStatut($status, $mode = 0)
911  {
912  // phpcs:enable
913  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
914  global $langs;
915  //$langs->load("recruitment");
916  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
917  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
918  $this->labelStatus[self::STATUS_RECRUITED] = $langs->transnoentitiesnoconv('Recruited');
919  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
920  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
921  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
922  $this->labelStatusShort[self::STATUS_RECRUITED] = $langs->transnoentitiesnoconv('Recruited');
923  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
924  }
925 
926  $statusType = 'status'.$status;
927  if ($status == self::STATUS_VALIDATED) {
928  $statusType = 'status4';
929  }
930  if ($status == self::STATUS_RECRUITED) {
931  $statusType = 'status6';
932  }
933  if ($status == self::STATUS_CANCELED) {
934  $statusType = 'status9';
935  }
936 
937  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
938  }
939 
946  public function info($id)
947  {
948  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
949  $sql .= ' fk_user_creat, fk_user_modif';
950  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
951  $sql .= ' WHERE t.rowid = '.((int) $id);
952  $result = $this->db->query($sql);
953  if ($result) {
954  if ($this->db->num_rows($result)) {
955  $obj = $this->db->fetch_object($result);
956  $this->id = $obj->rowid;
957 
958  $this->user_creation_id = $obj->fk_user_creat;
959  $this->user_modification_id = $obj->fk_user_modif;
960  $this->date_creation = $this->db->jdate($obj->datec);
961  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
962  }
963 
964  $this->db->free($result);
965  } else {
966  dol_print_error($this->db);
967  }
968  }
969 
976  public function initAsSpecimen()
977  {
978  $this->initAsSpecimenCommon();
979  }
980 
986  public function getLinesArray()
987  {
988  $this->lines = array();
989 
990  return $this->lines;
991  }
992 
998  public function getNextNumRef()
999  {
1000  global $langs, $conf;
1001  $langs->load("recruitment");
1002 
1003  if (empty($conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON)) {
1004  $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON = 'mod_recruitmentjobposition_standard';
1005  }
1006 
1007  if (!empty($conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON)) {
1008  $mybool = false;
1009 
1010  $file = $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON.".php";
1011  $classname = $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON;
1012 
1013  // Include file with class
1014  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1015  foreach ($dirmodels as $reldir) {
1016  $dir = dol_buildpath($reldir."core/modules/recruitment/");
1017 
1018  // Load file with numbering class (if found)
1019  $mybool |= @include_once $dir.$file;
1020  }
1021 
1022  if ($mybool === false) {
1023  dol_print_error('', "Failed to include file ".$file);
1024  return '';
1025  }
1026 
1027  if (class_exists($classname)) {
1028  $obj = new $classname();
1029  $numref = $obj->getNextValue($this);
1030 
1031  if ($numref != '' && $numref != '-1') {
1032  return $numref;
1033  } else {
1034  $this->error = $obj->error;
1035  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1036  return "";
1037  }
1038  } else {
1039  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1040  return "";
1041  }
1042  } else {
1043  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1044  return "";
1045  }
1046  }
1047 
1059  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1060  {
1061  global $conf, $langs;
1062 
1063  $result = 0;
1064  $includedocgeneration = 1;
1065 
1066  $langs->load("recruitment");
1067 
1068  if (!dol_strlen($modele)) {
1069  if (!empty($conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF)) {
1070  $modele = $conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF;
1071  } else {
1072  $modele = ''; // No default value. For job position, we allow to disable all PDF generation
1073  }
1074  }
1075 
1076  $modelpath = "core/modules/recruitment/doc/";
1077 
1078  if ($includedocgeneration && !empty($modele)) {
1079  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1080  }
1081 
1082  return $result;
1083  }
1084 
1092  public function doScheduledJob()
1093  {
1094  //global $conf, $langs;
1095 
1096  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1097 
1098  $error = 0;
1099  $this->output = '';
1100  $this->error = '';
1101 
1102  dol_syslog(__METHOD__, LOG_DEBUG);
1103 
1104  $now = dol_now();
1105 
1106  $this->db->begin();
1107 
1108  // ...
1109 
1110  $this->db->commit();
1111 
1112  return $error;
1113  }
1114 
1115 
1123  public function getKanbanView($option = '', $arraydata = null)
1124  {
1125  global $langs;
1126 
1127  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1128 
1129  $return = '<div class="box-flex-item box-flex-grow-zero">';
1130  $return .= '<div class="info-box info-box-sm">';
1131  $return .= '<span class="info-box-icon bg-infobox-action">';
1132  $return .= img_picto('', $this->picto);
1133  $return .= '</span>';
1134  $return .= '<div class="info-box-content">';
1135  $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1136  $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1137  if (property_exists($this, 'date_planned')) {
1138  $return .= '<br><span class="opacitymedium">'.$langs->trans("Date").'</span> : <span class="info-box-label">'.dol_print_date($this->db->jdate($this->date_planned), 'day').'</span>';
1139  }
1140  if (property_exists($this, 'qty')) {
1141  $return .= '<br><span class="opacitymedium" title="'.$langs->trans("NbOfEmployeesExpected").'">'.$langs->trans("NbOfEmployeesExpected", '', '', '', '', 2).'</span> : <span class="info-box-label">'.$this->qty.'</span>';
1142  }
1143  if (property_exists($this, 'remuneration_suggested')) {
1144  $return .= ' | <span class="opacitymedium">'.$langs->trans("Remuneration").'</span> : <span class="info-box-label">'.$this->remuneration_suggested.'</span>';
1145  }
1146  if (method_exists($this, 'getLibStatut')) {
1147  $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).' | <span class="opacitymedium" title="'.$langs->trans("RecruitmentCandidatures").'">'.$langs->trans("RecruitmentCandidatures", '', '', '', '', 5).'</span> : <span>';
1148  $return .= $arraydata['nbapplications'];
1149  $return .= '</span></div>';
1150  }
1151  $return .= '</div>';
1152  $return .= '</div>';
1153  $return .= '</div>';
1154  return $return;
1155  }
1156 }
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the 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.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for RecruitmentJobPosition.
validate($user, $notrigger=0)
Validate object.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load the info information in the object.
create(User $user, $notrigger=false)
Create object into database.
__construct(DoliDB $db)
Constructor.
cloture($user, $status, $note="", $notrigger=0)
Close the recruitment.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
setDraft($user, $notrigger=0)
Set draft status.
getLibStatut($mode=0)
Return label of the status.
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.
getLinesArray()
Create an array of lines.
reopen($user, $notrigger=0)
Set back to validated status.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
fetch($id, $ref=null)
Load object in memory from the database.
cancel($user, $notrigger=0)
Set cancel status.
createFromClone(User $user, $fromid)
Clone an object into another one.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
update(User $user, $notrigger=false)
Update object into database.
fetchLines()
Load object lines in memory from the database.
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.