31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42 public $module =
'hrm';
47 public $element =
'job';
52 public $table_element =
'hrm_job';
57 public $picto =
'technic';
60 const STATUS_DRAFT = 0;
61 const STATUS_VALIDATED = 1;
62 const STATUS_CANCELED = 9;
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,),
130 public $fk_user_creat;
134 public $fk_user_modif;
141 public $fk_element =
'fk_job';
146 protected $childtables = array(
147 'hrm_evaluation' => [
'name' =>
'Evaluation'],
148 'hrm_job_user' => [
'name' =>
'Job'],
156 protected $childtablesoncascade = array(
"@SkillRank:hrm/class/skillrank.class.php:fk_object:(objecttype:=:'job')");
172 global
$conf, $langs;
176 $this->ismultientitymanaged = 0;
177 $this->isextrafieldmanaged = 1;
180 $this->fields[
'rowid'][
'visible'] = 0;
182 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
183 $this->fields[
'entity'][
'enabled'] = 0;
193 foreach ($this->fields as $key => $val) {
194 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
195 unset($this->fields[$key]);
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);
224 return $resultcreate;
236 global $langs, $extrafields;
246 $result =
$object->fetchCommon($fromid);
254 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
257 $object->date_modification =
null;
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]);
271 $object->context[
'createfromclone'] =
'createfromclone';
272 $result =
$object->createCommon($user);
285 unset(
$object->context[
'createfromclone']);
292 $this->db->rollback();
304 public function fetch($id, $ref =
null)
318 $this->lines = array();
337 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
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).
')';
349 $sql .=
' WHERE 1 = 1';
356 $this->errors[] = $errormessage;
357 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
361 if (!empty($sortfield)) {
362 $sql .= $this->db->order($sortfield, $sortorder);
364 if (!empty($limit)) {
365 $sql .=
' '.$this->db->plimit($limit, $offset);
368 $resql = $this->db->query($sql);
370 $num = $this->db->num_rows($resql);
372 while ($i < ($limit ? min($limit, $num) : $num)) {
373 $obj = $this->db->fetch_object($resql);
375 $record =
new self($this->db);
376 $record->setVarsFromFetchObj($obj);
378 $records[$record->id] = $record;
382 $this->db->free($resql);
386 $this->errors[] =
'Error '.$this->db->lasterror();
387 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
412 public function delete(
User $user, $notrigger = 0)
429 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
446 global
$conf, $langs;
448 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
453 if ($this->
status == self::STATUS_VALIDATED) {
454 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
471 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
472 $num = $this->getNextNumRef();
474 $num = (string) $this->
ref;
476 $this->newref = $num;
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).
"'";
486 if (!empty($this->fields[
'fk_user_valid'])) {
487 $sql .=
", fk_user_valid = ".((int) $user->id);
489 $sql .=
" WHERE rowid = ".((int) $this->
id);
491 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
492 $resql = $this->db->query($sql);
494 dol_print_error($this->db);
495 $this->error = $this->db->lasterror();
499 if (!$error && !$notrigger) {
501 $result = $this->call_trigger(
'HRM_JOB_VALIDATE', $user);
510 $this->oldref = $this->ref;
513 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
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);
520 $this->error = $this->db->lasterror();
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);
527 $this->error = $this->db->lasterror();
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);
538 if (@rename($dirsource, $dirdest)) {
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);
557 $this->
status = self::STATUS_VALIDATED;
564 $this->db->rollback();
583 $lastpos = array_shift($Tab);
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;
620 if ($this->
status <= self::STATUS_DRAFT) {
631 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'JOB_UNVALIDATE');
641 public function cancel($user, $notrigger = 0)
644 if ($this->
status != self::STATUS_VALIDATED) {
655 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'JOB_CANCEL');
665 public function reopen($user, $notrigger = 0)
668 if ($this->
status != self::STATUS_CANCELED) {
679 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'JOB_REOPEN');
692 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
694 global
$conf, $langs, $hookmanager;
696 if (!empty(
$conf->dol_no_mouse_hover)) {
702 $label = img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"JobProfile").
'</u>';
703 if (isset($this->
status)) {
704 $label .=
' '.$this->getLibStatut(5);
707 $label .=
'<b>'.$langs->trans(
'Label').
':</b> '.$this->label;
709 $url =
dol_buildpath(
'/hrm/job_card.php', 1).
'?id='.$this->id;
711 if ($option !=
'nolink') {
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;
717 if ($add_save_lastsearch_values) {
718 $url .=
'&save_lastsearch_values=1';
723 if (empty($notooltip)) {
725 $label = $langs->trans(
"ShowJob");
726 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
728 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
729 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
731 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
734 if ($option ==
'nolink') {
735 $linkstart =
'<span';
737 $linkstart =
'<a href="'.$url.
'"';
739 $linkstart .= $linkclose.
'>';
740 if ($option ==
'nolink') {
741 $linkend =
'</span>';
746 $result .= $linkstart;
748 if (empty($this->showphoto_on_popup)) {
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);
754 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
756 list($class, $module) = explode(
'@', $this->picto);
759 $filename = $filearray[0][
'name'];
760 if (!empty($filename)) {
761 $pospoint = strpos($filearray[0][
'name'],
'.');
763 $pathtophoto = $class.
'/'.$this->label.
'/thumbs/'.
dol_substr($filename, 0, $pospoint).
'_mini'.
dol_substr($filename, $pospoint);
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>';
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>';
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);
777 if ($withpicto != 2) {
778 $result .= $this->label;
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);
789 $result = $hookmanager->resPrint;
791 $result .= $hookmanager->resPrint;
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);
837 if ($this->db->num_rows($result)) {
838 $obj = $this->db->fetch_object($result);
840 $this->
id = $obj->rowid;
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);
848 $this->db->free($result);
850 dol_print_error($this->db);
876 $this->lines = array();
878 $objectline =
new JobLine($this->db);
879 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0,
'(fk_job:=:'.((
int) $this->
id).
')');
881 if (is_numeric($result)) {
885 $this->lines = $result;
895 public function getNextNumRef()
897 global $langs,
$conf;
901 $conf->global->hrm_JOB_ADDON =
'mod_job_standard';
911 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
912 foreach ($dirmodels as $reldir) {
916 $mybool = ((bool) @include_once $dir.$file) || $mybool;
920 dol_print_error(
null,
"Failed to include file ".$file);
924 if (class_exists($classname)) {
925 $obj =
new $classname();
926 '@phan-var-force ModeleNumRefEvaluation $obj';
928 $numref = $obj->getNextValue($this);
930 if ($numref !=
'' && $numref !=
'-1') {
933 $this->error = $obj->error;
938 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
942 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
958 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
960 global
$conf, $langs;
967 $modele =
'standard_job';
969 if (!empty($this->model_pdf)) {
970 $modele = $this->model_pdf;
976 $modelpath =
"core/modules/hrm/doc/";
978 if (!empty($modele)) {
979 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
994 global $selected, $langs;
996 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
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"' :
'').
'>';
1014 $return .=
'<br><span class="info-box-label ">' .
dol_trunc($this->
description, 25) .
'</span>';
1016 $return .=
'</div>';
1017 $return .=
'</div>';
1018 $return .=
'</div>';
1032 $skillranks = array();
1033 $sql =
"SELECT rowid";
1034 $sql .=
" FROM ".MAIN_DB_PREFIX.
"hrm_skillrank";
1035 $sql .=
" WHERE fk_object = ".((int) $id);
1037 $resql = $this->db->query($sql);
1039 $num = $this->db->num_rows($resql);
1042 $obj = $this->db->fetch_object($resql);
1043 $skillranks[] = $obj->rowid;
1046 $this->db->free($resql);
1048 dol_print_error($this->db);
1055require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1074 $this->isextrafieldmanaged = 0;
if(! $sortfield) if(! $sortorder) $object
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.
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.
__construct(DoliDB $db)
Constructor.
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...
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.
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.