dolibarr 24.0.0-beta
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,),
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
347 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
348 {
349 global $conf, $langs, $hookmanager;
350
351 if (!empty($conf->dol_no_mouse_hover)) {
352 $notooltip = 1; // Force disable tooltips
353 }
354
355 $result = '';
356
357 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluationdet").'</u>';
358 if (isset($this->status)) {
359 $label .= ' '.$this->getLibStatut(5);
360 }
361 $label .= '<br>';
362 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
363
364 $url = dol_buildpath('/hrm/evaluationdet_card.php', 1).'?id='.$this->id;
365
366 if ($option != 'nolink') {
367 // Add param to save lastsearch_values or not
368 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
369 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
370 $add_save_lastsearch_values = 1;
371 }
372 if ($add_save_lastsearch_values) {
373 $url .= '&save_lastsearch_values=1';
374 }
375 }
376
377 $linkclose = '';
378 if (empty($notooltip)) {
379 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
380 $label = $langs->trans("ShowEvaluationdet");
381 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
382 }
383 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
384 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
385 } else {
386 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
387 }
388
389 if ($option == 'nolink') {
390 $linkstart = '<span';
391 } else {
392 $linkstart = '<a href="'.$url.'"';
393 }
394 $linkstart .= $linkclose.'>';
395 if ($option == 'nolink') {
396 $linkend = '</span>';
397 } else {
398 $linkend = '</a>';
399 }
400
401 $result .= $linkstart;
402
403 if (empty($this->showphoto_on_popup)) {
404 if ($withpicto) {
405 $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);
406 }
407 } else {
408 if ($withpicto) {
409 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
410
411 list($class, $module) = explode('@', $this->picto);
412 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
413 $filearray = dol_dir_list($upload_dir, "files");
414 $filename = $filearray[0]['name'];
415 if (!empty($filename)) {
416 $pospoint = strpos($filearray[0]['name'], '.');
417
418 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
419 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
420 $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>';
421 } else {
422 $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>';
423 }
424
425 $result .= '</div>';
426 } else {
427 $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);
428 }
429 }
430 }
431
432 if ($withpicto != 2) {
433 $result .= $this->ref;
434 }
435
436 $result .= $linkend;
437 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
438
439 global $action, $hookmanager;
440 $hookmanager->initHooks(array('evaluationlinedao'));
441 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
442 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
443 if ($reshook > 0) {
444 $result = $hookmanager->resPrint;
445 } else {
446 $result .= $hookmanager->resPrint;
447 }
448
449 return $result;
450 }
451
458 public function info($id)
459 {
460 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
461 $sql .= ' fk_user_creat, fk_user_modif';
462 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
463 $sql .= ' WHERE t.rowid = '.((int) $id);
464 $result = $this->db->query($sql);
465 if ($result) {
466 if ($this->db->num_rows($result)) {
467 $obj = $this->db->fetch_object($result);
468
469 $this->id = $obj->rowid;
470
471 $this->user_creation_id = $obj->fk_user_creat;
472 $this->user_modification_id = $obj->fk_user_modif;
473 $this->date_creation = $this->db->jdate($obj->datec);
474 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
475 }
476
477 $this->db->free($result);
478 } else {
479 dol_print_error($this->db);
480 }
481 }
482
489 public function initAsSpecimen()
490 {
491 // Set here init that are not commonf fields
492 // $this->property1 = ...
493 // $this->property2 = ...
494
495 return $this->initAsSpecimenCommon();
496 }
497
503 public function getNextNumRef()
504 {
505 global $langs, $conf;
506 $langs->load("hrm");
507
508 if (!getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
509 $conf->global->hrm_EVALUATIONLINE_ADDON = 'mod_evaluationdet_standard';
510 }
511
512 if (getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
513 $mybool = false;
514
515 $file = getDolGlobalString('hrm_EVALUATIONLINE_ADDON') . ".php";
516 $classname = getDolGlobalString('hrm_EVALUATIONLINE_ADDON');
517
518 // Include file with class
519 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
520 foreach ($dirmodels as $reldir) {
521 $dir = dol_buildpath($reldir."core/modules/hrm/");
522
523 // Load file with numbering class (if found)
524 $mybool = ((bool) @include_once $dir.$file) || $mybool;
525 }
526
527 if (!$mybool) {
528 dol_print_error(null, "Failed to include file ".$file);
529 return '';
530 }
531
532 if (class_exists($classname)) {
533 $obj = new $classname();
534 '@phan-var-force ModeleNumRefEvaluation $obj';
536 $numref = $obj->getNextValue($this);
537
538 if ($numref != '' && $numref != '-1') {
539 return $numref;
540 } else {
541 $this->error = $obj->error;
542 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
543 return "";
544 }
545 } else {
546 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
547 return "";
548 }
549 } else {
550 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
551 return "";
552 }
553 }
554}
$object ref
Definition info.php:90
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 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.
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.
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:168
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
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_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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...
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.