31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
32require_once DOL_DOCUMENT_ROOT .
'/hrm/lib/hrm_skillrank.lib.php';
42 public $module =
'hrm';
47 public $element =
'skillrank';
52 public $table_element =
'hrm_skillrank';
57 public $picto =
'skillrank@hrm';
60 const STATUS_DRAFT = 0;
61 const STATUS_VALIDATED = 1;
62 const STATUS_CANCELED = 9;
64 const SKILLRANK_TYPE_JOB =
"job";
65 const SKILLRANK_TYPE_USER =
"user";
66 const SKILLRANK_TYPE_EVALDET =
"evaluationdet";
98 public $fields = array(
99 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'visible' => 0,
'noteditable' => 1,
'index' => 1,
'css' =>
'left',
'comment' =>
"Id"),
100 'fk_skill' => array(
'type' =>
'integer:Skill:hrm/class/skill.class.php:1',
'label' =>
'Skill',
'enabled' => 1,
'position' => 3,
'notnull' => 1,
'visible' => 1,
'index' => 1,),
101 'rankorder' => array(
'type' =>
'integer',
'label' =>
'Rank',
'enabled' => 1,
'position' => 4,
'notnull' => 1,
'visible' => 1,
'default' =>
'0'),
102 'fk_object' => array(
'type' =>
'integer',
'label' =>
'object',
'enabled' => 1,
'position' => 5,
'notnull' => 1,
'visible' => 0,),
103 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 500,
'notnull' => 1,
'visible' => -2,),
104 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'position' => 501,
'notnull' => 0,
'visible' => -2,),
105 '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',),
106 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'position' => 511,
'notnull' => -1,
'visible' => -2,),
107 'objecttype' => array(
'type' =>
'varchar(128)',
'label' =>
'objecttype',
'enabled' => 1,
'position' => 6,
'notnull' => 1,
'visible' => 0,),
128 public $fk_user_creat;
132 public $fk_user_modif;
150 global
$conf, $langs;
154 $this->ismultientitymanaged = 0;
155 $this->isextrafieldmanaged = 0;
158 $this->fields[
'rowid'][
'visible'] = 0;
160 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
161 $this->fields[
'entity'][
'enabled'] = 0;
171 foreach ($this->fields as $key => $val) {
172 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
173 unset($this->fields[$key]);
178 if (is_object($langs)) {
179 foreach ($this->fields as $key => $val) {
180 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
181 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
182 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
200 $filter =
'(fk_object:=:'.((int) $this->fk_object).
") AND (objecttype:=:'".$this->db->escape($this->objecttype).
"') AND (fk_skill:=:".((int) $this->fk_skill).
")";
202 $alreadyLinked = $this->
fetchAll(
'ASC',
'rowid', 0, 0, $filter);
203 if (!empty($alreadyLinked)) {
204 $this->error = $langs->trans(
'ErrSkillAlreadyAdded');
210 return $resultcreate;
223 global $langs, $extrafields;
233 $result =
$object->fetchCommon($fromid);
234 if ($result > 0 && !empty(
$object->table_element_line)) {
245 unset(
$object->user_creation_id);
247 if (!empty($fk_object) && $fk_object > 0) {
253 if (property_exists(
$object,
'ref')) {
254 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
256 if (property_exists(
$object,
'status')) {
257 $object->status = self::STATUS_DRAFT;
259 if (property_exists(
$object,
'date_creation')) {
262 if (property_exists(
$object,
'date_modification')) {
263 $object->date_modification =
null;
265 if (!empty($fk_object) && $fk_object > 0) {
266 if (property_exists(
$object,
'fk_object')) {
267 $object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
272 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
273 $extrafields->fetch_name_optionals_label($this->table_element);
274 foreach (
$object->array_options as $key => $option) {
275 $shortkey = preg_replace(
'/options_/',
'', $key);
276 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
278 unset(
$object->array_options[$key]);
284 $object->context[
'createfromclone'] =
'createfromclone';
285 $result =
$object->createCommon($user);
298 unset(
$object->context[
'createfromclone']);
305 $this->db->rollback();
317 public function fetch($id, $ref =
null)
320 if ($result > 0 && !empty($this->table_element_line)) {
333 $this->lines = array();
351 $this->fk_skill = $currentSkill->fk_skill;
352 $this->rankorder = $currentSkill->rankorder;
353 $this->fk_object = $fk_user;
354 $this->date_creation =
dol_now();
355 $this->fk_user_creat = $user->id;
356 $this->fk_user_modif = $user->id;
357 $this->objecttype = self::SKILLRANK_TYPE_USER;
358 $result = $this->
create($user);
375 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
383 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
384 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
385 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
387 $sql .=
' WHERE 1 = 1';
394 $this->errors[] = $errormessage;
395 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
399 if (!empty($sortfield)) {
400 $sql .= $this->db->order($sortfield, $sortorder);
402 if (!empty($limit)) {
403 $sql .=
' '.$this->db->plimit($limit, $offset);
406 $resql = $this->db->query($sql);
408 $num = $this->db->num_rows($resql);
410 while ($i < ($limit ? min($limit, $num) : $num)) {
411 $obj = $this->db->fetch_object($resql);
413 $record =
new self($this->db);
414 $record->setVarsFromFetchObj($obj);
416 $records[$record->id] = $record;
420 $this->db->free($resql);
424 $this->errors[] =
'Error '.$this->db->lasterror();
425 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
450 public function delete(
User $user, $notrigger = 0)
467 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
484 global
$conf, $langs;
486 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
491 if ($this->
status == self::STATUS_VALIDATED) {
492 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
509 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
510 $num = $this->getNextNumRef();
512 $num = (string) $this->
ref;
514 $this->newref = $num;
518 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
519 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
520 $sql .=
" status = ".self::STATUS_VALIDATED;
521 if (!empty($this->fields[
'date_validation'])) {
522 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
524 if (!empty($this->fields[
'fk_user_valid'])) {
525 $sql .=
", fk_user_valid = ".((int) $user->id);
527 $sql .=
" WHERE rowid = ".((int) $this->
id);
529 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
530 $resql = $this->db->query($sql);
532 dol_print_error($this->db);
533 $this->error = $this->db->lasterror();
537 if (!$error && !$notrigger) {
539 $result = $this->call_trigger(
'HRM_SKILLRANK_VALIDATE', $user);
548 $this->oldref = $this->ref;
551 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
553 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'skillrank/".$this->db->escape($this->newref).
"'";
554 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'skillrank/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
555 $resql = $this->db->query($sql);
558 $this->error = $this->db->lasterror();
560 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref).
"'";
561 $sql .=
" WHERE filepath = 'skillrank/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
562 $resql = $this->db->query($sql);
565 $this->error = $this->db->lasterror();
571 $dirsource =
$conf->hrm->dir_output.
'/skillrank/'.$oldref;
572 $dirdest =
$conf->hrm->dir_output.
'/skillrank/'.$newref;
573 if (!$error && file_exists($dirsource)) {
574 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
576 if (@rename($dirsource, $dirdest)) {
579 $listoffiles =
dol_dir_list(
$conf->hrm->dir_output.
'/skillrank/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
580 foreach ($listoffiles as $fileentry) {
581 $dirsource = $fileentry[
'name'];
582 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
583 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
584 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
585 @rename($dirsource, $dirdest);
595 $this->
status = self::STATUS_VALIDATED;
602 $this->db->rollback();
618 if ($this->
status <= self::STATUS_DRAFT) {
629 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SKILLRANK_UNVALIDATE');
639 public function cancel($user, $notrigger = 0)
642 if ($this->
status != self::STATUS_VALIDATED) {
653 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'SKILLRANK_CANCEL');
663 public function reopen($user, $notrigger = 0)
666 if ($this->
status != self::STATUS_CANCELED) {
677 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'SKILLRANK_REOPEN');
690 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
692 global
$conf, $langs, $hookmanager;
694 if (!empty(
$conf->dol_no_mouse_hover)) {
700 $label = img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SkillRank").
'</u>';
701 if (isset($this->
status)) {
702 $label .=
' '.$this->getLibStatut(5);
705 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
707 $url =
dol_buildpath(
'/hrm/skillrank_card.php', 1).
'?id='.$this->id;
709 if ($option !=
'nolink') {
711 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
712 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
713 $add_save_lastsearch_values = 1;
715 if ($add_save_lastsearch_values) {
716 $url .=
'&save_lastsearch_values=1';
721 if (empty($notooltip)) {
723 $label = $langs->trans(
"ShowSkillRank");
724 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
726 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
727 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
729 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
732 if ($option ==
'nolink') {
733 $linkstart =
'<span';
735 $linkstart =
'<a href="'.$url.
'"';
737 $linkstart .= $linkclose.
'>';
738 if ($option ==
'nolink') {
739 $linkend =
'</span>';
744 $result .= $linkstart;
746 if (empty($this->showphoto_on_popup)) {
748 $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);
752 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
754 list($class, $module) = explode(
'@', $this->picto);
757 $filename = $filearray[0][
'name'];
758 if (!empty($filename)) {
759 $pospoint = strpos($filearray[0][
'name'],
'.');
761 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.
dol_substr($filename, 0, $pospoint).
'_mini'.
dol_substr($filename, $pospoint);
763 $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>';
765 $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>';
770 $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);
775 if ($withpicto != 2) {
776 $result .= $this->ref;
782 global $action, $hookmanager;
783 $hookmanager->initHooks(array(
'skillrankdao'));
784 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
785 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
787 $result = $hookmanager->resPrint;
789 $result .= $hookmanager->resPrint;
817 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
820 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
821 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
822 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
823 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
824 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
825 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
828 $statusType =
'status'.$status;
830 if ($status == self::STATUS_CANCELED) {
831 $statusType =
'status6';
834 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
845 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
846 $sql .=
' fk_user_creat, fk_user_modif';
847 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
848 $sql .=
' WHERE t.rowid = '.((int) $id);
849 $result = $this->db->query($sql);
851 if ($this->db->num_rows($result)) {
852 $obj = $this->db->fetch_object($result);
854 $this->
id = $obj->rowid;
856 $this->user_creation_id = $obj->fk_user_creat;
857 $this->user_modification_id = $obj->fk_user_modif;
858 $this->date_creation = $this->db->jdate($obj->datec);
859 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
862 $this->db->free($result);
864 dol_print_error($this->db);
890 $this->lines = array();
914 public function getNextNumRef()
916 global $langs,
$conf;
920 $conf->global->hrm_SKILLRANK_ADDON =
'mod_skillrank_standard';
930 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
931 foreach ($dirmodels as $reldir) {
935 $mybool = ((bool) @include_once $dir.$file) || $mybool;
939 dol_print_error(
null,
"Failed to include file ".$file);
943 if (class_exists($classname)) {
944 $obj =
new $classname();
945 '@phan-var-force ModeleNumRefEvaluation $obj';
947 $numref = $obj->getNextValue($this);
949 if ($numref !=
'' && $numref !=
'-1') {
952 $this->error = $obj->error;
957 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
961 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
977 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
979 global
$conf, $langs;
982 $includedocgeneration = 0;
987 $modele =
'standard_skillrank';
989 if (!empty($this->model_pdf)) {
990 $modele = $this->model_pdf;
996 $modelpath =
"core/modules/hrm/doc/";
998 if ($includedocgeneration && !empty($modele)) {
999 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
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.
Class to manage Dolibarr database access.
reopen($user, $notrigger=0)
Set back to validated status.
__construct(DoliDB $db)
Constructor.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
LibStatut($status, $mode=0)
Return the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
setDraft($user, $notrigger=0)
Set draft status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetchLines()
Load object lines in memory from the database.
fetch($id, $ref=null)
Load object in memory from the database.
cloneFromCurrentSkill($currentSkill, $fk_user)
Clone skillrank Object linked to job with user id The skillrank table is a join table that is marked ...
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
createFromClone(User $user, $fromid, $fk_object=0)
Clone an object into another one.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Update object into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load the info information in the object.
validate($user, $notrigger=0)
Validate object.
getLibStatut($mode=0)
Return the label of the status.
cancel($user, $notrigger=0)
Set cancel status.
getLinesArray()
Create an array of lines.
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...
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.
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.