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)) {
283 if (!empty($fk_object) && $fk_object > 0) {
289 if (property_exists(
$object,
'ref')) {
290 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
292 if (property_exists(
$object,
'label')) {
293 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".
$object->label : $this->fields[
'label'][
'default'];
295 if (property_exists(
$object,
'status')) {
296 $object->status = self::STATUS_DRAFT;
298 if (property_exists(
$object,
'date_creation')) {
301 if (property_exists(
$object,
'date_modification')) {
302 $object->date_modification =
null;
304 if (!empty($fk_object) && $fk_object > 0) {
305 if (property_exists(
$object,
'fk_object')) {
306 $object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
311 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
312 $extrafields->fetch_name_optionals_label($this->table_element);
313 foreach (
$object->array_options as $key => $option) {
314 $shortkey = preg_replace(
'/options_/',
'', $key);
315 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
317 unset(
$object->array_options[$key]);
323 $object->context[
'createfromclone'] =
'createfromclone';
324 $result =
$object->createCommon($user);
339 if (property_exists($this,
'fk_soc') && $this->fk_soc ==
$object->socid) {
346 unset(
$object->context[
'createfromclone']);
353 $this->db->rollback();
365 public function fetch($id, $ref =
null)
368 if ($result > 0 && !empty($this->table_element_line)) {
381 $this->lines = array();
399 $this->fk_skill = $currentSkill->fk_skill;
400 $this->rankorder = $currentSkill->rankorder;
401 $this->fk_object = $fk_user;
402 $this->date_creation =
dol_now();
403 $this->fk_user_creat = $user->id;
404 $this->fk_user_modif = $user->id;
405 $this->objecttype = self::SKILLRANK_TYPE_USER;
406 $result = $this->
create($user);
423 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
431 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
432 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
433 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
435 $sql .=
' WHERE 1 = 1';
442 $this->errors[] = $errormessage;
443 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
447 if (!empty($sortfield)) {
448 $sql .= $this->db->order($sortfield, $sortorder);
450 if (!empty($limit)) {
451 $sql .=
' '.$this->db->plimit($limit, $offset);
454 $resql = $this->db->query($sql);
456 $num = $this->db->num_rows($resql);
458 while ($i < ($limit ? min($limit, $num) : $num)) {
459 $obj = $this->db->fetch_object($resql);
461 $record =
new self($this->db);
462 $record->setVarsFromFetchObj($obj);
464 $records[$record->id] = $record;
468 $this->db->free($resql);
472 $this->errors[] =
'Error '.$this->db->lasterror();
473 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
498 public function delete(
User $user, $notrigger = 0)
515 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
532 global
$conf, $langs;
534 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
539 if ($this->
status == self::STATUS_VALIDATED) {
540 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
557 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
562 $this->newref = $num;
566 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
567 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
568 $sql .=
" status = ".self::STATUS_VALIDATED;
569 if (!empty($this->fields[
'date_validation'])) {
570 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
572 if (!empty($this->fields[
'fk_user_valid'])) {
573 $sql .=
", fk_user_valid = ".((int) $user->id);
575 $sql .=
" WHERE rowid = ".((int) $this->
id);
577 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
578 $resql = $this->db->query($sql);
581 $this->error = $this->db->lasterror();
585 if (!$error && !$notrigger) {
587 $result = $this->
call_trigger(
'HRM_SKILLRANK_VALIDATE', $user);
596 $this->oldref = $this->ref;
599 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
601 $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).
"'";
602 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'skillrank/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
603 $resql = $this->db->query($sql);
606 $this->error = $this->db->lasterror();
608 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref).
"'";
609 $sql .=
" WHERE filepath = 'skillrank/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
610 $resql = $this->db->query($sql);
613 $this->error = $this->db->lasterror();
619 $dirsource =
$conf->hrm->dir_output.
'/skillrank/'.$oldref;
620 $dirdest =
$conf->hrm->dir_output.
'/skillrank/'.$newref;
621 if (!$error && file_exists($dirsource)) {
622 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
624 if (@rename($dirsource, $dirdest)) {
627 $listoffiles =
dol_dir_list(
$conf->hrm->dir_output.
'/skillrank/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
628 foreach ($listoffiles as $fileentry) {
629 $dirsource = $fileentry[
'name'];
630 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
631 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
632 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
633 @rename($dirsource, $dirdest);
643 $this->
status = self::STATUS_VALIDATED;
650 $this->db->rollback();
666 if ($this->
status <= self::STATUS_DRAFT) {
677 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SKILLRANK_UNVALIDATE');
687 public function cancel($user, $notrigger = 0)
690 if ($this->
status != self::STATUS_VALIDATED) {
701 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'SKILLRANK_CANCEL');
711 public function reopen($user, $notrigger = 0)
714 if ($this->
status != self::STATUS_CANCELED) {
725 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'SKILLRANK_REOPEN');
738 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
740 global
$conf, $langs, $hookmanager;
742 if (!empty(
$conf->dol_no_mouse_hover)) {
748 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SkillRank").
'</u>';
749 if (isset($this->
status)) {
750 $label .=
' '.$this->getLibStatut(5);
753 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
755 $url =
dol_buildpath(
'/hrm/skillrank_card.php', 1).
'?id='.$this->id;
757 if ($option !=
'nolink') {
759 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
760 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
761 $add_save_lastsearch_values = 1;
763 if ($add_save_lastsearch_values) {
764 $url .=
'&save_lastsearch_values=1';
769 if (empty($notooltip)) {
771 $label = $langs->trans(
"ShowSkillRank");
772 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
774 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
775 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
777 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
780 if ($option ==
'nolink') {
781 $linkstart =
'<span';
783 $linkstart =
'<a href="'.$url.
'"';
785 $linkstart .= $linkclose.
'>';
786 if ($option ==
'nolink') {
787 $linkend =
'</span>';
792 $result .= $linkstart;
794 if (empty($this->showphoto_on_popup)) {
796 $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);
800 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
802 list($class, $module) = explode(
'@', $this->picto);
805 $filename = $filearray[0][
'name'];
806 if (!empty($filename)) {
807 $pospoint = strpos($filearray[0][
'name'],
'.');
809 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
811 $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>';
813 $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>';
818 $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);
823 if ($withpicto != 2) {
824 $result .= $this->ref;
830 global $action, $hookmanager;
831 $hookmanager->initHooks(array(
'skillrankdao'));
832 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
833 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
835 $result = $hookmanager->resPrint;
837 $result .= $hookmanager->resPrint;
865 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
868 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
869 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
870 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
871 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
872 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
873 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
876 $statusType =
'status'.$status;
878 if ($status == self::STATUS_CANCELED) {
879 $statusType =
'status6';
882 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
893 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
894 $sql .=
' fk_user_creat, fk_user_modif';
895 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
896 $sql .=
' WHERE t.rowid = '.((int) $id);
897 $result = $this->db->query($sql);
899 if ($this->db->num_rows($result)) {
900 $obj = $this->db->fetch_object($result);
902 $this->
id = $obj->rowid;
904 $this->user_creation_id = $obj->fk_user_creat;
905 $this->user_modification_id = $obj->fk_user_modif;
906 $this->date_creation = $this->db->jdate($obj->datec);
907 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
910 $this->db->free($result);
938 $this->lines = array();
964 global $langs,
$conf;
968 $conf->global->hrm_SKILLRANK_ADDON =
'mod_skillrank_standard';
978 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
979 foreach ($dirmodels as $reldir) {
983 $mybool = ((bool) @include_once $dir.$file) || $mybool;
991 if (class_exists($classname)) {
992 $obj =
new $classname();
993 '@phan-var-force ModeleNumRefEvaluation $obj';
994 $numref = $obj->getNextValue($this);
996 if ($numref !=
'' && $numref !=
'-1') {
999 $this->error = $obj->error;
1004 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
1008 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1024 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1026 global
$conf, $langs;
1029 $includedocgeneration = 0;
1031 $langs->load(
"hrm");
1034 $modele =
'standard_skillrank';
1036 if (!empty($this->model_pdf)) {
1037 $modele = $this->model_pdf;
1043 $modelpath =
"core/modules/hrm/doc/";
1045 if ($includedocgeneration && !empty($modele)) {
1046 $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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...