dolibarr 21.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 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 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
71 const STATUS_DRAFT = 0;
72 const STATUS_VALIDATED = 1;
73 const STATUS_CANCELED = 9;
74
75
102 // BEGIN MODULEBUILDER PROPERTIES
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,),
117 );
121 public $rowid;
125 public $fk_user_creat;
129 public $fk_user_modif;
133 public $fk_skill;
137 public $fk_evaluation;
141 public $fk_rank;
145 public $required_rank;
149 public $import_key;
150 // END MODULEBUILDER PROPERTIES
151
152
153 // If this object has a subtable with lines
154
155 // /**
156 // * @var string Name of subtable line
157 // */
158 // public $table_element_line = 'hrm_evaluationline';
159
160 // /**
161 // * @var string Field with ID of parent key if this object has a parent
162 // */
163 // public $fk_element = 'fk_evaluationdet';
164
165 // /**
166 // * @var string Name of subtable class that manage subtable lines
167 // */
168 // public $class_element_line = 'EvaluationLine';
169
170 // /**
171 // * @var array List of child tables. To test if we can delete object.
172 // */
173 // protected $childtables = array();
174
175 // /**
176 // * @var array List of child tables. To know object to delete on cascade.
177 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
178 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
179 // */
180 // protected $childtablesoncascade = array('hrm_evaluationdetdet');
181
182 // /**
183 // * @var EvaluationLine[] Array of subtable lines
184 // */
185 // public $lines = array();
186
187
193 public function __construct(DoliDB $db)
194 {
195 global $conf, $langs;
196
197 $this->db = $db;
198
199 $this->ismultientitymanaged = 0;
200 $this->isextrafieldmanaged = 1;
201
202 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
203 $this->fields['rowid']['visible'] = 0;
204 }
205 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
206 $this->fields['entity']['enabled'] = 0;
207 }
208
209 // Example to show how to set values of fields definition dynamically
210 /*if ($user->rights->hrm->evaluationdet->read) {
211 $this->fields['myfield']['visible'] = 1;
212 $this->fields['myfield']['noteditable'] = 0;
213 }*/
214
215 // Unset fields that are disabled
216 foreach ($this->fields as $key => $val) {
217 if (isset($val['enabled']) && empty($val['enabled'])) {
218 unset($this->fields[$key]);
219 }
220 }
221
222 // Translate some data of arrayofkeyval
223 if (is_object($langs)) {
224 foreach ($this->fields as $key => $val) {
225 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
226 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
227 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
228 }
229 }
230 }
231 }
232 }
233
241 public function create(User $user, $notrigger = 0)
242 {
243 $resultcreate = $this->createCommon($user, $notrigger);
244
245 return $resultcreate;
246 }
247
255 public function createFromClone(User $user, $fromid)
256 {
257 global $langs, $extrafields;
258 $error = 0;
259
260 dol_syslog(__METHOD__, LOG_DEBUG);
261
262 $object = new self($this->db);
263
264 $this->db->begin();
265
266 // Load source object
267 $result = $object->fetchCommon($fromid);
268 if ($result > 0 && !empty($object->table_element_line)) {
269 $object->fetchLines();
270 }
271
272 // get lines so they will be clone
273 //foreach($this->lines as $line)
274 // $line->fetch_optionals();
275
276 // Reset some properties
277 unset($object->id);
278 unset($object->fk_user_creat);
279 unset($object->import_key);
280
281 // Clear fields
282 if (property_exists($object, 'ref')) {
283 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
284 }
285 if (property_exists($object, 'label')) {
286 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
287 }
288 if (property_exists($object, 'status')) {
289 $object->status = self::STATUS_DRAFT;
290 }
291 if (property_exists($object, 'date_creation')) {
292 $object->date_creation = dol_now();
293 }
294 if (property_exists($object, 'date_modification')) {
295 $object->date_modification = null;
296 }
297 // ...
298 // Clear extrafields that are unique
299 if (is_array($object->array_options) && count($object->array_options) > 0) {
300 $extrafields->fetch_name_optionals_label($this->table_element);
301 foreach ($object->array_options as $key => $option) {
302 $shortkey = preg_replace('/options_/', '', $key);
303 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
304 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
305 unset($object->array_options[$key]);
306 }
307 }
308 }
309
310 // Create clone
311 $object->context['createfromclone'] = 'createfromclone';
312 $result = $object->createCommon($user);
313 if ($result < 0) {
314 $error++;
316 }
317
318 if (!$error) {
319 // copy internal contacts
320 if ($this->copy_linked_contact($object, 'internal') < 0) {
321 $error++;
322 }
323 }
324
325 if (!$error) {
326 // copy external contacts if same company
327 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
328 if ($this->copy_linked_contact($object, 'external') < 0) {
329 $error++;
330 }
331 }
332 }
333
334 unset($object->context['createfromclone']);
335
336 // End
337 if (!$error) {
338 $this->db->commit();
339 return $object;
340 } else {
341 $this->db->rollback();
342 return -1;
343 }
344 }
345
353 public function fetch($id, $ref = null)
354 {
355 $result = $this->fetchCommon($id, $ref);
356 if ($result > 0 && !empty($this->table_element_line)) {
357 $this->fetchLines();
358 }
359 return $result;
360 }
361
367 public function fetchLines()
368 {
369 $this->lines = array();
370
371 $result = $this->fetchLinesCommon();
372 return $result;
373 }
374
375
388 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
389 {
390 global $conf;
391
392 dol_syslog(__METHOD__, LOG_DEBUG);
393
394 $records = array();
395
396 $sql = 'SELECT ';
397 $sql .= $this->getFieldList('t');
398 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
399 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
400 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
401 } else {
402 $sql .= ' WHERE 1 = 1';
403 }
404
405 // Manage filter
406 $errormessage = '';
407 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
408 if ($errormessage) {
409 $this->errors[] = $errormessage;
410 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
411 return -1;
412 }
413
414 if (!empty($sortfield)) {
415 $sql .= $this->db->order($sortfield, $sortorder);
416 }
417 if (!empty($limit)) {
418 $sql .= ' '.$this->db->plimit($limit, $offset);
419 }
420
421 $resql = $this->db->query($sql);
422 if ($resql) {
423 $num = $this->db->num_rows($resql);
424 $i = 0;
425 while ($i < ($limit ? min($limit, $num) : $num)) {
426 $obj = $this->db->fetch_object($resql);
427
428 $record = new self($this->db);
429 $record->setVarsFromFetchObj($obj);
430
431 $records[$record->id] = $record;
432
433 $i++;
434 }
435 $this->db->free($resql);
436
437 return $records;
438 } else {
439 $this->errors[] = 'Error '.$this->db->lasterror();
440 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
441
442 return -1;
443 }
444 }
445
453 public function update(User $user, $notrigger = 0)
454 {
455 return $this->updateCommon($user, $notrigger);
456 }
457
465 public function delete(User $user, $notrigger = 0)
466 {
467 if ($this->fk_rank) {
468 $skillRank = new SkillRank($this->db);
469 $skillRank->fetch($this->fk_rank);
470 $skillRank->delete($user, $notrigger);
471 }
472 return $this->deleteCommon($user, $notrigger);
473 //return $this->deleteCommon($user, $notrigger, 1);
474 }
475
484 public function deleteLine(User $user, $idline, $notrigger = 0)
485 {
486 if ($this->status < 0) {
487 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
488 return -2;
489 }
490
491 return $this->deleteLineCommon($user, $idline, $notrigger);
492 }
493
494
502 public function validate($user, $notrigger = 0)
503 {
504 global $conf, $langs;
505
506 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
507
508 $error = 0;
509
510 // Protection
511 if ($this->status == self::STATUS_VALIDATED) {
512 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
513 return 0;
514 }
515
516 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->write))
517 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->evaluationdet_advance->validate))))
518 {
519 $this->error='NotEnoughPermissions';
520 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
521 return -1;
522 }*/
523
524 $now = dol_now();
525
526 $this->db->begin();
527
528 // Define new ref
529 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
530 $num = $this->getNextNumRef();
531 } else {
532 $num = $this->ref;
533 }
534 $this->newref = $num;
535
536 if (!empty($num)) {
537 // Validate
538 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
539 $sql .= " SET ref = '".$this->db->escape($num)."',";
540 $sql .= " status = ".self::STATUS_VALIDATED;
541 if (!empty($this->fields['date_validation'])) {
542 $sql .= ", date_validation = '".$this->db->idate($now)."'";
543 }
544 if (!empty($this->fields['fk_user_valid'])) {
545 $sql .= ", fk_user_valid = ".((int) $user->id);
546 }
547 $sql .= " WHERE rowid = ".((int) $this->id);
548
549 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
550 $resql = $this->db->query($sql);
551 if (!$resql) {
552 dol_print_error($this->db);
553 $this->error = $this->db->lasterror();
554 $error++;
555 }
556
557 if (!$error && !$notrigger) {
558 // Call trigger
559 $result = $this->call_trigger('HRM_EVALUATIONLINE_VALIDATE', $user);
560 if ($result < 0) {
561 $error++;
562 }
563 // End call triggers
564 }
565 }
566
567 if (!$error) {
568 $this->oldref = $this->ref;
569
570 // Rename directory if dir was a temporary ref
571 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
572 // Now we rename also files into index
573 $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)."'";
574 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
575 $resql = $this->db->query($sql);
576 if (!$resql) {
577 $error++;
578 $this->error = $this->db->lasterror();
579 }
580 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluationline/".$this->db->escape($this->newref)."'";
581 $sql .= " WHERE filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
582 $resql = $this->db->query($sql);
583 if (!$resql) {
584 $error++;
585 $this->error = $this->db->lasterror();
586 }
587
588 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
589 $oldref = dol_sanitizeFileName($this->ref);
590 $newref = dol_sanitizeFileName($num);
591 $dirsource = $conf->hrm->dir_output.'/evaluationline/'.$oldref;
592 $dirdest = $conf->hrm->dir_output.'/evaluationline/'.$newref;
593 if (!$error && file_exists($dirsource)) {
594 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
595
596 if (@rename($dirsource, $dirdest)) {
597 dol_syslog("Rename ok");
598 // Rename docs starting with $oldref with $newref
599 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluationline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
600 foreach ($listoffiles as $fileentry) {
601 $dirsource = $fileentry['name'];
602 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
603 $dirsource = $fileentry['path'].'/'.$dirsource;
604 $dirdest = $fileentry['path'].'/'.$dirdest;
605 @rename($dirsource, $dirdest);
606 }
607 }
608 }
609 }
610 }
611
612 // Set new ref and current status
613 if (!$error) {
614 $this->ref = $num;
615 $this->status = self::STATUS_VALIDATED;
616 }
617
618 if (!$error) {
619 $this->db->commit();
620 return 1;
621 } else {
622 $this->db->rollback();
623 return -1;
624 }
625 }
626
627
635 public function setDraft($user, $notrigger = 0)
636 {
637 // Protection
638 if ($this->status <= self::STATUS_DRAFT) {
639 return 0;
640 }
641
642 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
643 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
644 {
645 $this->error='Permission denied';
646 return -1;
647 }*/
648
649 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATIONLINE_UNVALIDATE');
650 }
651
659 public function cancel($user, $notrigger = 0)
660 {
661 // Protection
662 if ($this->status != self::STATUS_VALIDATED) {
663 return 0;
664 }
665
666 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
667 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
668 {
669 $this->error='Permission denied';
670 return -1;
671 }*/
672
673 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATIONLINE_CANCEL');
674 }
675
683 public function reopen($user, $notrigger = 0)
684 {
685 // Protection
686 if ($this->status != self::STATUS_CANCELED) {
687 return 0;
688 }
689
690 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
691 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
692 {
693 $this->error='Permission denied';
694 return -1;
695 }*/
696
697 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATIONLINE_REOPEN');
698 }
699
710 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
711 {
712 global $conf, $langs, $hookmanager;
713
714 if (!empty($conf->dol_no_mouse_hover)) {
715 $notooltip = 1; // Force disable tooltips
716 }
717
718 $result = '';
719
720 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluationdet").'</u>';
721 if (isset($this->status)) {
722 $label .= ' '.$this->getLibStatut(5);
723 }
724 $label .= '<br>';
725 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
726
727 $url = dol_buildpath('/hrm/evaluationdet_card.php', 1).'?id='.$this->id;
728
729 if ($option != 'nolink') {
730 // Add param to save lastsearch_values or not
731 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
732 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
733 $add_save_lastsearch_values = 1;
734 }
735 if ($add_save_lastsearch_values) {
736 $url .= '&save_lastsearch_values=1';
737 }
738 }
739
740 $linkclose = '';
741 if (empty($notooltip)) {
742 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
743 $label = $langs->trans("ShowEvaluationdet");
744 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
745 }
746 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
747 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
748 } else {
749 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
750 }
751
752 if ($option == 'nolink') {
753 $linkstart = '<span';
754 } else {
755 $linkstart = '<a href="'.$url.'"';
756 }
757 $linkstart .= $linkclose.'>';
758 if ($option == 'nolink') {
759 $linkend = '</span>';
760 } else {
761 $linkend = '</a>';
762 }
763
764 $result .= $linkstart;
765
766 if (empty($this->showphoto_on_popup)) {
767 if ($withpicto) {
768 $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);
769 }
770 } else {
771 if ($withpicto) {
772 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
773
774 list($class, $module) = explode('@', $this->picto);
775 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
776 $filearray = dol_dir_list($upload_dir, "files");
777 $filename = $filearray[0]['name'];
778 if (!empty($filename)) {
779 $pospoint = strpos($filearray[0]['name'], '.');
780
781 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
782 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
783 $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>';
784 } else {
785 $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>';
786 }
787
788 $result .= '</div>';
789 } else {
790 $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);
791 }
792 }
793 }
794
795 if ($withpicto != 2) {
796 $result .= $this->ref;
797 }
798
799 $result .= $linkend;
800 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
801
802 global $action, $hookmanager;
803 $hookmanager->initHooks(array('evaluationlinedao'));
804 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
805 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
806 if ($reshook > 0) {
807 $result = $hookmanager->resPrint;
808 } else {
809 $result .= $hookmanager->resPrint;
810 }
811
812 return $result;
813 }
814
821 public function getLibStatut($mode = 0)
822 {
823 return $this->LibStatut($this->status, $mode);
824 }
825
826 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
834 public function LibStatut($status, $mode = 0)
835 {
836 // phpcs:enable
837 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
838 global $langs;
839 //$langs->load("hrm");
840 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
841 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
842 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
843 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
844 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
845 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
846 }
847
848 $statusType = 'status'.$status;
849 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
850 if ($status == self::STATUS_CANCELED) {
851 $statusType = 'status6';
852 }
853
854 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
855 }
856
863 public function info($id)
864 {
865 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
866 $sql .= ' fk_user_creat, fk_user_modif';
867 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
868 $sql .= ' WHERE t.rowid = '.((int) $id);
869 $result = $this->db->query($sql);
870 if ($result) {
871 if ($this->db->num_rows($result)) {
872 $obj = $this->db->fetch_object($result);
873
874 $this->id = $obj->rowid;
875
876 $this->user_creation_id = $obj->fk_user_creat;
877 $this->user_modification_id = $obj->fk_user_modif;
878 $this->date_creation = $this->db->jdate($obj->datec);
879 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
880 }
881
882 $this->db->free($result);
883 } else {
884 dol_print_error($this->db);
885 }
886 }
887
894 public function initAsSpecimen()
895 {
896 // Set here init that are not commonf fields
897 // $this->property1 = ...
898 // $this->property2 = ...
899
900 return $this->initAsSpecimenCommon();
901 }
902
908 public function getLinesArray()
909 {
910 $this->lines = array();
911
912 $objectline = new EvaluationLine($this->db);
913 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_evaluationdet:=:'.((int) $this->id).')');
914
915 if (is_numeric($result)) {
916 $this->setErrorsFromObject($objectline);
917 return $result;
918 } else {
919 $this->lines = $result;
920 return $this->lines;
921 }
922 }
923
929 public function getNextNumRef()
930 {
931 global $langs, $conf;
932 $langs->load("hrm");
933
934 if (!getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
935 $conf->global->hrm_EVALUATIONLINE_ADDON = 'mod_evaluationdet_standard';
936 }
937
938 if (getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
939 $mybool = false;
940
941 $file = getDolGlobalString('hrm_EVALUATIONLINE_ADDON') . ".php";
942 $classname = getDolGlobalString('hrm_EVALUATIONLINE_ADDON');
943
944 // Include file with class
945 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
946 foreach ($dirmodels as $reldir) {
947 $dir = dol_buildpath($reldir."core/modules/hrm/");
948
949 // Load file with numbering class (if found)
950 $mybool = ((bool) @include_once $dir.$file) || $mybool;
951 }
952
953 if (!$mybool) {
954 dol_print_error(null, "Failed to include file ".$file);
955 return '';
956 }
957
958 if (class_exists($classname)) {
959 $obj = new $classname();
960 '@phan-var-force ModeleNumRefEvaluation $obj';
961 $numref = $obj->getNextValue($this);
962
963 if ($numref != '' && $numref != '-1') {
964 return $numref;
965 } else {
966 $this->error = $obj->error;
967 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
968 return "";
969 }
970 } else {
971 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
972 return "";
973 }
974 } else {
975 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
976 return "";
977 }
978 }
979
991 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
992 {
993 global $conf, $langs;
994
995 $result = 0;
996 $includedocgeneration = 0;
997
998 $langs->load("hrm");
999
1000 if (!dol_strlen($modele)) {
1001 $modele = 'standard_evaluationdet';
1002
1003 if (!empty($this->model_pdf)) {
1004 $modele = $this->model_pdf;
1005 } elseif (getDolGlobalString('EVALUATIONLINE_ADDON_PDF')) {
1006 $modele = getDolGlobalString('EVALUATIONLINE_ADDON_PDF');
1007 }
1008 }
1009
1010 $modelpath = "core/modules/hrm/doc/";
1011
1012 if ($includedocgeneration && !empty($modele)) {
1013 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1014 }
1015
1016 return $result;
1017 }
1018}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
$object ref
Definition info.php:79
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.
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.
getLibStatut($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
createFromClone(User $user, $fromid)
Clone an object into another one.
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.
setDraft($user, $notrigger=0)
Set draft status.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
getLinesArray()
Create an array of lines.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
cancel($user, $notrigger=0)
Set cancel status.
LibStatut($status, $mode=0)
Return the status.
validate($user, $notrigger=0)
Validate object.
reopen($user, $notrigger=0)
Set back to validated status.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
fetchLines()
Load object lines in memory from the 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:162
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:63
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.
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.