dolibarr  16.0.5
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
29 require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
30 require_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 
37 class Evaluation extends CommonObject
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', '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', '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', 'label'=>'User', 'enabled'=>'1', 'position'=>504, 'notnull'=>1, 'visible'=>1,),
122  'fk_job' => array('type'=>'integer:Job:/hrm/class/job.class.php', 'label'=>'Job', 'enabled'=>'1', 'position'=>505, 'notnull'=>1, 'visible'=>1,),
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;
186 
187  $this->db = $db;
188 
189  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
190  $this->fields['rowid']['visible'] = 0;
191  }
192  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
193  $this->fields['entity']['enabled'] = 0;
194  }
195 
196  $this->date_eval = dol_now();
197 
198  // Unset fields that are disabled
199  foreach ($this->fields as $key => $val) {
200  if (isset($val['enabled']) && empty($val['enabled'])) {
201  unset($this->fields[$key]);
202  }
203  }
204 
205  // Translate some data of arrayofkeyval
206  if (is_object($langs)) {
207  foreach ($this->fields as $key => $val) {
208  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
209  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
210  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
211  }
212  }
213  }
214  }
215  }
216 
224  public function create(User $user, $notrigger = false)
225  {
226  $resultcreate = $this->createCommon($user, $notrigger);
227 
228  if ($resultcreate > 0) {
229  require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
230  $skillRank = new SkillRank($this->db);
231  $TRequiredRanks = $skillRank->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_object='.$this->fk_job." AND objecttype='job'"));
232 
233  if (is_array($TRequiredRanks) && !empty($TRequiredRanks)) {
234  $this->lines = array();
235  foreach ($TRequiredRanks as $required) {
236  $line = new Evaluationline($this->db);
237  $line->fk_evaluation = $resultcreate;
238  $line->fk_skill = $required->fk_skill;
239  $line->required_rank = $required->rankorder;
240  $line->fk_rank = 0;
241 
242  $res = $line->create($user, $notrigger);
243  if ($res > 0) $this->lines[] = $line;
244  }
245  }
246  }
247 
248  return $resultcreate;
249  }
250 
258  public function createFromClone(User $user, $fromid)
259  {
260  global $langs, $extrafields;
261  $error = 0;
262 
263  dol_syslog(__METHOD__, LOG_DEBUG);
264 
265  $object = new self($this->db);
266 
267  $this->db->begin();
268 
269  // Load source object
270  $result = $object->fetchCommon($fromid);
271  if ($result > 0 && !empty($object->table_element_line)) {
272  $object->fetchLines();
273  }
274 
275  // get lines so they will be clone
276  //foreach($this->lines as $line)
277  // $line->fetch_optionals();
278 
279  // Reset some properties
280  unset($object->id);
281  unset($object->fk_user_creat);
282  unset($object->import_key);
283 
284  // Clear fields
285  if (property_exists($object, 'ref')) {
286  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
287  }
288  if (property_exists($object, 'label')) {
289  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
290  }
291  if (property_exists($object, 'status')) {
292  $object->status = self::STATUS_DRAFT;
293  }
294  if (property_exists($object, 'date_creation')) {
295  $object->date_creation = dol_now();
296  }
297  if (property_exists($object, 'date_modification')) {
298  $object->date_modification = null;
299  }
300  // ...
301  // Clear extrafields that are unique
302  if (is_array($object->array_options) && count($object->array_options) > 0) {
303  $extrafields->fetch_name_optionals_label($this->table_element);
304  foreach ($object->array_options as $key => $option) {
305  $shortkey = preg_replace('/options_/', '', $key);
306  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
307  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
308  unset($object->array_options[$key]);
309  }
310  }
311  }
312 
313  // Create clone
314  $object->context['createfromclone'] = 'createfromclone';
315  $result = $object->createCommon($user);
316  if ($result < 0) {
317  $error++;
318  $this->error = $object->error;
319  $this->errors = $object->errors;
320  }
321 
322  if (!$error) {
323  // copy internal contacts
324  if ($this->copy_linked_contact($object, 'internal') < 0) {
325  $error++;
326  }
327  }
328 
329  if (!$error) {
330  // copy external contacts if same company
331  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
332  if ($this->copy_linked_contact($object, 'external') < 0) {
333  $error++;
334  }
335  }
336  }
337 
338  unset($object->context['createfromclone']);
339 
340  // End
341  if (!$error) {
342  $this->db->commit();
343  return $object;
344  } else {
345  $this->db->rollback();
346  return -1;
347  }
348  }
349 
357  public function fetch($id, $ref = null)
358  {
359  $result = $this->fetchCommon($id, $ref);
360  if ($result > 0 && !empty($this->table_element_line)) {
361  $this->fetchLines();
362  }
363  return $result;
364  }
365 
371  public function fetchLines()
372  {
373  $this->lines = array();
374 
375  $result = $this->fetchLinesCommon();
376  return $result;
377  }
378 
379 
391  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
392  {
393  global $conf;
394 
395  dol_syslog(__METHOD__, LOG_DEBUG);
396 
397  $records = array();
398 
399  $sql = 'SELECT ';
400  $sql .= $this->getFieldList('t');
401  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
402  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
403  $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
404  } else {
405  $sql .= ' WHERE 1 = 1';
406  }
407  // Manage filter
408  $sqlwhere = array();
409  if (count($filter) > 0) {
410  foreach ($filter as $key => $value) {
411  if ($key == 't.rowid') {
412  $sqlwhere[] = $key.'='.$value;
413  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
414  $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
415  } elseif ($key == 'customsql') {
416  $sqlwhere[] = $value;
417  } elseif (strpos($value, '%') === false) {
418  $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
419  } else {
420  $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
421  }
422  }
423  }
424  if (count($sqlwhere) > 0) {
425  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
426  }
427 
428  if (!empty($sortfield)) {
429  $sql .= $this->db->order($sortfield, $sortorder);
430  }
431  if (!empty($limit)) {
432  $sql .= ' '.$this->db->plimit($limit, $offset);
433  }
434 
435  $resql = $this->db->query($sql);
436  if ($resql) {
437  $num = $this->db->num_rows($resql);
438  $i = 0;
439  while ($i < ($limit ? min($limit, $num) : $num)) {
440  $obj = $this->db->fetch_object($resql);
441 
442  $record = new self($this->db);
443  $record->setVarsFromFetchObj($obj);
444 
445  $records[$record->id] = $record;
446 
447  $i++;
448  }
449  $this->db->free($resql);
450 
451  return $records;
452  } else {
453  $this->errors[] = 'Error '.$this->db->lasterror();
454  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
455 
456  return -1;
457  }
458  }
459 
467  public function update(User $user, $notrigger = false)
468  {
469  return $this->updateCommon($user, $notrigger);
470  }
471 
479  public function delete(User $user, $notrigger = false)
480  {
481  return $this->deleteCommon($user, $notrigger);
482  //return $this->deleteCommon($user, $notrigger, 1);
483  }
484 
493  public function deleteLine(User $user, $idline, $notrigger = false)
494  {
495  if ($this->status < 0) {
496  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
497  return -2;
498  }
499 
500  return $this->deleteLineCommon($user, $idline, $notrigger);
501  }
502 
503 
511  public function validate($user, $notrigger = 0)
512  {
513  global $conf, $langs;
514 
515  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
516 
517  $error = 0;
518 
519  // Protection
520  if ($this->status == self::STATUS_VALIDATED) {
521  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
522  return 0;
523  }
524 
525 
526 
527  $now = dol_now();
528 
529  $this->db->begin();
530 
531  // Define new ref
532  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
533  $num = $this->getNextNumRef();
534  } else {
535  $num = $this->ref;
536  }
537  $this->newref = $num;
538 
539  if (!empty($num)) {
540  // Validate
541  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
542  $sql .= " SET ref = '".$this->db->escape($num)."',";
543  $sql .= " status = ".self::STATUS_VALIDATED;
544  if (!empty($this->fields['date_validation'])) {
545  $sql .= ", date_validation = '".$this->db->idate($now)."'";
546  }
547  if (!empty($this->fields['fk_user_valid'])) {
548  $sql .= ", fk_user_valid = ".((int) $user->id);
549  }
550  $sql .= " WHERE rowid = ".((int) $this->id);
551 
552  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
553  $resql = $this->db->query($sql);
554  if (!$resql) {
555  dol_print_error($this->db);
556  $this->error = $this->db->lasterror();
557  $error++;
558  }
559 
560  if (!$error && !$notrigger) {
561  // Call trigger
562  $result = $this->call_trigger('EVALUATION_VALIDATE', $user);
563  if ($result < 0) {
564  $error++;
565  }
566  // End call triggers
567  }
568  }
569 
570  if (!$error) {
571  $this->oldref = $this->ref;
572 
573  // Rename directory if dir was a temporary ref
574  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
575  // Now we rename also files into index
576  $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)."'";
577  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
578  $resql = $this->db->query($sql);
579  if (!$resql) {
580  $error++; $this->error = $this->db->lasterror();
581  }
582 
583  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
584  $oldref = dol_sanitizeFileName($this->ref);
585  $newref = dol_sanitizeFileName($num);
586  $dirsource = $conf->hrm->dir_output.'/evaluation/'.$oldref;
587  $dirdest = $conf->hrm->dir_output.'/evaluation/'.$newref;
588  if (!$error && file_exists($dirsource)) {
589  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
590 
591  if (@rename($dirsource, $dirdest)) {
592  dol_syslog("Rename ok");
593  // Rename docs starting with $oldref with $newref
594  $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
595  foreach ($listoffiles as $fileentry) {
596  $dirsource = $fileentry['name'];
597  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
598  $dirsource = $fileentry['path'].'/'.$dirsource;
599  $dirdest = $fileentry['path'].'/'.$dirdest;
600  @rename($dirsource, $dirdest);
601  }
602  }
603  }
604  }
605  }
606 
607  // Set new ref and current status
608  if (!$error) {
609  $this->ref = $num;
610  $this->status = self::STATUS_VALIDATED;
611  }
612 
613  if (!$error) {
614  $this->db->commit();
615  return 1;
616  } else {
617  $this->db->rollback();
618  return -1;
619  }
620  }
621 
628  public function getLastEvaluationForUser($fk_user)
629  {
630  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."hrm_evaluation ";
631  $sql.= "WHERE fk_user=".((int) $fk_user)." ";
632  $sql.= "ORDER BY date_eval DESC ";
633  $sql.= "LIMIT 1 ";
634 
635  $res = $this->db->query($sql);
636  if (!$res) { dol_print_error($this->db);}
637 
638  $Tab = $this->db->fetch_object($res);
639 
640  if (empty($Tab)) return null;
641  else {
642  $evaluation = new Evaluation($this->db);
643  $evaluation->fetch($Tab->rowid);
644 
645  return $evaluation;
646  }
647  }
648 
649 
657  public function setDraft($user, $notrigger = 0)
658  {
659  // Protection
660  if ($this->status <= self::STATUS_DRAFT) {
661  return 0;
662  }
663 
664 
665 
666  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATION_UNVALIDATE');
667  }
668 
676  public function cancel($user, $notrigger = 0)
677  {
678  // Protection
679  if ($this->status != self::STATUS_VALIDATED) {
680  return 0;
681  }
682 
683 
684 
685  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATION_CANCEL');
686  }
687 
695  public function reopen($user, $notrigger = 0)
696  {
697  // Protection
698  if ($this->status != self::STATUS_CANCELED) {
699  return 0;
700  }
701 
702 
703 
704  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATION_REOPEN');
705  }
706 
717  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
718  {
719  global $conf, $langs, $hookmanager;
720 
721  if (!empty($conf->dol_no_mouse_hover)) {
722  $notooltip = 1; // Force disable tooltips
723  }
724 
725  $result = '';
726 
727  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluation").'</u>';
728  if (isset($this->status)) {
729  $label .= ' '.$this->getLibStatut(5);
730  }
731  $label .= '<br>';
732  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
733 
734  $url = dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$this->id;
735 
736  if ($option != 'nolink') {
737  // Add param to save lastsearch_values or not
738  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
739  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
740  $add_save_lastsearch_values = 1;
741  }
742  if ($add_save_lastsearch_values) {
743  $url .= '&save_lastsearch_values=1';
744  }
745  }
746 
747  $linkclose = '';
748  if (empty($notooltip)) {
749  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
750  $label = $langs->trans("ShowEvaluation");
751  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
752  }
753  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
754  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
755  } else {
756  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
757  }
758 
759  if ($option == 'nolink') {
760  $linkstart = '<span';
761  } else {
762  $linkstart = '<a href="'.$url.'"';
763  }
764  $linkstart .= $linkclose.'>';
765  if ($option == 'nolink') {
766  $linkend = '</span>';
767  } else {
768  $linkend = '</a>';
769  }
770 
771  $result .= $linkstart;
772 
773  if (empty($this->showphoto_on_popup)) {
774  if ($withpicto) {
775  $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);
776  }
777  } else {
778  if ($withpicto) {
779  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
780 
781  list($class, $module) = explode('@', $this->picto);
782  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
783  $filearray = dol_dir_list($upload_dir, "files");
784  $filename = $filearray[0]['name'];
785  if (!empty($filename)) {
786  $pospoint = strpos($filearray[0]['name'], '.');
787 
788  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
789  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
790  $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>';
791  } else {
792  $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>';
793  }
794 
795  $result .= '</div>';
796  } else {
797  $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);
798  }
799  }
800  }
801 
802  if ($withpicto != 2) {
803  $result .= $this->ref;
804  }
805 
806  $result .= $linkend;
807  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
808 
809  global $action, $hookmanager;
810  $hookmanager->initHooks(array('evaluationdao'));
811  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
812  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
813  if ($reshook > 0) {
814  $result = $hookmanager->resPrint;
815  } else {
816  $result .= $hookmanager->resPrint;
817  }
818 
819  return $result;
820  }
821 
828  public function getLibStatut($mode = 0)
829  {
830  return $this->LibStatut($this->status, $mode);
831  }
832 
833  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
841  public function LibStatut($status, $mode = 0)
842  {
843  // phpcs:enable
844  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
845  global $langs;
846  //$langs->load("hrm");
847  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
848  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
849  $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
850  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
851  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
852  $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
853  }
854 
855  $statusType = 'status'.$status;
856  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
857  if ($status == self::STATUS_CANCELED) {
858  $statusType = 'status6';
859  }
860 
861  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
862  }
863 
870  public function info($id)
871  {
872  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
873  $sql .= ' fk_user_creat, fk_user_modif';
874  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
875  $sql .= ' WHERE t.rowid = '.((int) $id);
876  $result = $this->db->query($sql);
877  if ($result) {
878  if ($this->db->num_rows($result)) {
879  $obj = $this->db->fetch_object($result);
880  $this->id = $obj->rowid;
881 
882  $this->user_creation_id = $obj->fk_user_creat;
883  $this->user_modification_id = $obj->fk_user_modif;
884  $this->date_creation = $this->db->jdate($obj->datec);
885  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
886  }
887 
888  $this->db->free($result);
889  } else {
890  dol_print_error($this->db);
891  }
892  }
893 
900  public function initAsSpecimen()
901  {
902  // Set here init that are not commonf fields
903  // $this->property1 = ...
904  // $this->property2 = ...
905 
906  $this->initAsSpecimenCommon();
907  }
908 
914  public function getLinesArray()
915  {
916  $this->lines = array();
917 
918  $objectline = new Evaluationline($this->db);
919  $result = $objectline->fetchAll('ASC', '', 0, 0, array('customsql'=>'fk_evaluation = '.$this->id));
920 
921  if (is_numeric($result)) {
922  $this->error = $this->error;
923  $this->errors = $this->errors;
924  return $result;
925  } else {
926  $this->lines = $result;
927  return $this->lines;
928  }
929  }
930 
936  public function getNextNumRef()
937  {
938  global $langs, $conf;
939  $langs->load("hrm");
940 
941  if (empty($conf->global->HRMTEST_EVALUATION_ADDON)) {
942  $conf->global->HRMTEST_EVALUATION_ADDON = 'mod_evaluation_standard';
943  }
944 
945  if (!empty($conf->global->HRMTEST_EVALUATION_ADDON)) {
946  $mybool = false;
947 
948  $file = $conf->global->HRMTEST_EVALUATION_ADDON.".php";
949  $classname = $conf->global->HRMTEST_EVALUATION_ADDON;
950 
951  // Include file with class
952  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
953  foreach ($dirmodels as $reldir) {
954  $dir = dol_buildpath($reldir."core/modules/hrm/");
955 
956  // Load file with numbering class (if found)
957  $mybool |= @include_once $dir.$file;
958  }
959 
960  if ($mybool === false) {
961  dol_print_error('', "Failed to include file ".$file);
962  return '';
963  }
964 
965  if (class_exists($classname)) {
966  $obj = new $classname();
967  $numref = $obj->getNextValue($this);
968 
969  if ($numref != '' && $numref != '-1') {
970  return $numref;
971  } else {
972  $this->error = $obj->error;
973  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
974  return "";
975  }
976  } else {
977  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
978  return "";
979  }
980  } else {
981  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
982  return "";
983  }
984  }
985 
997  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
998  {
999  global $conf, $langs;
1000 
1001  $result = 0;
1002  $includedocgeneration = 0;
1003 
1004  $langs->load("hrm");
1005 
1006  if (!dol_strlen($modele)) {
1007  $modele = 'standard_evaluation';
1008 
1009  if (!empty($this->model_pdf)) {
1010  $modele = $this->model_pdf;
1011  } elseif (!empty($conf->global->EVALUATION_ADDON_PDF)) {
1012  $modele = $conf->global->EVALUATION_ADDON_PDF;
1013  }
1014  }
1015 
1016  $modelpath = "core/modules/hrm/doc/";
1017 
1018  if ($includedocgeneration && !empty($modele)) {
1019  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1020  }
1021 
1022  return $result;
1023  }
1024 
1032  public function doScheduledJob()
1033  {
1034  global $conf, $langs;
1035 
1036  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1037 
1038  $error = 0;
1039  $this->output = '';
1040  $this->error = '';
1041 
1042  dol_syslog(__METHOD__, LOG_DEBUG);
1043 
1044  $now = dol_now();
1045 
1046  $this->db->begin();
1047 
1048  // ...
1049 
1050  $this->db->commit();
1051 
1052  return $error;
1053  }
1054 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9683
db
$conf db
API class for accounts.
Definition: inc.php:41
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
Evaluation\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: evaluation.class.php:900
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1217
Evaluation\create
create(User $user, $notrigger=false)
Create object into database.
Definition: evaluation.class.php:224
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
Evaluation\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: evaluation.class.php:936
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
Evaluation\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: evaluation.class.php:493
Evaluationline
Class for Evaluationline.
Definition: evaluationdet.class.php:37
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9258
Evaluation\update
update(User $user, $notrigger=false)
Update object into database.
Definition: evaluation.class.php:467
ref
$object ref
Definition: info.php:77
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
Evaluation\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: evaluation.class.php:695
Evaluation\__construct
__construct(DoliDB $db)
Constructor.
Definition: evaluation.class.php:183
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
Evaluation\getLinesArray
getLinesArray()
Create an array of lines.
Definition: evaluation.class.php:914
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
Evaluation\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: evaluation.class.php:258
Evaluation\info
info($id)
Load the info information in the object.
Definition: evaluation.class.php:870
Evaluation\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: evaluation.class.php:828
Evaluation\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: evaluation.class.php:1032
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Evaluation\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: evaluation.class.php:717
Evaluation\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: evaluation.class.php:657
Evaluation\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: evaluation.class.php:357
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
Evaluation\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: evaluation.class.php:841
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
Evaluation
Class for Evaluation.
Definition: evaluation.class.php:37
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Evaluation\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: evaluation.class.php:371
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9622
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
Evaluation\validate
validate($user, $notrigger=0)
Validate object.
Definition: evaluation.class.php:511
Evaluation\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: evaluation.class.php:676
SkillRank
Class for SkillRank.
Definition: skillrank.class.php:35
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:8987
Evaluation\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: evaluation.class.php:391
Evaluation\getLastEvaluationForUser
getLastEvaluationForUser($fk_user)
Get the last evaluation by date for the user assigned.
Definition: evaluation.class.php:628
Evaluation\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: evaluation.class.php:997