dolibarr 19.0.3
evaluation.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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
30require_once DOL_DOCUMENT_ROOT . '/hrm/class/evaluationdet.class.php';
31//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
32//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
33
38{
42 public $module = 'hrm';
43
47 public $element = 'evaluation';
48
52 public $table_element = 'hrm_evaluation';
53
58 public $ismultientitymanaged = 0;
59
63 public $isextrafieldmanaged = 1;
64
68 public $picto = 'label';
69
70
71 const STATUS_DRAFT = 0;
72 const STATUS_VALIDATED = 1;
73 const STATUS_CANCELED = 9;
74 const STATUS_CLOSED = 6;
75
76
103 // BEGIN MODULEBUILDER PROPERTIES
107 public $fields=array(
108 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
109 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
110 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'showoncombobox'=>'2',),
111 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3,),
112 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
113 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
114 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
115 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
116 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php:0', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
117 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php:0', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
118 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
119 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'default'=>0, 'visible'=>5, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '6' => 'Closed'),),
120 'date_eval' => array('type'=>'date', 'label'=>'DateEval', 'enabled'=>'1', 'position'=>502, 'notnull'=>1, 'visible'=>1,),
121 'fk_user' => array('type'=>'integer:User:user/class/user.class.php:0', 'label'=>'Employee', 'enabled'=>'1', 'position'=>504, 'notnull'=>1, 'visible'=>1, 'picto'=>'user', 'css'=>'maxwidth300 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150'),
122 'fk_job' => array('type'=>'integer:Job:/hrm/class/job.class.php', 'label'=>'JobProfile', 'enabled'=>'1', 'position'=>505, 'notnull'=>1, 'visible'=>1, 'picto'=>'jobprofile', 'css'=>'maxwidth300 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150'),
123 );
124 public $rowid;
125 public $ref;
126 public $label;
127 public $description;
128 public $note_public;
129 public $note_private;
130 public $date_creation;
131 public $tms;
132 public $fk_user_creat;
133 public $fk_user_modif;
134 public $import_key;
135 public $status;
136 public $date_eval;
137 public $fk_user;
138 public $fk_job;
139 // END MODULEBUILDER PROPERTIES
140
141
142 // If this object has a subtable with lines
143
147 public $table_element_line = 'hrm_evaluationdet';
148
152 public $fk_element = 'fk_evaluation';
153
157 public $class_element_line = 'EvaluationLine';
158
159 // /**
160 // * @var array List of child tables. To test if we can delete object.
161 // */
162 // protected $childtables = array();
163
164 // /**
165 // * @var array List of child tables. To know object to delete on cascade.
166 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
167 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
168 // */
169 protected $childtablesoncascade = array('@EvaluationLine:hrm/class/evaluationdet.class.php:fk_evaluation');
170
174 public $lines = array();
175
176
177
183 public function __construct(DoliDB $db)
184 {
185 global $conf, $langs, $user;
186
187 $this->db = $db;
188
189 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
190 $this->fields['rowid']['visible'] = 0;
191 }
192 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
193 $this->fields['entity']['enabled'] = 0;
194 }
195
196 if (!$user->hasRight('hrm', 'evaluation', 'readall')) {
197 $this->fields['fk_user']['type'].= ':rowid IN('.$this->db->sanitize(implode(", ", $user->getAllChildIds(1))).')';
198 }
199
200 $this->date_eval = dol_now();
201
202 // Unset fields that are disabled
203 foreach ($this->fields as $key => $val) {
204 if (isset($val['enabled']) && empty($val['enabled'])) {
205 unset($this->fields[$key]);
206 }
207 }
208
209 // Translate some data of arrayofkeyval
210 if (is_object($langs)) {
211 foreach ($this->fields as $key => $val) {
212 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
213 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
214 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
215 }
216 }
217 }
218 }
219 }
220
228 public function create(User $user, $notrigger = false)
229 {
230 $resultcreate = $this->createCommon($user, $notrigger);
231
232 if ($resultcreate > 0) {
233 require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
234 $skillRank = new SkillRank($this->db);
235 $TRequiredRanks = $skillRank->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_object='.$this->fk_job." AND objecttype='job'"));
236
237 if (is_array($TRequiredRanks) && !empty($TRequiredRanks)) {
238 $this->lines = array();
239 foreach ($TRequiredRanks as $required) {
240 $line = new EvaluationLine($this->db);
241 $line->fk_evaluation = $resultcreate;
242 $line->fk_skill = $required->fk_skill;
243 $line->required_rank = $required->rankorder;
244 $line->fk_rank = 0;
245
246 $res = $line->create($user, $notrigger);
247 if ($res > 0) {
248 $this->lines[] = $line;
249 }
250 }
251 }
252 }
253
254 return $resultcreate;
255 }
256
264 public function createFromClone(User $user, $fromid)
265 {
266 global $langs, $extrafields;
267 $error = 0;
268
269 dol_syslog(__METHOD__, LOG_DEBUG);
270
271 $object = new self($this->db);
272
273 $this->db->begin();
274
275 // Load source object
276 $result = $object->fetchCommon($fromid);
277 if ($result > 0 && !empty($object->table_element_line)) {
278 $object->fetchLines();
279 }
280
281 // get lines so they will be clone
282 //foreach($this->lines as $line)
283 // $line->fetch_optionals();
284
285 // Reset some properties
286 unset($object->id);
287 unset($object->fk_user_creat);
288 unset($object->import_key);
289
290 // Clear fields
291 if (property_exists($object, 'ref')) {
292 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
293 }
294 if (property_exists($object, 'label')) {
295 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
296 }
297 if (property_exists($object, 'status')) {
298 $object->status = self::STATUS_DRAFT;
299 }
300 if (property_exists($object, 'date_creation')) {
301 $object->date_creation = dol_now();
302 }
303 if (property_exists($object, 'date_modification')) {
304 $object->date_modification = null;
305 }
306 // ...
307 // Clear extrafields that are unique
308 if (is_array($object->array_options) && count($object->array_options) > 0) {
309 $extrafields->fetch_name_optionals_label($this->table_element);
310 foreach ($object->array_options as $key => $option) {
311 $shortkey = preg_replace('/options_/', '', $key);
312 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
313 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
314 unset($object->array_options[$key]);
315 }
316 }
317 }
318
319 // Create clone
320 $object->context['createfromclone'] = 'createfromclone';
321 $result = $object->createCommon($user);
322 if ($result < 0) {
323 $error++;
324 $this->error = $object->error;
325 $this->errors = $object->errors;
326 }
327
328 if (!$error) {
329 // copy internal contacts
330 if ($this->copy_linked_contact($object, 'internal') < 0) {
331 $error++;
332 }
333 }
334
335 if (!$error) {
336 // copy external contacts if same company
337 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
338 if ($this->copy_linked_contact($object, 'external') < 0) {
339 $error++;
340 }
341 }
342 }
343
344 unset($object->context['createfromclone']);
345
346 // End
347 if (!$error) {
348 $this->db->commit();
349 return $object;
350 } else {
351 $this->db->rollback();
352 return -1;
353 }
354 }
355
363 public function fetch($id, $ref = null)
364 {
365 $result = $this->fetchCommon($id, $ref);
366 if ($result > 0 && !empty($this->table_element_line)) {
367 $this->fetchLines();
368 }
369 return $result;
370 }
371
377 public function fetchLines()
378 {
379 $this->lines = array();
380
381 $result = $this->fetchLinesCommon();
382 return $result;
383 }
384
385
397 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
398 {
399 global $conf;
400
401 dol_syslog(__METHOD__, LOG_DEBUG);
402
403 $records = array();
404
405 $sql = 'SELECT ';
406 $sql .= $this->getFieldList('t');
407 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
408 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
409 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
410 } else {
411 $sql .= ' WHERE 1 = 1';
412 }
413 // Manage filter
414 $sqlwhere = array();
415 if (count($filter) > 0) {
416 foreach ($filter as $key => $value) {
417 if ($key == 't.rowid') {
418 $sqlwhere[] = $key.'='.$value;
419 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
420 $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
421 } elseif ($key == 'customsql') {
422 $sqlwhere[] = $value;
423 } elseif (strpos($value, '%') === false) {
424 $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
425 } else {
426 $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
427 }
428 }
429 }
430 if (count($sqlwhere) > 0) {
431 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
432 }
433
434 if (!empty($sortfield)) {
435 $sql .= $this->db->order($sortfield, $sortorder);
436 }
437 if (!empty($limit)) {
438 $sql .= ' '.$this->db->plimit($limit, $offset);
439 }
440
441 $resql = $this->db->query($sql);
442 if ($resql) {
443 $num = $this->db->num_rows($resql);
444 $i = 0;
445 while ($i < ($limit ? min($limit, $num) : $num)) {
446 $obj = $this->db->fetch_object($resql);
447
448 $record = new self($this->db);
449 $record->setVarsFromFetchObj($obj);
450
451 $records[$record->id] = $record;
452
453 $i++;
454 }
455 $this->db->free($resql);
456
457 return $records;
458 } else {
459 $this->errors[] = 'Error '.$this->db->lasterror();
460 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
461
462 return -1;
463 }
464 }
465
473 public function update(User $user, $notrigger = false)
474 {
475 return $this->updateCommon($user, $notrigger);
476 }
477
485 public function delete(User $user, $notrigger = false)
486 {
487 return $this->deleteCommon($user, $notrigger);
488 //return $this->deleteCommon($user, $notrigger, 1);
489 }
490
499 public function deleteLine(User $user, $idline, $notrigger = false)
500 {
501 if ($this->status < 0) {
502 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
503 return -2;
504 }
505
506 return $this->deleteLineCommon($user, $idline, $notrigger);
507 }
508
509
517 public function validate($user, $notrigger = 0)
518 {
519 global $conf, $langs;
520
521 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
522
523 $error = 0;
524
525 // Protection
526 if ($this->status == self::STATUS_VALIDATED) {
527 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
528 return 0;
529 }
530
531
532
533 $now = dol_now();
534
535 $this->db->begin();
536
537 // Define new ref
538 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
539 $num = $this->getNextNumRef();
540 } else {
541 $num = $this->ref;
542 }
543 $this->newref = $num;
544
545 if (!empty($num)) {
546 // Validate
547 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
548 $sql .= " SET ref = '".$this->db->escape($num)."',";
549 $sql .= " status = ".self::STATUS_VALIDATED;
550 if (!empty($this->fields['date_validation'])) {
551 $sql .= ", date_validation = '".$this->db->idate($now)."'";
552 }
553 if (!empty($this->fields['fk_user_valid'])) {
554 $sql .= ", fk_user_valid = ".((int) $user->id);
555 }
556 $sql .= " WHERE rowid = ".((int) $this->id);
557
558 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
559 $resql = $this->db->query($sql);
560 if (!$resql) {
561 dol_print_error($this->db);
562 $this->error = $this->db->lasterror();
563 $error++;
564 }
565
566 if (!$error && !$notrigger) {
567 // Call trigger
568 $result = $this->call_trigger('HRM_EVALUATION_VALIDATE', $user);
569 if ($result < 0) {
570 $error++;
571 }
572 // End call triggers
573 }
574 }
575
576 if (!$error) {
577 $this->oldref = $this->ref;
578
579 // Rename directory if dir was a temporary ref
580 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
581 // Now we rename also files into index
582 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'evaluation/".$this->db->escape($this->newref)."'";
583 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
584 $resql = $this->db->query($sql);
585 if (!$resql) {
586 $error++;
587 $this->error = $this->db->lasterror();
588 }
589 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluation/".$this->db->escape($this->newref)."'";
590 $sql .= " WHERE filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
591 $resql = $this->db->query($sql);
592 if (!$resql) {
593 $error++;
594 $this->error = $this->db->lasterror();
595 }
596
597 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
598 $oldref = dol_sanitizeFileName($this->ref);
599 $newref = dol_sanitizeFileName($num);
600 $dirsource = $conf->hrm->dir_output.'/evaluation/'.$oldref;
601 $dirdest = $conf->hrm->dir_output.'/evaluation/'.$newref;
602 if (!$error && file_exists($dirsource)) {
603 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
604
605 if (@rename($dirsource, $dirdest)) {
606 dol_syslog("Rename ok");
607 // Rename docs starting with $oldref with $newref
608 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
609 foreach ($listoffiles as $fileentry) {
610 $dirsource = $fileentry['name'];
611 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
612 $dirsource = $fileentry['path'].'/'.$dirsource;
613 $dirdest = $fileentry['path'].'/'.$dirdest;
614 @rename($dirsource, $dirdest);
615 }
616 }
617 }
618 }
619 }
620
621 // Set new ref and current status
622 if (!$error) {
623 $this->ref = $num;
624 $this->status = self::STATUS_VALIDATED;
625 }
626
627 if (!$error) {
628 $this->db->commit();
629 return 1;
630 } else {
631 $this->db->rollback();
632 return -1;
633 }
634 }
635
642 public function getLastEvaluationForUser($fk_user)
643 {
644 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."hrm_evaluation ";
645 $sql.= "WHERE fk_user=".((int) $fk_user)." ";
646 $sql.= "ORDER BY date_eval DESC ";
647 $sql.= "LIMIT 1 ";
648
649 $res = $this->db->query($sql);
650 if (!$res) {
651 dol_print_error($this->db);
652 }
653
654 $Tab = $this->db->fetch_object($res);
655
656 if (empty($Tab)) {
657 return null;
658 } else {
659 $evaluation = new Evaluation($this->db);
660 $evaluation->fetch($Tab->rowid);
661
662 return $evaluation;
663 }
664 }
665
666
674 public function setDraft($user, $notrigger = 0)
675 {
676 // Protection
677 if ($this->status <= self::STATUS_DRAFT) {
678 return 0;
679 }
680
681 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'HRM_EVALUATION_UNVALIDATE');
682 }
683
691 public function cancel($user, $notrigger = 0)
692 {
693 // Protection
694 if ($this->status != self::STATUS_VALIDATED) {
695 return 0;
696 }
697
698 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'HRM_EVALUATION_CANCEL');
699 }
700
708 public function reopen($user, $notrigger = 0)
709 {
710 // Protection
711 if ($this->status != self::STATUS_CANCELED) {
712 return 0;
713 }
714
715 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'HRM_EVALUATION_REOPEN');
716 }
717
728 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
729 {
730 global $conf, $langs, $hookmanager;
731
732 if (!empty($conf->dol_no_mouse_hover)) {
733 $notooltip = 1; // Force disable tooltips
734 }
735
736 $result = '';
737
738 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluation").'</u>';
739 if (isset($this->status)) {
740 $label .= ' '.$this->getLibStatut(5);
741 }
742 $label .= '<br>';
743 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
744
745 $url = dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$this->id;
746
747 if ($option != 'nolink') {
748 // Add param to save lastsearch_values or not
749 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
750 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
751 $add_save_lastsearch_values = 1;
752 }
753 if ($add_save_lastsearch_values) {
754 $url .= '&save_lastsearch_values=1';
755 }
756 }
757
758 $linkclose = '';
759 if (empty($notooltip)) {
760 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
761 $label = $langs->trans("ShowEvaluation");
762 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
763 }
764 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
765 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
766 } else {
767 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
768 }
769
770 if ($option == 'nolink') {
771 $linkstart = '<span';
772 } else {
773 $linkstart = '<a href="'.$url.'"';
774 }
775 $linkstart .= $linkclose.'>';
776 if ($option == 'nolink') {
777 $linkend = '</span>';
778 } else {
779 $linkend = '</a>';
780 }
781
782 $result .= $linkstart;
783
784 if (empty($this->showphoto_on_popup)) {
785 if ($withpicto) {
786 $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);
787 }
788 } else {
789 if ($withpicto) {
790 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
791
792 list($class, $module) = explode('@', $this->picto);
793 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
794 $filearray = dol_dir_list($upload_dir, "files");
795 $filename = $filearray[0]['name'];
796 if (!empty($filename)) {
797 $pospoint = strpos($filearray[0]['name'], '.');
798
799 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
800 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
801 $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>';
802 } else {
803 $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>';
804 }
805
806 $result .= '</div>';
807 } else {
808 $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);
809 }
810 }
811 }
812
813 if ($withpicto != 2) {
814 $result .= $this->ref;
815 }
816
817 $result .= $linkend;
818 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
819
820 global $action, $hookmanager;
821 $hookmanager->initHooks(array('evaluationdao'));
822 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
823 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
824 if ($reshook > 0) {
825 $result = $hookmanager->resPrint;
826 } else {
827 $result .= $hookmanager->resPrint;
828 }
829
830 return $result;
831 }
832
839 public function getLibStatut($mode = 0)
840 {
841 return $this->LibStatut($this->status, $mode);
842 }
843
844 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
852 public function LibStatut($status, $mode = 0)
853 {
854 // phpcs:enable
855 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
856 global $langs;
857 //$langs->load("hrm");
858 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
859 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
860 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
861 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
862 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
863 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
864 }
865
866 $statusType = 'status'.$status;
867 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
868 if ($status == self::STATUS_CANCELED) {
869 $statusType = 'status6';
870 }
871
872 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
873 }
874
881 public function info($id)
882 {
883 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
884 $sql .= ' fk_user_creat, fk_user_modif';
885 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
886 $sql .= ' WHERE t.rowid = '.((int) $id);
887 $result = $this->db->query($sql);
888 if ($result) {
889 if ($this->db->num_rows($result)) {
890 $obj = $this->db->fetch_object($result);
891
892 $this->id = $obj->rowid;
893
894 $this->user_creation_id = $obj->fk_user_creat;
895 $this->user_modification_id = $obj->fk_user_modif;
896 $this->date_creation = $this->db->jdate($obj->datec);
897 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
898 }
899
900 $this->db->free($result);
901 } else {
902 dol_print_error($this->db);
903 }
904 }
905
912 public function initAsSpecimen()
913 {
914 // Set here init that are not commonf fields
915 // $this->property1 = ...
916 // $this->property2 = ...
917
918 $this->initAsSpecimenCommon();
919 }
920
926 public function getLinesArray()
927 {
928 $this->lines = array();
929
930 $objectline = new EvaluationLine($this->db);
931 $result = $objectline->fetchAll('ASC', '', 0, 0, array('customsql'=>'fk_evaluation = '.$this->id));
932
933 if (is_numeric($result)) {
934 $this->error = $objectline->error;
935 $this->errors = $objectline->errors;
936 return $result;
937 } else {
938 $this->lines = $result;
939 return $this->lines;
940 }
941 }
942
948 public function getNextNumRef()
949 {
950 global $langs, $conf;
951 $langs->load("hrm");
952
953 if (!getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
954 $conf->global->HRMTEST_EVALUATION_ADDON = 'mod_evaluation_standard';
955 }
956
957 if (getDolGlobalString('HRMTEST_EVALUATION_ADDON')) {
958 $mybool = false;
959
960 $file = getDolGlobalString('HRMTEST_EVALUATION_ADDON') . ".php";
961 $classname = $conf->global->HRMTEST_EVALUATION_ADDON;
962
963 // Include file with class
964 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
965 foreach ($dirmodels as $reldir) {
966 $dir = dol_buildpath($reldir."core/modules/hrm/");
967
968 // Load file with numbering class (if found)
969 $mybool |= @include_once $dir.$file;
970 }
971
972 if ($mybool === false) {
973 dol_print_error('', "Failed to include file ".$file);
974 return '';
975 }
976
977 if (class_exists($classname)) {
978 $obj = new $classname();
979 $numref = $obj->getNextValue($this);
980
981 if ($numref != '' && $numref != '-1') {
982 return $numref;
983 } else {
984 $this->error = $obj->error;
985 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
986 return "";
987 }
988 } else {
989 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
990 return "";
991 }
992 } else {
993 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
994 return "";
995 }
996 }
997
1009 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1010 {
1011 global $conf, $langs;
1012
1013 $result = 0;
1014
1015 $langs->load("hrm");
1016
1017 if (!dol_strlen($modele)) {
1018 $modele = 'standard';
1019
1020 if (!empty($this->model_pdf)) {
1021 $modele = $this->model_pdf;
1022 } elseif (getDolGlobalString('EVALUATION_ADDON_PDF')) {
1023 $modele = $conf->global->EVALUATION_ADDON_PDF;
1024 }
1025 }
1026
1027 $modelpath = "core/modules/hrm/doc/";
1028
1029 if (!empty($modele)) {
1030 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1031 }
1032
1033 return $result;
1034 }
1035
1043 public function doScheduledJob()
1044 {
1045 global $conf, $langs;
1046
1047 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1048
1049 $error = 0;
1050 $this->output = '';
1051 $this->error = '';
1052
1053 dol_syslog(__METHOD__, LOG_DEBUG);
1054
1055 $now = dol_now();
1056
1057 $this->db->begin();
1058
1059 // ...
1060
1061 $this->db->commit();
1062
1063 return $error;
1064 }
1065
1073 public function getKanbanView($option = '', $arraydata = null)
1074 {
1075 global $selected, $langs;
1076
1077 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1078
1079 $return = '<div class="box-flex-item box-flex-grow-zero">';
1080 $return .= '<div class="info-box info-box-sm">';
1081 $return .= '<span class="info-box-icon bg-infobox-action">';
1082 $return .= img_picto('', $this->picto);
1083 $return .= '</span>';
1084 $return .= '<div class="info-box-content">';
1085 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1086 $return .= '<input class="fright" id="cb'.$this->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1087 if (!empty($arraydata['user'])) {
1088 $return .= '<br><span class="info-box-label ">'.$arraydata['user'].'</span>';
1089 }
1090 if (!empty($arraydata['job'])) {
1091 $return .= '<br><span class="info-box-label ">'.$arraydata['job'].'</span>';
1092 }
1093 if (method_exists($this, 'getLibStatut')) {
1094 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1095 }
1096 $return .= '</div>';
1097 $return .= '</div>';
1098 $return .= '</div>';
1099 return $return;
1100 }
1101}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for Evaluation.
getLinesArray()
Create an array of lines.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
fetchLines()
Load object lines in memory from the database.
cancel($user, $notrigger=0)
Set cancel status.
createFromClone(User $user, $fromid)
Clone an object into another one.
create(User $user, $notrigger=false)
Create object into database.
fetch($id, $ref=null)
Load object in memory from the database.
LibStatut($status, $mode=0)
Return the status.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
validate($user, $notrigger=0)
Validate object.
__construct(DoliDB $db)
Constructor.
reopen($user, $notrigger=0)
Set back to validated status.
info($id)
Load the info information in the object.
update(User $user, $notrigger=false)
Update object into database.
getLastEvaluationForUser($fk_user)
Get the last evaluation by date for the user assigned.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getLibStatut($mode=0)
Return the label of the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
setDraft($user, $notrigger=0)
Set draft status.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
Class for EvaluationLine.
Class for SkillRank.
Class to manage Dolibarr users.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.