dolibarr  17.0.3
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  *
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/skillrank.class.php';
31 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
32 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
33 
38 {
42  public $module = 'hrm';
43 
47  public $element = 'evaluationdet';
48 
52  public $table_element = 'hrm_evaluationdet';
53 
58  public $ismultientitymanaged = 0;
59 
63  public $isextrafieldmanaged = 1;
64 
68  public $picto = 'evaluationdet@hrm';
69 
70 
71  const STATUS_DRAFT = 0;
72  const STATUS_VALIDATED = 1;
73  const STATUS_CANCELED = 9;
74 
75 
102  // BEGIN MODULEBUILDER PROPERTIES
106  public $fields=array(
107  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
108  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
109  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
110  'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
111  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
112  'fk_skill' => array('type'=>'integer:Skill:hrm/class/skill.class.php:1', 'label'=>'Skill', 'enabled'=>'1', 'position'=>3, 'notnull'=>1, 'visible'=>1, 'index'=>1,),
113  'fk_evaluation' => array('type'=>'integer:Evaluation:hrm/class/evaluation.class.php:1', 'label'=>'Evaluation', 'enabled'=>'1', 'position'=>3, 'notnull'=>1, 'visible'=>1, 'index'=>1,),
114  'rankorder' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>'1', 'position'=>4, 'notnull'=>1, 'visible'=>1,),
115  'required_rank' => array('type'=>'integer', 'label'=>'requiredRank', 'enabled'=>'1', 'position'=>5, 'notnull'=>1, 'visible'=>1,),
116  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
117  );
118  public $rowid;
119  public $date_creation;
120  public $tms;
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 
166 
172  public function __construct(DoliDB $db)
173  {
174  global $conf, $langs;
175 
176  $this->db = $db;
177 
178  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
179  $this->fields['rowid']['visible'] = 0;
180  }
181  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
182  $this->fields['entity']['enabled'] = 0;
183  }
184 
185  // Example to show how to set values of fields definition dynamically
186  /*if ($user->rights->hrm->evaluationdet->read) {
187  $this->fields['myfield']['visible'] = 1;
188  $this->fields['myfield']['noteditable'] = 0;
189  }*/
190 
191  // Unset fields that are disabled
192  foreach ($this->fields as $key => $val) {
193  if (isset($val['enabled']) && empty($val['enabled'])) {
194  unset($this->fields[$key]);
195  }
196  }
197 
198  // Translate some data of arrayofkeyval
199  if (is_object($langs)) {
200  foreach ($this->fields as $key => $val) {
201  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
202  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
203  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
204  }
205  }
206  }
207  }
208  }
209 
217  public function create(User $user, $notrigger = false)
218  {
219  $resultcreate = $this->createCommon($user, $notrigger);
220 
221  return $resultcreate;
222  }
223 
231  public function createFromClone(User $user, $fromid)
232  {
233  global $langs, $extrafields;
234  $error = 0;
235 
236  dol_syslog(__METHOD__, LOG_DEBUG);
237 
238  $object = new self($this->db);
239 
240  $this->db->begin();
241 
242  // Load source object
243  $result = $object->fetchCommon($fromid);
244  if ($result > 0 && !empty($object->table_element_line)) {
245  $object->fetchLines();
246  }
247 
248  // get lines so they will be clone
249  //foreach($this->lines as $line)
250  // $line->fetch_optionals();
251 
252  // Reset some properties
253  unset($object->id);
254  unset($object->fk_user_creat);
255  unset($object->import_key);
256 
257  // Clear fields
258  if (property_exists($object, 'ref')) {
259  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
260  }
261  if (property_exists($object, 'label')) {
262  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
263  }
264  if (property_exists($object, 'status')) {
265  $object->status = self::STATUS_DRAFT;
266  }
267  if (property_exists($object, 'date_creation')) {
268  $object->date_creation = dol_now();
269  }
270  if (property_exists($object, 'date_modification')) {
271  $object->date_modification = null;
272  }
273  // ...
274  // Clear extrafields that are unique
275  if (is_array($object->array_options) && count($object->array_options) > 0) {
276  $extrafields->fetch_name_optionals_label($this->table_element);
277  foreach ($object->array_options as $key => $option) {
278  $shortkey = preg_replace('/options_/', '', $key);
279  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
280  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
281  unset($object->array_options[$key]);
282  }
283  }
284  }
285 
286  // Create clone
287  $object->context['createfromclone'] = 'createfromclone';
288  $result = $object->createCommon($user);
289  if ($result < 0) {
290  $error++;
291  $this->error = $object->error;
292  $this->errors = $object->errors;
293  }
294 
295  if (!$error) {
296  // copy internal contacts
297  if ($this->copy_linked_contact($object, 'internal') < 0) {
298  $error++;
299  }
300  }
301 
302  if (!$error) {
303  // copy external contacts if same company
304  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
305  if ($this->copy_linked_contact($object, 'external') < 0) {
306  $error++;
307  }
308  }
309  }
310 
311  unset($object->context['createfromclone']);
312 
313  // End
314  if (!$error) {
315  $this->db->commit();
316  return $object;
317  } else {
318  $this->db->rollback();
319  return -1;
320  }
321  }
322 
330  public function fetch($id, $ref = null)
331  {
332  $result = $this->fetchCommon($id, $ref);
333  if ($result > 0 && !empty($this->table_element_line)) {
334  $this->fetchLines();
335  }
336  return $result;
337  }
338 
344  public function fetchLines()
345  {
346  $this->lines = array();
347 
348  $result = $this->fetchLinesCommon();
349  return $result;
350  }
351 
352 
364  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
365  {
366  global $conf;
367 
368  dol_syslog(__METHOD__, LOG_DEBUG);
369 
370  $records = array();
371 
372  $sql = 'SELECT ';
373  $sql .= $this->getFieldList('t');
374  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
375  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
376  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
377  } else {
378  $sql .= ' WHERE 1 = 1';
379  }
380  // Manage filter
381  $sqlwhere = array();
382  if (count($filter) > 0) {
383  foreach ($filter as $key => $value) {
384  if ($key == 't.rowid') {
385  $sqlwhere[] = $key.'='.$value;
386  } elseif ($key == 'customsql') {
387  $sqlwhere[] = $value;
388  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
389  $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
390  } elseif (strpos($value, '%') === false) {
391  $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
392  } else {
393  $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
394  }
395  }
396  }
397  if (count($sqlwhere) > 0) {
398  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
399  }
400 
401  if (!empty($sortfield)) {
402  $sql .= $this->db->order($sortfield, $sortorder);
403  }
404  if (!empty($limit)) {
405  $sql .= ' '.$this->db->plimit($limit, $offset);
406  }
407 
408  $resql = $this->db->query($sql);
409  if ($resql) {
410  $num = $this->db->num_rows($resql);
411  $i = 0;
412  while ($i < ($limit ? min($limit, $num) : $num)) {
413  $obj = $this->db->fetch_object($resql);
414 
415  $record = new self($this->db);
416  $record->setVarsFromFetchObj($obj);
417 
418  $records[$record->id] = $record;
419 
420  $i++;
421  }
422  $this->db->free($resql);
423 
424  return $records;
425  } else {
426  $this->errors[] = 'Error '.$this->db->lasterror();
427  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
428 
429  return -1;
430  }
431  }
432 
440  public function update(User $user, $notrigger = false)
441  {
442  return $this->updateCommon($user, $notrigger);
443  }
444 
452  public function delete(User $user, $notrigger = false)
453  {
454  if ($this->fk_rank) {
455  $skillRank = new SkillRank($this->db);
456  $skillRank->fetch($this->fk_rank);
457  $skillRank->delete($user, $notrigger);
458  }
459  return $this->deleteCommon($user, $notrigger);
460  //return $this->deleteCommon($user, $notrigger, 1);
461  }
462 
471  public function deleteLine(User $user, $idline, $notrigger = false)
472  {
473  if ($this->status < 0) {
474  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
475  return -2;
476  }
477 
478  return $this->deleteLineCommon($user, $idline, $notrigger);
479  }
480 
481 
489  public function validate($user, $notrigger = 0)
490  {
491  global $conf, $langs;
492 
493  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
494 
495  $error = 0;
496 
497  // Protection
498  if ($this->status == self::STATUS_VALIDATED) {
499  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
500  return 0;
501  }
502 
503  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->write))
504  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->evaluationdet_advance->validate))))
505  {
506  $this->error='NotEnoughPermissions';
507  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
508  return -1;
509  }*/
510 
511  $now = dol_now();
512 
513  $this->db->begin();
514 
515  // Define new ref
516  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
517  $num = $this->getNextNumRef();
518  } else {
519  $num = $this->ref;
520  }
521  $this->newref = $num;
522 
523  if (!empty($num)) {
524  // Validate
525  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
526  $sql .= " SET ref = '".$this->db->escape($num)."',";
527  $sql .= " status = ".self::STATUS_VALIDATED;
528  if (!empty($this->fields['date_validation'])) {
529  $sql .= ", date_validation = '".$this->db->idate($now)."'";
530  }
531  if (!empty($this->fields['fk_user_valid'])) {
532  $sql .= ", fk_user_valid = ".((int) $user->id);
533  }
534  $sql .= " WHERE rowid = ".((int) $this->id);
535 
536  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
537  $resql = $this->db->query($sql);
538  if (!$resql) {
539  dol_print_error($this->db);
540  $this->error = $this->db->lasterror();
541  $error++;
542  }
543 
544  if (!$error && !$notrigger) {
545  // Call trigger
546  $result = $this->call_trigger('EVALUATIONLINE_VALIDATE', $user);
547  if ($result < 0) {
548  $error++;
549  }
550  // End call triggers
551  }
552  }
553 
554  if (!$error) {
555  $this->oldref = $this->ref;
556 
557  // Rename directory if dir was a temporary ref
558  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
559  // Now we rename also files into index
560  $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)."'";
561  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
562  $resql = $this->db->query($sql);
563  if (!$resql) {
564  $error++;
565  $this->error = $this->db->lasterror();
566  }
567 
568  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
569  $oldref = dol_sanitizeFileName($this->ref);
570  $newref = dol_sanitizeFileName($num);
571  $dirsource = $conf->hrm->dir_output.'/evaluationline/'.$oldref;
572  $dirdest = $conf->hrm->dir_output.'/evaluationline/'.$newref;
573  if (!$error && file_exists($dirsource)) {
574  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
575 
576  if (@rename($dirsource, $dirdest)) {
577  dol_syslog("Rename ok");
578  // Rename docs starting with $oldref with $newref
579  $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluationline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
580  foreach ($listoffiles as $fileentry) {
581  $dirsource = $fileentry['name'];
582  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
583  $dirsource = $fileentry['path'].'/'.$dirsource;
584  $dirdest = $fileentry['path'].'/'.$dirdest;
585  @rename($dirsource, $dirdest);
586  }
587  }
588  }
589  }
590  }
591 
592  // Set new ref and current status
593  if (!$error) {
594  $this->ref = $num;
595  $this->status = self::STATUS_VALIDATED;
596  }
597 
598  if (!$error) {
599  $this->db->commit();
600  return 1;
601  } else {
602  $this->db->rollback();
603  return -1;
604  }
605  }
606 
607 
615  public function setDraft($user, $notrigger = 0)
616  {
617  // Protection
618  if ($this->status <= self::STATUS_DRAFT) {
619  return 0;
620  }
621 
622  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
623  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
624  {
625  $this->error='Permission denied';
626  return -1;
627  }*/
628 
629  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATIONLINE_UNVALIDATE');
630  }
631 
639  public function cancel($user, $notrigger = 0)
640  {
641  // Protection
642  if ($this->status != self::STATUS_VALIDATED) {
643  return 0;
644  }
645 
646  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
647  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
648  {
649  $this->error='Permission denied';
650  return -1;
651  }*/
652 
653  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATIONLINE_CANCEL');
654  }
655 
663  public function reopen($user, $notrigger = 0)
664  {
665  // Protection
666  if ($this->status != self::STATUS_CANCELED) {
667  return 0;
668  }
669 
670  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
671  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
672  {
673  $this->error='Permission denied';
674  return -1;
675  }*/
676 
677  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATIONLINE_REOPEN');
678  }
679 
690  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
691  {
692  global $conf, $langs, $hookmanager;
693 
694  if (!empty($conf->dol_no_mouse_hover)) {
695  $notooltip = 1; // Force disable tooltips
696  }
697 
698  $result = '';
699 
700  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluationdet").'</u>';
701  if (isset($this->status)) {
702  $label .= ' '.$this->getLibStatut(5);
703  }
704  $label .= '<br>';
705  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
706 
707  $url = dol_buildpath('/hrm/evaluationdet_card.php', 1).'?id='.$this->id;
708 
709  if ($option != 'nolink') {
710  // Add param to save lastsearch_values or not
711  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
712  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
713  $add_save_lastsearch_values = 1;
714  }
715  if ($add_save_lastsearch_values) {
716  $url .= '&save_lastsearch_values=1';
717  }
718  }
719 
720  $linkclose = '';
721  if (empty($notooltip)) {
722  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
723  $label = $langs->trans("ShowEvaluationdet");
724  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
725  }
726  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
727  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
728  } else {
729  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
730  }
731 
732  if ($option == 'nolink') {
733  $linkstart = '<span';
734  } else {
735  $linkstart = '<a href="'.$url.'"';
736  }
737  $linkstart .= $linkclose.'>';
738  if ($option == 'nolink') {
739  $linkend = '</span>';
740  } else {
741  $linkend = '</a>';
742  }
743 
744  $result .= $linkstart;
745 
746  if (empty($this->showphoto_on_popup)) {
747  if ($withpicto) {
748  $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);
749  }
750  } else {
751  if ($withpicto) {
752  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
753 
754  list($class, $module) = explode('@', $this->picto);
755  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
756  $filearray = dol_dir_list($upload_dir, "files");
757  $filename = $filearray[0]['name'];
758  if (!empty($filename)) {
759  $pospoint = strpos($filearray[0]['name'], '.');
760 
761  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
762  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
763  $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>';
764  } else {
765  $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>';
766  }
767 
768  $result .= '</div>';
769  } else {
770  $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);
771  }
772  }
773  }
774 
775  if ($withpicto != 2) {
776  $result .= $this->ref;
777  }
778 
779  $result .= $linkend;
780  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
781 
782  global $action, $hookmanager;
783  $hookmanager->initHooks(array('evaluationlinedao'));
784  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
785  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
786  if ($reshook > 0) {
787  $result = $hookmanager->resPrint;
788  } else {
789  $result .= $hookmanager->resPrint;
790  }
791 
792  return $result;
793  }
794 
801  public function getLibStatut($mode = 0)
802  {
803  return $this->LibStatut($this->status, $mode);
804  }
805 
806  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
814  public function LibStatut($status, $mode = 0)
815  {
816  // phpcs:enable
817  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
818  global $langs;
819  //$langs->load("hrm");
820  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
821  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
822  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
823  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
824  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
825  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
826  }
827 
828  $statusType = 'status'.$status;
829  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
830  if ($status == self::STATUS_CANCELED) {
831  $statusType = 'status6';
832  }
833 
834  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
835  }
836 
843  public function info($id)
844  {
845  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
846  $sql .= ' fk_user_creat, fk_user_modif';
847  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
848  $sql .= ' WHERE t.rowid = '.((int) $id);
849  $result = $this->db->query($sql);
850  if ($result) {
851  if ($this->db->num_rows($result)) {
852  $obj = $this->db->fetch_object($result);
853  $this->id = $obj->rowid;
854 
855  $this->user_creation_id = $obj->fk_user_creat;
856  $this->user_modification_id = $obj->fk_user_modif;
857  $this->date_creation = $this->db->jdate($obj->datec);
858  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
859  }
860 
861  $this->db->free($result);
862  } else {
863  dol_print_error($this->db);
864  }
865  }
866 
873  public function initAsSpecimen()
874  {
875  // Set here init that are not commonf fields
876  // $this->property1 = ...
877  // $this->property2 = ...
878 
879  $this->initAsSpecimenCommon();
880  }
881 
887  public function getLinesArray()
888  {
889  $this->lines = array();
890 
891  $objectline = new EvaluationLine($this->db);
892  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_evaluationdet = '.$this->id));
893 
894  if (is_numeric($result)) {
895  $this->error = $objectline->error;
896  $this->errors = $objectline->errors;
897  return $result;
898  } else {
899  $this->lines = $result;
900  return $this->lines;
901  }
902  }
903 
909  public function getNextNumRef()
910  {
911  global $langs, $conf;
912  $langs->load("hrm");
913 
914  if (empty($conf->global->hrm_EVALUATIONLINE_ADDON)) {
915  $conf->global->hrm_EVALUATIONLINE_ADDON = 'mod_evaluationdet_standard';
916  }
917 
918  if (!empty($conf->global->hrm_EVALUATIONLINE_ADDON)) {
919  $mybool = false;
920 
921  $file = $conf->global->hrm_EVALUATIONLINE_ADDON.".php";
922  $classname = $conf->global->hrm_EVALUATIONLINE_ADDON;
923 
924  // Include file with class
925  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
926  foreach ($dirmodels as $reldir) {
927  $dir = dol_buildpath($reldir."core/modules/hrm/");
928 
929  // Load file with numbering class (if found)
930  $mybool |= @include_once $dir.$file;
931  }
932 
933  if ($mybool === false) {
934  dol_print_error('', "Failed to include file ".$file);
935  return '';
936  }
937 
938  if (class_exists($classname)) {
939  $obj = new $classname();
940  $numref = $obj->getNextValue($this);
941 
942  if ($numref != '' && $numref != '-1') {
943  return $numref;
944  } else {
945  $this->error = $obj->error;
946  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
947  return "";
948  }
949  } else {
950  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
951  return "";
952  }
953  } else {
954  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
955  return "";
956  }
957  }
958 
970  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
971  {
972  global $conf, $langs;
973 
974  $result = 0;
975  $includedocgeneration = 0;
976 
977  $langs->load("hrm");
978 
979  if (!dol_strlen($modele)) {
980  $modele = 'standard_evaluationdet';
981 
982  if (!empty($this->model_pdf)) {
983  $modele = $this->model_pdf;
984  } elseif (!empty($conf->global->EVALUATIONLINE_ADDON_PDF)) {
985  $modele = $conf->global->EVALUATIONLINE_ADDON_PDF;
986  }
987  }
988 
989  $modelpath = "core/modules/hrm/doc/";
990 
991  if ($includedocgeneration && !empty($modele)) {
992  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
993  }
994 
995  return $result;
996  }
997 
1005  public function doScheduledJob()
1006  {
1007  global $conf, $langs;
1008 
1009  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1010 
1011  $error = 0;
1012  $this->output = '';
1013  $this->error = '';
1014 
1015  dol_syslog(__METHOD__, LOG_DEBUG);
1016 
1017  $now = dol_now();
1018 
1019  $this->db->begin();
1020 
1021  // ...
1022 
1023  $this->db->commit();
1024 
1025  return $error;
1026  }
1027 }
1028 
1029 
1030 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
Evaluationline\update
update(User $user, $notrigger=false)
Update object into database.
Definition: evaluationdet.class.php:440
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
Evaluationline\info
info($id)
Load the info information in the object.
Definition: evaluationdet.class.php:843
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9363
Evaluationline\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: evaluationdet.class.php:690
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
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
Evaluationline\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: evaluationdet.class.php:970
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
Evaluationline
Class for Evaluationline.
Definition: evaluationdet.class.php:37
ref
$object ref
Definition: info.php:78
Evaluationline\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: evaluationdet.class.php:231
Evaluationline\validate
validate($user, $notrigger=0)
Validate object.
Definition: evaluationdet.class.php:489
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1061
Evaluationline\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: evaluationdet.class.php:364
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
Evaluationline\create
create(User $user, $notrigger=false)
Create object into database.
Definition: evaluationdet.class.php:217
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
Evaluationline\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: evaluationdet.class.php:330
Evaluationline\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: evaluationdet.class.php:639
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
Evaluationline\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: evaluationdet.class.php:801
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9191
Evaluationline\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: evaluationdet.class.php:615
Evaluationline\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: evaluationdet.class.php:471
Evaluationline\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: evaluationdet.class.php:909
Evaluationline\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: evaluationdet.class.php:344
Evaluationline\getLinesArray
getLinesArray()
Create an array of lines.
Definition: evaluationdet.class.php:887
$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
Evaluationline\__construct
__construct(DoliDB $db)
Constructor.
Definition: evaluationdet.class.php:172
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9469
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3887
Evaluationline\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: evaluationdet.class.php:814
Evaluationline\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: evaluationdet.class.php:663
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
User
Class to manage Dolibarr users.
Definition: user.class.php:46
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
Evaluationline\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: evaluationdet.class.php:1005
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
Evaluationline\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: evaluationdet.class.php:873
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
SkillRank
Class for SkillRank.
Definition: skillrank.class.php:35
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9143