dolibarr 25.0.0-alpha
evaluationdet.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5 * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6 * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT . '/core/class/commonobjectline.class.php';
32require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
33
34
39{
43 public $module = 'hrm';
44
48 public $element = 'evaluationdet';
49
53 public $table_element = 'hrm_evaluationdet';
54
58 public $parent_element = 'hrm_evaluation';
59
63 public $fk_parent_attribute = 'fk_evaluation';
64
68 public $picto = 'evaluationdet@hrm';
69
70
97 // BEGIN MODULEBUILDER PROPERTIES
101 public $fields = array(
102 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
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 'fk_skill' => array('type' => 'integer:Skill:hrm/class/skill.class.php:1', 'label' => 'Skill', 'enabled' => 1, 'position' => 3, 'notnull' => 1, 'visible' => 1, 'index' => 1,),
108 'fk_evaluation' => array('type' => 'integer:Evaluation:hrm/class/evaluation.class.php:1', 'label' => 'Evaluation', 'enabled' => 1, 'position' => 3, 'notnull' => 1, 'visible' => 1, 'index' => 1,),
109 'rankorder' => array('type' => 'integer', 'label' => 'Rank', 'enabled' => 1, 'position' => 4, 'notnull' => 1, 'visible' => 1, 'uieditable' => 1,),
110 'required_rank' => array('type' => 'integer', 'label' => 'requiredRank', 'enabled' => 1, 'position' => 5, 'notnull' => 1, 'visible' => 1,),
111 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
112 );
116 public $rowid;
120 public $fk_user_creat;
124 public $fk_user_modif;
128 public $fk_skill;
132 public $fk_evaluation;
136 public $fk_rank;
140 public $rankorder;
144 public $required_rank;
148 public $import_key;
149 // END MODULEBUILDER PROPERTIES
150
156 public function __construct(DoliDB $db)
157 {
158 global $conf, $langs;
159
160 $this->db = $db;
161
162 $this->ismultientitymanaged = 0;
163 $this->isextrafieldmanaged = 1;
164
165 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
166 $this->fields['rowid']['visible'] = 0;
167 }
168 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
169 $this->fields['entity']['enabled'] = 0;
170 }
171
172 // Unset fields that are disabled
173 foreach ($this->fields as $key => $val) {
174 if (isset($val['enabled']) && empty($val['enabled'])) {
175 unset($this->fields[$key]);
176 }
177 }
178
179 // Translate some data of arrayofkeyval
180 if (is_object($langs)) {
181 foreach ($this->fields as $key => $val) {
182 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
183 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
184 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
185 }
186 }
187 }
188 }
189 }
190
198 public function create(User $user, $notrigger = 0)
199 {
200 $resultcreate = $this->createCommon($user, $notrigger);
201
202 return $resultcreate;
203 }
204
212 public function fetch($id, $ref = null)
213 {
214 $result = $this->fetchCommon($id, $ref);
215
216 return $result;
217 }
218
231 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
232 {
233 global $conf;
234
235 dol_syslog(__METHOD__, LOG_DEBUG);
236
237 $records = array();
238
239 $sql = 'SELECT ';
240 $sql .= $this->getFieldList('t');
241 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
242 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
243 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
244 } else {
245 $sql .= ' WHERE 1 = 1';
246 }
247
248 // Manage filter
249 $errormessage = '';
250 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
251 if ($errormessage) {
252 $this->errors[] = $errormessage;
253 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
254 return -1;
255 }
256
257 if (!empty($sortfield)) {
258 $sql .= $this->db->order($sortfield, $sortorder);
259 }
260 if (!empty($limit)) {
261 $sql .= ' '.$this->db->plimit($limit, $offset);
262 }
263
264 $resql = $this->db->query($sql);
265 if ($resql) {
266 $num = $this->db->num_rows($resql);
267 $i = 0;
268 while ($i < ($limit ? min($limit, $num) : $num)) {
269 $obj = $this->db->fetch_object($resql);
270
271 $record = new self($this->db);
272 $record->setVarsFromFetchObj($obj);
273
274 $records[$record->id] = $record;
275
276 $i++;
277 }
278 $this->db->free($resql);
279
280 return $records;
281 } else {
282 $this->errors[] = 'Error '.$this->db->lasterror();
283 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
284
285 return -1;
286 }
287 }
288
296 public function update(User $user, $notrigger = 0)
297 {
298 return $this->updateCommon($user, $notrigger);
299 }
300
308 public function delete(User $user, $notrigger = 0)
309 {
310 if ($this->fk_rank) {
311 $skillRank = new SkillRank($this->db);
312 $skillRank->fetch($this->fk_rank);
313 $skillRank->delete($user, $notrigger);
314 }
315 return $this->deleteCommon($user, $notrigger);
316 //return $this->deleteCommon($user, $notrigger, 1);
317 }
318
327 public function deleteLine(User $user, $idline, $notrigger = 0)
328 {
329 if ($this->status < 0) {
330 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
331 return -2;
332 }
333
334 return $this->deleteLineCommon($user, $idline, $notrigger);
335 }
336
344 public function hasUserPermission(User $user, $mode = 'write')
345 {
346 if ($mode == 'create') {
347 $mode = 'write';
348 }
349
350 return in_array($mode, array('read', 'write', 'delete')) && $user->hasRight('hrm', 'evaluation', $mode);
351 }
352
359 protected function isFieldBlockedByObjectState($field)
360 {
361 require_once DOL_DOCUMENT_ROOT.'/hrm/class/evaluation.class.php';
362 $evaluation = new Evaluation($this->db);
363 if ($evaluation->fetch($this->fk_evaluation) <= 0) {
364 return true;
365 }
366
367 return (int) $evaluation->status !== Evaluation::STATUS_DRAFT;
368 }
369
377 public function getFieldValueFromAjaxPost($field)
378 {
379 $value = parent::getFieldValueFromAjaxPost($field);
380
381 if ($field == 'rankorder' && !is_null($value)) {
382 require_once DOL_DOCUMENT_ROOT.'/hrm/class/skill.class.php';
383 if ($value < -1 || $value > getDolGlobalInt('HRM_MAXRANK', Skill::DEFAULT_MAX_RANK_PER_SKILL)) {
384 return null;
385 }
386 }
387
388 return $value;
389 }
390
401 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
402 {
403 global $conf, $langs, $hookmanager;
404
405 if (!empty($conf->dol_no_mouse_hover)) {
406 $notooltip = 1; // Force disable tooltips
407 }
408
409 $result = '';
410
411 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluationdet").'</u>';
412 if (isset($this->status)) {
413 $label .= ' '.$this->getLibStatut(5);
414 }
415 $label .= '<br>';
416 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
417
418 $url = dol_buildpath('/hrm/evaluationdet_card.php', 1).'?id='.$this->id;
419
420 if ($option != 'nolink') {
421 // Add param to save lastsearch_values or not
422 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
423 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
424 $add_save_lastsearch_values = 1;
425 }
426 if ($add_save_lastsearch_values) {
427 $url .= '&save_lastsearch_values=1';
428 }
429 }
430
431 $linkclose = '';
432 if (empty($notooltip)) {
433 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
434 $label = $langs->trans("ShowEvaluationdet");
435 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
436 }
437 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
438 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
439 } else {
440 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
441 }
442
443 if ($option == 'nolink') {
444 $linkstart = '<span';
445 } else {
446 $linkstart = '<a href="'.$url.'"';
447 }
448 $linkstart .= $linkclose.'>';
449 if ($option == 'nolink') {
450 $linkend = '</span>';
451 } else {
452 $linkend = '</a>';
453 }
454
455 $result .= $linkstart;
456
457 if (empty($this->showphoto_on_popup)) {
458 if ($withpicto) {
459 $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);
460 }
461 } else {
462 if ($withpicto) {
463 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
464
465 list($class, $module) = explode('@', $this->picto);
466 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
467 $filearray = dol_dir_list($upload_dir, "files");
468 $filename = $filearray[0]['name'];
469 if (!empty($filename)) {
470 $pospoint = strpos($filearray[0]['name'], '.');
471
472 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.dol_substr($filename, 0, $pospoint).'_mini'.dol_substr($filename, $pospoint);
473 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
474 $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>';
475 } else {
476 $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>';
477 }
478
479 $result .= '</div>';
480 } else {
481 $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);
482 }
483 }
484 }
485
486 if ($withpicto != 2) {
487 $result .= $this->ref;
488 }
489
490 $result .= $linkend;
491 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
492
493 global $action, $hookmanager;
494 $hookmanager->initHooks(array('evaluationlinedao'));
495 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
496 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
497 if ($reshook > 0) {
498 $result = $hookmanager->resPrint;
499 } else {
500 $result .= $hookmanager->resPrint;
501 }
502
503 return $result;
504 }
505
512 public function info($id)
513 {
514 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
515 $sql .= ' fk_user_creat, fk_user_modif';
516 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
517 $sql .= ' WHERE t.rowid = '.((int) $id);
518 $result = $this->db->query($sql);
519 if ($result) {
520 if ($this->db->num_rows($result)) {
521 $obj = $this->db->fetch_object($result);
522
523 $this->id = $obj->rowid;
524
525 $this->user_creation_id = $obj->fk_user_creat;
526 $this->user_modification_id = $obj->fk_user_modif;
527 $this->date_creation = $this->db->jdate($obj->datec);
528 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
529 }
530
531 $this->db->free($result);
532 } else {
533 dol_print_error($this->db);
534 }
535 }
536
543 public function initAsSpecimen()
544 {
545 // Set here init that are not commonf fields
546 // $this->property1 = ...
547 // $this->property2 = ...
548
549 return $this->initAsSpecimenCommon();
550 }
551
557 public function getNextNumRef()
558 {
559 global $langs, $conf;
560 $langs->load("hrm");
561
562 if (!getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
563 $conf->global->hrm_EVALUATIONLINE_ADDON = 'mod_evaluationdet_standard';
564 }
565
566 if (getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
567 $mybool = false;
568
569 $file = getDolGlobalString('hrm_EVALUATIONLINE_ADDON') . ".php";
570 $classname = getDolGlobalString('hrm_EVALUATIONLINE_ADDON');
571
572 // Include file with class
573 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
574 foreach ($dirmodels as $reldir) {
575 $dir = dol_buildpath($reldir."core/modules/hrm/");
576
577 // Load file with numbering class (if found)
578 $mybool = ((bool) @include_once $dir.$file) || $mybool;
579 }
580
581 if (!$mybool) {
582 dol_print_error(null, "Failed to include file ".$file);
583 return '';
584 }
585
586 if (class_exists($classname)) {
587 $obj = new $classname();
588 '@phan-var-force ModeleNumRefEvaluation $obj';
590 $numref = $obj->getNextValue($this);
591
592 if ($numref != '' && $numref != '-1') {
593 return $numref;
594 } else {
595 $this->error = $obj->error;
596 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
597 return "";
598 }
599 } else {
600 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
601 return "";
602 }
603 } else {
604 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
605 return "";
606 }
607 }
608}
$object ref
Definition info.php:90
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.
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.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
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.
Class for Evaluation.
Class for EvaluationLine.
update(User $user, $notrigger=0)
Update object into database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetch($id, $ref=null)
Load object in memory from the database.
hasUserPermission(User $user, $mode='write')
Check if user has a permission on evaluations, the lines of an evaluation have no permission of their...
isFieldBlockedByObjectState($field)
A line can be changed only while its evaluation is a draft.
info($id)
Load the info information in the object.
create(User $user, $notrigger=0)
Create object into database.
__construct(DoliDB $db)
Constructor.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $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=0)
Delete a line of object in database.
getFieldValueFromAjaxPost($field)
Return the value of a field posted by the user interface (core/ajax/objectfield.php).
Class for SkillRank.
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...
Definition index.php:169
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.
Definition files.lib.php:66
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.