29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
30require_once DOL_DOCUMENT_ROOT .
'/hrm/class/skillrank.class.php';
42 public $module =
'hrm';
47 public $element =
'evaluationdet';
52 public $table_element =
'hrm_evaluationdet';
58 public $ismultientitymanaged = 0;
63 public $isextrafieldmanaged = 1;
68 public $picto =
'evaluationdet@hrm';
71 const STATUS_DRAFT = 0;
72 const STATUS_VALIDATED = 1;
73 const STATUS_CANCELED = 9;
106 public $fields=array(
107 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>1,
'notnull'=>1,
'visible'=>0,
'noteditable'=>
'1',
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
108 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>500,
'notnull'=>1,
'visible'=>-2,),
109 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>
'1',
'position'=>501,
'notnull'=>0,
'visible'=>-2,),
110 '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',),
111 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>-2,),
112 'fk_skill' => array(
'type'=>
'integer:Skill:hrm/class/skill.class.php:1',
'label'=>
'Skill',
'enabled'=>
'1',
'position'=>3,
'notnull'=>1,
'visible'=>1,
'index'=>1,),
113 'fk_evaluation' => array(
'type'=>
'integer:Evaluation:hrm/class/evaluation.class.php:1',
'label'=>
'Evaluation',
'enabled'=>
'1',
'position'=>3,
'notnull'=>1,
'visible'=>1,
'index'=>1,),
114 'rankorder' => array(
'type'=>
'integer',
'label'=>
'Rank',
'enabled'=>
'1',
'position'=>4,
'notnull'=>1,
'visible'=>1,),
115 'required_rank' => array(
'type'=>
'integer',
'label'=>
'requiredRank',
'enabled'=>
'1',
'position'=>5,
'notnull'=>1,
'visible'=>1,),
116 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>-1,
'visible'=>-2,),
119 public $date_creation;
121 public $fk_user_creat;
122 public $fk_user_modif;
124 public $fk_evaluation;
126 public $required_rank;
173 global $conf, $langs;
177 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
178 $this->fields[
'rowid'][
'visible'] = 0;
180 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
181 $this->fields[
'entity'][
'enabled'] = 0;
191 foreach ($this->fields as $key => $val) {
192 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
193 unset($this->fields[$key]);
198 if (is_object($langs)) {
199 foreach ($this->fields as $key => $val) {
200 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
201 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
202 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
220 return $resultcreate;
232 global $langs, $extrafields;
237 $object =
new self($this->db);
242 $result = $object->fetchCommon($fromid);
243 if ($result > 0 && !empty($object->table_element_line)) {
244 $object->fetchLines();
253 unset($object->fk_user_creat);
254 unset($object->import_key);
257 if (property_exists($object,
'ref')) {
258 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
260 if (property_exists($object,
'label')) {
261 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
263 if (property_exists($object,
'status')) {
264 $object->status = self::STATUS_DRAFT;
266 if (property_exists($object,
'date_creation')) {
267 $object->date_creation =
dol_now();
269 if (property_exists($object,
'date_modification')) {
270 $object->date_modification =
null;
274 if (is_array($object->array_options) && count($object->array_options) > 0) {
275 $extrafields->fetch_name_optionals_label($this->table_element);
276 foreach ($object->array_options as $key => $option) {
277 $shortkey = preg_replace(
'/options_/',
'', $key);
278 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
280 unset($object->array_options[$key]);
286 $object->context[
'createfromclone'] =
'createfromclone';
287 $result = $object->createCommon($user);
290 $this->error = $object->error;
291 $this->errors = $object->errors;
303 if (property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
310 unset($object->context[
'createfromclone']);
317 $this->db->rollback();
329 public function fetch($id, $ref =
null)
332 if ($result > 0 && !empty($this->table_element_line)) {
345 $this->lines = array();
363 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
373 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
374 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
375 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
377 $sql .=
' WHERE 1 = 1';
381 if (count($filter) > 0) {
382 foreach ($filter as $key => $value) {
383 if ($key ==
't.rowid') {
384 $sqlwhere[] = $key.
'='.$value;
385 } elseif ($key ==
'customsql') {
386 $sqlwhere[] = $value;
387 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
388 $sqlwhere[] = $key.
' = \''.$this->db->idate($value).
'\'';
389 } elseif (strpos($value,
'%') ===
false) {
390 $sqlwhere[] = $key.
' IN ('.$this->db->sanitize($this->db->escape($value)).
')';
392 $sqlwhere[] = $key.
' LIKE \'%'.$this->db->escape($value).
'%\'';
396 if (count($sqlwhere) > 0) {
397 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
400 if (!empty($sortfield)) {
401 $sql .= $this->db->order($sortfield, $sortorder);
403 if (!empty($limit)) {
404 $sql .=
' '.$this->db->plimit($limit, $offset);
407 $resql = $this->db->query($sql);
409 $num = $this->db->num_rows($resql);
411 while ($i < ($limit ? min($limit, $num) : $num)) {
412 $obj = $this->db->fetch_object($resql);
414 $record =
new self($this->db);
415 $record->setVarsFromFetchObj($obj);
417 $records[$record->id] = $record;
421 $this->db->free($resql);
425 $this->errors[] =
'Error '.$this->db->lasterror();
426 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
451 public function delete(
User $user, $notrigger =
false)
453 if ($this->fk_rank) {
455 $skillRank->fetch($this->fk_rank);
456 $skillRank->delete($user, $notrigger);
472 if ($this->status < 0) {
473 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
490 global $conf, $langs;
492 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
497 if ($this->status == self::STATUS_VALIDATED) {
498 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
515 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
520 $this->newref = $num;
524 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
525 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
526 $sql .=
" status = ".self::STATUS_VALIDATED;
527 if (!empty($this->fields[
'date_validation'])) {
528 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
530 if (!empty($this->fields[
'fk_user_valid'])) {
531 $sql .=
", fk_user_valid = ".((int) $user->id);
533 $sql .=
" WHERE rowid = ".((int) $this->
id);
535 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
536 $resql = $this->db->query($sql);
539 $this->error = $this->db->lasterror();
543 if (!$error && !$notrigger) {
545 $result = $this->
call_trigger(
'HRM_EVALUATIONLINE_VALIDATE', $user);
554 $this->oldref = $this->ref;
557 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
559 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'evaluationline/".$this->db->escape($this->newref).
"'";
560 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'evaluationline/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
561 $resql = $this->db->query($sql);
564 $this->error = $this->db->lasterror();
566 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'evaluationline/".$this->db->escape($this->newref).
"'";
567 $sql .=
" WHERE filepath = 'evaluationline/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
568 $resql = $this->db->query($sql);
570 $error++; $this->error = $this->db->lasterror();
576 $dirsource = $conf->hrm->dir_output.
'/evaluationline/'.$oldref;
577 $dirdest = $conf->hrm->dir_output.
'/evaluationline/'.$newref;
578 if (!$error && file_exists($dirsource)) {
579 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
581 if (@rename($dirsource, $dirdest)) {
584 $listoffiles =
dol_dir_list($conf->hrm->dir_output.
'/evaluationline/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
585 foreach ($listoffiles as $fileentry) {
586 $dirsource = $fileentry[
'name'];
587 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
588 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
589 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
590 @rename($dirsource, $dirdest);
600 $this->status = self::STATUS_VALIDATED;
607 $this->db->rollback();
623 if ($this->status <= self::STATUS_DRAFT) {
634 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'EVALUATIONLINE_UNVALIDATE');
644 public function cancel($user, $notrigger = 0)
647 if ($this->status != self::STATUS_VALIDATED) {
658 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'EVALUATIONLINE_CANCEL');
668 public function reopen($user, $notrigger = 0)
671 if ($this->status != self::STATUS_CANCELED) {
682 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'EVALUATIONLINE_REOPEN');
695 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
697 global $conf, $langs, $hookmanager;
699 if (!empty($conf->dol_no_mouse_hover)) {
705 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Evaluationdet").
'</u>';
706 if (isset($this->status)) {
707 $label .=
' '.$this->getLibStatut(5);
710 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
712 $url =
dol_buildpath(
'/hrm/evaluationdet_card.php', 1).
'?id='.$this->id;
714 if ($option !=
'nolink') {
716 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
717 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
718 $add_save_lastsearch_values = 1;
720 if ($add_save_lastsearch_values) {
721 $url .=
'&save_lastsearch_values=1';
726 if (empty($notooltip)) {
727 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
728 $label = $langs->trans(
"ShowEvaluationdet");
729 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
731 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
732 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
734 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
737 if ($option ==
'nolink') {
738 $linkstart =
'<span';
740 $linkstart =
'<a href="'.$url.
'"';
742 $linkstart .= $linkclose.
'>';
743 if ($option ==
'nolink') {
744 $linkend =
'</span>';
749 $result .= $linkstart;
751 if (empty($this->showphoto_on_popup)) {
753 $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);
757 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
759 list($class, $module) = explode(
'@', $this->picto);
762 $filename = $filearray[0][
'name'];
763 if (!empty($filename)) {
764 $pospoint = strpos($filearray[0][
'name'],
'.');
766 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
767 if (empty($conf->global->{strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS'})) {
768 $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>';
770 $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>';
775 $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);
780 if ($withpicto != 2) {
781 $result .= $this->ref;
787 global $action, $hookmanager;
788 $hookmanager->initHooks(array(
'evaluationlinedao'));
789 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
790 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
792 $result = $hookmanager->resPrint;
794 $result .= $hookmanager->resPrint;
808 return $this->LibStatut($this->status, $mode);
822 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
825 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
826 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
827 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
828 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
829 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
830 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
833 $statusType =
'status'.$status;
835 if ($status == self::STATUS_CANCELED) {
836 $statusType =
'status6';
839 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
850 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
851 $sql .=
' fk_user_creat, fk_user_modif';
852 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
853 $sql .=
' WHERE t.rowid = '.((int) $id);
854 $result = $this->db->query($sql);
856 if ($this->db->num_rows($result)) {
857 $obj = $this->db->fetch_object($result);
858 $this->
id = $obj->rowid;
860 $this->user_creation_id = $obj->fk_user_creat;
861 $this->user_modification_id = $obj->fk_user_modif;
862 $this->date_creation = $this->db->jdate($obj->datec);
863 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
866 $this->db->free($result);
884 $this->initAsSpecimenCommon();
894 $this->lines = array();
897 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_evaluationdet = '.$this->
id));
899 if (is_numeric($result)) {
900 $this->error = $objectline->error;
901 $this->errors = $objectline->errors;
904 $this->lines = $result;
916 global $langs, $conf;
919 if (empty($conf->global->hrm_EVALUATIONLINE_ADDON)) {
920 $conf->global->hrm_EVALUATIONLINE_ADDON =
'mod_evaluationdet_standard';
923 if (!empty($conf->global->hrm_EVALUATIONLINE_ADDON)) {
926 $file = $conf->global->hrm_EVALUATIONLINE_ADDON.
".php";
927 $classname = $conf->global->hrm_EVALUATIONLINE_ADDON;
930 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
931 foreach ($dirmodels as $reldir) {
935 $mybool |= @include_once $dir.$file;
938 if ($mybool ===
false) {
943 if (class_exists($classname)) {
944 $obj =
new $classname();
945 $numref = $obj->getNextValue($this);
947 if ($numref !=
'' && $numref !=
'-1') {
950 $this->error = $obj->error;
955 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
959 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
975 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
977 global $conf, $langs;
980 $includedocgeneration = 0;
985 $modele =
'standard_evaluationdet';
987 if (!empty($this->model_pdf)) {
988 $modele = $this->model_pdf;
989 } elseif (!empty($conf->global->EVALUATIONLINE_ADDON_PDF)) {
990 $modele = $conf->global->EVALUATIONLINE_ADDON_PDF;
994 $modelpath =
"core/modules/hrm/doc/";
996 if ($includedocgeneration && !empty($modele)) {
997 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1012 global $conf, $langs;
1028 $this->db->commit();
1035require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for Evaluationline.
cancel($user, $notrigger=0)
Set cancel status.
fetch($id, $ref=null)
Load object in memory from the database.
getLinesArray()
Create an array of lines.
fetchLines()
Load object lines in memory from the database.
validate($user, $notrigger=0)
Validate object.
getLibStatut($mode=0)
Return the label of the status.
reopen($user, $notrigger=0)
Set back to validated status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
update(User $user, $notrigger=false)
Update object into database.
createFromClone(User $user, $fromid)
Clone an object into another one.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
info($id)
Load the info information in the object.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
__construct(DoliDB $db)
Constructor.
LibStatut($status, $mode=0)
Return the status.
create(User $user, $notrigger=false)
Create object into database.
setDraft($user, $notrigger=0)
Set draft status.
Class to manage Dolibarr users.
dol_dir_list($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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.