dolibarr 22.0.5
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->user_creation_id);
280 unset($object->import_key);
281
282 // Clear fields
283 if (property_exists($object, 'ref')) {
284 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
285 }
286 if (property_exists($object, 'status')) {
287 $object->status = self::STATUS_DRAFT;
288 }
289 if (property_exists($object, 'date_creation')) {
290 $object->date_creation = dol_now();
291 }
292 if (property_exists($object, 'date_modification')) {
293 $object->date_modification = null;
294 }
295 // ...
296 // Clear extrafields that are unique
297 if (is_array($object->array_options) && count($object->array_options) > 0) {
298 $extrafields->fetch_name_optionals_label($this->table_element);
299 foreach ($object->array_options as $key => $option) {
300 $shortkey = preg_replace('/options_/', '', $key);
301 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
302 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
303 unset($object->array_options[$key]);
304 }
305 }
306 }
307
308 // Create clone
309 $object->context['createfromclone'] = 'createfromclone';
310 $result = $object->createCommon($user);
311 if ($result < 0) {
312 $error++;
314 }
315
316 if (!$error) {
317 // copy internal contacts
318 if ($this->copy_linked_contact($object, 'internal') < 0) {
319 $error++;
320 }
321 }
322
323 if (!$error) {
324 // copy external contacts if same company
325 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
326 if ($this->copy_linked_contact($object, 'external') < 0) {
327 $error++;
328 }
329 }
330 }
331
332 unset($object->context['createfromclone']);
333
334 // End
335 if (!$error) {
336 $this->db->commit();
337 return $object;
338 } else {
339 $this->db->rollback();
340 return -1;
341 }
342 }
343
351 public function fetch($id, $ref = null)
352 {
353 $result = $this->fetchCommon($id, $ref);
354 if ($result > 0 && !empty($this->table_element_line)) {
355 $this->fetchLines();
356 }
357 return $result;
358 }
359
365 public function fetchLines()
366 {
367 $this->lines = array();
368
369 $result = $this->fetchLinesCommon();
370 return $result;
371 }
372
373
386 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
387 {
388 global $conf;
389
390 dol_syslog(__METHOD__, LOG_DEBUG);
391
392 $records = array();
393
394 $sql = 'SELECT ';
395 $sql .= $this->getFieldList('t');
396 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
397 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
398 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
399 } else {
400 $sql .= ' WHERE 1 = 1';
401 }
402
403 // Manage filter
404 $errormessage = '';
405 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
406 if ($errormessage) {
407 $this->errors[] = $errormessage;
408 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
409 return -1;
410 }
411
412 if (!empty($sortfield)) {
413 $sql .= $this->db->order($sortfield, $sortorder);
414 }
415 if (!empty($limit)) {
416 $sql .= ' '.$this->db->plimit($limit, $offset);
417 }
418
419 $resql = $this->db->query($sql);
420 if ($resql) {
421 $num = $this->db->num_rows($resql);
422 $i = 0;
423 while ($i < ($limit ? min($limit, $num) : $num)) {
424 $obj = $this->db->fetch_object($resql);
425
426 $record = new self($this->db);
427 $record->setVarsFromFetchObj($obj);
428
429 $records[$record->id] = $record;
430
431 $i++;
432 }
433 $this->db->free($resql);
434
435 return $records;
436 } else {
437 $this->errors[] = 'Error '.$this->db->lasterror();
438 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
439
440 return -1;
441 }
442 }
443
451 public function update(User $user, $notrigger = 0)
452 {
453 return $this->updateCommon($user, $notrigger);
454 }
455
463 public function delete(User $user, $notrigger = 0)
464 {
465 if ($this->fk_rank) {
466 $skillRank = new SkillRank($this->db);
467 $skillRank->fetch($this->fk_rank);
468 $skillRank->delete($user, $notrigger);
469 }
470 return $this->deleteCommon($user, $notrigger);
471 //return $this->deleteCommon($user, $notrigger, 1);
472 }
473
482 public function deleteLine(User $user, $idline, $notrigger = 0)
483 {
484 if ($this->status < 0) {
485 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
486 return -2;
487 }
488
489 return $this->deleteLineCommon($user, $idline, $notrigger);
490 }
491
492
500 public function validate($user, $notrigger = 0)
501 {
502 global $conf, $langs;
503
504 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
505
506 $error = 0;
507
508 // Protection
509 if ($this->status == self::STATUS_VALIDATED) {
510 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
511 return 0;
512 }
513
514 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->write))
515 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->evaluationdet_advance->validate))))
516 {
517 $this->error='NotEnoughPermissions';
518 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
519 return -1;
520 }*/
521
522 $now = dol_now();
523
524 $this->db->begin();
525
526 // Define new ref
527 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
528 $num = $this->getNextNumRef();
529 } else {
530 $num = $this->ref;
531 }
532 $this->newref = $num;
533
534 if (!empty($num)) {
535 // Validate
536 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
537 $sql .= " SET ref = '".$this->db->escape($num)."',";
538 $sql .= " status = ".self::STATUS_VALIDATED;
539 if (!empty($this->fields['date_validation'])) {
540 $sql .= ", date_validation = '".$this->db->idate($now)."'";
541 }
542 if (!empty($this->fields['fk_user_valid'])) {
543 $sql .= ", fk_user_valid = ".((int) $user->id);
544 }
545 $sql .= " WHERE rowid = ".((int) $this->id);
546
547 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
548 $resql = $this->db->query($sql);
549 if (!$resql) {
550 dol_print_error($this->db);
551 $this->error = $this->db->lasterror();
552 $error++;
553 }
554
555 if (!$error && !$notrigger) {
556 // Call trigger
557 $result = $this->call_trigger('HRM_EVALUATIONLINE_VALIDATE', $user);
558 if ($result < 0) {
559 $error++;
560 }
561 // End call triggers
562 }
563 }
564
565 if (!$error) {
566 $this->oldref = $this->ref;
567
568 // Rename directory if dir was a temporary ref
569 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
570 // Now we rename also files into index
571 $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)."'";
572 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
573 $resql = $this->db->query($sql);
574 if (!$resql) {
575 $error++;
576 $this->error = $this->db->lasterror();
577 }
578 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluationline/".$this->db->escape($this->newref)."'";
579 $sql .= " WHERE filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
580 $resql = $this->db->query($sql);
581 if (!$resql) {
582 $error++;
583 $this->error = $this->db->lasterror();
584 }
585
586 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
587 $oldref = dol_sanitizeFileName($this->ref);
588 $newref = dol_sanitizeFileName($num);
589 $dirsource = $conf->hrm->dir_output.'/evaluationline/'.$oldref;
590 $dirdest = $conf->hrm->dir_output.'/evaluationline/'.$newref;
591 if (!$error && file_exists($dirsource)) {
592 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
593
594 if (@rename($dirsource, $dirdest)) {
595 dol_syslog("Rename ok");
596 // Rename docs starting with $oldref with $newref
597 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluationline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
598 foreach ($listoffiles as $fileentry) {
599 $dirsource = $fileentry['name'];
600 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
601 $dirsource = $fileentry['path'].'/'.$dirsource;
602 $dirdest = $fileentry['path'].'/'.$dirdest;
603 @rename($dirsource, $dirdest);
604 }
605 }
606 }
607 }
608 }
609
610 // Set new ref and current status
611 if (!$error) {
612 $this->ref = $num;
613 $this->status = self::STATUS_VALIDATED;
614 }
615
616 if (!$error) {
617 $this->db->commit();
618 return 1;
619 } else {
620 $this->db->rollback();
621 return -1;
622 }
623 }
624
625
633 public function setDraft($user, $notrigger = 0)
634 {
635 // Protection
636 if ($this->status <= self::STATUS_DRAFT) {
637 return 0;
638 }
639
640 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
641 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
642 {
643 $this->error='Permission denied';
644 return -1;
645 }*/
646
647 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATIONLINE_UNVALIDATE');
648 }
649
657 public function cancel($user, $notrigger = 0)
658 {
659 // Protection
660 if ($this->status != self::STATUS_VALIDATED) {
661 return 0;
662 }
663
664 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
665 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
666 {
667 $this->error='Permission denied';
668 return -1;
669 }*/
670
671 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATIONLINE_CANCEL');
672 }
673
681 public function reopen($user, $notrigger = 0)
682 {
683 // Protection
684 if ($this->status != self::STATUS_CANCELED) {
685 return 0;
686 }
687
688 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
689 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
690 {
691 $this->error='Permission denied';
692 return -1;
693 }*/
694
695 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATIONLINE_REOPEN');
696 }
697
708 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
709 {
710 global $conf, $langs, $hookmanager;
711
712 if (!empty($conf->dol_no_mouse_hover)) {
713 $notooltip = 1; // Force disable tooltips
714 }
715
716 $result = '';
717
718 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluationdet").'</u>';
719 if (isset($this->status)) {
720 $label .= ' '.$this->getLibStatut(5);
721 }
722 $label .= '<br>';
723 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
724
725 $url = dol_buildpath('/hrm/evaluationdet_card.php', 1).'?id='.$this->id;
726
727 if ($option != 'nolink') {
728 // Add param to save lastsearch_values or not
729 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
730 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
731 $add_save_lastsearch_values = 1;
732 }
733 if ($add_save_lastsearch_values) {
734 $url .= '&save_lastsearch_values=1';
735 }
736 }
737
738 $linkclose = '';
739 if (empty($notooltip)) {
740 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
741 $label = $langs->trans("ShowEvaluationdet");
742 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
743 }
744 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
745 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
746 } else {
747 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
748 }
749
750 if ($option == 'nolink') {
751 $linkstart = '<span';
752 } else {
753 $linkstart = '<a href="'.$url.'"';
754 }
755 $linkstart .= $linkclose.'>';
756 if ($option == 'nolink') {
757 $linkend = '</span>';
758 } else {
759 $linkend = '</a>';
760 }
761
762 $result .= $linkstart;
763
764 if (empty($this->showphoto_on_popup)) {
765 if ($withpicto) {
766 $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);
767 }
768 } else {
769 if ($withpicto) {
770 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
771
772 list($class, $module) = explode('@', $this->picto);
773 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
774 $filearray = dol_dir_list($upload_dir, "files");
775 $filename = $filearray[0]['name'];
776 if (!empty($filename)) {
777 $pospoint = strpos($filearray[0]['name'], '.');
778
779 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
780 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
781 $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>';
782 } else {
783 $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>';
784 }
785
786 $result .= '</div>';
787 } else {
788 $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);
789 }
790 }
791 }
792
793 if ($withpicto != 2) {
794 $result .= $this->ref;
795 }
796
797 $result .= $linkend;
798 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
799
800 global $action, $hookmanager;
801 $hookmanager->initHooks(array('evaluationlinedao'));
802 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
803 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
804 if ($reshook > 0) {
805 $result = $hookmanager->resPrint;
806 } else {
807 $result .= $hookmanager->resPrint;
808 }
809
810 return $result;
811 }
812
819 public function getLibStatut($mode = 0)
820 {
821 return $this->LibStatut($this->status, $mode);
822 }
823
824 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
832 public function LibStatut($status, $mode = 0)
833 {
834 // phpcs:enable
835 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
836 global $langs;
837 //$langs->load("hrm");
838 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
839 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
840 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
841 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
842 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
843 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
844 }
845
846 $statusType = 'status'.$status;
847 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
848 if ($status == self::STATUS_CANCELED) {
849 $statusType = 'status6';
850 }
851
852 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
853 }
854
861 public function info($id)
862 {
863 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
864 $sql .= ' fk_user_creat, fk_user_modif';
865 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
866 $sql .= ' WHERE t.rowid = '.((int) $id);
867 $result = $this->db->query($sql);
868 if ($result) {
869 if ($this->db->num_rows($result)) {
870 $obj = $this->db->fetch_object($result);
871
872 $this->id = $obj->rowid;
873
874 $this->user_creation_id = $obj->fk_user_creat;
875 $this->user_modification_id = $obj->fk_user_modif;
876 $this->date_creation = $this->db->jdate($obj->datec);
877 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
878 }
879
880 $this->db->free($result);
881 } else {
882 dol_print_error($this->db);
883 }
884 }
885
892 public function initAsSpecimen()
893 {
894 // Set here init that are not commonf fields
895 // $this->property1 = ...
896 // $this->property2 = ...
897
898 return $this->initAsSpecimenCommon();
899 }
900
906 public function getLinesArray()
907 {
908 $this->lines = array();
909
910 $objectline = new EvaluationLine($this->db);
911 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_evaluationdet:=:'.((int) $this->id).')');
912
913 if (is_numeric($result)) {
914 $this->setErrorsFromObject($objectline);
915 return $result;
916 } else {
917 $this->lines = $result;
918 return $this->lines;
919 }
920 }
921
927 public function getNextNumRef()
928 {
929 global $langs, $conf;
930 $langs->load("hrm");
931
932 if (!getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
933 $conf->global->hrm_EVALUATIONLINE_ADDON = 'mod_evaluationdet_standard';
934 }
935
936 if (getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
937 $mybool = false;
938
939 $file = getDolGlobalString('hrm_EVALUATIONLINE_ADDON') . ".php";
940 $classname = getDolGlobalString('hrm_EVALUATIONLINE_ADDON');
941
942 // Include file with class
943 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
944 foreach ($dirmodels as $reldir) {
945 $dir = dol_buildpath($reldir."core/modules/hrm/");
946
947 // Load file with numbering class (if found)
948 $mybool = ((bool) @include_once $dir.$file) || $mybool;
949 }
950
951 if (!$mybool) {
952 dol_print_error(null, "Failed to include file ".$file);
953 return '';
954 }
955
956 if (class_exists($classname)) {
957 $obj = new $classname();
958 '@phan-var-force ModeleNumRefEvaluation $obj';
959 $numref = $obj->getNextValue($this);
960
961 if ($numref != '' && $numref != '-1') {
962 return $numref;
963 } else {
964 $this->error = $obj->error;
965 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
966 return "";
967 }
968 } else {
969 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
970 return "";
971 }
972 } else {
973 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
974 return "";
975 }
976 }
977
989 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
990 {
991 global $conf, $langs;
992
993 $result = 0;
994 $includedocgeneration = 0;
995
996 $langs->load("hrm");
997
998 if (!dol_strlen($modele)) {
999 $modele = 'standard_evaluationdet';
1000
1001 if (!empty($this->model_pdf)) {
1002 $modele = $this->model_pdf;
1003 } elseif (getDolGlobalString('EVALUATIONLINE_ADDON_PDF')) {
1004 $modele = getDolGlobalString('EVALUATIONLINE_ADDON_PDF');
1005 }
1006 }
1007
1008 $modelpath = "core/modules/hrm/doc/";
1009
1010 if ($includedocgeneration && !empty($modele)) {
1011 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1012 }
1013
1014 return $result;
1015 }
1016}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$object ref
Definition info.php:90
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:171
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_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_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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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...
Definition member.php:79