dolibarr  16.0.5
recruitmentjobposition.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 = 'recruitmentjobposition';
43 
47  public $table_element = 'recruitment_recruitmentjobposition';
48 
53  public $ismultientitymanaged = 1;
54 
58  public $isextrafieldmanaged = 1;
59 
63  public $picto = 'recruitmentjobposition';
64 
65 
66  const STATUS_DRAFT = 0;
67  const STATUS_VALIDATED = 1;
68  const STATUS_RECRUITED = 3;
69  const STATUS_CANCELED = 9;
70 
71 
97  // BEGIN MODULEBUILDER PROPERTIES
101  public $fields = array(
102  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'comment'=>"Id"),
103  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1),
104  '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'),
105  '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),
106  'qty' => array('type'=>'integer', 'label'=>'NbOfEmployeesExpected', 'enabled'=>'1', 'position'=>45, 'notnull'=>1, 'visible'=>1, 'default'=>'1', 'isameasure'=>'1', 'css'=>'maxwidth75imp'),
107  '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'),
108  'fk_user_recruiter' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'ResponsibleOfRecruitement', 'enabled'=>'1', 'position'=>54, 'notnull'=>1, 'visible'=>1, 'foreignkey'=>'user.rowid', 'css'=>'maxwidth500', 'csslist'=>'tdoverflowmax150', 'picto'=>'user'),
109  'email_recruiter' => array('type'=>'varchar(255)', 'label'=>'EmailRecruiter', 'enabled'=>'1', 'position'=>54, 'notnull'=>0, 'visible'=>-1, 'help'=>'ToUseAGenericEmail', 'picto'=>'email'),
110  'fk_user_supervisor' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'FutureManager', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>-1, 'foreignkey'=>'user.rowid', 'css'=>'maxwidth500', 'csslist'=>'tdoverflowmax150', 'picto'=>'user'),
111  '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',),
112  'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'WorkPlace', 'enabled'=>'$conf->societe->enabled', 'position'=>57, 'notnull'=>-1, 'visible'=>-1, 'css'=>'maxwidth500', 'index'=>1, 'help'=>"IfJobIsLocatedAtAPartner", 'picto'=>'company'),
113  'date_planned' => array('type'=>'date', 'label'=>'DateExpected', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>1,),
114  'remuneration_suggested' => array('type'=>'varchar(255)', 'label'=>'Remuneration', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>1,),
115  'description' => array('type'=>'html', 'label'=>'Description', 'enabled'=>'1', 'position'=>65, 'notnull'=>0, 'visible'=>3,),
116  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>101, 'notnull'=>0, 'visible'=>0,),
117  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>102, 'notnull'=>0, 'visible'=>0,),
118  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-4,),
119  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
120  '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',),
121  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
122  'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>900, 'notnull'=>0, 'visible'=>0,),
123  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
124  'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
125  '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'),),
126  );
127  public $rowid;
128 
132  public $ref;
133  public $entity;
134 
138  public $label;
139  public $qty;
140  public $fk_soc;
141  public $fk_project;
142  public $fk_user_recruiter;
143 
147  public $email_recruiter;
148 
152  public $remuneration_suggested;
153 
154  public $fk_user_supervisor;
155  public $fk_establishment;
156  public $date_planned;
157  public $description;
158  public $note_public;
159  public $note_private;
160  public $date_creation;
161  public $tms;
162  public $fk_user_creat;
163  public $fk_user_modif;
164  public $last_main_doc;
165  public $import_key;
166  public $model_pdf;
167  public $status;
168  // END MODULEBUILDER PROPERTIES
169 
170 
176  public function __construct(DoliDB $db)
177  {
178  global $conf, $langs;
179 
180  $this->db = $db;
181 
182  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
183  $this->fields['rowid']['visible'] = 0;
184  }
185  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
186  $this->fields['entity']['enabled'] = 0;
187  }
188 
189  // Example to show how to set values of fields definition dynamically
190  /*if ($user->rights->recruitment->recruitmentjobposition->read) {
191  $this->fields['myfield']['visible'] = 1;
192  $this->fields['myfield']['noteditable'] = 0;
193  }*/
194 
195  // Unset fields that are disabled
196  foreach ($this->fields as $key => $val) {
197  if (isset($val['enabled']) && empty($val['enabled'])) {
198  unset($this->fields[$key]);
199  }
200  }
201 
202  // Translate some data of arrayofkeyval
203  if (is_object($langs)) {
204  foreach ($this->fields as $key => $val) {
205  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
206  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
207  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
208  }
209  }
210  }
211  }
212  }
213 
221  public function create(User $user, $notrigger = false)
222  {
223  return $this->createCommon($user, $notrigger);
224  }
225 
233  public function createFromClone(User $user, $fromid)
234  {
235  global $langs, $extrafields;
236  $error = 0;
237 
238  dol_syslog(__METHOD__, LOG_DEBUG);
239 
240  $object = new self($this->db);
241 
242  $this->db->begin();
243 
244  // Load source object
245  $result = $object->fetchCommon($fromid);
246  if ($result > 0 && !empty($object->table_element_line)) {
247  $object->fetchLines();
248  }
249 
250  // get lines so they will be clone
251  //foreach($this->lines as $line)
252  // $line->fetch_optionals();
253 
254  // Reset some properties
255  unset($object->id);
256  unset($object->fk_user_creat);
257  unset($object->import_key);
258 
259  // Clear fields
260  if (property_exists($object, 'ref')) {
261  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
262  }
263  if (property_exists($object, 'label')) {
264  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
265  }
266  if (property_exists($object, 'status')) {
267  $object->status = self::STATUS_DRAFT;
268  }
269  if (property_exists($object, 'date_creation')) {
270  $object->date_creation = dol_now();
271  }
272  if (property_exists($object, 'date_modification')) {
273  $object->date_modification = null;
274  }
275  // ...
276  // Clear extrafields that are unique
277  if (is_array($object->array_options) && count($object->array_options) > 0) {
278  $extrafields->fetch_name_optionals_label($this->table_element);
279  foreach ($object->array_options as $key => $option) {
280  $shortkey = preg_replace('/options_/', '', $key);
281  if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
282  //var_dump($key);
283  //var_dump($clonedObj->array_options[$key]); exit;
284  unset($object->array_options[$key]);
285  }
286  }
287  }
288 
289  // Create clone
290  $object->context['createfromclone'] = 'createfromclone';
291  $result = $object->createCommon($user);
292  if ($result < 0) {
293  $error++;
294  $this->error = $object->error;
295  $this->errors = $object->errors;
296  }
297 
298  if (!$error) {
299  // copy internal contacts
300  if ($this->copy_linked_contact($object, 'internal') < 0) {
301  $error++;
302  }
303  }
304 
305  if (!$error) {
306  // copy external contacts if same company
307  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
308  if ($this->copy_linked_contact($object, 'external') < 0) {
309  $error++;
310  }
311  }
312  }
313 
314  unset($object->context['createfromclone']);
315 
316  // End
317  if (!$error) {
318  $this->db->commit();
319  return $object;
320  } else {
321  $this->db->rollback();
322  return -1;
323  }
324  }
325 
333  public function fetch($id, $ref = null)
334  {
335  $result = $this->fetchCommon($id, $ref);
336  if ($result > 0 && !empty($this->table_element_line)) {
337  $this->fetchLines();
338  }
339  return $result;
340  }
341 
347  public function fetchLines()
348  {
349  $this->lines = array();
350 
351  $result = $this->fetchLinesCommon();
352  return $result;
353  }
354 
355 
367  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
368  {
369  global $conf;
370 
371  dol_syslog(__METHOD__, LOG_DEBUG);
372 
373  $records = array();
374 
375  $sql = 'SELECT ';
376  $sql .= $this->getFieldList();
377  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
378  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
379  $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
380  } else {
381  $sql .= ' WHERE 1 = 1';
382  }
383  // Manage filter
384  $sqlwhere = array();
385  if (count($filter) > 0) {
386  foreach ($filter as $key => $value) {
387  if ($key == 't.rowid') {
388  $sqlwhere[] = $key." = ".((int) $value);
389  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
390  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
391  } elseif ($key == 'customsql') {
392  $sqlwhere[] = $value;
393  } elseif (strpos($value, '%') === false) {
394  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
395  } else {
396  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
397  }
398  }
399  }
400  if (count($sqlwhere) > 0) {
401  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
402  }
403 
404  if (!empty($sortfield)) {
405  $sql .= $this->db->order($sortfield, $sortorder);
406  }
407  if (!empty($limit)) {
408  $sql .= $this->db->plimit($limit, $offset);
409  }
410 
411  $resql = $this->db->query($sql);
412  if ($resql) {
413  $num = $this->db->num_rows($resql);
414  $i = 0;
415  while ($i < ($limit ? min($limit, $num) : $num)) {
416  $obj = $this->db->fetch_object($resql);
417 
418  $record = new self($this->db);
419  $record->setVarsFromFetchObj($obj);
420 
421  $records[$record->id] = $record;
422 
423  $i++;
424  }
425  $this->db->free($resql);
426 
427  return $records;
428  } else {
429  $this->errors[] = 'Error '.$this->db->lasterror();
430  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
431 
432  return -1;
433  }
434  }
435 
443  public function update(User $user, $notrigger = false)
444  {
445  return $this->updateCommon($user, $notrigger);
446  }
447 
455  public function delete(User $user, $notrigger = false)
456  {
457  return $this->deleteCommon($user, $notrigger);
458  //return $this->deleteCommon($user, $notrigger, 1);
459  }
460 
469  public function deleteLine(User $user, $idline, $notrigger = false)
470  {
471  if ($this->status < 0) {
472  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
473  return -2;
474  }
475 
476  return $this->deleteLineCommon($user, $idline, $notrigger);
477  }
478 
479 
487  public function validate($user, $notrigger = 0)
488  {
489  global $conf, $langs;
490 
491  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
492 
493  $error = 0;
494 
495  // Protection
496  if ($this->status == self::STATUS_VALIDATED) {
497  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
498  return 0;
499  }
500 
501  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitmentjobposition->create))
502  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitmentjobposition->recruitmentjobposition_advance->validate))))
503  {
504  $this->error='NotEnoughPermissions';
505  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
506  return -1;
507  }*/
508 
509  $now = dol_now();
510 
511  $this->db->begin();
512 
513  // Define new ref
514  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
515  $num = $this->getNextNumRef();
516  } else {
517  $num = $this->ref;
518  }
519  $this->newref = $num;
520 
521  if (!empty($num)) {
522  // Validate
523  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
524  $sql .= " SET ref = '".$this->db->escape($num)."',";
525  $sql .= " status = ".self::STATUS_VALIDATED;
526  if (!empty($this->fields['date_validation'])) {
527  $sql .= ", date_validation = '".$this->db->idate($now)."',";
528  }
529  if (!empty($this->fields['fk_user_valid'])) {
530  $sql .= ", fk_user_valid = ".$user->id;
531  }
532  $sql .= " WHERE rowid = ".((int) $this->id);
533 
534  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
535  $resql = $this->db->query($sql);
536  if (!$resql) {
537  dol_print_error($this->db);
538  $this->error = $this->db->lasterror();
539  $error++;
540  }
541 
542  if (!$error && !$notrigger) {
543  // Call trigger
544  $result = $this->call_trigger('RECRUITMENTJOBPOSITION_VALIDATE', $user);
545  if ($result < 0) {
546  $error++;
547  }
548  // End call triggers
549  }
550  }
551 
552  if (!$error) {
553  $this->oldref = $this->ref;
554 
555  // Rename directory if dir was a temporary ref
556  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
557  // Now we rename also files into index
558  $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)."'";
559  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentjobposition/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
560  $resql = $this->db->query($sql);
561  if (!$resql) {
562  $error++; $this->error = $this->db->lasterror();
563  }
564 
565  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
566  $oldref = dol_sanitizeFileName($this->ref);
567  $newref = dol_sanitizeFileName($num);
568  $dirsource = $conf->recruitment->dir_output.'/recruitmentjobposition/'.$oldref;
569  $dirdest = $conf->recruitment->dir_output.'/recruitmentjobposition/'.$newref;
570  if (!$error && file_exists($dirsource)) {
571  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
572 
573  if (@rename($dirsource, $dirdest)) {
574  dol_syslog("Rename ok");
575  // Rename docs starting with $oldref with $newref
576  $listoffiles = dol_dir_list($conf->recruitment->dir_output.'/recruitmentjobposition/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
577  foreach ($listoffiles as $fileentry) {
578  $dirsource = $fileentry['name'];
579  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
580  $dirsource = $fileentry['path'].'/'.$dirsource;
581  $dirdest = $fileentry['path'].'/'.$dirdest;
582  @rename($dirsource, $dirdest);
583  }
584  }
585  }
586  }
587  }
588 
589  // Set new ref and current status
590  if (!$error) {
591  $this->ref = $num;
592  $this->status = self::STATUS_VALIDATED;
593  }
594 
595  if (!$error) {
596  $this->db->commit();
597  return 1;
598  } else {
599  $this->db->rollback();
600  return -1;
601  }
602  }
603 
604 
612  public function setDraft($user, $notrigger = 0)
613  {
614  // Protection
615  if ($this->status <= self::STATUS_DRAFT) {
616  return 0;
617  }
618 
619  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
620  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
621  {
622  $this->error='Permission denied';
623  return -1;
624  }*/
625 
626  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'RECRUITMENTJOBPOSITION_UNVALIDATE');
627  }
628 
636  public function cancel($user, $notrigger = 0)
637  {
638  // Protection
639  if ($this->status != self::STATUS_VALIDATED) {
640  return 0;
641  }
642 
643  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
644  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
645  {
646  $this->error='Permission denied';
647  return -1;
648  }*/
649 
650  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'RECRUITMENTJOBPOSITION_CLOSE');
651  }
652 
662  public function cloture($user, $status, $note = "", $notrigger = 0)
663  {
664  global $langs, $conf;
665 
666  $error = 0;
667  $now = dol_now();
668 
669  $this->db->begin();
670 
671  $newprivatenote = dol_concatdesc($this->note_private, $note);
672 
673  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
674  $sql .= " SET status = ".((int) $status).", note_private = '".$this->db->escape($newprivatenote)."'";
675  //$sql .= ", date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
676  $sql .= " WHERE rowid = ".((int) $this->id);
677 
678  $resql = $this->db->query($sql);
679  if ($resql) {
680  $modelpdf = $this->model_pdf;
681  $triggerName = 'RECRUITMENTJOB_CLOSE_REFUSED';
682 
683  if ($status == self::STATUS_RECRUITED) {
684  $triggerName = 'RECRUITMENTJOB_CLOSE_RECRUITED';
685  $modelpdf = $this->model_pdf;
686 
687  if ($result < 0) {
688  $this->error = $this->db->lasterror();
689  $this->db->rollback();
690  return -2;
691  }
692  }
693 
694  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
695  // Define output language
696  $outputlangs = $langs;
697  if (!empty($conf->global->MAIN_MULTILANGS)) {
698  $outputlangs = new Translate("", $conf);
699  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang);
700  $outputlangs->setDefaultLang($newlang);
701  }
702 
703  // PDF
704  $hidedetails = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
705  $hidedesc = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
706  $hideref = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
707 
708  //$ret=$object->fetch($id); // Reload to get new records
709  $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
710  }
711 
712  if (!$error) {
713  $this->oldcopy = clone $this;
714  $this->status = $status;
715  $this->date_cloture = $now;
716  $this->note_private = $newprivatenote;
717  }
718 
719  if (!$notrigger && empty($error)) {
720  // Call trigger
721  $result = $this->call_trigger($triggerName, $user);
722  if ($result < 0) {
723  $error++;
724  }
725  // End call triggers
726  }
727 
728  if (!$error) {
729  $this->db->commit();
730  return 1;
731  } else {
732  $this->status = $this->oldcopy->status;
733  $this->date_cloture = $this->oldcopy->date_cloture;
734  $this->note_private = $this->oldcopy->note_private;
735 
736  $this->db->rollback();
737  return -1;
738  }
739  } else {
740  $this->error = $this->db->lasterror();
741  $this->db->rollback();
742  return -1;
743  }
744  }
745 
753  public function reopen($user, $notrigger = 0)
754  {
755  // Protection
756  if ($this->status != self::STATUS_CANCELED) {
757  return 0;
758  }
759 
760  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
761  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
762  {
763  $this->error='Permission denied';
764  return -1;
765  }*/
766 
767  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'RECRUITMENTJOBPOSITION_REOPEN');
768  }
769 
780  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
781  {
782  global $conf, $langs, $hookmanager;
783 
784  if (!empty($conf->dol_no_mouse_hover)) {
785  $notooltip = 1; // Force disable tooltips
786  }
787 
788  $result = '';
789 
790  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("PositionToBeFilled").'</u>';
791  if (isset($this->status)) {
792  $label .= ' '.$this->getLibStatut(5);
793  }
794  $label .= '<br>';
795  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
796  $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
797 
798  $url = dol_buildpath('/recruitment/recruitmentjobposition_card.php', 1).'?id='.$this->id;
799 
800  if ($option != 'nolink') {
801  // Add param to save lastsearch_values or not
802  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
803  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
804  $add_save_lastsearch_values = 1;
805  }
806  if ($add_save_lastsearch_values) {
807  $url .= '&save_lastsearch_values=1';
808  }
809  }
810 
811  $linkclose = '';
812  if (empty($notooltip)) {
813  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
814  $label = $langs->trans("ShowRecruitmentJobPosition");
815  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
816  }
817  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
818  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
819  } else {
820  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
821  }
822 
823  $linkstart = '<a href="'.$url.'"';
824  $linkstart .= $linkclose.'>';
825  $linkend = '</a>';
826 
827  $result .= $linkstart;
828 
829  if (empty($this->showphoto_on_popup)) {
830  if ($withpicto) {
831  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
832  }
833  } else {
834  if ($withpicto) {
835  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
836 
837  list($class, $module) = explode('@', $this->picto);
838  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
839  $filearray = dol_dir_list($upload_dir, "files");
840  $filename = $filearray[0]['name'];
841  if (!empty($filename)) {
842  $pospoint = strpos($filearray[0]['name'], '.');
843 
844  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
845  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
846  $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
847  } else {
848  $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
849  }
850 
851  $result .= '</div>';
852  } else {
853  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
854  }
855  }
856  }
857 
858  if ($withpicto != 2) {
859  $result .= $this->ref;
860  }
861 
862  $result .= $linkend;
863  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
864 
865  global $action, $hookmanager;
866  $hookmanager->initHooks(array('recruitmentjobpositiondao'));
867  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
868  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
869  if ($reshook > 0) {
870  $result = $hookmanager->resPrint;
871  } else {
872  $result .= $hookmanager->resPrint;
873  }
874 
875  return $result;
876  }
877 
884  public function getLibStatut($mode = 0)
885  {
886  return $this->LibStatut($this->status, $mode);
887  }
888 
889  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
897  public function LibStatut($status, $mode = 0)
898  {
899  // phpcs:enable
900  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
901  global $langs;
902  //$langs->load("recruitment");
903  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
904  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
905  $this->labelStatus[self::STATUS_RECRUITED] = $langs->transnoentitiesnoconv('Recruited');
906  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
907  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
908  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
909  $this->labelStatusShort[self::STATUS_RECRUITED] = $langs->transnoentitiesnoconv('Recruited');
910  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
911  }
912 
913  $statusType = 'status'.$status;
914  if ($status == self::STATUS_VALIDATED) {
915  $statusType = 'status4';
916  }
917  if ($status == self::STATUS_RECRUITED) {
918  $statusType = 'status6';
919  }
920  if ($status == self::STATUS_CANCELED) {
921  $statusType = 'status9';
922  }
923 
924  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
925  }
926 
933  public function info($id)
934  {
935  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
936  $sql .= ' fk_user_creat, fk_user_modif';
937  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
938  $sql .= ' WHERE t.rowid = '.((int) $id);
939  $result = $this->db->query($sql);
940  if ($result) {
941  if ($this->db->num_rows($result)) {
942  $obj = $this->db->fetch_object($result);
943  $this->id = $obj->rowid;
944 
945  $this->user_creation_id = $obj->fk_user_creat;
946  $this->user_modification_id = $obj->fk_user_modif;
947  $this->date_creation = $this->db->jdate($obj->datec);
948  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
949  }
950 
951  $this->db->free($result);
952  } else {
953  dol_print_error($this->db);
954  }
955  }
956 
963  public function initAsSpecimen()
964  {
965  $this->initAsSpecimenCommon();
966  }
967 
973  public function getLinesArray()
974  {
975  $this->lines = array();
976 
977  return $this->lines;
978  }
979 
985  public function getNextNumRef()
986  {
987  global $langs, $conf;
988  $langs->load("recruitment");
989 
990  if (empty($conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON)) {
991  $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON = 'mod_recruitmentjobposition_standard';
992  }
993 
994  if (!empty($conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON)) {
995  $mybool = false;
996 
997  $file = $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON.".php";
998  $classname = $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON;
999 
1000  // Include file with class
1001  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1002  foreach ($dirmodels as $reldir) {
1003  $dir = dol_buildpath($reldir."core/modules/recruitment/");
1004 
1005  // Load file with numbering class (if found)
1006  $mybool |= @include_once $dir.$file;
1007  }
1008 
1009  if ($mybool === false) {
1010  dol_print_error('', "Failed to include file ".$file);
1011  return '';
1012  }
1013 
1014  if (class_exists($classname)) {
1015  $obj = new $classname();
1016  $numref = $obj->getNextValue($this);
1017 
1018  if ($numref != '' && $numref != '-1') {
1019  return $numref;
1020  } else {
1021  $this->error = $obj->error;
1022  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1023  return "";
1024  }
1025  } else {
1026  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1027  return "";
1028  }
1029  } else {
1030  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1031  return "";
1032  }
1033  }
1034 
1046  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1047  {
1048  global $conf, $langs;
1049 
1050  $result = 0;
1051  $includedocgeneration = 1;
1052 
1053  $langs->load("recruitment");
1054 
1055  if (!dol_strlen($modele)) {
1056  if (!empty($conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF)) {
1057  $modele = $conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF;
1058  } else {
1059  $modele = ''; // No default value. For job position, we allow to disable all PDF generation
1060  }
1061  }
1062 
1063  $modelpath = "core/modules/recruitment/doc/";
1064 
1065  if ($includedocgeneration && !empty($modele)) {
1066  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1067  }
1068 
1069  return $result;
1070  }
1071 
1079  public function doScheduledJob()
1080  {
1081  global $conf, $langs;
1082 
1083  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1084 
1085  $error = 0;
1086  $this->output = '';
1087  $this->error = '';
1088 
1089  dol_syslog(__METHOD__, LOG_DEBUG);
1090 
1091  $now = dol_now();
1092 
1093  $this->db->begin();
1094 
1095  // ...
1096 
1097  $this->db->commit();
1098 
1099  return $error;
1100  }
1101 }
RecruitmentJobPosition\validate
validate($user, $notrigger=0)
Validate object.
Definition: recruitmentjobposition.class.php:487
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9683
db
$conf db
API class for accounts.
Definition: inc.php:41
RecruitmentJobPosition\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: recruitmentjobposition.class.php:367
RecruitmentJobPosition\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: recruitmentjobposition.class.php:233
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1217
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
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:4844
RecruitmentJobPosition\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: recruitmentjobposition.class.php:985
Translate
Class to manage translations.
Definition: translate.class.php:30
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
RecruitmentJobPosition\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: recruitmentjobposition.class.php:753
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9258
RecruitmentJobPosition\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: recruitmentjobposition.class.php:1079
RecruitmentJobPosition
Class for RecruitmentJobPosition.
Definition: recruitmentjobposition.class.php:32
RecruitmentJobPosition\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: recruitmentjobposition.class.php:333
ref
$object ref
Definition: info.php:77
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)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
RecruitmentJobPosition\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: recruitmentjobposition.class.php:612
RecruitmentJobPosition\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: recruitmentjobposition.class.php:347
RecruitmentJobPosition\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: recruitmentjobposition.class.php:1046
dol_concatdesc
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...
Definition: functions.lib.php:7248
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:3880
RecruitmentJobPosition\create
create(User $user, $notrigger=false)
Create object into database.
Definition: recruitmentjobposition.class.php:221
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
RecruitmentJobPosition\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: recruitmentjobposition.class.php:469
RecruitmentJobPosition\cloture
cloture($user, $status, $note="", $notrigger=0)
Close the commercial proposal.
Definition: recruitmentjobposition.class.php:662
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
RecruitmentJobPosition\__construct
__construct(DoliDB $db)
Constructor.
Definition: recruitmentjobposition.class.php:176
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
User
Class to manage Dolibarr users.
Definition: user.class.php:44
RecruitmentJobPosition\update
update(User $user, $notrigger=false)
Update object into database.
Definition: recruitmentjobposition.class.php:443
CommonObject\$note
$note
Definition: commonobject.class.php:444
RecruitmentJobPosition\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: recruitmentjobposition.class.php:780
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
RecruitmentJobPosition\info
info($id)
Load the info information in the object.
Definition: recruitmentjobposition.class.php:933
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:4211
RecruitmentJobPosition\getLibStatut
getLibStatut($mode=0)
Return label of the status.
Definition: recruitmentjobposition.class.php:884
RecruitmentJobPosition\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: recruitmentjobposition.class.php:897
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9622
RecruitmentJobPosition\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: recruitmentjobposition.class.php:636
RecruitmentJobPosition\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: recruitmentjobposition.class.php:963
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
RecruitmentJobPosition\getLinesArray
getLinesArray()
Create an array of lines.
Definition: recruitmentjobposition.class.php:973
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:8987