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;
187 global
$conf, $langs;
191 $this->ismultientitymanaged = 0;
192 $this->isextrafieldmanaged = 0;
195 $this->fields[
'rowid'][
'visible'] = 0;
197 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
198 $this->fields[
'entity'][
'enabled'] = 0;
208 foreach ($this->fields as $key => $val) {
209 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
210 unset($this->fields[$key]);
215 if (is_object($langs)) {
216 foreach ($this->fields as $key => $val) {
217 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
218 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
219 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
237 $filter =
'(fk_object:=:'.((int) $this->fk_object).
") AND (objecttype:=:'".$this->db->escape($this->objecttype).
"') AND (fk_skill:=:".((int) $this->fk_skill).
")";
239 $alreadyLinked = $this->
fetchAll(
'ASC',
'rowid', 0, 0, $filter);
240 if (!empty($alreadyLinked)) {
241 $this->error = $langs->trans(
'ErrSkillAlreadyAdded');
247 return $resultcreate;
260 global $langs, $extrafields;
270 $result =
$object->fetchCommon($fromid);
271 if ($result > 0 && !empty(
$object->table_element_line)) {
282 unset(
$object->user_creation_id);
284 if (!empty($fk_object) && $fk_object > 0) {
290 if (property_exists(
$object,
'ref')) {
291 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
293 if (property_exists(
$object,
'status')) {
294 $object->status = self::STATUS_DRAFT;
296 if (property_exists(
$object,
'date_creation')) {
299 if (property_exists(
$object,
'date_modification')) {
300 $object->date_modification =
null;
302 if (!empty($fk_object) && $fk_object > 0) {
303 if (property_exists(
$object,
'fk_object')) {
304 $object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
309 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
310 $extrafields->fetch_name_optionals_label($this->table_element);
311 foreach (
$object->array_options as $key => $option) {
312 $shortkey = preg_replace(
'/options_/',
'', $key);
313 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
315 unset(
$object->array_options[$key]);
321 $object->context[
'createfromclone'] =
'createfromclone';
322 $result =
$object->createCommon($user);
337 if (property_exists($this,
'fk_soc') && $this->fk_soc ==
$object->socid) {
344 unset(
$object->context[
'createfromclone']);
351 $this->db->rollback();
363 public function fetch($id, $ref =
null)
366 if ($result > 0 && !empty($this->table_element_line)) {
379 $this->lines = array();
397 $this->fk_skill = $currentSkill->fk_skill;
398 $this->rankorder = $currentSkill->rankorder;
399 $this->fk_object = $fk_user;
400 $this->date_creation =
dol_now();
401 $this->fk_user_creat = $user->id;
402 $this->fk_user_modif = $user->id;
403 $this->objecttype = self::SKILLRANK_TYPE_USER;
404 $result = $this->
create($user);
421 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
429 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
430 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
431 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
433 $sql .=
' WHERE 1 = 1';
440 $this->errors[] = $errormessage;
441 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
445 if (!empty($sortfield)) {
446 $sql .= $this->db->order($sortfield, $sortorder);
448 if (!empty($limit)) {
449 $sql .=
' '.$this->db->plimit($limit, $offset);
452 $resql = $this->db->query($sql);
454 $num = $this->db->num_rows($resql);
456 while ($i < ($limit ? min($limit, $num) : $num)) {
457 $obj = $this->db->fetch_object($resql);
459 $record =
new self($this->db);
460 $record->setVarsFromFetchObj($obj);
462 $records[$record->id] = $record;
466 $this->db->free($resql);
470 $this->errors[] =
'Error '.$this->db->lasterror();
471 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
496 public function delete(
User $user, $notrigger = 0)
513 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
530 global
$conf, $langs;
532 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
537 if ($this->
status == self::STATUS_VALIDATED) {
538 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
555 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
560 $this->newref = $num;
564 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
565 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
566 $sql .=
" status = ".self::STATUS_VALIDATED;
567 if (!empty($this->fields[
'date_validation'])) {
568 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
570 if (!empty($this->fields[
'fk_user_valid'])) {
571 $sql .=
", fk_user_valid = ".((int) $user->id);
573 $sql .=
" WHERE rowid = ".((int) $this->
id);
575 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
576 $resql = $this->db->query($sql);
579 $this->error = $this->db->lasterror();
583 if (!$error && !$notrigger) {
585 $result = $this->
call_trigger(
'HRM_SKILLRANK_VALIDATE', $user);
594 $this->oldref = $this->ref;
597 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
599 $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).
"'";
600 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'skillrank/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
601 $resql = $this->db->query($sql);
604 $this->error = $this->db->lasterror();
606 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref).
"'";
607 $sql .=
" WHERE filepath = 'skillrank/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
608 $resql = $this->db->query($sql);
611 $this->error = $this->db->lasterror();
617 $dirsource =
$conf->hrm->dir_output.
'/skillrank/'.$oldref;
618 $dirdest =
$conf->hrm->dir_output.
'/skillrank/'.$newref;
619 if (!$error && file_exists($dirsource)) {
620 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
622 if (@rename($dirsource, $dirdest)) {
625 $listoffiles =
dol_dir_list(
$conf->hrm->dir_output.
'/skillrank/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
626 foreach ($listoffiles as $fileentry) {
627 $dirsource = $fileentry[
'name'];
628 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
629 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
630 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
631 @rename($dirsource, $dirdest);
641 $this->
status = self::STATUS_VALIDATED;
648 $this->db->rollback();
664 if ($this->
status <= self::STATUS_DRAFT) {
675 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SKILLRANK_UNVALIDATE');
685 public function cancel($user, $notrigger = 0)
688 if ($this->
status != self::STATUS_VALIDATED) {
699 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'SKILLRANK_CANCEL');
709 public function reopen($user, $notrigger = 0)
712 if ($this->
status != self::STATUS_CANCELED) {
723 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'SKILLRANK_REOPEN');
736 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
738 global
$conf, $langs, $hookmanager;
740 if (!empty(
$conf->dol_no_mouse_hover)) {
746 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SkillRank").
'</u>';
747 if (isset($this->
status)) {
748 $label .=
' '.$this->getLibStatut(5);
751 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
753 $url =
dol_buildpath(
'/hrm/skillrank_card.php', 1).
'?id='.$this->id;
755 if ($option !=
'nolink') {
757 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
758 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
759 $add_save_lastsearch_values = 1;
761 if ($add_save_lastsearch_values) {
762 $url .=
'&save_lastsearch_values=1';
767 if (empty($notooltip)) {
769 $label = $langs->trans(
"ShowSkillRank");
770 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
772 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
773 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
775 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
778 if ($option ==
'nolink') {
779 $linkstart =
'<span';
781 $linkstart =
'<a href="'.$url.
'"';
783 $linkstart .= $linkclose.
'>';
784 if ($option ==
'nolink') {
785 $linkend =
'</span>';
790 $result .= $linkstart;
792 if (empty($this->showphoto_on_popup)) {
794 $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);
798 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
800 list($class, $module) = explode(
'@', $this->picto);
803 $filename = $filearray[0][
'name'];
804 if (!empty($filename)) {
805 $pospoint = strpos($filearray[0][
'name'],
'.');
807 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
809 $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>';
811 $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>';
816 $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);
821 if ($withpicto != 2) {
822 $result .= $this->ref;
828 global $action, $hookmanager;
829 $hookmanager->initHooks(array(
'skillrankdao'));
830 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
831 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
833 $result = $hookmanager->resPrint;
835 $result .= $hookmanager->resPrint;
863 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
866 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
867 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
868 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
869 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
870 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
871 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
874 $statusType =
'status'.$status;
876 if ($status == self::STATUS_CANCELED) {
877 $statusType =
'status6';
880 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
891 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
892 $sql .=
' fk_user_creat, fk_user_modif';
893 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
894 $sql .=
' WHERE t.rowid = '.((int) $id);
895 $result = $this->db->query($sql);
897 if ($this->db->num_rows($result)) {
898 $obj = $this->db->fetch_object($result);
900 $this->
id = $obj->rowid;
902 $this->user_creation_id = $obj->fk_user_creat;
903 $this->user_modification_id = $obj->fk_user_modif;
904 $this->date_creation = $this->db->jdate($obj->datec);
905 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
908 $this->db->free($result);
936 $this->lines = array();
962 global $langs,
$conf;
966 $conf->global->hrm_SKILLRANK_ADDON =
'mod_skillrank_standard';
976 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
977 foreach ($dirmodels as $reldir) {
981 $mybool = ((bool) @include_once $dir.$file) || $mybool;
989 if (class_exists($classname)) {
990 $obj =
new $classname();
991 '@phan-var-force ModeleNumRefEvaluation $obj';
992 $numref = $obj->getNextValue($this);
994 if ($numref !=
'' && $numref !=
'-1') {
997 $this->error = $obj->error;
1002 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
1006 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1022 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1024 global
$conf, $langs;
1027 $includedocgeneration = 0;
1029 $langs->load(
"hrm");
1032 $modele =
'standard_skillrank';
1034 if (!empty($this->model_pdf)) {
1035 $modele = $this->model_pdf;
1041 $modelpath =
"core/modules/hrm/doc/";
1043 if ($includedocgeneration && !empty($modele)) {
1044 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...