dolibarr  19.0.0-dev
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 
171  public function __construct(DoliDB $db)
172  {
173  global $conf, $langs;
174 
175  $this->db = $db;
176 
177  if (empty($conf->global->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 = false)
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++;
290  $this->error = $object->error;
291  $this->errors = $object->errors;
292  }
293 
294  if (!$error) {
295  // copy internal contacts
296  if ($this->copy_linked_contact($object, 'internal') < 0) {
297  $error++;
298  }
299  }
300 
301  if (!$error) {
302  // copy external contacts if same company
303  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
304  if ($this->copy_linked_contact($object, 'external') < 0) {
305  $error++;
306  }
307  }
308  }
309 
310  unset($object->context['createfromclone']);
311 
312  // End
313  if (!$error) {
314  $this->db->commit();
315  return $object;
316  } else {
317  $this->db->rollback();
318  return -1;
319  }
320  }
321 
329  public function fetch($id, $ref = null)
330  {
331  $result = $this->fetchCommon($id, $ref);
332  if ($result > 0 && !empty($this->table_element_line)) {
333  $this->fetchLines();
334  }
335  return $result;
336  }
337 
343  public function fetchLines()
344  {
345  $this->lines = array();
346 
347  $result = $this->fetchLinesCommon();
348  return $result;
349  }
350 
351 
363  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $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  // Manage filter
380  $sqlwhere = array();
381  if (count($filter) > 0) {
382  foreach ($filter as $key => $value) {
383  if ($key == 't.rowid') {
384  $sqlwhere[] = $key.'='.$value;
385  } elseif ($key == 'customsql') {
386  $sqlwhere[] = $value;
387  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
388  $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
389  } elseif (strpos($value, '%') === false) {
390  $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
391  } else {
392  $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
393  }
394  }
395  }
396  if (count($sqlwhere) > 0) {
397  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
398  }
399 
400  if (!empty($sortfield)) {
401  $sql .= $this->db->order($sortfield, $sortorder);
402  }
403  if (!empty($limit)) {
404  $sql .= ' '.$this->db->plimit($limit, $offset);
405  }
406 
407  $resql = $this->db->query($sql);
408  if ($resql) {
409  $num = $this->db->num_rows($resql);
410  $i = 0;
411  while ($i < ($limit ? min($limit, $num) : $num)) {
412  $obj = $this->db->fetch_object($resql);
413 
414  $record = new self($this->db);
415  $record->setVarsFromFetchObj($obj);
416 
417  $records[$record->id] = $record;
418 
419  $i++;
420  }
421  $this->db->free($resql);
422 
423  return $records;
424  } else {
425  $this->errors[] = 'Error '.$this->db->lasterror();
426  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
427 
428  return -1;
429  }
430  }
431 
439  public function update(User $user, $notrigger = false)
440  {
441  return $this->updateCommon($user, $notrigger);
442  }
443 
451  public function delete(User $user, $notrigger = false)
452  {
453  if ($this->fk_rank) {
454  $skillRank = new SkillRank($this->db);
455  $skillRank->fetch($this->fk_rank);
456  $skillRank->delete($user, $notrigger);
457  }
458  return $this->deleteCommon($user, $notrigger);
459  //return $this->deleteCommon($user, $notrigger, 1);
460  }
461 
470  public function deleteLine(User $user, $idline, $notrigger = false)
471  {
472  if ($this->status < 0) {
473  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
474  return -2;
475  }
476 
477  return $this->deleteLineCommon($user, $idline, $notrigger);
478  }
479 
480 
488  public function validate($user, $notrigger = 0)
489  {
490  global $conf, $langs;
491 
492  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
493 
494  $error = 0;
495 
496  // Protection
497  if ($this->status == self::STATUS_VALIDATED) {
498  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
499  return 0;
500  }
501 
502  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->write))
503  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->evaluationdet->evaluationdet_advance->validate))))
504  {
505  $this->error='NotEnoughPermissions';
506  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
507  return -1;
508  }*/
509 
510  $now = dol_now();
511 
512  $this->db->begin();
513 
514  // Define new ref
515  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
516  $num = $this->getNextNumRef();
517  } else {
518  $num = $this->ref;
519  }
520  $this->newref = $num;
521 
522  if (!empty($num)) {
523  // Validate
524  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
525  $sql .= " SET ref = '".$this->db->escape($num)."',";
526  $sql .= " status = ".self::STATUS_VALIDATED;
527  if (!empty($this->fields['date_validation'])) {
528  $sql .= ", date_validation = '".$this->db->idate($now)."'";
529  }
530  if (!empty($this->fields['fk_user_valid'])) {
531  $sql .= ", fk_user_valid = ".((int) $user->id);
532  }
533  $sql .= " WHERE rowid = ".((int) $this->id);
534 
535  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
536  $resql = $this->db->query($sql);
537  if (!$resql) {
538  dol_print_error($this->db);
539  $this->error = $this->db->lasterror();
540  $error++;
541  }
542 
543  if (!$error && !$notrigger) {
544  // Call trigger
545  $result = $this->call_trigger('EVALUATIONLINE_VALIDATE', $user);
546  if ($result < 0) {
547  $error++;
548  }
549  // End call triggers
550  }
551  }
552 
553  if (!$error) {
554  $this->oldref = $this->ref;
555 
556  // Rename directory if dir was a temporary ref
557  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
558  // Now we rename also files into index
559  $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)."'";
560  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'evaluationline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
561  $resql = $this->db->query($sql);
562  if (!$resql) {
563  $error++;
564  $this->error = $this->db->lasterror();
565  }
566 
567  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
568  $oldref = dol_sanitizeFileName($this->ref);
569  $newref = dol_sanitizeFileName($num);
570  $dirsource = $conf->hrm->dir_output.'/evaluationline/'.$oldref;
571  $dirdest = $conf->hrm->dir_output.'/evaluationline/'.$newref;
572  if (!$error && file_exists($dirsource)) {
573  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
574 
575  if (@rename($dirsource, $dirdest)) {
576  dol_syslog("Rename ok");
577  // Rename docs starting with $oldref with $newref
578  $listoffiles = dol_dir_list($conf->hrm->dir_output.'/evaluationline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
579  foreach ($listoffiles as $fileentry) {
580  $dirsource = $fileentry['name'];
581  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
582  $dirsource = $fileentry['path'].'/'.$dirsource;
583  $dirdest = $fileentry['path'].'/'.$dirdest;
584  @rename($dirsource, $dirdest);
585  }
586  }
587  }
588  }
589  }
590 
591  // Set new ref and current status
592  if (!$error) {
593  $this->ref = $num;
594  $this->status = self::STATUS_VALIDATED;
595  }
596 
597  if (!$error) {
598  $this->db->commit();
599  return 1;
600  } else {
601  $this->db->rollback();
602  return -1;
603  }
604  }
605 
606 
614  public function setDraft($user, $notrigger = 0)
615  {
616  // Protection
617  if ($this->status <= self::STATUS_DRAFT) {
618  return 0;
619  }
620 
621  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
622  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
623  {
624  $this->error='Permission denied';
625  return -1;
626  }*/
627 
628  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'EVALUATIONLINE_UNVALIDATE');
629  }
630 
638  public function cancel($user, $notrigger = 0)
639  {
640  // Protection
641  if ($this->status != self::STATUS_VALIDATED) {
642  return 0;
643  }
644 
645  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
646  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
647  {
648  $this->error='Permission denied';
649  return -1;
650  }*/
651 
652  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'EVALUATIONLINE_CANCEL');
653  }
654 
662  public function reopen($user, $notrigger = 0)
663  {
664  // Protection
665  if ($this->status != self::STATUS_CANCELED) {
666  return 0;
667  }
668 
669  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
670  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
671  {
672  $this->error='Permission denied';
673  return -1;
674  }*/
675 
676  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'EVALUATIONLINE_REOPEN');
677  }
678 
689  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
690  {
691  global $conf, $langs, $hookmanager;
692 
693  if (!empty($conf->dol_no_mouse_hover)) {
694  $notooltip = 1; // Force disable tooltips
695  }
696 
697  $result = '';
698 
699  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Evaluationdet").'</u>';
700  if (isset($this->status)) {
701  $label .= ' '.$this->getLibStatut(5);
702  }
703  $label .= '<br>';
704  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
705 
706  $url = dol_buildpath('/hrm/evaluationdet_card.php', 1).'?id='.$this->id;
707 
708  if ($option != 'nolink') {
709  // Add param to save lastsearch_values or not
710  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
711  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
712  $add_save_lastsearch_values = 1;
713  }
714  if ($add_save_lastsearch_values) {
715  $url .= '&save_lastsearch_values=1';
716  }
717  }
718 
719  $linkclose = '';
720  if (empty($notooltip)) {
721  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
722  $label = $langs->trans("ShowEvaluationdet");
723  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
724  }
725  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
726  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
727  } else {
728  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
729  }
730 
731  if ($option == 'nolink') {
732  $linkstart = '<span';
733  } else {
734  $linkstart = '<a href="'.$url.'"';
735  }
736  $linkstart .= $linkclose.'>';
737  if ($option == 'nolink') {
738  $linkend = '</span>';
739  } else {
740  $linkend = '</a>';
741  }
742 
743  $result .= $linkstart;
744 
745  if (empty($this->showphoto_on_popup)) {
746  if ($withpicto) {
747  $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);
748  }
749  } else {
750  if ($withpicto) {
751  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
752 
753  list($class, $module) = explode('@', $this->picto);
754  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
755  $filearray = dol_dir_list($upload_dir, "files");
756  $filename = $filearray[0]['name'];
757  if (!empty($filename)) {
758  $pospoint = strpos($filearray[0]['name'], '.');
759 
760  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
761  if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
762  $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>';
763  } else {
764  $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>';
765  }
766 
767  $result .= '</div>';
768  } else {
769  $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);
770  }
771  }
772  }
773 
774  if ($withpicto != 2) {
775  $result .= $this->ref;
776  }
777 
778  $result .= $linkend;
779  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
780 
781  global $action, $hookmanager;
782  $hookmanager->initHooks(array('evaluationlinedao'));
783  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
784  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
785  if ($reshook > 0) {
786  $result = $hookmanager->resPrint;
787  } else {
788  $result .= $hookmanager->resPrint;
789  }
790 
791  return $result;
792  }
793 
800  public function getLibStatut($mode = 0)
801  {
802  return $this->LibStatut($this->status, $mode);
803  }
804 
805  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
813  public function LibStatut($status, $mode = 0)
814  {
815  // phpcs:enable
816  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
817  global $langs;
818  //$langs->load("hrm");
819  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
820  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
821  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
822  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
823  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
824  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
825  }
826 
827  $statusType = 'status'.$status;
828  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
829  if ($status == self::STATUS_CANCELED) {
830  $statusType = 'status6';
831  }
832 
833  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
834  }
835 
842  public function info($id)
843  {
844  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
845  $sql .= ' fk_user_creat, fk_user_modif';
846  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
847  $sql .= ' WHERE t.rowid = '.((int) $id);
848  $result = $this->db->query($sql);
849  if ($result) {
850  if ($this->db->num_rows($result)) {
851  $obj = $this->db->fetch_object($result);
852  $this->id = $obj->rowid;
853 
854  $this->user_creation_id = $obj->fk_user_creat;
855  $this->user_modification_id = $obj->fk_user_modif;
856  $this->date_creation = $this->db->jdate($obj->datec);
857  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
858  }
859 
860  $this->db->free($result);
861  } else {
862  dol_print_error($this->db);
863  }
864  }
865 
872  public function initAsSpecimen()
873  {
874  // Set here init that are not commonf fields
875  // $this->property1 = ...
876  // $this->property2 = ...
877 
878  $this->initAsSpecimenCommon();
879  }
880 
886  public function getLinesArray()
887  {
888  $this->lines = array();
889 
890  $objectline = new Evaluationline($this->db);
891  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_evaluationdet = '.$this->id));
892 
893  if (is_numeric($result)) {
894  $this->error = $objectline->error;
895  $this->errors = $objectline->errors;
896  return $result;
897  } else {
898  $this->lines = $result;
899  return $this->lines;
900  }
901  }
902 
908  public function getNextNumRef()
909  {
910  global $langs, $conf;
911  $langs->load("hrm");
912 
913  if (empty($conf->global->hrm_EVALUATIONLINE_ADDON)) {
914  $conf->global->hrm_EVALUATIONLINE_ADDON = 'mod_evaluationdet_standard';
915  }
916 
917  if (!empty($conf->global->hrm_EVALUATIONLINE_ADDON)) {
918  $mybool = false;
919 
920  $file = $conf->global->hrm_EVALUATIONLINE_ADDON.".php";
921  $classname = $conf->global->hrm_EVALUATIONLINE_ADDON;
922 
923  // Include file with class
924  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
925  foreach ($dirmodels as $reldir) {
926  $dir = dol_buildpath($reldir."core/modules/hrm/");
927 
928  // Load file with numbering class (if found)
929  $mybool |= @include_once $dir.$file;
930  }
931 
932  if ($mybool === false) {
933  dol_print_error('', "Failed to include file ".$file);
934  return '';
935  }
936 
937  if (class_exists($classname)) {
938  $obj = new $classname();
939  $numref = $obj->getNextValue($this);
940 
941  if ($numref != '' && $numref != '-1') {
942  return $numref;
943  } else {
944  $this->error = $obj->error;
945  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
946  return "";
947  }
948  } else {
949  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
950  return "";
951  }
952  } else {
953  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
954  return "";
955  }
956  }
957 
969  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
970  {
971  global $conf, $langs;
972 
973  $result = 0;
974  $includedocgeneration = 0;
975 
976  $langs->load("hrm");
977 
978  if (!dol_strlen($modele)) {
979  $modele = 'standard_evaluationdet';
980 
981  if (!empty($this->model_pdf)) {
982  $modele = $this->model_pdf;
983  } elseif (!empty($conf->global->EVALUATIONLINE_ADDON_PDF)) {
984  $modele = $conf->global->EVALUATIONLINE_ADDON_PDF;
985  }
986  }
987 
988  $modelpath = "core/modules/hrm/doc/";
989 
990  if ($includedocgeneration && !empty($modele)) {
991  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
992  }
993 
994  return $result;
995  }
996 
1004  public function doScheduledJob()
1005  {
1006  global $conf, $langs;
1007 
1008  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1009 
1010  $error = 0;
1011  $this->output = '';
1012  $this->error = '';
1013 
1014  dol_syslog(__METHOD__, LOG_DEBUG);
1015 
1016  $now = dol_now();
1017 
1018  $this->db->begin();
1019 
1020  // ...
1021 
1022  $this->db->commit();
1023 
1024  return $error;
1025  }
1026 }
1027 
1028 
1029 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
getFieldList($alias='')
Function to concat keys of fields.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in 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.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for Evaluationline.
cancel($user, $notrigger=0)
Set cancel status.
fetch($id, $ref=null)
Load object in memory from the database.
getLinesArray()
Create an array of lines.
fetchLines()
Load object lines in memory from the database.
validate($user, $notrigger=0)
Validate object.
getLibStatut($mode=0)
Return the label of the status.
reopen($user, $notrigger=0)
Set back to validated status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $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.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
update(User $user, $notrigger=false)
Update object into database.
createFromClone(User $user, $fromid)
Clone an object into another one.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
info($id)
Load the info information in the object.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
__construct(DoliDB $db)
Constructor.
LibStatut($status, $mode=0)
Return the status.
create(User $user, $notrigger=false)
Create object into database.
setDraft($user, $notrigger=0)
Set draft status.
Class for SkillRank.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.