dolibarr  16.0.5
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 (empty($conf->multicompany->enabled) && 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->table_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  global $db;
611 
612  $j = new Job($db);
613  $Tab = $j->getForUser($fk_user);
614 
615  if (empty($Tab)) return '';
616 
617  $job = array_shift($Tab);
618 
619  return $job;
620  }
621 
628  public function getForUser($userid)
629  {
630  global $db;
631 
632  $TReturn = array();
633  $position = new Position($db);
634  $TPosition = $position->getForUser($userid);
635  foreach ($TPosition as $UPosition) {
636  $TReturn[$UPosition->Job->rowid] = $UPosition->Job->ref;
637  }
638  return $TReturn;
639  }
640 
648  public function setDraft($user, $notrigger = 0)
649  {
650  // Protection
651  if ($this->status <= self::STATUS_DRAFT) {
652  return 0;
653  }
654 
655  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
656  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
657  {
658  $this->error='Permission denied';
659  return -1;
660  }*/
661 
662  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'JOB_UNVALIDATE');
663  }
664 
672  public function cancel($user, $notrigger = 0)
673  {
674  // Protection
675  if ($this->status != self::STATUS_VALIDATED) {
676  return 0;
677  }
678 
679  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
680  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
681  {
682  $this->error='Permission denied';
683  return -1;
684  }*/
685 
686  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'JOB_CANCEL');
687  }
688 
696  public function reopen($user, $notrigger = 0)
697  {
698  // Protection
699  if ($this->status != self::STATUS_CANCELED) {
700  return 0;
701  }
702 
703  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
704  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
705  {
706  $this->error='Permission denied';
707  return -1;
708  }*/
709 
710  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'JOB_REOPEN');
711  }
712 
723  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
724  {
725  global $conf, $langs, $hookmanager;
726 
727  if (!empty($conf->dol_no_mouse_hover)) {
728  $notooltip = 1; // Force disable tooltips
729  }
730 
731  $result = '';
732 
733  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Job").'</u>';
734  if (isset($this->status)) {
735  $label .= ' '.$this->getLibStatut(5);
736  }
737  $label .= '<br>';
738  $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
739 
740  $url = dol_buildpath('/hrm/job_card.php', 1).'?id='.$this->id;
741 
742  if ($option != 'nolink') {
743  // Add param to save lastsearch_values or not
744  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
745  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
746  $add_save_lastsearch_values = 1;
747  }
748  if ($add_save_lastsearch_values) {
749  $url .= '&save_lastsearch_values=1';
750  }
751  }
752 
753  $linkclose = '';
754  if (empty($notooltip)) {
755  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
756  $label = $langs->trans("ShowJob");
757  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
758  }
759  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
760  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
761  } else {
762  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
763  }
764 
765  if ($option == 'nolink') {
766  $linkstart = '<span';
767  } else {
768  $linkstart = '<a href="'.$url.'"';
769  }
770  $linkstart .= $linkclose.'>';
771  if ($option == 'nolink') {
772  $linkend = '</span>';
773  } else {
774  $linkend = '</a>';
775  }
776 
777  $result .= $linkstart;
778 
779  if (empty($this->showphoto_on_popup)) {
780  if ($withpicto) {
781  $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);
782  }
783  } else {
784  if ($withpicto) {
785  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
786 
787  list($class, $module) = explode('@', $this->picto);
788  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->label);
789  $filearray = dol_dir_list($upload_dir, "files");
790  $filename = $filearray[0]['name'];
791  if (!empty($filename)) {
792  $pospoint = strpos($filearray[0]['name'], '.');
793 
794  $pathtophoto = $class.'/'.$this->label.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
795  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
796  $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>';
797  } else {
798  $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>';
799  }
800 
801  $result .= '</div>';
802  } else {
803  $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);
804  }
805  }
806  }
807 
808  if ($withpicto != 2) {
809  $result .= $this->label;
810  }
811 
812  $result .= $linkend;
813  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
814 
815  global $action, $hookmanager;
816  $hookmanager->initHooks(array('jobdao'));
817  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
818  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
819  if ($reshook > 0) {
820  $result = $hookmanager->resPrint;
821  } else {
822  $result .= $hookmanager->resPrint;
823  }
824 
825  return $result;
826  }
827 
834  public function getLibStatut($mode = 0)
835  {
836  return $this->LibStatut($this->status, $mode);
837  }
838 
839  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
847  public function LibStatut($status, $mode = 0)
848  {
849  // phpcs:enable
850  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
851  global $langs;
852  //$langs->load("hrm");
853  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
854  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
855  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
856  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
857  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
858  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
859  }
860 
861  $statusType = 'status'.$status;
862  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
863  if ($status == self::STATUS_CANCELED) {
864  $statusType = 'status6';
865  }
866 
867  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
868  }
869 
876  public function info($id)
877  {
878  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
879  $sql .= ' fk_user_creat, fk_user_modif';
880  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
881  $sql .= ' WHERE t.rowid = '.((int) $id);
882  $result = $this->db->query($sql);
883  if ($result) {
884  if ($this->db->num_rows($result)) {
885  $obj = $this->db->fetch_object($result);
886  $this->id = $obj->rowid;
887 
888  $this->user_creation_id = $obj->fk_user_creat;
889  $this->user_modification_id = $obj->fk_user_modif;
890  $this->date_creation = $this->db->jdate($obj->datec);
891  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
892  }
893 
894  $this->db->free($result);
895  } else {
896  dol_print_error($this->db);
897  }
898  }
899 
906  public function initAsSpecimen()
907  {
908  // Set here init that are not commonf fields
909  // $this->property1 = ...
910  // $this->property2 = ...
911 
912  $this->initAsSpecimenCommon();
913  }
914 
920  public function getLinesArray()
921  {
922  $this->lines = array();
923 
924  $objectline = new JobLine($this->db);
925  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_job = '.$this->id));
926 
927  if (is_numeric($result)) {
928  $this->error = $this->error;
929  $this->errors = $this->errors;
930  return $result;
931  } else {
932  $this->lines = $result;
933  return $this->lines;
934  }
935  }
936 
942  public function getNextNumRef()
943  {
944  global $langs, $conf;
945  $langs->load("hrm");
946 
947  if (empty($conf->global->hrm_JOB_ADDON)) {
948  $conf->global->hrm_JOB_ADDON = 'mod_job_standard';
949  }
950 
951  if (!empty($conf->global->hrm_JOB_ADDON)) {
952  $mybool = false;
953 
954  $file = $conf->global->hrm_JOB_ADDON.".php";
955  $classname = $conf->global->hrm_JOB_ADDON;
956 
957  // Include file with class
958  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
959  foreach ($dirmodels as $reldir) {
960  $dir = dol_buildpath($reldir."core/modules/hrm/");
961 
962  // Load file with numbering class (if found)
963  $mybool |= @include_once $dir.$file;
964  }
965 
966  if ($mybool === false) {
967  dol_print_error('', "Failed to include file ".$file);
968  return '';
969  }
970 
971  if (class_exists($classname)) {
972  $obj = new $classname();
973  $numref = $obj->getNextValue($this);
974 
975  if ($numref != '' && $numref != '-1') {
976  return $numref;
977  } else {
978  $this->error = $obj->error;
979  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
980  return "";
981  }
982  } else {
983  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
984  return "";
985  }
986  } else {
987  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
988  return "";
989  }
990  }
991 
1003  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1004  {
1005  global $conf, $langs;
1006 
1007  $result = 0;
1008  $includedocgeneration = 0;
1009 
1010  $langs->load("hrm");
1011 
1012  if (!dol_strlen($modele)) {
1013  $modele = 'standard_job';
1014 
1015  if (!empty($this->model_pdf)) {
1016  $modele = $this->model_pdf;
1017  } elseif (!empty($conf->global->JOB_ADDON_PDF)) {
1018  $modele = $conf->global->JOB_ADDON_PDF;
1019  }
1020  }
1021 
1022  $modelpath = "core/modules/hrm/doc/";
1023 
1024  if ($includedocgeneration && !empty($modele)) {
1025  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1026  }
1027 
1028  return $result;
1029  }
1030 
1038  public function doScheduledJob()
1039  {
1040  global $conf, $langs;
1041 
1042  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1043 
1044  $error = 0;
1045  $this->output = '';
1046  $this->error = '';
1047 
1048  dol_syslog(__METHOD__, LOG_DEBUG);
1049 
1050  $now = dol_now();
1051 
1052  $this->db->begin();
1053 
1054  // ...
1055 
1056  $this->db->commit();
1057 
1058  return $error;
1059  }
1060 }
1061 
1062 
1063 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1064 
1069 {
1070  // To complete with content of an object JobLine
1071  // We should have a field rowid, fk_job and position
1072 
1076  public $isextrafieldmanaged = 0;
1077 
1083  public function __construct(DoliDB $db)
1084  {
1085  $this->db = $db;
1086  }
1087 }
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: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
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
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:1226
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1217
Job\getLastJobForUser
getLastJobForUser($fk_user)
Get last job for 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:906
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
JobLine
Class JobLine.
Definition: job.class.php:1068
Job\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: job.class.php:834
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
Job\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: job.class.php:232
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9258
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
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:1003
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:876
Job\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: job.class.php:648
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
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
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 jobs for user.
Definition: job.class.php:628
Position
Class for Position.
Definition: position.class.php:36
Job\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: job.class.php:672
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:920
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Job\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: job.class.php:942
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
JobLine\__construct
__construct(DoliDB $db)
Constructor.
Definition: job.class.php:1083
Job\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: job.class.php:696
Job\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: job.class.php:1038
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:723
User
Class to manage Dolibarr users.
Definition: user.class.php:44
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:10338
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
Job\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: job.class.php:847
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: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
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
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:8987