dolibarr 25.0.0-alpha
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32
33
37class Job extends CommonObject
38{
42 public $module = 'hrm';
43
47 public $element = 'job';
48
52 public $table_element = 'hrm_job';
53
57 public $picto = 'technic';
58
59
60 const STATUS_DRAFT = 0;
61 const STATUS_VALIDATED = 1;
62 const STATUS_CANCELED = 9;
63
64
91 // BEGIN MODULEBUILDER PROPERTIES
95 public $fields = array(
96 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
97 '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"),
98 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 21, 'notnull' => 0, 'visible' => 1,),
99 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
100 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
101 'deplacement' => array('type' => 'select', 'required' => 1,'label' => 'NeedBusinessTravels', 'enabled' => 1, 'position' => 90, 'notnull' => 1, 'visible' => 1, 'arrayofkeyval' => array(0 => "No", 1 => "Yes"), 'default' => '0'),
102 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 70, 'notnull' => 0, 'visible' => 0,),
103 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 71, 'notnull' => 0, 'visible' => 0,),
104 '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',),
105 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
106 );
110 public $rowid;
114 public $ref;
118 public $label;
122 public $description;
126 public $deplacement;
130 public $fk_user_creat;
134 public $fk_user_modif;
135 // END MODULEBUILDER PROPERTIES
136
137
141 public $fk_element = 'fk_job';
142
146 protected $childtables = array(
147 'hrm_evaluation' => ['name' => 'Evaluation'],
148 'hrm_job_user' => ['name' => 'Job'],
149 );
150
156 protected $childtablesoncascade = array("@SkillRank:hrm/class/skillrank.class.php:fk_object:(objecttype:=:'job')");
157
158 // /**
159 // * @var JobLine[] Array of subtable lines
160 // */
161 // public $lines = array();
162
163
164
170 public function __construct(DoliDB $db)
171 {
172 global $conf, $langs;
173
174 $this->db = $db;
175
176 $this->ismultientitymanaged = 0;
177 $this->isextrafieldmanaged = 1;
178
179 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
180 $this->fields['rowid']['visible'] = 0;
181 }
182 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
183 $this->fields['entity']['enabled'] = 0;
184 }
185
186 // Example to show how to set values of fields definition dynamically
187 /*if ($user->rights->hrm->job->read) {
188 $this->fields['myfield']['visible'] = 1;
189 $this->fields['myfield']['noteditable'] = 0;
190 }*/
191
192 // Unset fields that are disabled
193 foreach ($this->fields as $key => $val) {
194 if (isset($val['enabled']) && empty($val['enabled'])) {
195 unset($this->fields[$key]);
196 }
197 }
198
199 // Translate some data of arrayofkeyval
200 if (is_object($langs)) {
201 foreach ($this->fields as $key => $val) {
202 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
203 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
204 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
205 }
206 }
207 }
208 }
209 }
210
218 public function create(User $user, $notrigger = 0)
219 {
220 $resultcreate = $this->createCommon($user, $notrigger);
221
222 //$resultvalidate = $this->validate($user, $notrigger);
223
224 return $resultcreate;
225 }
226
234 public function createFromClone(User $user, $fromid)
235 {
236 global $langs, $extrafields;
237 $error = 0;
238
239 dol_syslog(__METHOD__, LOG_DEBUG);
240
241 $object = new self($this->db);
242
243 $this->db->begin();
244
245 // Load source object
246 $result = $object->fetchCommon($fromid);
247
248 // Reset some properties
249 unset($object->id);
250 unset($object->fk_user_creat);
251 unset($object->import_key);
252
253 // Clear fields
254 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
255 $object->label = $langs->trans("CopyOf")." ".$object->label;
256 $object->date_creation = dol_now();
257 $object->date_modification = null;
258
259 // Clear extrafields that are unique
260 if (is_array($object->array_options) && count($object->array_options) > 0) {
261 $extrafields->fetch_name_optionals_label($this->table_element);
262 foreach ($object->array_options as $key => $option) {
263 $shortkey = preg_replace('/options_/', '', $key);
264 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
265 unset($object->array_options[$key]);
266 }
267 }
268 }
269
270 // Create clone
271 $object->context['createfromclone'] = 'createfromclone';
272 $result = $object->createCommon($user);
273 if ($result < 0) {
274 $error++;
276 }
277
278 if (!$error) {
279 // copy internal contacts
280 if ($this->copy_linked_contact($object, 'internal') < 0) {
281 $error++;
282 }
283 }
284
285 unset($object->context['createfromclone']);
286
287 // End
288 if (!$error) {
289 $this->db->commit();
290 return $object;
291 } else {
292 $this->db->rollback();
293 return -1;
294 }
295 }
296
304 public function fetch($id, $ref = null)
305 {
306 $result = $this->fetchCommon($id, $ref);
307
308 return $result;
309 }
310
316 public function fetchLines()
317 {
318 $this->lines = array();
319
320 $result = $this->fetchLinesCommon();
321 return $result;
322 }
323
324
337 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
338 {
339 dol_syslog(__METHOD__, LOG_DEBUG);
340
341 $records = array();
342
343 $sql = 'SELECT ';
344 $sql .= $this->getFieldList('t');
345 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
346 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
347 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
348 } else {
349 $sql .= ' WHERE 1 = 1';
350 }
351
352 // Manage filter
353 $errormessage = '';
354 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
355 if ($errormessage) {
356 $this->errors[] = $errormessage;
357 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
358 return -1;
359 }
360
361 if (!empty($sortfield)) {
362 $sql .= $this->db->order($sortfield, $sortorder);
363 }
364 if (!empty($limit)) {
365 $sql .= ' '.$this->db->plimit($limit, $offset);
366 }
367
368 $resql = $this->db->query($sql);
369 if ($resql) {
370 $num = $this->db->num_rows($resql);
371 $i = 0;
372 while ($i < ($limit ? min($limit, $num) : $num)) {
373 $obj = $this->db->fetch_object($resql);
374
375 $record = new self($this->db);
376 $record->setVarsFromFetchObj($obj);
377
378 $records[$record->id] = $record;
379
380 $i++;
381 }
382 $this->db->free($resql);
383
384 return $records;
385 } else {
386 $this->errors[] = 'Error '.$this->db->lasterror();
387 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
388
389 return -1;
390 }
391 }
392
400 public function update(User $user, $notrigger = 0)
401 {
402 return $this->updateCommon($user, $notrigger);
403 }
404
412 public function delete(User $user, $notrigger = 0)
413 {
414 return $this->deleteCommon($user, $notrigger);
415 //return $this->deleteCommon($user, $notrigger, 1);
416 }
417
426 public function deleteLine(User $user, $idline, $notrigger = 0)
427 {
428 if ($this->status < 0) {
429 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
430 return -2;
431 }
432
433 return $this->deleteLineCommon($user, $idline, $notrigger);
434 }
435
436
444 public function validate($user, $notrigger = 0)
445 {
446 global $conf, $langs;
447
448 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
449
450 $error = 0;
451
452 // Protection
453 if ($this->status == self::STATUS_VALIDATED) {
454 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
455 return 0;
456 }
457
458 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->job->write))
459 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->job->job_advance->validate))))
460 {
461 $this->error='NotEnoughPermissions';
462 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
463 return -1;
464 }*/
465
466 $now = dol_now();
467
468 $this->db->begin();
469
470 // Define new ref
471 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
472 $num = $this->getNextNumRef();
473 } else {
474 $num = (string) $this->ref;
475 }
476 $this->newref = $num;
477
478 if (!empty($num)) {
479 // Validate
480 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
481 $sql .= " SET ref = '".$this->db->escape($num)."',";
482 $sql .= " status = ".self::STATUS_VALIDATED;
483 if (!empty($this->fields['date_validation'])) {
484 $sql .= ", date_validation = '".$this->db->idate($now)."'";
485 }
486 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
487 $sql .= ", fk_user_valid = ".((int) $user->id);
488 }
489 $sql .= " WHERE rowid = ".((int) $this->id);
490
491 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
492 $resql = $this->db->query($sql);
493 if (!$resql) {
494 dol_print_error($this->db);
495 $this->error = $this->db->lasterror();
496 $error++;
497 }
498
499 if (!$error && !$notrigger) {
500 // Call trigger
501 $result = $this->call_trigger('HRM_JOB_VALIDATE', $user);
502 if ($result < 0) {
503 $error++;
504 }
505 // End call triggers
506 }
507 }
508
509 if (!$error) {
510 $this->oldref = $this->ref;
511
512 // Rename directory if dir was a temporary ref
513 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
514 // Now we rename also files into index
515 $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)."'";
516 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'job/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
517 $resql = $this->db->query($sql);
518 if (!$resql) {
519 $error++;
520 $this->error = $this->db->lasterror();
521 }
522 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'job/".$this->db->escape($this->newref)."'";
523 $sql .= " WHERE filepath = 'job/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
524 $resql = $this->db->query($sql);
525 if (!$resql) {
526 $error++;
527 $this->error = $this->db->lasterror();
528 }
529
530 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
531 $oldref = dol_sanitizeFileName($this->ref);
532 $newref = dol_sanitizeFileName($num);
533 $dirsource = $conf->hrm->dir_output.'/job/'.$oldref;
534 $dirdest = $conf->hrm->dir_output.'/job/'.$newref;
535 if (!$error && file_exists($dirsource)) {
536 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
537
538 if (@rename($dirsource, $dirdest)) {
539 dol_syslog("Rename ok");
540 // Rename docs starting with $oldref with $newref
541 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/job/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
542 foreach ($listoffiles as $fileentry) {
543 $dirsource = $fileentry['name'];
544 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
545 $dirsource = $fileentry['path'].'/'.$dirsource;
546 $dirdest = $fileentry['path'].'/'.$dirdest;
547 @rename($dirsource, $dirdest);
548 }
549 }
550 }
551 }
552 }
553
554 // Set new ref and current status
555 if (!$error) {
556 $this->ref = $num;
557 $this->status = self::STATUS_VALIDATED;
558 }
559
560 if (!$error) {
561 $this->db->commit();
562 return 1;
563 } else {
564 $this->db->rollback();
565 return -1;
566 }
567 }
568
575 public function getLastJobForUser($fk_user)
576 {
577 $Tab = $this->getForUser($fk_user);
578
579 if (empty($Tab)) {
580 return '';
581 }
582
583 $lastpos = array_shift($Tab);
584
585 return $lastpos;
586 }
587
594 public function getForUser($userid)
595 {
596 global $db;
597
598 $TReturn = array();
599 $position = new Position($db);
600 $TPosition = $position->getForUser($userid);
601 foreach ($TPosition as $UPosition) {
602 $tmpjob = new Job($db);
603 if ($tmpjob->fetch($UPosition->fk_job) > 0) {
604 $TReturn[$tmpjob->id] = $tmpjob->label;
605 }
606 }
607 return $TReturn;
608 }
609
617 public function setDraft($user, $notrigger = 0)
618 {
619 // Protection
620 if ($this->status <= self::STATUS_DRAFT) {
621 return 0;
622 }
623
624 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
625 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
626 {
627 $this->error='Permission denied';
628 return -1;
629 }*/
630
631 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'JOB_UNVALIDATE');
632 }
633
641 public function cancel($user, $notrigger = 0)
642 {
643 // Protection
644 if ($this->status != self::STATUS_VALIDATED) {
645 return 0;
646 }
647
648 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
649 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
650 {
651 $this->error='Permission denied';
652 return -1;
653 }*/
654
655 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'JOB_CANCEL');
656 }
657
665 public function reopen($user, $notrigger = 0)
666 {
667 // Protection
668 if ($this->status != self::STATUS_CANCELED) {
669 return 0;
670 }
671
672 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
673 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
674 {
675 $this->error='Permission denied';
676 return -1;
677 }*/
678
679 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'JOB_REOPEN');
680 }
681
692 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
693 {
694 global $conf, $langs, $hookmanager;
695
696 if (!empty($conf->dol_no_mouse_hover)) {
697 $notooltip = 1; // Force disable tooltips
698 }
699
700 $result = '';
701
702 $label = img_picto('', $this->picto).' <u>'.$langs->trans("JobProfile").'</u>';
703 if (isset($this->status)) {
704 $label .= ' '.$this->getLibStatut(5);
705 }
706 $label .= '<br>';
707 $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
708
709 $url = dol_buildpath('/hrm/job_card.php', 1).'?id='.$this->id;
710
711 if ($option != 'nolink') {
712 // Add param to save lastsearch_values or not
713 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
714 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
715 $add_save_lastsearch_values = 1;
716 }
717 if ($add_save_lastsearch_values) {
718 $url .= '&save_lastsearch_values=1';
719 }
720 }
721
722 $linkclose = '';
723 if (empty($notooltip)) {
724 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
725 $label = $langs->trans("ShowJob");
726 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
727 }
728 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
729 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
730 } else {
731 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
732 }
733
734 if ($option == 'nolink') {
735 $linkstart = '<span';
736 } else {
737 $linkstart = '<a href="'.$url.'"';
738 }
739 $linkstart .= $linkclose.'>';
740 if ($option == 'nolink') {
741 $linkend = '</span>';
742 } else {
743 $linkend = '</a>';
744 }
745
746 $result .= $linkstart;
747
748 if (empty($this->showphoto_on_popup)) {
749 if ($withpicto) {
750 $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);
751 }
752 } else {
753 if ($withpicto) {
754 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
755
756 list($class, $module) = explode('@', $this->picto);
757 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->label);
758 $filearray = dol_dir_list($upload_dir, "files");
759 $filename = $filearray[0]['name'];
760 if (!empty($filename)) {
761 $pospoint = strpos($filearray[0]['name'], '.');
762
763 $pathtophoto = $class.'/'.$this->label.'/thumbs/'.dol_substr($filename, 0, $pospoint).'_mini'.dol_substr($filename, $pospoint);
764 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
765 $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>';
766 } else {
767 $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>';
768 }
769
770 $result .= '</div>';
771 } else {
772 $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);
773 }
774 }
775 }
776
777 if ($withpicto != 2) {
778 $result .= $this->label;
779 }
780
781 $result .= $linkend;
782 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
783
784 global $action, $hookmanager;
785 $hookmanager->initHooks(array('jobdao'));
786 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
787 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
788 if ($reshook > 0) {
789 $result = $hookmanager->resPrint;
790 } else {
791 $result .= $hookmanager->resPrint;
792 }
793
794 return $result;
795 }
796
803 public function getLibStatut($mode = 0)
804 {
805 return $this->LibStatut($this->status, $mode);
806 }
807
808 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
816 public function LibStatut($status, $mode = 0)
817 {
818 // phpcs:enable
819
820 return ''; // There is no status on job profile for the moment
821 }
822
829 public function info($id)
830 {
831 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
832 $sql .= ' fk_user_creat, fk_user_modif';
833 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
834 $sql .= ' WHERE t.rowid = '.((int) $id);
835 $result = $this->db->query($sql);
836 if ($result) {
837 if ($this->db->num_rows($result)) {
838 $obj = $this->db->fetch_object($result);
839
840 $this->id = $obj->rowid;
841
842 $this->user_creation_id = $obj->fk_user_creat;
843 $this->user_modification_id = $obj->fk_user_modif;
844 $this->date_creation = $this->db->jdate($obj->datec);
845 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
846 }
847
848 $this->db->free($result);
849 } else {
850 dol_print_error($this->db);
851 }
852 }
853
860 public function initAsSpecimen()
861 {
862 // Set here init that are not commonf fields
863 // $this->property1 = ...
864 // $this->property2 = ...
865
866 return $this->initAsSpecimenCommon();
867 }
868
874 public function getLinesArray()
875 {
876 $this->lines = array();
877
878 $objectline = new JobLine($this->db);
879 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_job:=:'.((int) $this->id).')');
880
881 if (is_numeric($result)) {
882 $this->setErrorsFromObject($objectline);
883 return $result;
884 } else {
885 $this->lines = $result;
886 return $this->lines;
887 }
888 }
889
895 public function getNextNumRef()
896 {
897 global $langs, $conf;
898 $langs->load("hrm");
899
900 if (!getDolGlobalString('hrm_JOB_ADDON')) {
901 $conf->global->hrm_JOB_ADDON = 'mod_job_standard';
902 }
903
904 if (getDolGlobalString('hrm_JOB_ADDON')) {
905 $mybool = false;
906
907 $file = getDolGlobalString('hrm_JOB_ADDON') . ".php";
908 $classname = getDolGlobalString('hrm_JOB_ADDON');
909
910 // Include file with class
911 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
912 foreach ($dirmodels as $reldir) {
913 $dir = dol_buildpath($reldir."core/modules/hrm/");
914
915 // Load file with numbering class (if found)
916 $mybool = ((bool) @include_once $dir.$file) || $mybool;
917 }
918
919 if (!$mybool) {
920 dol_print_error(null, "Failed to include file ".$file);
921 return '';
922 }
923
924 if (class_exists($classname)) {
925 $obj = new $classname();
926 '@phan-var-force ModeleNumRefEvaluation $obj';
928 $numref = $obj->getNextValue($this);
929
930 if ($numref != '' && $numref != '-1') {
931 return $numref;
932 } else {
933 $this->error = $obj->error;
934 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
935 return "";
936 }
937 } else {
938 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
939 return "";
940 }
941 } else {
942 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
943 return "";
944 }
945 }
946
958 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
959 {
960 global $conf, $langs;
961
962 $result = 0;
963
964 $langs->load("hrm");
965
966 if (!dol_strlen($modele)) {
967 $modele = 'standard_job';
968
969 if (!empty($this->model_pdf)) {
970 $modele = $this->model_pdf;
971 } elseif (getDolGlobalString('JOB_ADDON_PDF')) {
972 $modele = getDolGlobalString('JOB_ADDON_PDF');
973 }
974 }
975
976 $modelpath = "core/modules/hrm/doc/";
977
978 if (!empty($modele)) {
979 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
980 }
981
982 return $result;
983 }
984
992 public function getKanbanView($option = '', $arraydata = null)
993 {
994 global $selected, $langs;
995
996 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
997
998 $return = '<div class="box-flex-item box-flex-grow-zero">';
999 $return .= '<div class="info-box info-box-sm">';
1000 $return .= '<span class="info-box-icon bg-infobox-action">';
1001 $return .= img_picto('', $this->picto);
1002 $return .= '</span>';
1003 $return .= '<div class="info-box-content">';
1004 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(0) . '</span>';
1005 if ($selected >= 0) {
1006 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1007 }
1008 /*if (property_exists($this, 'deplacement')) {
1009 $return .= '<br><span class="opacitymedium">'.$langs->trans("Type").'</span>';
1010 $return .= ' : <span class="info-box-label ">'.$this->fields['deplacement']['arrayofkeyval'][$this->deplacement].'</span>';
1011 }*/
1012 if (empty($this->description)) {
1013 //$return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Description").'</span> : ';
1014 $return .= '<br><span class="info-box-label ">' . dol_trunc($this->description, 25) . '</span>';
1015 }
1016 $return .= '</div>';
1017 $return .= '</div>';
1018 $return .= '</div>';
1019 return $return;
1020 }
1021
1027 public function getSkillRankForJob($id)
1028 {
1029 if (empty($id)) {
1030 return -1;
1031 }
1032 $skillranks = array();
1033 $sql = "SELECT rowid";
1034 $sql .= " FROM ".MAIN_DB_PREFIX."hrm_skillrank";
1035 $sql .= " WHERE fk_object = ".((int) $id);
1036
1037 $resql = $this->db->query($sql);
1038 if ($resql) {
1039 $num = $this->db->num_rows($resql);
1040 $i = 0;
1041 while ($i < $num) {
1042 $obj = $this->db->fetch_object($resql);
1043 $skillranks[] = $obj->rowid;
1044 $i++;
1045 }
1046 $this->db->free($resql);
1047 } else {
1048 dol_print_error($this->db);
1049 }
1050 return $skillranks;
1051 }
1052}
1053
1054
1055require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1056
1061{
1062 // To complete with content of an object JobLine
1063 // We should have a field rowid, fk_job and position
1064
1070 public function __construct(DoliDB $db)
1071 {
1072 $this->db = $db;
1073
1074 $this->isextrafieldmanaged = 0;
1075 }
1076}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for Job.
Definition job.class.php:38
getLastJobForUser($fk_user)
Get the last job occupied by a user.
fetchLines()
Load object lines in memory from the database.
cancel($user, $notrigger=0)
Set cancel status.
__construct(DoliDB $db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
setDraft($user, $notrigger=0)
Set draft status.
update(User $user, $notrigger=0)
Update object into database.
validate($user, $notrigger=0)
Validate object.
getLibStatut($mode=0)
Return the label of the status.
getLinesArray()
Create an array of lines.
fetch($id, $ref=null)
Load object in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
LibStatut($status, $mode=0)
Return the status.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
createFromClone(User $user, $fromid)
Clone an object into another one.
reopen($user, $notrigger=0)
Set back to validated status.
getSkillRankForJob($id)
function for get required skills associate to job object
create(User $user, $notrigger=0)
Create object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getForUser($userid)
Get array of jobs occupied by a user.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
info($id)
Load the info information in the object.
Class JobLine.
__construct(DoliDB $db)
Constructor.
Class for Position.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($utf8_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:66
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.