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