dolibarr  17.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
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:0', 'label'=>'User', 'enabled'=>'1', 'position'=>504, 'notnull'=>1, 'visible'=>1,),
122  'fk_job' => array('type'=>'integer:Job:/hrm/class/job.class.php', 'label'=>'JobProfile', '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, $user;
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 (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
193  $this->fields['entity']['enabled'] = 0;
194  }
195 
196  if (empty($user->rights->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) $this->lines[] = $line;
248  }
249  }
250  }
251 
252  return $resultcreate;
253  }
254 
262  public function createFromClone(User $user, $fromid)
263  {
264  global $langs, $extrafields;
265  $error = 0;
266 
267  dol_syslog(__METHOD__, LOG_DEBUG);
268 
269  $object = new self($this->db);
270 
271  $this->db->begin();
272 
273  // Load source object
274  $result = $object->fetchCommon($fromid);
275  if ($result > 0 && !empty($object->table_element_line)) {
276  $object->fetchLines();
277  }
278 
279  // get lines so they will be clone
280  //foreach($this->lines as $line)
281  // $line->fetch_optionals();
282 
283  // Reset some properties
284  unset($object->id);
285  unset($object->fk_user_creat);
286  unset($object->import_key);
287 
288  // Clear fields
289  if (property_exists($object, 'ref')) {
290  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
291  }
292  if (property_exists($object, 'label')) {
293  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
294  }
295  if (property_exists($object, 'status')) {
296  $object->status = self::STATUS_DRAFT;
297  }
298  if (property_exists($object, 'date_creation')) {
299  $object->date_creation = dol_now();
300  }
301  if (property_exists($object, 'date_modification')) {
302  $object->date_modification = null;
303  }
304  // ...
305  // Clear extrafields that are unique
306  if (is_array($object->array_options) && count($object->array_options) > 0) {
307  $extrafields->fetch_name_optionals_label($this->table_element);
308  foreach ($object->array_options as $key => $option) {
309  $shortkey = preg_replace('/options_/', '', $key);
310  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
311  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
312  unset($object->array_options[$key]);
313  }
314  }
315  }
316 
317  // Create clone
318  $object->context['createfromclone'] = 'createfromclone';
319  $result = $object->createCommon($user);
320  if ($result < 0) {
321  $error++;
322  $this->error = $object->error;
323  $this->errors = $object->errors;
324  }
325 
326  if (!$error) {
327  // copy internal contacts
328  if ($this->copy_linked_contact($object, 'internal') < 0) {
329  $error++;
330  }
331  }
332 
333  if (!$error) {
334  // copy external contacts if same company
335  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
336  if ($this->copy_linked_contact($object, 'external') < 0) {
337  $error++;
338  }
339  }
340  }
341 
342  unset($object->context['createfromclone']);
343 
344  // End
345  if (!$error) {
346  $this->db->commit();
347  return $object;
348  } else {
349  $this->db->rollback();
350  return -1;
351  }
352  }
353 
361  public function fetch($id, $ref = null)
362  {
363  $result = $this->fetchCommon($id, $ref);
364  if ($result > 0 && !empty($this->table_element_line)) {
365  $this->fetchLines();
366  }
367  return $result;
368  }
369 
375  public function fetchLines()
376  {
377  $this->lines = array();
378 
379  $result = $this->fetchLinesCommon();
380  return $result;
381  }
382 
383 
395  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
396  {
397  global $conf;
398 
399  dol_syslog(__METHOD__, LOG_DEBUG);
400 
401  $records = array();
402 
403  $sql = 'SELECT ';
404  $sql .= $this->getFieldList('t');
405  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
406  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
407  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
408  } else {
409  $sql .= ' WHERE 1 = 1';
410  }
411  // Manage filter
412  $sqlwhere = array();
413  if (count($filter) > 0) {
414  foreach ($filter as $key => $value) {
415  if ($key == 't.rowid') {
416  $sqlwhere[] = $key.'='.$value;
417  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
418  $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
419  } elseif ($key == 'customsql') {
420  $sqlwhere[] = $value;
421  } elseif (strpos($value, '%') === false) {
422  $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
423  } else {
424  $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
425  }
426  }
427  }
428  if (count($sqlwhere) > 0) {
429  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
430  }
431 
432  if (!empty($sortfield)) {
433  $sql .= $this->db->order($sortfield, $sortorder);
434  }
435  if (!empty($limit)) {
436  $sql .= ' '.$this->db->plimit($limit, $offset);
437  }
438 
439  $resql = $this->db->query($sql);
440  if ($resql) {
441  $num = $this->db->num_rows($resql);
442  $i = 0;
443  while ($i < ($limit ? min($limit, $num) : $num)) {
444  $obj = $this->db->fetch_object($resql);
445 
446  $record = new self($this->db);
447  $record->setVarsFromFetchObj($obj);
448 
449  $records[$record->id] = $record;
450 
451  $i++;
452  }
453  $this->db->free($resql);
454 
455  return $records;
456  } else {
457  $this->errors[] = 'Error '.$this->db->lasterror();
458  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
459 
460  return -1;
461  }
462  }
463 
471  public function update(User $user, $notrigger = false)
472  {
473  return $this->updateCommon($user, $notrigger);
474  }
475 
483  public function delete(User $user, $notrigger = false)
484  {
485  return $this->deleteCommon($user, $notrigger);
486  //return $this->deleteCommon($user, $notrigger, 1);
487  }
488 
497  public function deleteLine(User $user, $idline, $notrigger = false)
498  {
499  if ($this->status < 0) {
500  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
501  return -2;
502  }
503 
504  return $this->deleteLineCommon($user, $idline, $notrigger);
505  }
506 
507 
515  public function validate($user, $notrigger = 0)
516  {
517  global $conf, $langs;
518 
519  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
520 
521  $error = 0;
522 
523  // Protection
524  if ($this->status == self::STATUS_VALIDATED) {
525  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
526  return 0;
527  }
528 
529 
530 
531  $now = dol_now();
532 
533  $this->db->begin();
534 
535  // Define new ref
536  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
537  $num = $this->getNextNumRef();
538  } else {
539  $num = $this->ref;
540  }
541  $this->newref = $num;
542 
543  if (!empty($num)) {
544  // Validate
545  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
546  $sql .= " SET ref = '".$this->db->escape($num)."',";
547  $sql .= " status = ".self::STATUS_VALIDATED;
548  if (!empty($this->fields['date_validation'])) {
549  $sql .= ", date_validation = '".$this->db->idate($now)."'";
550  }
551  if (!empty($this->fields['fk_user_valid'])) {
552  $sql .= ", fk_user_valid = ".((int) $user->id);
553  }
554  $sql .= " WHERE rowid = ".((int) $this->id);
555 
556  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
557  $resql = $this->db->query($sql);
558  if (!$resql) {
559  dol_print_error($this->db);
560  $this->error = $this->db->lasterror();
561  $error++;
562  }
563 
564  if (!$error && !$notrigger) {
565  // Call trigger
566  $result = $this->call_trigger('EVALUATION_VALIDATE', $user);
567  if ($result < 0) {
568  $error++;
569  }
570  // End call triggers
571  }
572  }
573 
574  if (!$error) {
575  $this->oldref = $this->ref;
576 
577  // Rename directory if dir was a temporary ref
578  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
579  // Now we rename also files into index
580  $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)."'";
581  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
582  $resql = $this->db->query($sql);
583  if (!$resql) {
584  $error++; $this->error = $this->db->lasterror();
585  }
586 
587  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
588  $oldref = dol_sanitizeFileName($this->ref);
589  $newref = dol_sanitizeFileName($num);
590  $dirsource = $conf->hrm->dir_output.'/evaluation/'.$oldref;
591  $dirdest = $conf->hrm->dir_output.'/evaluation/'.$newref;
592  if (!$error && file_exists($dirsource)) {
593  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
594 
595  if (@rename($dirsource, $dirdest)) {
596  dol_syslog("Rename ok");
597  // Rename docs starting with $oldref with $newref
598  $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
599  foreach ($listoffiles as $fileentry) {
600  $dirsource = $fileentry['name'];
601  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
602  $dirsource = $fileentry['path'].'/'.$dirsource;
603  $dirdest = $fileentry['path'].'/'.$dirdest;
604  @rename($dirsource, $dirdest);
605  }
606  }
607  }
608  }
609  }
610 
611  // Set new ref and current status
612  if (!$error) {
613  $this->ref = $num;
614  $this->status = self::STATUS_VALIDATED;
615  }
616 
617  if (!$error) {
618  $this->db->commit();
619  return 1;
620  } else {
621  $this->db->rollback();
622  return -1;
623  }
624  }
625 
632  public function getLastEvaluationForUser($fk_user)
633  {
634  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."hrm_evaluation ";
635  $sql.= "WHERE fk_user=".((int) $fk_user)." ";
636  $sql.= "ORDER BY date_eval DESC ";
637  $sql.= "LIMIT 1 ";
638 
639  $res = $this->db->query($sql);
640  if (!$res) { dol_print_error($this->db);}
641 
642  $Tab = $this->db->fetch_object($res);
643 
644  if (empty($Tab)) return null;
645  else {
646  $evaluation = new Evaluation($this->db);
647  $evaluation->fetch($Tab->rowid);
648 
649  return $evaluation;
650  }
651  }
652 
653 
661  public function setDraft($user, $notrigger = 0)
662  {
663  // Protection
664  if ($this->status <= self::STATUS_DRAFT) {
665  return 0;
666  }
667 
668 
669 
670  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATION_UNVALIDATE');
671  }
672 
680  public function cancel($user, $notrigger = 0)
681  {
682  // Protection
683  if ($this->status != self::STATUS_VALIDATED) {
684  return 0;
685  }
686 
687 
688 
689  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATION_CANCEL');
690  }
691 
699  public function reopen($user, $notrigger = 0)
700  {
701  // Protection
702  if ($this->status != self::STATUS_CANCELED) {
703  return 0;
704  }
705 
706 
707 
708  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATION_REOPEN');
709  }
710 
721  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
722  {
723  global $conf, $langs, $hookmanager;
724 
725  if (!empty($conf->dol_no_mouse_hover)) {
726  $notooltip = 1; // Force disable tooltips
727  }
728 
729  $result = '';
730 
731  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluation").'</u>';
732  if (isset($this->status)) {
733  $label .= ' '.$this->getLibStatut(5);
734  }
735  $label .= '<br>';
736  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
737 
738  $url = dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$this->id;
739 
740  if ($option != 'nolink') {
741  // Add param to save lastsearch_values or not
742  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
743  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
744  $add_save_lastsearch_values = 1;
745  }
746  if ($add_save_lastsearch_values) {
747  $url .= '&save_lastsearch_values=1';
748  }
749  }
750 
751  $linkclose = '';
752  if (empty($notooltip)) {
753  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
754  $label = $langs->trans("ShowEvaluation");
755  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
756  }
757  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
758  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
759  } else {
760  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
761  }
762 
763  if ($option == 'nolink') {
764  $linkstart = '<span';
765  } else {
766  $linkstart = '<a href="'.$url.'"';
767  }
768  $linkstart .= $linkclose.'>';
769  if ($option == 'nolink') {
770  $linkend = '</span>';
771  } else {
772  $linkend = '</a>';
773  }
774 
775  $result .= $linkstart;
776 
777  if (empty($this->showphoto_on_popup)) {
778  if ($withpicto) {
779  $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);
780  }
781  } else {
782  if ($withpicto) {
783  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
784 
785  list($class, $module) = explode('@', $this->picto);
786  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
787  $filearray = dol_dir_list($upload_dir, "files");
788  $filename = $filearray[0]['name'];
789  if (!empty($filename)) {
790  $pospoint = strpos($filearray[0]['name'], '.');
791 
792  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
793  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
794  $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>';
795  } else {
796  $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>';
797  }
798 
799  $result .= '</div>';
800  } else {
801  $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);
802  }
803  }
804  }
805 
806  if ($withpicto != 2) {
807  $result .= $this->ref;
808  }
809 
810  $result .= $linkend;
811  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
812 
813  global $action, $hookmanager;
814  $hookmanager->initHooks(array('evaluationdao'));
815  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
816  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
817  if ($reshook > 0) {
818  $result = $hookmanager->resPrint;
819  } else {
820  $result .= $hookmanager->resPrint;
821  }
822 
823  return $result;
824  }
825 
832  public function getLibStatut($mode = 0)
833  {
834  return $this->LibStatut($this->status, $mode);
835  }
836 
837  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
845  public function LibStatut($status, $mode = 0)
846  {
847  // phpcs:enable
848  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
849  global $langs;
850  //$langs->load("hrm");
851  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
852  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
853  $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
854  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
855  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
856  $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
857  }
858 
859  $statusType = 'status'.$status;
860  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
861  if ($status == self::STATUS_CANCELED) {
862  $statusType = 'status6';
863  }
864 
865  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
866  }
867 
874  public function info($id)
875  {
876  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
877  $sql .= ' fk_user_creat, fk_user_modif';
878  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
879  $sql .= ' WHERE t.rowid = '.((int) $id);
880  $result = $this->db->query($sql);
881  if ($result) {
882  if ($this->db->num_rows($result)) {
883  $obj = $this->db->fetch_object($result);
884  $this->id = $obj->rowid;
885 
886  $this->user_creation_id = $obj->fk_user_creat;
887  $this->user_modification_id = $obj->fk_user_modif;
888  $this->date_creation = $this->db->jdate($obj->datec);
889  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
890  }
891 
892  $this->db->free($result);
893  } else {
894  dol_print_error($this->db);
895  }
896  }
897 
904  public function initAsSpecimen()
905  {
906  // Set here init that are not commonf fields
907  // $this->property1 = ...
908  // $this->property2 = ...
909 
910  $this->initAsSpecimenCommon();
911  }
912 
918  public function getLinesArray()
919  {
920  $this->lines = array();
921 
922  $objectline = new Evaluationline($this->db);
923  $result = $objectline->fetchAll('ASC', '', 0, 0, array('customsql'=>'fk_evaluation = '.$this->id));
924 
925  if (is_numeric($result)) {
926  $this->error = $objectline->error;
927  $this->errors = $objectline->errors;
928  return $result;
929  } else {
930  $this->lines = $result;
931  return $this->lines;
932  }
933  }
934 
940  public function getNextNumRef()
941  {
942  global $langs, $conf;
943  $langs->load("hrm");
944 
945  if (empty($conf->global->HRMTEST_EVALUATION_ADDON)) {
946  $conf->global->HRMTEST_EVALUATION_ADDON = 'mod_evaluation_standard';
947  }
948 
949  if (!empty($conf->global->HRMTEST_EVALUATION_ADDON)) {
950  $mybool = false;
951 
952  $file = $conf->global->HRMTEST_EVALUATION_ADDON.".php";
953  $classname = $conf->global->HRMTEST_EVALUATION_ADDON;
954 
955  // Include file with class
956  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
957  foreach ($dirmodels as $reldir) {
958  $dir = dol_buildpath($reldir."core/modules/hrm/");
959 
960  // Load file with numbering class (if found)
961  $mybool |= @include_once $dir.$file;
962  }
963 
964  if ($mybool === false) {
965  dol_print_error('', "Failed to include file ".$file);
966  return '';
967  }
968 
969  if (class_exists($classname)) {
970  $obj = new $classname();
971  $numref = $obj->getNextValue($this);
972 
973  if ($numref != '' && $numref != '-1') {
974  return $numref;
975  } else {
976  $this->error = $obj->error;
977  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
978  return "";
979  }
980  } else {
981  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
982  return "";
983  }
984  } else {
985  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
986  return "";
987  }
988  }
989 
1001  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1002  {
1003  global $conf, $langs;
1004 
1005  $result = 0;
1006  $includedocgeneration = 0;
1007 
1008  $langs->load("hrm");
1009 
1010  if (!dol_strlen($modele)) {
1011  $modele = 'standard_evaluation';
1012 
1013  if (!empty($this->model_pdf)) {
1014  $modele = $this->model_pdf;
1015  } elseif (!empty($conf->global->EVALUATION_ADDON_PDF)) {
1016  $modele = $conf->global->EVALUATION_ADDON_PDF;
1017  }
1018  }
1019 
1020  $modelpath = "core/modules/hrm/doc/";
1021 
1022  if ($includedocgeneration && !empty($modele)) {
1023  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1024  }
1025 
1026  return $result;
1027  }
1028 
1036  public function doScheduledJob()
1037  {
1038  global $conf, $langs;
1039 
1040  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1041 
1042  $error = 0;
1043  $this->output = '';
1044  $this->error = '';
1045 
1046  dol_syslog(__METHOD__, LOG_DEBUG);
1047 
1048  $now = dol_now();
1049 
1050  $this->db->begin();
1051 
1052  // ...
1053 
1054  $this->db->commit();
1055 
1056  return $error;
1057  }
1058 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9573
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9851
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:9363
Evaluation\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: evaluation.class.php:904
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1236
Evaluation\create
create(User $user, $notrigger=false)
Create object into database.
Definition: evaluation.class.php:228
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:940
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:4993
Evaluation\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: evaluation.class.php:497
Evaluationline
Class for Evaluationline.
Definition: evaluationdet.class.php:37
ref
$object ref
Definition: info.php:78
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1061
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, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9419
Evaluation\update
update(User $user, $notrigger=false)
Update object into database.
Definition: evaluation.class.php:471
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:699
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:4024
Evaluation\getLinesArray
getLinesArray()
Create an array of lines.
Definition: evaluation.class.php:918
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9191
Evaluation\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: evaluation.class.php:262
Evaluation\info
info($id)
Load the info information in the object.
Definition: evaluation.class.php:874
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
Evaluation\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: evaluation.class.php:832
Evaluation\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: evaluation.class.php:1036
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
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:721
Evaluation\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: evaluation.class.php:661
Evaluation\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: evaluation.class.php:361
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9469
Evaluation\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: evaluation.class.php:845
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3887
Evaluation
Class for Evaluation.
Definition: evaluation.class.php:37
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
User
Class to manage Dolibarr users.
Definition: user.class.php:46
Evaluation\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: evaluation.class.php:375
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10745
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:4360
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9789
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5818
Evaluation\validate
validate($user, $notrigger=0)
Validate object.
Definition: evaluation.class.php:515
Evaluation\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: evaluation.class.php:680
SkillRank
Class for SkillRank.
Definition: skillrank.class.php:35
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9143
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:395
Evaluation\getLastEvaluationForUser
getLastEvaluationForUser($fk_user)
Get the last evaluation by date for the user assigned.
Definition: evaluation.class.php:632
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:1001