dolibarr 23.0.3
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2025 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
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32
36class 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
62 public $picto = 'shapes';
63
64
65 const STATUS_DRAFT = 0;
66 const STATUS_VALIDATED = 1;
67 const STATUS_CANCELED = 9;
68 const DEFAULT_MAX_RANK_PER_SKILL = 3;
69
96 // BEGIN MODULEBUILDER PROPERTIES
100 public $fields = array(
101 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
102 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'showoncombobox' => 2,),
103 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 3,),
104 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
105 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
106 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php:0', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
107 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php:0', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
108 'required_level' => array('type' => 'integer', 'label' => 'requiredLevel', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 0,),
109 'date_validite' => array('type' => 'integer', 'label' => 'date_validite', 'enabled' => 1, 'position' => 52, 'notnull' => 1, 'visible' => 0,),
110 'temps_theorique' => array('type' => 'double(24,8)', 'label' => 'temps_theorique', 'enabled' => 1, 'position' => 54, 'notnull' => 1, 'visible' => 0,),
111 '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'),
112 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 70, 'notnull' => 0, 'visible' => 0,),
113 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 71, 'notnull' => 0, 'visible' => 0,),
114 );
118 public $rowid;
122 public $label;
126 public $description;
130 public $fk_user_creat;
134 public $fk_user_modif;
138 public $required_level;
142 public $date_validite; // Note: misspelled!
146 public $temps_theorique;
150 public $skill_type;
151 // END MODULEBUILDER PROPERTIES
152
153
154 // If this object has a subtable with lines
155
156 // /**
157 // * @var string Name of subtable line
158 // */
159 // public $table_element_line = 'hrm_skillline';
160
164 public $fk_element = 'fk_skill';
165
166 // /**
167 // * @var string Name of subtable class that manage subtable lines
168 // */
169 // public $class_element_line = 'Skillline';
170
174 protected $childtables = array(
175 'hrm_skillrank' => ['name' => 'SkillRank'],
176 'hrm_evaluationdet' => ['name' => 'EvaluationDet'],
177 );
178
184 protected $childtablesoncascade = array('hrm_skilldet');
185
186 // /**
187 // * @var SkillLine[] Array of subtable lines
188 // */
189 // public $lines = array();
190
191
192
198 public function __construct(DoliDB $db)
199 {
200 global $langs;
201
202 $this->db = $db;
203
204 $this->ismultientitymanaged = 0;
205 $this->isextrafieldmanaged = 1;
206
207 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
208 $this->fields['rowid']['visible'] = 0;
209 }
210 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
211 $this->fields['entity']['enabled'] = 0;
212 }
213
214 // Example to show how to set values of fields definition dynamically
215 /*if ($user->rights->hrm->skill->read) {
216 $this->fields['myfield']['visible'] = 1;
217 $this->fields['myfield']['noteditable'] = 0;
218 }*/
219
220 // Unset fields that are disabled
221 foreach ($this->fields as $key => $val) {
222 if (isset($val['enabled']) && empty($val['enabled'])) {
223 unset($this->fields[$key]);
224 }
225 }
226
227 // Translate some data of arrayofkeyval
228 if (is_object($langs)) {
229 foreach ($this->fields as $key => $val) {
230 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
231 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
232 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
233 }
234 }
235 }
236 }
237 }
238
246 public function create(User $user, $notrigger = 0)
247 {
248 $resultcreate = $this->createCommon($user, $notrigger);
249
250 if ($resultcreate > 0) {
251 // skillDet create
252 $this->createSkills();
253 }
254
255 return $resultcreate;
256 }
257
264 public function createSkills($i = 1)
265 {
266 global $user, $langs;
267
268 $maxNumberSkill = getDolGlobalInt('HRM_MAXRANK', self::DEFAULT_MAX_RANK_PER_SKILL);
269 $defaultSkillDesc = getDolGlobalString('HRM_DEFAULT_SKILL_DESCRIPTION', $langs->trans("NoDescription"));
270
271 $error = 0;
272
273 require_once __DIR__ . '/skilldet.class.php';
274
275 $this->db->begin();
276
277 // Create level 0 of skills
278 /* Removed this. if a skill is not required for a job, the skill will just not be added to the job profile or will be added with expected level = N/A
279 $skilldet = new Skilldet($this->db);
280 $skilldet->description = $langs->transnoentitiesnoconv('SkillNotRequired');
281 $skilldet->rankorder = 0;
282 $skilldet->fk_skill = $this->id;
283
284 $result = $skilldet->create($user);
285 if ($result <= 0) {
286 $error++;
287 }
288 */
289
290 // Create level of skills
291 while ($i <= $maxNumberSkill) {
292 $skilldet = new Skilldet($this->db);
293 $skilldet->description = $defaultSkillDesc . " " . $i;
294 $skilldet->rankorder = $i;
295 $skilldet->fk_skill = $this->id;
296
297 $result = $skilldet->create($user);
298
299 if ($result <= 0) {
300 $error++;
301 }
302 $i++;
303 }
304
305 if (!$error) {
306 $this->db->commit();
307
308 setEventMessage($langs->trans('SkillCreated', $i - 1));
309 return 1;
310 } else {
311 $this->db->rollback();
312 return -1;
313 }
314 }
315
323 public function createFromClone(User $user, $fromid)
324 {
325 global $langs, $extrafields;
326 $error = 0;
327
328 dol_syslog(__METHOD__, LOG_DEBUG);
329
330 $object = new self($this->db);
331
332 $this->db->begin();
333
334 // Load source object
335 $result = $object->fetchCommon($fromid);
336 if ($result > 0 && !empty($object->table_element_line)) {
337 $object->fetchLines();
338 }
339
340 // get lines so they will be clone
341 //foreach($this->lines as $line)
342 // $line->fetch_optionals();
343
344 // Reset some properties
345 unset($object->id);
346 unset($object->fk_user_creat);
347 unset($object->user_creation_id);
348 unset($object->import_key);
349
350 // Clear fields
351 if (property_exists($object, 'ref')) {
352 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
353 }
354 if (property_exists($object, 'label')) {
355 // @phan-suppress-next-line PhanTypeInvalidDimOffset
356 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
357 }
358 if (property_exists($object, 'status')) {
359 $object->status = self::STATUS_DRAFT;
360 }
361 if (property_exists($object, 'date_creation')) {
362 $object->date_creation = dol_now();
363 }
364 if (property_exists($object, 'date_modification')) {
365 $object->date_modification = null;
366 }
367 // ...
368 // Clear extrafields that are unique
369 if (is_array($object->array_options) && count($object->array_options) > 0) {
370 $extrafields->fetch_name_optionals_label($this->table_element);
371 foreach ($object->array_options as $key => $option) {
372 $shortkey = preg_replace('/options_/', '', $key);
373 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
374 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
375 unset($object->array_options[$key]);
376 }
377 }
378 }
379
380 // Create clone
381 $object->context['createfromclone'] = 'createfromclone';
382 $result = $object->createCommon($user);
383 if ($result < 0) {
384 $error++;
386 }
387
388 if (!$error) {
389 // copy internal contacts
390 if ($this->copy_linked_contact($object, 'internal') < 0) {
391 $error++;
392 }
393 }
394
395 if (!$error) {
396 // copy external contacts if same company
397 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
398 if ($this->copy_linked_contact($object, 'external') < 0) {
399 $error++;
400 }
401 }
402 }
403
404 unset($object->context['createfromclone']);
405
406 // End
407 if (!$error) {
408 $this->db->commit();
409 return $object;
410 } else {
411 $this->db->rollback();
412 return -1;
413 }
414 }
415
423 public function fetch($id, $ref = null)
424 {
425 $result = $this->fetchCommon($id, $ref);
426 if ($result > 0 && !empty($this->table_element_line)) {
427 $this->fetchLines();
428 }
429 return $result;
430 }
431
437 public function fetchLines()
438 {
439 $this->lines = array();
440 require_once __DIR__ . '/skilldet.class.php';
441 $skilldet = new Skilldet($this->db);
442 $this->lines = $skilldet->fetchAll('ASC', '', 0, 0, '(fk_skill:=:'.$this->id.')');
443
444 if (is_array($this->lines)) {
445 return (count($this->lines) > 0) ? $this->lines : array();
446 } elseif ($this->lines < 0) {
447 $this->setErrorsFromObject($skilldet);
448 return $this->lines;
449 }
450 return [];
451 }
452
453
466 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
467 {
468 dol_syslog(__METHOD__, LOG_DEBUG);
469
470 $records = array();
471
472 $sql = 'SELECT ';
473 $sql .= $this->getFieldList('t');
474 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
475 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
476 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
477 } else {
478 $sql .= ' WHERE 1 = 1';
479 }
480
481 // Manage filter
482 $errormessage = '';
483 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
484 if ($errormessage) {
485 $this->errors[] = $errormessage;
486 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
487 return -1;
488 }
489
490 if (!empty($sortfield)) {
491 $sql .= $this->db->order($sortfield, $sortorder);
492 }
493 if (!empty($limit)) {
494 $sql .= ' '.$this->db->plimit($limit, $offset);
495 }
496
497 $resql = $this->db->query($sql);
498 if ($resql) {
499 $num = $this->db->num_rows($resql);
500 $i = 0;
501 while ($i < ($limit ? min($limit, $num) : $num)) {
502 $obj = $this->db->fetch_object($resql);
503
504 $record = new self($this->db);
505 $record->setVarsFromFetchObj($obj);
506
507 $records[$record->id] = $record;
508
509 $i++;
510 }
511 $this->db->free($resql);
512
513 return $records;
514 } else {
515 $this->errors[] = 'Error '.$this->db->lasterror();
516 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
517
518 return -1;
519 }
520 }
521
529 public function update(User $user, $notrigger = 0)
530 {
531 return $this->updateCommon($user, $notrigger);
532 }
533
541 public function delete(User $user, $notrigger = 0)
542 {
543 return $this->deleteCommon($user, $notrigger);
544 }
545
554 public function deleteLine(User $user, $idline, $notrigger = 0)
555 {
556 if ($this->status < 0) {
557 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
558 return -2;
559 }
560
561 return $this->deleteLineCommon($user, $idline, $notrigger);
562 }
563
564
572 public function validate($user, $notrigger = 0)
573 {
574 global $conf;
575
576 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
577
578 $error = 0;
579
580 // Protection
581 if ($this->status == self::STATUS_VALIDATED) {
582 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
583 return 0;
584 }
585
586 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->write))
587 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->skill_advance->validate))))
588 {
589 $this->error='NotEnoughPermissions';
590 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
591 return -1;
592 }*/
593
594 $now = dol_now();
595
596 $this->db->begin();
597
598 // Define new ref
599 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
600 $num = $this->getNextNumRef();
601 } else {
602 $num = (string) $this->ref;
603 }
604 $this->newref = $num;
605
606 if (!empty($num)) {
607 // Validate
608 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
609 $sql .= " SET ref = '".$this->db->escape($num)."',";
610 $sql .= " status = ".self::STATUS_VALIDATED;
611 if (!empty($this->fields['date_validation'])) {
612 $sql .= ", date_validation = '".$this->db->idate($now)."'";
613 }
614 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
615 $sql .= ", fk_user_valid = ".((int) $user->id);
616 }
617 $sql .= " WHERE rowid = ".((int) $this->id);
618
619 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
620 $resql = $this->db->query($sql);
621 if (!$resql) {
622 dol_print_error($this->db);
623 $this->error = $this->db->lasterror();
624 $error++;
625 }
626
627 if (!$error && !$notrigger) {
628 // Call trigger
629 $result = $this->call_trigger('HRM_SKILL_VALIDATE', $user);
630 if ($result < 0) {
631 $error++;
632 }
633 // End call triggers
634 }
635 }
636
637 if (!$error) {
638 $this->oldref = $this->ref;
639
640 // Rename directory if dir was a temporary ref
641 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
642 // Now we rename also files into index
643 $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)."'";
644 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
645 $resql = $this->db->query($sql);
646 if (!$resql) {
647 $error++;
648 $this->error = $this->db->lasterror();
649 }
650 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skill/".$this->db->escape($this->newref)."'";
651 $sql .= " WHERE filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
652 $resql = $this->db->query($sql);
653 if (!$resql) {
654 $error++;
655 $this->error = $this->db->lasterror();
656 }
657
658 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
659 $oldref = dol_sanitizeFileName($this->ref);
660 $newref = dol_sanitizeFileName($num);
661 $dirsource = $conf->hrm->dir_output.'/skill/'.$oldref;
662 $dirdest = $conf->hrm->dir_output.'/skill/'.$newref;
663 if (!$error && file_exists($dirsource)) {
664 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
665
666 if (@rename($dirsource, $dirdest)) {
667 dol_syslog("Rename ok");
668 // Rename docs starting with $oldref with $newref
669 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skill/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
670 foreach ($listoffiles as $fileentry) {
671 $dirsource = $fileentry['name'];
672 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
673 $dirsource = $fileentry['path'].'/'.$dirsource;
674 $dirdest = $fileentry['path'].'/'.$dirdest;
675 @rename($dirsource, $dirdest);
676 }
677 }
678 }
679 }
680 }
681
682 // Set new ref and current status
683 if (!$error) {
684 $this->ref = $num;
685 $this->status = self::STATUS_VALIDATED;
686 }
687
688 if (!$error) {
689 $this->db->commit();
690 return 1;
691 } else {
692 $this->db->rollback();
693 return -1;
694 }
695 }
696
697
705 public function setDraft($user, $notrigger = 0)
706 {
707 // Protection
708 if ($this->status <= self::STATUS_DRAFT) {
709 return 0;
710 }
711
712 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
713 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
714 {
715 $this->error='Permission denied';
716 return -1;
717 }*/
718
719 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILL_UNVALIDATE');
720 }
721
729 public function cancel($user, $notrigger = 0)
730 {
731 // Protection
732 if ($this->status != self::STATUS_VALIDATED) {
733 return 0;
734 }
735
736 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
737 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
738 {
739 $this->error='Permission denied';
740 return -1;
741 }*/
742
743 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILL_CANCEL');
744 }
745
753 public function reopen($user, $notrigger = 0)
754 {
755 // Protection
756 if ($this->status != self::STATUS_CANCELED) {
757 return 0;
758 }
759
760 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
761 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
762 {
763 $this->error='Permission denied';
764 return -1;
765 }*/
766
767 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILL_REOPEN');
768 }
769
790 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
791 {
792 global $conf, $langs, $hookmanager;
793
794 if (!empty($conf->dol_no_mouse_hover)) {
795 $notooltip = 1; // Force disable tooltips
796 }
797
798 $result = '';
799
800 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skill").'</u>';
801 if (isset($this->status)) {
802 $label .= ' '.$this->getLibStatut(5);
803 }
804 $label .= '<br>';
805 $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
806 $label .= '<br><b>'.$langs->trans('Description').':</b> '.dol_htmlentitiesbr(dolGetFirstLineOfText($this->description, 10), 1);
807
808 $url = dol_buildpath('/hrm/skill_card.php', 1).'?id='.$this->id;
809
810 if ($option != 'nolink') {
811 // Add param to save lastsearch_values or not
812 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
813 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
814 $add_save_lastsearch_values = 1;
815 }
816 if ($add_save_lastsearch_values) {
817 $url .= '&save_lastsearch_values=1';
818 }
819 }
820
821 $linkclose = '';
822 if (empty($notooltip)) {
823 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
824 $label = $langs->trans("ShowSkill");
825 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
826 }
827 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
828 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
829 } else {
830 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
831 }
832
833 if ($option == 'nolink') {
834 $linkstart = '<span';
835 } else {
836 $linkstart = '<a href="'.$url.'"';
837 }
838 $linkstart .= $linkclose.'>';
839 if ($option == 'nolink') {
840 $linkend = '</span>';
841 } else {
842 $linkend = '</a>';
843 }
844
845 $result .= $linkstart;
846
847 if (empty($this->showphoto_on_popup)) {
848 if ($withpicto) {
849 $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);
850 }
851 } else {
852 if ($withpicto) {
853 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
854
855 list($class, $module) = explode('@', $this->picto);
856 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
857 $filearray = dol_dir_list($upload_dir, "files");
858 $filename = $filearray[0]['name'];
859 if (!empty($filename)) {
860 $pospoint = strpos($filearray[0]['name'], '.');
861
862 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
863 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
864 $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>';
865 } else {
866 $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>';
867 }
868
869 $result .= '</div>';
870 } else {
871 $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);
872 }
873 }
874 }
875
876 if ($withpicto != 2) {
877 $result .= $this->label;
878 }
879
880 $result .= $linkend;
881 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
882
883 global $action, $hookmanager;
884 $hookmanager->initHooks(array('skilldao'));
885 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
886 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
887 if ($reshook > 0) {
888 $result = $hookmanager->resPrint;
889 } else {
890 $result .= $hookmanager->resPrint;
891 }
892
893 return $result;
894 }
895
902 public function getLibStatut($mode = 0)
903 {
904 return $this->LibStatut($this->status, $mode);
905 }
906
907 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
915 public function LibStatut($status, $mode = 0)
916 {
917 // phpcs:enable
918 if (empty($status)) {
919 $status = 0;
920 }
921
922 return '';
923 /*
924 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
925 global $langs;
926 //$langs->load("hrm");
927 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
928 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
929 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
930 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
931 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
932 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
933 }
934
935 $statusType = 'status'.$status;
936 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
937 if ($status == self::STATUS_CANCELED) {
938 $statusType = 'status6';
939 }
940
941 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
942 */
943 }
944
951 public function info($id)
952 {
953 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
954 $sql .= ' fk_user_creat, fk_user_modif';
955 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
956 $sql .= ' WHERE t.rowid = '.((int) $id);
957 $result = $this->db->query($sql);
958 if ($result) {
959 if ($this->db->num_rows($result)) {
960 $obj = $this->db->fetch_object($result);
961
962 $this->id = $obj->rowid;
963
964 $this->user_creation_id = $obj->fk_user_creat;
965 $this->user_modification_id = $obj->fk_user_modif;
966 $this->date_creation = $this->db->jdate($obj->datec);
967 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
968 }
969
970 $this->db->free($result);
971 } else {
972 dol_print_error($this->db);
973 }
974 }
975
982 public function initAsSpecimen()
983 {
984 // Set here init that are not commonf fields
985 // $this->property1 = ...
986 // $this->property2 = ...
987
988 return $this->initAsSpecimenCommon();
989 }
990
996 public function getLinesArray()
997 {
998 $this->lines = array();
999
1000 $objectline = new Skilldet($this->db);
1001 $result = $objectline->fetchAll('ASC', 'rankorder', 0, 0, '(fk_skill:=:'.((int) $this->id).')');
1002
1003 if (is_numeric($result)) {
1004 $this->setErrorsFromObject($objectline);
1005 return $result;
1006 } else {
1007 $this->lines = $result;
1008 return $this->lines;
1009 }
1010 }
1011
1017 public function getNextNumRef()
1018 {
1019 global $langs, $conf;
1020 $langs->load("hrm");
1021
1022 if (!getDolGlobalString('hrm_SKILL_ADDON')) {
1023 $conf->global->hrm_SKILL_ADDON = 'mod_skill_standard';
1024 }
1025
1026 if (getDolGlobalString('hrm_SKILL_ADDON')) {
1027 $mybool = false;
1028
1029 $file = getDolGlobalString('hrm_SKILL_ADDON') . ".php";
1030 $classname = getDolGlobalString('hrm_SKILL_ADDON');
1031
1032 // Include file with class
1033 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1034 foreach ($dirmodels as $reldir) {
1035 $dir = dol_buildpath($reldir."core/modules/hrm/");
1036
1037 // Load file with numbering class (if found)
1038 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1039 }
1040
1041 if (!$mybool) {
1042 dol_print_error(null, "Failed to include file ".$file);
1043 return '';
1044 }
1045
1046 if (class_exists($classname)) {
1047 $obj = new $classname();
1048 '@phan-var-force ModeleNumRefEvaluation $obj';
1049 $numref = $obj->getNextValue($this);
1050
1051 if ($numref != '' && $numref != '-1') {
1052 return $numref;
1053 } else {
1054 $this->error = $obj->error;
1055 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1056 return "";
1057 }
1058 } else {
1059 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1060 return "";
1061 }
1062 } else {
1063 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1064 return "";
1065 }
1066 }
1067
1079 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1080 {
1081 global $conf, $langs;
1082
1083 $result = 0;
1084 $includedocgeneration = 0;
1085
1086 $langs->load("hrm");
1087
1088 if (!dol_strlen($modele)) {
1089 $modele = 'standard_skill';
1090
1091 if (!empty($this->model_pdf)) {
1092 $modele = $this->model_pdf;
1093 } elseif (getDolGlobalString('SKILL_ADDON_PDF')) {
1094 $modele = getDolGlobalString('SKILL_ADDON_PDF');
1095 }
1096 }
1097
1098 $modelpath = "core/modules/hrm/doc/";
1099
1100 if ($includedocgeneration && !empty($modele)) {
1101 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1102 }
1103
1104 return $result;
1105 }
1106
1111 public static function typeCodeToLabel($code)
1112 {
1113 global $langs;
1114 $result = '';
1115 switch ($code) {
1116 case 0: $result = $langs->trans("TypeKnowHow");
1117 break; //"Savoir Faire"
1118 case 1: $result = $langs->trans("TypeHowToBe");
1119 break; // "Savoir être"
1120 case 9: $result = $langs->trans("TypeKnowledge");
1121 break; //"Savoir"
1122 }
1123 return $result;
1124 }
1125
1133 public function getKanbanView($option = '', $arraydata = null)
1134 {
1135 global $selected, $langs;
1136
1137 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1138
1139 $return = '<div class="box-flex-item box-flex-grow-zero">';
1140 $return .= '<div class="info-box info-box-sm">';
1141 $return .= '<span class="info-box-icon bg-infobox-action">';
1142 $return .= img_picto('', $this->picto);
1143 $return .= '</span>';
1144 $return .= '<div class="info-box-content">';
1145 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1146 if ($selected >= 0) {
1147 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1148 }
1149 if (property_exists($this, 'skill_type')) {
1150 $return .= '<br><span class="opacitymedium">'.$langs->trans("Type").'</span>';
1151 $return .= ' : <span class="info-box-label ">'.$this->fields['skill_type']['arrayofkeyval'][$this->skill_type].'</span>';
1152 }
1153 if (property_exists($this, 'description')) {
1154 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Description").'</span> : ';
1155 $return .= '<br><span class="info-box-label ">'.(strlen($this->description) > 30 ? dol_substr($this->description, 0, 25).'...' : $this->description).'</span>';
1156 }
1157 $return .= '</div>';
1158 $return .= '</div>';
1159 $return .= '</div>';
1160 return $return;
1161 }
1162}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
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.
Class to manage Dolibarr database access.
Class for Skill.
LibStatut($status, $mode=0)
Return the status.
createSkills($i=1)
createSkills
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
info($id)
Load the info information in the object.
__construct(DoliDB $db)
Constructor.
getLinesArray()
Create an array of lines.
static typeCodeToLabel($code)
create(User $user, $notrigger=0)
Create object into database.
cancel($user, $notrigger=0)
Set cancel status.
getLibStatut($mode=0)
Return the label of the status.
update(User $user, $notrigger=0)
Update object into database.
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.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
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 clickable link of object (with eventually picto)
fetchLines()
Load object lines in memory from the 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 optionally the picto)
Class for Skilldet.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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:64
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a 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.