dolibarr  19.0.0-dev
skill.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 . '/societe/class/societe.class.php';
31 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32 
36 class Skill extends CommonObject
37 {
41  public $module = 'hrm';
42 
46  public $element = 'skill';
47 
51  public $table_element = 'hrm_skill';
52 
53 
57  public $table_element_line = 'skilldet';
58 
63  public $ismultientitymanaged = 0;
64 
68  public $isextrafieldmanaged = 1;
69 
73  public $picto = 'shapes';
74 
75 
76  const STATUS_DRAFT = 0;
77  const STATUS_VALIDATED = 1;
78  const STATUS_CANCELED = 9;
79  const DEFAULT_MAX_RANK_PER_SKILL = 3;
80 
107  // BEGIN MODULEBUILDER PROPERTIES
111  public $fields=array(
112  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
113  'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'showoncombobox'=>'2',),
114  'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3,),
115  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
116  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
117  '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',),
118  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
119  'required_level' => array('type'=>'integer', 'label'=>'requiredLevel', 'enabled'=>'1', 'position'=>50, 'notnull'=>1, 'visible'=>0,),
120  'date_validite' => array('type'=>'integer', 'label'=>'date_validite', 'enabled'=>'1', 'position'=>52, 'notnull'=>1, 'visible'=>0,),
121  'temps_theorique' => array('type'=>'double(24,8)', 'label'=>'temps_theorique', 'enabled'=>'1', 'position'=>54, 'notnull'=>1, 'visible'=>0,),
122  'skill_type' => array('type'=>'integer', 'label'=>'SkillType', 'enabled'=>'1', 'position'=>55, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'css'=>'minwidth200', 'arrayofkeyval'=>array('0'=>'TypeKnowHow', '1'=>'TypeHowToBe', '9'=>'TypeKnowledge'), 'default'=>0),
123  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>70, 'notnull'=>0, 'visible'=>0,),
124  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>71, 'notnull'=>0, 'visible'=>0,),
125  );
126  public $rowid;
127  public $label;
128  public $description;
129  public $date_creation;
130  public $tms;
131  public $fk_user_creat;
132  public $fk_user_modif;
133  public $required_level;
134  public $date_validite;
135  public $temps_theorique;
136  public $skill_type;
137  public $note_public;
138  public $note_private;
139  // END MODULEBUILDER PROPERTIES
140 
141 
142  // If this object has a subtable with lines
143 
144  // /**
145  // * @var string Name of subtable line
146  // */
147  // public $table_element_line = 'hrm_skillline';
148 
149  // /**
150  // * @var string Field with ID of parent key if this object has a parent
151  // */
152  public $fk_element = 'fk_skill';
153 
154  // /**
155  // * @var string Name of subtable class that manage subtable lines
156  // */
157  // public $class_element_line = 'Skillline';
158 
159  // /**
160  // * @var array List of child tables. To test if we can delete object.
161  // */
162  protected $childtables = array('hrm_skillrank', 'hrm_evaluationdet');
163 
164  // /**
165  // * @var array List of child tables. To know object to delete on cascade.
166  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
167  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
168  // */
169  protected $childtablesoncascade = array('hrm_skilldet');
170 
171  // /**
172  // * @var SkillLine[] Array of subtable lines
173  // */
174  // public $lines = array();
175 
176 
177 
183  public function __construct(DoliDB $db)
184  {
185  global $conf, $langs;
186 
187  $this->db = $db;
188 
189  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
190  $this->fields['rowid']['visible'] = 0;
191  }
192  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
193  $this->fields['entity']['enabled'] = 0;
194  }
195 
196  // Example to show how to set values of fields definition dynamically
197  /*if ($user->rights->hrm->skill->read) {
198  $this->fields['myfield']['visible'] = 1;
199  $this->fields['myfield']['noteditable'] = 0;
200  }*/
201 
202  // Unset fields that are disabled
203  foreach ($this->fields as $key => $val) {
204  if (isset($val['enabled']) && empty($val['enabled'])) {
205  unset($this->fields[$key]);
206  }
207  }
208 
209  // Translate some data of arrayofkeyval
210  if (is_object($langs)) {
211  foreach ($this->fields as $key => $val) {
212  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
213  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
214  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
215  }
216  }
217  }
218  }
219  }
220 
228  public function create(User $user, $notrigger = false)
229  {
230  global $langs,$conf;
231 
232  $resultcreate = $this->createCommon($user, $notrigger);
233 
234 
235  if ($resultcreate > 0) {
236  // skillDet create
237  $this->createSkills();
238  }
239 
240  return $resultcreate;
241  }
242 
249  public function createSkills($i = 1)
250  {
251  global $conf, $user, $langs;
252 
253  $MaxNumberSkill = isset($conf->global->HRM_MAXRANK) ? $conf->global->HRM_MAXRANK : self::DEFAULT_MAX_RANK_PER_SKILL;
254  $defaultSkillDesc = !empty($conf->global->HRM_DEFAULT_SKILL_DESCRIPTION) ? $conf->global->HRM_DEFAULT_SKILL_DESCRIPTION : $langs->trans("NoDescription");
255 
256  $error = 0;
257 
258  require_once __DIR__ . '/skilldet.class.php';
259 
260  $this->db->begin();
261 
262  // Create level of skills
263  for ($i; $i <= $MaxNumberSkill ; $i++) {
264  $skilldet = new Skilldet($this->db);
265  $skilldet->description = $defaultSkillDesc . " " . $i;
266  $skilldet->rankorder = $i;
267  $skilldet->fk_skill = $this->id;
268 
269  $result = $skilldet->create($user);
270  if ($result <= 0) {
271  $error++;
272  }
273  }
274 
275  if (! $error) {
276  $this->db->commit();
277 
278  setEventMessage($langs->trans('SkillCreated'), $i);
279  return 1;
280  } else {
281  $this->db->rollback();
282  return -1;
283  }
284  }
285 
293  public function createFromClone(User $user, $fromid)
294  {
295  global $langs, $extrafields;
296  $error = 0;
297 
298  dol_syslog(__METHOD__, LOG_DEBUG);
299 
300  $object = new self($this->db);
301 
302  $this->db->begin();
303 
304  // Load source object
305  $result = $object->fetchCommon($fromid);
306  if ($result > 0 && !empty($object->table_element_line)) {
307  $object->fetchLines();
308  }
309 
310  // get lines so they will be clone
311  //foreach($this->lines as $line)
312  // $line->fetch_optionals();
313 
314  // Reset some properties
315  unset($object->id);
316  unset($object->fk_user_creat);
317  unset($object->import_key);
318 
319  // Clear fields
320  if (property_exists($object, 'ref')) {
321  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
322  }
323  if (property_exists($object, 'label')) {
324  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
325  }
326  if (property_exists($object, 'status')) {
327  $object->status = self::STATUS_DRAFT;
328  }
329  if (property_exists($object, 'date_creation')) {
330  $object->date_creation = dol_now();
331  }
332  if (property_exists($object, 'date_modification')) {
333  $object->date_modification = null;
334  }
335  // ...
336  // Clear extrafields that are unique
337  if (is_array($object->array_options) && count($object->array_options) > 0) {
338  $extrafields->fetch_name_optionals_label($this->table_element);
339  foreach ($object->array_options as $key => $option) {
340  $shortkey = preg_replace('/options_/', '', $key);
341  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
342  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
343  unset($object->array_options[$key]);
344  }
345  }
346  }
347 
348  // Create clone
349  $object->context['createfromclone'] = 'createfromclone';
350  $result = $object->createCommon($user);
351  if ($result < 0) {
352  $error++;
353  $this->error = $object->error;
354  $this->errors = $object->errors;
355  }
356 
357  if (!$error) {
358  // copy internal contacts
359  if ($this->copy_linked_contact($object, 'internal') < 0) {
360  $error++;
361  }
362  }
363 
364  if (!$error) {
365  // copy external contacts if same company
366  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
367  if ($this->copy_linked_contact($object, 'external') < 0) {
368  $error++;
369  }
370  }
371  }
372 
373  unset($object->context['createfromclone']);
374 
375  // End
376  if (!$error) {
377  $this->db->commit();
378  return $object;
379  } else {
380  $this->db->rollback();
381  return -1;
382  }
383  }
384 
392  public function fetch($id, $ref = null)
393  {
394  $result = $this->fetchCommon($id, $ref);
395  if ($result > 0 && !empty($this->table_element_line)) {
396  $this->fetchLines();
397  }
398  return $result;
399  }
400 
406  public function fetchLines()
407  {
408  $this->lines = array();
409  require_once __DIR__ . '/skilldet.class.php';
410  $skilldet = new Skilldet($this->db);
411  $this->lines = $skilldet->fetchAll('ASC', '', '', '', array('fk_skill' => $this->id), '');
412 
413  if (is_array($this->lines)) {
414  return (count($this->lines) > 0) ? $this->lines : array();
415  } elseif ($this->lines < 0) {
416  $this->errors = array_merge($this->errors, $skilldet->errors);
417  $this->error = $skilldet->error;
418  return $this->lines;
419  }
420  return [];
421  }
422 
423 
435  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
436  {
437  global $conf;
438 
439  dol_syslog(__METHOD__, LOG_DEBUG);
440 
441  $records = array();
442 
443  $sql = 'SELECT ';
444  $sql .= $this->getFieldList('t');
445  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
446  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
447  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
448  } else {
449  $sql .= ' WHERE 1 = 1';
450  }
451  // Manage filter
452  $sqlwhere = array();
453  if (count($filter) > 0) {
454  foreach ($filter as $key => $value) {
455  if ($key == 't.rowid') {
456  $sqlwhere[] = $key.'='.$value;
457  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
458  $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
459  } elseif ($key == 'customsql') {
460  $sqlwhere[] = $value;
461  } elseif (strpos($value, '%') === false) {
462  $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
463  } else {
464  $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
465  }
466  }
467  }
468  if (count($sqlwhere) > 0) {
469  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
470  }
471 
472  if (!empty($sortfield)) {
473  $sql .= $this->db->order($sortfield, $sortorder);
474  }
475  if (!empty($limit)) {
476  $sql .= ' '.$this->db->plimit($limit, $offset);
477  }
478 
479  $resql = $this->db->query($sql);
480  if ($resql) {
481  $num = $this->db->num_rows($resql);
482  $i = 0;
483  while ($i < ($limit ? min($limit, $num) : $num)) {
484  $obj = $this->db->fetch_object($resql);
485 
486  $record = new self($this->db);
487  $record->setVarsFromFetchObj($obj);
488 
489  $records[$record->id] = $record;
490 
491  $i++;
492  }
493  $this->db->free($resql);
494 
495  return $records;
496  } else {
497  $this->errors[] = 'Error '.$this->db->lasterror();
498  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
499 
500  return -1;
501  }
502  }
503 
511  public function update(User $user, $notrigger = false)
512  {
513  return $this->updateCommon($user, $notrigger);
514  }
515 
523  public function delete(User $user, $notrigger = false)
524  {
525  return $this->deleteCommon($user, $notrigger);
526  }
527 
536  public function deleteLine(User $user, $idline, $notrigger = false)
537  {
538  if ($this->status < 0) {
539  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
540  return -2;
541  }
542 
543  return $this->deleteLineCommon($user, $idline, $notrigger);
544  }
545 
546 
554  public function validate($user, $notrigger = 0)
555  {
556  global $conf, $langs;
557 
558  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
559 
560  $error = 0;
561 
562  // Protection
563  if ($this->status == self::STATUS_VALIDATED) {
564  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
565  return 0;
566  }
567 
568  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->write))
569  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->skill_advance->validate))))
570  {
571  $this->error='NotEnoughPermissions';
572  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
573  return -1;
574  }*/
575 
576  $now = dol_now();
577 
578  $this->db->begin();
579 
580  // Define new ref
581  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
582  $num = $this->getNextNumRef();
583  } else {
584  $num = $this->ref;
585  }
586  $this->newref = $num;
587 
588  if (!empty($num)) {
589  // Validate
590  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
591  $sql .= " SET ref = '".$this->db->escape($num)."',";
592  $sql .= " status = ".self::STATUS_VALIDATED;
593  if (!empty($this->fields['date_validation'])) {
594  $sql .= ", date_validation = '".$this->db->idate($now)."'";
595  }
596  if (!empty($this->fields['fk_user_valid'])) {
597  $sql .= ", fk_user_valid = ".((int) $user->id);
598  }
599  $sql .= " WHERE rowid = ".((int) $this->id);
600 
601  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
602  $resql = $this->db->query($sql);
603  if (!$resql) {
604  dol_print_error($this->db);
605  $this->error = $this->db->lasterror();
606  $error++;
607  }
608 
609  if (!$error && !$notrigger) {
610  // Call trigger
611  $result = $this->call_trigger('SKILL_VALIDATE', $user);
612  if ($result < 0) {
613  $error++;
614  }
615  // End call triggers
616  }
617  }
618 
619  if (!$error) {
620  $this->oldref = $this->ref;
621 
622  // Rename directory if dir was a temporary ref
623  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
624  // Now we rename also files into index
625  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'skill/".$this->db->escape($this->newref)."'";
626  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
627  $resql = $this->db->query($sql);
628  if (!$resql) {
629  $error++; $this->error = $this->db->lasterror();
630  }
631 
632  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
633  $oldref = dol_sanitizeFileName($this->ref);
634  $newref = dol_sanitizeFileName($num);
635  $dirsource = $conf->hrm->dir_output.'/skill/'.$oldref;
636  $dirdest = $conf->hrm->dir_output.'/skill/'.$newref;
637  if (!$error && file_exists($dirsource)) {
638  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
639 
640  if (@rename($dirsource, $dirdest)) {
641  dol_syslog("Rename ok");
642  // Rename docs starting with $oldref with $newref
643  $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skill/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
644  foreach ($listoffiles as $fileentry) {
645  $dirsource = $fileentry['name'];
646  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
647  $dirsource = $fileentry['path'].'/'.$dirsource;
648  $dirdest = $fileentry['path'].'/'.$dirdest;
649  @rename($dirsource, $dirdest);
650  }
651  }
652  }
653  }
654  }
655 
656  // Set new ref and current status
657  if (!$error) {
658  $this->ref = $num;
659  $this->status = self::STATUS_VALIDATED;
660  }
661 
662  if (!$error) {
663  $this->db->commit();
664  return 1;
665  } else {
666  $this->db->rollback();
667  return -1;
668  }
669  }
670 
671 
679  public function setDraft($user, $notrigger = 0)
680  {
681  // Protection
682  if ($this->status <= self::STATUS_DRAFT) {
683  return 0;
684  }
685 
686  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
687  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
688  {
689  $this->error='Permission denied';
690  return -1;
691  }*/
692 
693  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILL_UNVALIDATE');
694  }
695 
703  public function cancel($user, $notrigger = 0)
704  {
705  // Protection
706  if ($this->status != self::STATUS_VALIDATED) {
707  return 0;
708  }
709 
710  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
711  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
712  {
713  $this->error='Permission denied';
714  return -1;
715  }*/
716 
717  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILL_CANCEL');
718  }
719 
727  public function reopen($user, $notrigger = 0)
728  {
729  // Protection
730  if ($this->status != self::STATUS_CANCELED) {
731  return 0;
732  }
733 
734  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
735  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
736  {
737  $this->error='Permission denied';
738  return -1;
739  }*/
740 
741  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILL_REOPEN');
742  }
743 
764  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
765  {
766  global $conf, $langs, $hookmanager;
767 
768  if (!empty($conf->dol_no_mouse_hover)) {
769  $notooltip = 1; // Force disable tooltips
770  }
771 
772  $result = '';
773 
774  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skill").'</u>';
775  if (isset($this->status)) {
776  $label .= ' '.$this->getLibStatut(5);
777  }
778  $label .= '<br>';
779  $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
780 
781  $url = dol_buildpath('/hrm/skill_card.php', 1).'?id='.$this->id;
782 
783  if ($option != 'nolink') {
784  // Add param to save lastsearch_values or not
785  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
786  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
787  $add_save_lastsearch_values = 1;
788  }
789  if ($add_save_lastsearch_values) {
790  $url .= '&save_lastsearch_values=1';
791  }
792  }
793 
794  $linkclose = '';
795  if (empty($notooltip)) {
796  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
797  $label = $langs->trans("ShowSkill");
798  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
799  }
800  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
801  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
802  } else {
803  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
804  }
805 
806  if ($option == 'nolink') {
807  $linkstart = '<span';
808  } else {
809  $linkstart = '<a href="'.$url.'"';
810  }
811  $linkstart .= $linkclose.'>';
812  if ($option == 'nolink') {
813  $linkend = '</span>';
814  } else {
815  $linkend = '</a>';
816  }
817 
818  $result .= $linkstart;
819 
820  if (empty($this->showphoto_on_popup)) {
821  if ($withpicto) {
822  $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);
823  }
824  } else {
825  if ($withpicto) {
826  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
827 
828  list($class, $module) = explode('@', $this->picto);
829  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
830  $filearray = dol_dir_list($upload_dir, "files");
831  $filename = $filearray[0]['name'];
832  if (!empty($filename)) {
833  $pospoint = strpos($filearray[0]['name'], '.');
834 
835  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
836  if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
837  $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>';
838  } else {
839  $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>';
840  }
841 
842  $result .= '</div>';
843  } else {
844  $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);
845  }
846  }
847  }
848 
849  if ($withpicto != 2) {
850  $result .= $this->label;
851  }
852 
853  $result .= $linkend;
854  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
855 
856  global $action, $hookmanager;
857  $hookmanager->initHooks(array('skilldao'));
858  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
859  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
860  if ($reshook > 0) {
861  $result = $hookmanager->resPrint;
862  } else {
863  $result .= $hookmanager->resPrint;
864  }
865 
866  return $result;
867  }
868 
875  public function getLibStatut($mode = 0)
876  {
877  return $this->LibStatut($this->status, $mode);
878  }
879 
880  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
888  public function LibStatut($status, $mode = 0)
889  {
890  // phpcs:enable
891  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
892  global $langs;
893  //$langs->load("hrm");
894  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
895  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
896  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
897  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
898  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
899  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
900  }
901 
902  $statusType = 'status'.$status;
903  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
904  if ($status == self::STATUS_CANCELED) {
905  $statusType = 'status6';
906  }
907 
908  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
909  }
910 
917  public function info($id)
918  {
919  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
920  $sql .= ' fk_user_creat, fk_user_modif';
921  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
922  $sql .= ' WHERE t.rowid = '.((int) $id);
923  $result = $this->db->query($sql);
924  if ($result) {
925  if ($this->db->num_rows($result)) {
926  $obj = $this->db->fetch_object($result);
927  $this->id = $obj->rowid;
928 
929  $this->user_creation_id = $obj->fk_user_creat;
930  $this->user_modification_id = $obj->fk_user_modif;
931  $this->date_creation = $this->db->jdate($obj->datec);
932  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
933  }
934 
935  $this->db->free($result);
936  } else {
937  dol_print_error($this->db);
938  }
939  }
940 
947  public function initAsSpecimen()
948  {
949  // Set here init that are not commonf fields
950  // $this->property1 = ...
951  // $this->property2 = ...
952 
953  $this->initAsSpecimenCommon();
954  }
955 
961  public function getLinesArray()
962  {
963  $this->lines = array();
964 
965  $objectline = new Skilldet($this->db);
966  $result = $objectline->fetchAll('ASC', 'rankorder', 0, 0, array('customsql'=>'fk_skill = '.$this->id));
967 
968  if (is_numeric($result)) {
969  $this->error = $objectline->error;
970  $this->errors = $objectline->errors;
971  return $result;
972  } else {
973  $this->lines = $result;
974  return $this->lines;
975  }
976  }
977 
983  public function getNextNumRef()
984  {
985  global $langs, $conf;
986  $langs->load("hrm");
987 
988  if (empty($conf->global->hrm_SKILL_ADDON)) {
989  $conf->global->hrm_SKILL_ADDON = 'mod_skill_standard';
990  }
991 
992  if (!empty($conf->global->hrm_SKILL_ADDON)) {
993  $mybool = false;
994 
995  $file = $conf->global->hrm_SKILL_ADDON.".php";
996  $classname = $conf->global->hrm_SKILL_ADDON;
997 
998  // Include file with class
999  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1000  foreach ($dirmodels as $reldir) {
1001  $dir = dol_buildpath($reldir."core/modules/hrm/");
1002 
1003  // Load file with numbering class (if found)
1004  $mybool |= @include_once $dir.$file;
1005  }
1006 
1007  if ($mybool === false) {
1008  dol_print_error('', "Failed to include file ".$file);
1009  return '';
1010  }
1011 
1012  if (class_exists($classname)) {
1013  $obj = new $classname();
1014  $numref = $obj->getNextValue($this);
1015 
1016  if ($numref != '' && $numref != '-1') {
1017  return $numref;
1018  } else {
1019  $this->error = $obj->error;
1020  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1021  return "";
1022  }
1023  } else {
1024  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1025  return "";
1026  }
1027  } else {
1028  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1029  return "";
1030  }
1031  }
1032 
1044  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1045  {
1046  global $conf, $langs;
1047 
1048  $result = 0;
1049  $includedocgeneration = 0;
1050 
1051  $langs->load("hrm");
1052 
1053  if (!dol_strlen($modele)) {
1054  $modele = 'standard_skill';
1055 
1056  if (!empty($this->model_pdf)) {
1057  $modele = $this->model_pdf;
1058  } elseif (!empty($conf->global->SKILL_ADDON_PDF)) {
1059  $modele = $conf->global->SKILL_ADDON_PDF;
1060  }
1061  }
1062 
1063  $modelpath = "core/modules/hrm/doc/";
1064 
1065  if ($includedocgeneration && !empty($modele)) {
1066  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1067  }
1068 
1069  return $result;
1070  }
1071 
1079  public function doScheduledJob()
1080  {
1081  global $conf, $langs;
1082 
1083  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1084 
1085  $error = 0;
1086  $this->output = '';
1087  $this->error = '';
1088 
1089  dol_syslog(__METHOD__, LOG_DEBUG);
1090 
1091  $now = dol_now();
1092 
1093  $this->db->begin();
1094 
1095  // ...
1096 
1097  $this->db->commit();
1098 
1099  return $error;
1100  }
1101 
1106  public static function typeCodeToLabel($code)
1107  {
1108  global $langs;
1109  $result = '';
1110  switch ($code) {
1111  case 0 : $result = $langs->trans("TypeKnowHow"); break; //"Savoir Faire"
1112  case 1 : $result = $langs->trans("TypeHowToBe"); break; // "Savoir être"
1113  case 9 : $result = $langs->trans("TypeKnowledge"); break; //"Savoir"
1114  }
1115  return $result;
1116  }
1117 
1125  public function getKanbanView($option = '', $arraydata = null)
1126  {
1127  global $selected, $langs;
1128 
1129  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1130 
1131  $return = '<div class="box-flex-item box-flex-grow-zero">';
1132  $return .= '<div class="info-box info-box-sm">';
1133  $return .= '<span class="info-box-icon bg-infobox-action">';
1134  $return .= img_picto('', $this->picto);
1135  $return .= '</span>';
1136  $return .= '<div class="info-box-content">';
1137  $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1138  $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1139  if (property_exists($this, 'skill_type')) {
1140  $return .= '<br><span class="opacitymedium">'.$langs->trans("Type").'</span>';
1141  $return .= ' : <span class="info-box-label ">'.$this->fields['skill_type']['arrayofkeyval'][$this->skill_type].'</span>';
1142  }
1143  if (property_exists($this, 'description')) {
1144  $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Description").'</span> : ';
1145  $return .= '<br><span class="info-box-label ">'.(strlen($this->description) > 30 ? dol_substr($this->description, 0, 25).'...' : $this->description).'</span>';
1146  }
1147  $return .= '</div>';
1148  $return .= '</div>';
1149  $return .= '</div>';
1150  return $return;
1151  }
1152 }
$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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for Skill.
Definition: skill.class.php:37
LibStatut($status, $mode=0)
Return the status.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createSkills($i=1)
createSkills
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load the info information in the object.
__construct(DoliDB $db)
Constructor.
getLinesArray()
Create an array of lines.
static typeCodeToLabel($code)
cancel($user, $notrigger=0)
Set cancel status.
create(User $user, $notrigger=false)
Create object into database.
getLibStatut($mode=0)
Return the label of the status.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
createFromClone(User $user, $fromid)
Clone an object into another one.
setDraft($user, $notrigger=0)
Set draft status.
reopen($user, $notrigger=0)
Set back to validated status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id, $ref=null)
Load object in memory from the database.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
fetchLines()
Load object lines in memory from the database.
update(User $user, $notrigger=false)
Update object into database.
validate($user, $notrigger=0)
Validate object.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Class for Skilldet.
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
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
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_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
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.