dolibarr  20.0.0-alpha
evaluationdet.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4  * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5  * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6  * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
7  * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 // Put here all includes required by your class file
31 require_once DOL_DOCUMENT_ROOT . '/core/class/commonobjectline.class.php';
32 require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
33 
34 
39 {
43  public $module = 'hrm';
44 
48  public $element = 'evaluationdet';
49 
53  public $table_element = 'hrm_evaluationdet';
54 
59  public $ismultientitymanaged = 0;
60 
64  public $isextrafieldmanaged = 1;
65 
69  public $picto = 'evaluationdet@hrm';
70 
71 
72  const STATUS_DRAFT = 0;
73  const STATUS_VALIDATED = 1;
74  const STATUS_CANCELED = 9;
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  'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
110  'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
111  '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',),
112  'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
113  'fk_skill' => array('type' => 'integer:Skill:hrm/class/skill.class.php:1', 'label' => 'Skill', 'enabled' => 1, 'position' => 3, 'notnull' => 1, 'visible' => 1, 'index' => 1,),
114  'fk_evaluation' => array('type' => 'integer:Evaluation:hrm/class/evaluation.class.php:1', 'label' => 'Evaluation', 'enabled' => 1, 'position' => 3, 'notnull' => 1, 'visible' => 1, 'index' => 1,),
115  'rankorder' => array('type' => 'integer', 'label' => 'Rank', 'enabled' => 1, 'position' => 4, 'notnull' => 1, 'visible' => 1,),
116  'required_rank' => array('type' => 'integer', 'label' => 'requiredRank', 'enabled' => 1, 'position' => 5, 'notnull' => 1, 'visible' => 1,),
117  'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
118  );
119  public $rowid;
120  public $date_creation;
121  public $fk_user_creat;
122  public $fk_user_modif;
123  public $fk_skill;
124  public $fk_evaluation;
125  public $fk_rank;
126  public $required_rank;
127  public $import_key;
128  // END MODULEBUILDER PROPERTIES
129 
130 
131  // If this object has a subtable with lines
132 
133  // /**
134  // * @var string Name of subtable line
135  // */
136  // public $table_element_line = 'hrm_evaluationline';
137 
138  // /**
139  // * @var string Field with ID of parent key if this object has a parent
140  // */
141  // public $fk_element = 'fk_evaluationdet';
142 
143  // /**
144  // * @var string Name of subtable class that manage subtable lines
145  // */
146  // public $class_element_line = 'EvaluationLine';
147 
148  // /**
149  // * @var array List of child tables. To test if we can delete object.
150  // */
151  // protected $childtables = array();
152 
153  // /**
154  // * @var array List of child tables. To know object to delete on cascade.
155  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
156  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
157  // */
158  // protected $childtablesoncascade = array('hrm_evaluationdetdet');
159 
160  // /**
161  // * @var EvaluationLine[] Array of subtable lines
162  // */
163  // public $lines = array();
164 
165 
171  public function __construct(DoliDB $db)
172  {
173  global $conf, $langs;
174 
175  $this->db = $db;
176 
177  if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
178  $this->fields['rowid']['visible'] = 0;
179  }
180  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
181  $this->fields['entity']['enabled'] = 0;
182  }
183 
184  // Example to show how to set values of fields definition dynamically
185  /*if ($user->rights->hrm->evaluationdet->read) {
186  $this->fields['myfield']['visible'] = 1;
187  $this->fields['myfield']['noteditable'] = 0;
188  }*/
189 
190  // Unset fields that are disabled
191  foreach ($this->fields as $key => $val) {
192  if (isset($val['enabled']) && empty($val['enabled'])) {
193  unset($this->fields[$key]);
194  }
195  }
196 
197  // Translate some data of arrayofkeyval
198  if (is_object($langs)) {
199  foreach ($this->fields as $key => $val) {
200  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
201  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
202  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
203  }
204  }
205  }
206  }
207  }
208 
216  public function create(User $user, $notrigger = 0)
217  {
218  $resultcreate = $this->createCommon($user, $notrigger);
219 
220  return $resultcreate;
221  }
222 
230  public function createFromClone(User $user, $fromid)
231  {
232  global $langs, $extrafields;
233  $error = 0;
234 
235  dol_syslog(__METHOD__, LOG_DEBUG);
236 
237  $object = new self($this->db);
238 
239  $this->db->begin();
240 
241  // Load source object
242  $result = $object->fetchCommon($fromid);
243  if ($result > 0 && !empty($object->table_element_line)) {
244  $object->fetchLines();
245  }
246 
247  // get lines so they will be clone
248  //foreach($this->lines as $line)
249  // $line->fetch_optionals();
250 
251  // Reset some properties
252  unset($object->id);
253  unset($object->fk_user_creat);
254  unset($object->import_key);
255 
256  // Clear fields
257  if (property_exists($object, 'ref')) {
258  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
259  }
260  if (property_exists($object, 'label')) {
261  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
262  }
263  if (property_exists($object, 'status')) {
264  $object->status = self::STATUS_DRAFT;
265  }
266  if (property_exists($object, 'date_creation')) {
267  $object->date_creation = dol_now();
268  }
269  if (property_exists($object, 'date_modification')) {
270  $object->date_modification = null;
271  }
272  // ...
273  // Clear extrafields that are unique
274  if (is_array($object->array_options) && count($object->array_options) > 0) {
275  $extrafields->fetch_name_optionals_label($this->table_element);
276  foreach ($object->array_options as $key => $option) {
277  $shortkey = preg_replace('/options_/', '', $key);
278  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
279  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
280  unset($object->array_options[$key]);
281  }
282  }
283  }
284 
285  // Create clone
286  $object->context['createfromclone'] = 'createfromclone';
287  $result = $object->createCommon($user);
288  if ($result < 0) {
289  $error++;
291  }
292 
293  if (!$error) {
294  // copy internal contacts
295  if ($this->copy_linked_contact($object, 'internal') < 0) {
296  $error++;
297  }
298  }
299 
300  if (!$error) {
301  // copy external contacts if same company
302  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
303  if ($this->copy_linked_contact($object, 'external') < 0) {
304  $error++;
305  }
306  }
307  }
308 
309  unset($object->context['createfromclone']);
310 
311  // End
312  if (!$error) {
313  $this->db->commit();
314  return $object;
315  } else {
316  $this->db->rollback();
317  return -1;
318  }
319  }
320 
328  public function fetch($id, $ref = null)
329  {
330  $result = $this->fetchCommon($id, $ref);
331  if ($result > 0 && !empty($this->table_element_line)) {
332  $this->fetchLines();
333  }
334  return $result;
335  }
336 
342  public function fetchLines()
343  {
344  $this->lines = array();
345 
346  $result = $this->fetchLinesCommon();
347  return $result;
348  }
349 
350 
363  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
364  {
365  global $conf;
366 
367  dol_syslog(__METHOD__, LOG_DEBUG);
368 
369  $records = array();
370 
371  $sql = 'SELECT ';
372  $sql .= $this->getFieldList('t');
373  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
374  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
375  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
376  } else {
377  $sql .= ' WHERE 1 = 1';
378  }
379 
380  // Manage filter
381  $errormessage = '';
382  $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
383  if ($errormessage) {
384  $this->errors[] = $errormessage;
385  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
386  return -1;
387  }
388 
389  if (!empty($sortfield)) {
390  $sql .= $this->db->order($sortfield, $sortorder);
391  }
392  if (!empty($limit)) {
393  $sql .= ' '.$this->db->plimit($limit, $offset);
394  }
395 
396  $resql = $this->db->query($sql);
397  if ($resql) {
398  $num = $this->db->num_rows($resql);
399  $i = 0;
400  while ($i < ($limit ? min($limit, $num) : $num)) {
401  $obj = $this->db->fetch_object($resql);
402 
403  $record = new self($this->db);
404  $record->setVarsFromFetchObj($obj);
405 
406  $records[$record->id] = $record;
407 
408  $i++;
409  }
410  $this->db->free($resql);
411 
412  return $records;
413  } else {
414  $this->errors[] = 'Error '.$this->db->lasterror();
415  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
416 
417  return -1;
418  }
419  }
420 
428  public function update(User $user, $notrigger = 0)
429  {
430  return $this->updateCommon($user, $notrigger);
431  }
432 
440  public function delete(User $user, $notrigger = 0)
441  {
442  if ($this->fk_rank) {
443  $skillRank = new SkillRank($this->db);
444  $skillRank->fetch($this->fk_rank);
445  $skillRank->delete($user, $notrigger);
446  }
447  return $this->deleteCommon($user, $notrigger);
448  //return $this->deleteCommon($user, $notrigger, 1);
449  }
450 
459  public function deleteLine(User $user, $idline, $notrigger = 0)
460  {
461  if ($this->status < 0) {
462  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
463  return -2;
464  }
465 
466  return $this->deleteLineCommon($user, $idline, $notrigger);
467  }
468 
469 
477  public function validate($user, $notrigger = 0)
478  {
479  global $conf, $langs;
480 
481  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
482 
483  $error = 0;
484 
485  // Protection
486  if ($this->status == self::STATUS_VALIDATED) {
487  dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
488  return 0;
489  }
490 
491  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->write))
492  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->evaluationdet_advance->validate))))
493  {
494  $this->error='NotEnoughPermissions';
495  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
496  return -1;
497  }*/
498 
499  $now = dol_now();
500 
501  $this->db->begin();
502 
503  // Define new ref
504  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
505  $num = $this->getNextNumRef();
506  } else {
507  $num = $this->ref;
508  }
509  $this->newref = $num;
510 
511  if (!empty($num)) {
512  // Validate
513  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
514  $sql .= " SET ref = '".$this->db->escape($num)."',";
515  $sql .= " status = ".self::STATUS_VALIDATED;
516  if (!empty($this->fields['date_validation'])) {
517  $sql .= ", date_validation = '".$this->db->idate($now)."'";
518  }
519  if (!empty($this->fields['fk_user_valid'])) {
520  $sql .= ", fk_user_valid = ".((int) $user->id);
521  }
522  $sql .= " WHERE rowid = ".((int) $this->id);
523 
524  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
525  $resql = $this->db->query($sql);
526  if (!$resql) {
527  dol_print_error($this->db);
528  $this->error = $this->db->lasterror();
529  $error++;
530  }
531 
532  if (!$error && !$notrigger) {
533  // Call trigger
534  $result = $this->call_trigger('HRM_EVALUATIONLINE_VALIDATE', $user);
535  if ($result < 0) {
536  $error++;
537  }
538  // End call triggers
539  }
540  }
541 
542  if (!$error) {
543  $this->oldref = $this->ref;
544 
545  // Rename directory if dir was a temporary ref
546  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
547  // Now we rename also files into index
548  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'evaluationline/".$this->db->escape($this->newref)."'";
549  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
550  $resql = $this->db->query($sql);
551  if (!$resql) {
552  $error++;
553  $this->error = $this->db->lasterror();
554  }
555  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'evaluationline/".$this->db->escape($this->newref)."'";
556  $sql .= " WHERE filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
557  $resql = $this->db->query($sql);
558  if (!$resql) {
559  $error++;
560  $this->error = $this->db->lasterror();
561  }
562 
563  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
564  $oldref = dol_sanitizeFileName($this->ref);
565  $newref = dol_sanitizeFileName($num);
566  $dirsource = $conf->hrm->dir_output.'/evaluationline/'.$oldref;
567  $dirdest = $conf->hrm->dir_output.'/evaluationline/'.$newref;
568  if (!$error && file_exists($dirsource)) {
569  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
570 
571  if (@rename($dirsource, $dirdest)) {
572  dol_syslog("Rename ok");
573  // Rename docs starting with $oldref with $newref
574  $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluationline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
575  foreach ($listoffiles as $fileentry) {
576  $dirsource = $fileentry['name'];
577  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
578  $dirsource = $fileentry['path'].'/'.$dirsource;
579  $dirdest = $fileentry['path'].'/'.$dirdest;
580  @rename($dirsource, $dirdest);
581  }
582  }
583  }
584  }
585  }
586 
587  // Set new ref and current status
588  if (!$error) {
589  $this->ref = $num;
590  $this->status = self::STATUS_VALIDATED;
591  }
592 
593  if (!$error) {
594  $this->db->commit();
595  return 1;
596  } else {
597  $this->db->rollback();
598  return -1;
599  }
600  }
601 
602 
610  public function setDraft($user, $notrigger = 0)
611  {
612  // Protection
613  if ($this->status <= self::STATUS_DRAFT) {
614  return 0;
615  }
616 
617  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
618  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
619  {
620  $this->error='Permission denied';
621  return -1;
622  }*/
623 
624  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATIONLINE_UNVALIDATE');
625  }
626 
634  public function cancel($user, $notrigger = 0)
635  {
636  // Protection
637  if ($this->status != self::STATUS_VALIDATED) {
638  return 0;
639  }
640 
641  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
642  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
643  {
644  $this->error='Permission denied';
645  return -1;
646  }*/
647 
648  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATIONLINE_CANCEL');
649  }
650 
658  public function reopen($user, $notrigger = 0)
659  {
660  // Protection
661  if ($this->status != self::STATUS_CANCELED) {
662  return 0;
663  }
664 
665  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
666  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
667  {
668  $this->error='Permission denied';
669  return -1;
670  }*/
671 
672  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATIONLINE_REOPEN');
673  }
674 
685  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
686  {
687  global $conf, $langs, $hookmanager;
688 
689  if (!empty($conf->dol_no_mouse_hover)) {
690  $notooltip = 1; // Force disable tooltips
691  }
692 
693  $result = '';
694 
695  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluationdet").'</u>';
696  if (isset($this->status)) {
697  $label .= ' '.$this->getLibStatut(5);
698  }
699  $label .= '<br>';
700  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
701 
702  $url = dol_buildpath('/hrm/evaluationdet_card.php', 1).'?id='.$this->id;
703 
704  if ($option != 'nolink') {
705  // Add param to save lastsearch_values or not
706  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
707  if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
708  $add_save_lastsearch_values = 1;
709  }
710  if ($add_save_lastsearch_values) {
711  $url .= '&save_lastsearch_values=1';
712  }
713  }
714 
715  $linkclose = '';
716  if (empty($notooltip)) {
717  if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
718  $label = $langs->trans("ShowEvaluationdet");
719  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
720  }
721  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
722  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
723  } else {
724  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
725  }
726 
727  if ($option == 'nolink') {
728  $linkstart = '<span';
729  } else {
730  $linkstart = '<a href="'.$url.'"';
731  }
732  $linkstart .= $linkclose.'>';
733  if ($option == 'nolink') {
734  $linkend = '</span>';
735  } else {
736  $linkend = '</a>';
737  }
738 
739  $result .= $linkstart;
740 
741  if (empty($this->showphoto_on_popup)) {
742  if ($withpicto) {
743  $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);
744  }
745  } else {
746  if ($withpicto) {
747  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
748 
749  list($class, $module) = explode('@', $this->picto);
750  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
751  $filearray = dol_dir_list($upload_dir, "files");
752  $filename = $filearray[0]['name'];
753  if (!empty($filename)) {
754  $pospoint = strpos($filearray[0]['name'], '.');
755 
756  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
757  if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
758  $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>';
759  } else {
760  $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>';
761  }
762 
763  $result .= '</div>';
764  } else {
765  $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);
766  }
767  }
768  }
769 
770  if ($withpicto != 2) {
771  $result .= $this->ref;
772  }
773 
774  $result .= $linkend;
775  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
776 
777  global $action, $hookmanager;
778  $hookmanager->initHooks(array('evaluationlinedao'));
779  $parameters = array('id' => $this->id, 'getnomurl' => &$result);
780  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
781  if ($reshook > 0) {
782  $result = $hookmanager->resPrint;
783  } else {
784  $result .= $hookmanager->resPrint;
785  }
786 
787  return $result;
788  }
789 
796  public function getLibStatut($mode = 0)
797  {
798  return $this->LibStatut($this->status, $mode);
799  }
800 
801  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
809  public function LibStatut($status, $mode = 0)
810  {
811  // phpcs:enable
812  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
813  global $langs;
814  //$langs->load("hrm");
815  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
816  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
817  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
818  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
819  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
820  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
821  }
822 
823  $statusType = 'status'.$status;
824  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
825  if ($status == self::STATUS_CANCELED) {
826  $statusType = 'status6';
827  }
828 
829  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
830  }
831 
838  public function info($id)
839  {
840  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
841  $sql .= ' fk_user_creat, fk_user_modif';
842  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
843  $sql .= ' WHERE t.rowid = '.((int) $id);
844  $result = $this->db->query($sql);
845  if ($result) {
846  if ($this->db->num_rows($result)) {
847  $obj = $this->db->fetch_object($result);
848 
849  $this->id = $obj->rowid;
850 
851  $this->user_creation_id = $obj->fk_user_creat;
852  $this->user_modification_id = $obj->fk_user_modif;
853  $this->date_creation = $this->db->jdate($obj->datec);
854  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
855  }
856 
857  $this->db->free($result);
858  } else {
859  dol_print_error($this->db);
860  }
861  }
862 
869  public function initAsSpecimen()
870  {
871  // Set here init that are not commonf fields
872  // $this->property1 = ...
873  // $this->property2 = ...
874 
875  return $this->initAsSpecimenCommon();
876  }
877 
883  public function getLinesArray()
884  {
885  $this->lines = array();
886 
887  $objectline = new EvaluationLine($this->db);
888  $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_evaluationdet:=:'.((int) $this->id).')');
889 
890  if (is_numeric($result)) {
891  $this->setErrorsFromObject($objectline);
892  return $result;
893  } else {
894  $this->lines = $result;
895  return $this->lines;
896  }
897  }
898 
904  public function getNextNumRef()
905  {
906  global $langs, $conf;
907  $langs->load("hrm");
908 
909  if (!getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
910  $conf->global->hrm_EVALUATIONLINE_ADDON = 'mod_evaluationdet_standard';
911  }
912 
913  if (getDolGlobalString('hrm_EVALUATIONLINE_ADDON')) {
914  $mybool = false;
915 
916  $file = getDolGlobalString('hrm_EVALUATIONLINE_ADDON') . ".php";
917  $classname = getDolGlobalString('hrm_EVALUATIONLINE_ADDON');
918 
919  // Include file with class
920  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
921  foreach ($dirmodels as $reldir) {
922  $dir = dol_buildpath($reldir."core/modules/hrm/");
923 
924  // Load file with numbering class (if found)
925  $mybool = ((bool) @include_once $dir.$file) || $mybool;
926  }
927 
928  if ($mybool === false) {
929  dol_print_error(null, "Failed to include file ".$file);
930  return '';
931  }
932 
933  if (class_exists($classname)) {
934  $obj = new $classname();
935  $numref = $obj->getNextValue($this);
936 
937  if ($numref != '' && $numref != '-1') {
938  return $numref;
939  } else {
940  $this->error = $obj->error;
941  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
942  return "";
943  }
944  } else {
945  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
946  return "";
947  }
948  } else {
949  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
950  return "";
951  }
952  }
953 
965  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
966  {
967  global $conf, $langs;
968 
969  $result = 0;
970  $includedocgeneration = 0;
971 
972  $langs->load("hrm");
973 
974  if (!dol_strlen($modele)) {
975  $modele = 'standard_evaluationdet';
976 
977  if (!empty($this->model_pdf)) {
978  $modele = $this->model_pdf;
979  } elseif (getDolGlobalString('EVALUATIONLINE_ADDON_PDF')) {
980  $modele = getDolGlobalString('EVALUATIONLINE_ADDON_PDF');
981  }
982  }
983 
984  $modelpath = "core/modules/hrm/doc/";
985 
986  if ($includedocgeneration && !empty($modele)) {
987  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
988  }
989 
990  return $result;
991  }
992 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition: security.php:604
$object ref
Definition: info.php:79
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object into database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for EvaluationLine.
update(User $user, $notrigger=0)
Update object into database.
getLibStatut($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
createFromClone(User $user, $fromid)
Clone an object into another one.
fetch($id, $ref=null)
Load object in memory from the database.
info($id)
Load the info information in the object.
create(User $user, $notrigger=0)
Create object into database.
__construct(DoliDB $db)
Constructor.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
setDraft($user, $notrigger=0)
Set draft status.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
getLinesArray()
Create an array of lines.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
cancel($user, $notrigger=0)
Set cancel status.
LibStatut($status, $mode=0)
Return the status.
validate($user, $notrigger=0)
Validate object.
reopen($user, $notrigger=0)
Set back to validated status.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
fetchLines()
Load object lines in memory from the database.
Class for SkillRank.
Class to manage Dolibarr users.
Definition: user.class.php:50
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.