dolibarr  17.0.2
job.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4  * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5  * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6  * Copyright (C) 2021 GrĂ©gory BLEMAND <gregory.blemand@atm-consulting.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Put here all includes required by your class file
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32 
36 class Job extends CommonObject
37 {
41  public $module = 'hrm';
42 
46  public $element = 'job';
47 
51  public $table_element = 'hrm_job';
52 
57  public $ismultientitymanaged = 0;
58 
62  public $isextrafieldmanaged = 1;
63 
67  public $picto = 'technic';
68 
69 
70  const STATUS_DRAFT = 0;
71  const STATUS_VALIDATED = 1;
72  const STATUS_CANCELED = 9;
73 
74 
101  // BEGIN MODULEBUILDER PROPERTIES
105  public $fields=array(
106  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
107  'label' => array('type'=>'varchar(128)', 'label'=>'Label', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Label of object"),
108  'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>21, 'notnull'=>0, 'visible'=>1,),
109  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>2,),
110  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>2,),
111  'deplacement' => array('type'=>'select', 'required'=> 1,'label'=> 'NeedBusinessTravels', 'enabled'=> 1, 'position'=> 90, 'notnull'=> 1, 'visible'=> 1, 'arrayofkeyval'=> array(0 =>"No", 1=>"Yes"), 'default'=>0),
112  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>70, 'notnull'=>0, 'visible'=>0,),
113  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>71, 'notnull'=>0, 'visible'=>0,),
114  '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',),
115  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
116  );
117  public $rowid;
118  public $ref;
119  public $description;
120  public $date_creation;
121  public $tms;
122  public $deplacement;
123  public $note_public;
124  public $note_private;
125  public $fk_user_creat;
126  public $fk_user_modif;
127  // END MODULEBUILDER PROPERTIES
128 
129 
130  // If this object has a subtable with lines
131 
132  // /**
133  // * @var string Name of subtable line
134  // */
135  // public $table_element_line = 'hrm_jobline';
136 
137  // /**
138  // * @var string Field with ID of parent key if this object has a parent
139  // */
140  public $fk_element = 'fk_job';
141 
142  // /**
143  // * @var string Name of subtable class that manage subtable lines
144  // */
145  // public $class_element_line = 'Jobline';
146 
147  // /**
148  // * @var array List of child tables. To test if we can delete object.
149  // */
150  protected $childtables = array('hrm_evaluation', 'hrm_job_user');
151 
152  // /**
153  // * @var array List of child tables. To know object to delete on cascade.
154  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
155  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
156  // */
157  protected $childtablesoncascade = array("@SkillRank:hrm/class/skillrank.class.php:fk_object:objecttype='job'");
158 
159  // /**
160  // * @var JobLine[] Array of subtable lines
161  // */
162  // public $lines = array();
163 
164 
165 
171  public function __construct(DoliDB $db)
172  {
173  global $conf, $langs;
174 
175  $this->db = $db;
176 
177  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
178  $this->fields['rowid']['visible'] = 0;
179  }
180  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
181  $this->fields['entity']['enabled'] = 0;
182  }
183 
184  // Example to show how to set values of fields definition dynamically
185  /*if ($user->rights->hrm->job->read) {
186  $this->fields['myfield']['visible'] = 1;
187  $this->fields['myfield']['noteditable'] = 0;
188  }*/
189 
190  // Unset fields that are disabled
191  foreach ($this->fields as $key => $val) {
192  if (isset($val['enabled']) && empty($val['enabled'])) {
193  unset($this->fields[$key]);
194  }
195  }
196 
197  // Translate some data of arrayofkeyval
198  if (is_object($langs)) {
199  foreach ($this->fields as $key => $val) {
200  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
201  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
202  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
203  }
204  }
205  }
206  }
207  }
208 
216  public function create(User $user, $notrigger = false)
217  {
218  $resultcreate = $this->createCommon($user, $notrigger);
219 
220  //$resultvalidate = $this->validate($user, $notrigger);
221 
222  return $resultcreate;
223  }
224 
232  public function createFromClone(User $user, $fromid)
233  {
234  global $langs, $extrafields;
235  $error = 0;
236 
237  dol_syslog(__METHOD__, LOG_DEBUG);
238 
239  $object = new self($this->db);
240 
241  $this->db->begin();
242 
243  // Load source object
244  $result = $object->fetchCommon($fromid);
245  if ($result > 0 && !empty($object->table_element_line)) {
246  $object->fetchLines();
247  }
248 
249  // get lines so they will be clone
250  //foreach($this->lines as $line)
251  // $line->fetch_optionals();
252 
253  // Reset some properties
254  unset($object->id);
255  unset($object->fk_user_creat);
256  unset($object->import_key);
257 
258  // Clear fields
259  if (property_exists($object, 'ref')) {
260  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
261  }
262  if (property_exists($object, 'label')) {
263  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
264  }
265  if (property_exists($object, 'status')) {
266  $object->status = self::STATUS_DRAFT;
267  }
268  if (property_exists($object, 'date_creation')) {
269  $object->date_creation = dol_now();
270  }
271  if (property_exists($object, 'date_modification')) {
272  $object->date_modification = null;
273  }
274  // ...
275  // Clear extrafields that are unique
276  if (is_array($object->array_options) && count($object->array_options) > 0) {
277  $extrafields->fetch_name_optionals_label($this->table_element);
278  foreach ($object->array_options as $key => $option) {
279  $shortkey = preg_replace('/options_/', '', $key);
280  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
281  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
282  unset($object->array_options[$key]);
283  }
284  }
285  }
286 
287  // Create clone
288  $object->context['createfromclone'] = 'createfromclone';
289  $result = $object->createCommon($user);
290  if ($result < 0) {
291  $error++;
292  $this->error = $object->error;
293  $this->errors = $object->errors;
294  }
295 
296  if (!$error) {
297  // copy internal contacts
298  if ($this->copy_linked_contact($object, 'internal') < 0) {
299  $error++;
300  }
301  }
302 
303  if (!$error) {
304  // copy external contacts if same company
305  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
306  if ($this->copy_linked_contact($object, 'external') < 0) {
307  $error++;
308  }
309  }
310  }
311 
312  unset($object->context['createfromclone']);
313 
314  // End
315  if (!$error) {
316  $this->db->commit();
317  return $object;
318  } else {
319  $this->db->rollback();
320  return -1;
321  }
322  }
323 
331  public function fetch($id, $ref = null)
332  {
333  $result = $this->fetchCommon($id, $ref);
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('t');
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.'='.$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(" ".$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->hrm->job->write))
500  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->job->job_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 = ".((int) $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('JOB_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 = 'job/".$this->db->escape($this->newref)."'";
557  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'job/".$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->hrm->dir_output.'/job/'.$oldref;
567  $dirdest = $conf->hrm->dir_output.'/job/'.$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->hrm->dir_output.'/job/'.$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 
608  public function getLastJobForUser($fk_user)
609  {
610  $Tab = $this->getForUser($fk_user);
611 
612  if (empty($Tab)) return '';
613 
614  $lastpos = array_shift($Tab);
615 
616  return $lastpos;
617  }
618 
625  public function getForUser($userid)
626  {
627  global $db;
628 
629  $TReturn = array();
630  $position = new Position($db);
631  $TPosition = $position->getForUser($userid);
632  foreach ($TPosition as $UPosition) {
633  $TReturn[$UPosition->Job->rowid] = $UPosition->Job->ref;
634  }
635  return $TReturn;
636  }
637 
645  public function setDraft($user, $notrigger = 0)
646  {
647  // Protection
648  if ($this->status <= self::STATUS_DRAFT) {
649  return 0;
650  }
651 
652  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
653  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
654  {
655  $this->error='Permission denied';
656  return -1;
657  }*/
658 
659  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'JOB_UNVALIDATE');
660  }
661 
669  public function cancel($user, $notrigger = 0)
670  {
671  // Protection
672  if ($this->status != self::STATUS_VALIDATED) {
673  return 0;
674  }
675 
676  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
677  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
678  {
679  $this->error='Permission denied';
680  return -1;
681  }*/
682 
683  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'JOB_CANCEL');
684  }
685 
693  public function reopen($user, $notrigger = 0)
694  {
695  // Protection
696  if ($this->status != self::STATUS_CANCELED) {
697  return 0;
698  }
699 
700  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
701  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
702  {
703  $this->error='Permission denied';
704  return -1;
705  }*/
706 
707  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'JOB_REOPEN');
708  }
709 
720  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
721  {
722  global $conf, $langs, $hookmanager;
723 
724  if (!empty($conf->dol_no_mouse_hover)) {
725  $notooltip = 1; // Force disable tooltips
726  }
727 
728  $result = '';
729 
730  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Job").'</u>';
731  if (isset($this->status)) {
732  $label .= ' '.$this->getLibStatut(5);
733  }
734  $label .= '<br>';
735  $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
736 
737  $url = dol_buildpath('/hrm/job_card.php', 1).'?id='.$this->id;
738 
739  if ($option != 'nolink') {
740  // Add param to save lastsearch_values or not
741  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
742  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
743  $add_save_lastsearch_values = 1;
744  }
745  if ($add_save_lastsearch_values) {
746  $url .= '&save_lastsearch_values=1';
747  }
748  }
749 
750  $linkclose = '';
751  if (empty($notooltip)) {
752  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
753  $label = $langs->trans("ShowJob");
754  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
755  }
756  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
757  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
758  } else {
759  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
760  }
761 
762  if ($option == 'nolink') {
763  $linkstart = '<span';
764  } else {
765  $linkstart = '<a href="'.$url.'"';
766  }
767  $linkstart .= $linkclose.'>';
768  if ($option == 'nolink') {
769  $linkend = '</span>';
770  } else {
771  $linkend = '</a>';
772  }
773 
774  $result .= $linkstart;
775 
776  if (empty($this->showphoto_on_popup)) {
777  if ($withpicto) {
778  $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);
779  }
780  } else {
781  if ($withpicto) {
782  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
783 
784  list($class, $module) = explode('@', $this->picto);
785  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->label);
786  $filearray = dol_dir_list($upload_dir, "files");
787  $filename = $filearray[0]['name'];
788  if (!empty($filename)) {
789  $pospoint = strpos($filearray[0]['name'], '.');
790 
791  $pathtophoto = $class.'/'.$this->label.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
792  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
793  $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>';
794  } else {
795  $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>';
796  }
797 
798  $result .= '</div>';
799  } else {
800  $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);
801  }
802  }
803  }
804 
805  if ($withpicto != 2) {
806  $result .= $this->label;
807  }
808 
809  $result .= $linkend;
810  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
811 
812  global $action, $hookmanager;
813  $hookmanager->initHooks(array('jobdao'));
814  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
815  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
816  if ($reshook > 0) {
817  $result = $hookmanager->resPrint;
818  } else {
819  $result .= $hookmanager->resPrint;
820  }
821 
822  return $result;
823  }
824 
831  public function getLibStatut($mode = 0)
832  {
833  return $this->LibStatut($this->status, $mode);
834  }
835 
836  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
844  public function LibStatut($status, $mode = 0)
845  {
846  // phpcs:enable
847  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
848  global $langs;
849  //$langs->load("hrm");
850  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
851  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
852  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
853  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
854  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
855  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
856  }
857 
858  $statusType = 'status'.$status;
859  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
860  if ($status == self::STATUS_CANCELED) {
861  $statusType = 'status6';
862  }
863 
864  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
865  }
866 
873  public function info($id)
874  {
875  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
876  $sql .= ' fk_user_creat, fk_user_modif';
877  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
878  $sql .= ' WHERE t.rowid = '.((int) $id);
879  $result = $this->db->query($sql);
880  if ($result) {
881  if ($this->db->num_rows($result)) {
882  $obj = $this->db->fetch_object($result);
883  $this->id = $obj->rowid;
884 
885  $this->user_creation_id = $obj->fk_user_creat;
886  $this->user_modification_id = $obj->fk_user_modif;
887  $this->date_creation = $this->db->jdate($obj->datec);
888  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
889  }
890 
891  $this->db->free($result);
892  } else {
893  dol_print_error($this->db);
894  }
895  }
896 
903  public function initAsSpecimen()
904  {
905  // Set here init that are not commonf fields
906  // $this->property1 = ...
907  // $this->property2 = ...
908 
909  $this->initAsSpecimenCommon();
910  }
911 
917  public function getLinesArray()
918  {
919  $this->lines = array();
920 
921  $objectline = new JobLine($this->db);
922  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_job = '.$this->id));
923 
924  if (is_numeric($result)) {
925  $this->error = $objectline->error;
926  $this->errors = $objectline->errors;
927  return $result;
928  } else {
929  $this->lines = $result;
930  return $this->lines;
931  }
932  }
933 
939  public function getNextNumRef()
940  {
941  global $langs, $conf;
942  $langs->load("hrm");
943 
944  if (empty($conf->global->hrm_JOB_ADDON)) {
945  $conf->global->hrm_JOB_ADDON = 'mod_job_standard';
946  }
947 
948  if (!empty($conf->global->hrm_JOB_ADDON)) {
949  $mybool = false;
950 
951  $file = $conf->global->hrm_JOB_ADDON.".php";
952  $classname = $conf->global->hrm_JOB_ADDON;
953 
954  // Include file with class
955  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
956  foreach ($dirmodels as $reldir) {
957  $dir = dol_buildpath($reldir."core/modules/hrm/");
958 
959  // Load file with numbering class (if found)
960  $mybool |= @include_once $dir.$file;
961  }
962 
963  if ($mybool === false) {
964  dol_print_error('', "Failed to include file ".$file);
965  return '';
966  }
967 
968  if (class_exists($classname)) {
969  $obj = new $classname();
970  $numref = $obj->getNextValue($this);
971 
972  if ($numref != '' && $numref != '-1') {
973  return $numref;
974  } else {
975  $this->error = $obj->error;
976  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
977  return "";
978  }
979  } else {
980  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
981  return "";
982  }
983  } else {
984  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
985  return "";
986  }
987  }
988 
1000  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1001  {
1002  global $conf, $langs;
1003 
1004  $result = 0;
1005  $includedocgeneration = 0;
1006 
1007  $langs->load("hrm");
1008 
1009  if (!dol_strlen($modele)) {
1010  $modele = 'standard_job';
1011 
1012  if (!empty($this->model_pdf)) {
1013  $modele = $this->model_pdf;
1014  } elseif (!empty($conf->global->JOB_ADDON_PDF)) {
1015  $modele = $conf->global->JOB_ADDON_PDF;
1016  }
1017  }
1018 
1019  $modelpath = "core/modules/hrm/doc/";
1020 
1021  if ($includedocgeneration && !empty($modele)) {
1022  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1023  }
1024 
1025  return $result;
1026  }
1027 
1035  public function doScheduledJob()
1036  {
1037  global $conf, $langs;
1038 
1039  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1040 
1041  $error = 0;
1042  $this->output = '';
1043  $this->error = '';
1044 
1045  dol_syslog(__METHOD__, LOG_DEBUG);
1046 
1047  $now = dol_now();
1048 
1049  $this->db->begin();
1050 
1051  // ...
1052 
1053  $this->db->commit();
1054 
1055  return $error;
1056  }
1057 }
1058 
1059 
1060 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1061 
1066 {
1067  // To complete with content of an object JobLine
1068  // We should have a field rowid, fk_job and position
1069 
1073  public $isextrafieldmanaged = 0;
1074 
1080  public function __construct(DoliDB $db)
1081  {
1082  $this->db = $db;
1083  }
1084 }
Job\__construct
__construct(DoliDB $db)
Constructor.
Definition: job.class.php:171
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9548
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9826
db
$conf db
API class for accounts.
Definition: inc.php:41
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9338
Job\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: job.class.php:345
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:1237
Job\getLastJobForUser
getLastJobForUser($fk_user)
Get the last occupied position for a user.
Definition: job.class.php:608
Job\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: job.class.php:903
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
JobLine
Class JobLine.
Definition: job.class.php:1065
Job\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: job.class.php:831
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
Job\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: job.class.php:232
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:9394
Job\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: job.class.php:1000
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
Job\info
info($id)
Load the info information in the object.
Definition: job.class.php:873
Job\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: job.class.php:645
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:9171
Job\update
update(User $user, $notrigger=false)
Update object into database.
Definition: job.class.php:441
Job\validate
validate($user, $notrigger=0)
Validate object.
Definition: job.class.php:485
Job\getForUser
getForUser($userid)
Get array of occupied positions for a user.
Definition: job.class.php:625
Position
Class for Position.
Definition: position.class.php:36
$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
Job\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: job.class.php:669
Job\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: job.class.php:467
Job\getLinesArray
getLinesArray()
Create an array of lines.
Definition: job.class.php:917
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
Job\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: job.class.php:939
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9444
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3887
JobLine\__construct
__construct(DoliDB $db)
Constructor.
Definition: job.class.php:1080
Job\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: job.class.php:693
Job\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: job.class.php:1035
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
Job\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: job.class.php:720
User
Class to manage Dolibarr users.
Definition: user.class.php:46
Job\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: job.class.php:331
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10740
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
Job\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: job.class.php:844
Job\create
create(User $user, $notrigger=false)
Create object into database.
Definition: job.class.php:216
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9764
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5806
Job
Class for Job.
Definition: job.class.php:36
Job\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: job.class.php:365
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9123