dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 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 unset($object->context['createfromclone']);
396
397 // End
398 if (!$error) {
399 $this->db->commit();
400 return $object;
401 } else {
402 $this->db->rollback();
403 return -1;
404 }
405 }
406
414 public function fetch($id, $ref = null)
415 {
416 $result = $this->fetchCommon($id, $ref);
417 if ($result > 0 && !empty($this->table_element_line)) {
418 $this->fetchLines();
419 }
420 return $result;
421 }
422
428 public function fetchLines()
429 {
430 $this->lines = array();
431 require_once __DIR__ . '/skilldet.class.php';
432 $skilldet = new Skilldet($this->db);
433 $this->lines = $skilldet->fetchAll('ASC', '', 0, 0, '(fk_skill:=:'.$this->id.')');
434
435 if (is_array($this->lines)) {
436 return (count($this->lines) > 0) ? $this->lines : array();
437 } elseif ($this->lines < 0) {
438 $this->setErrorsFromObject($skilldet);
439 return $this->lines;
440 }
441 return [];
442 }
443
444
457 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
458 {
459 dol_syslog(__METHOD__, LOG_DEBUG);
460
461 $records = array();
462
463 $sql = 'SELECT ';
464 $sql .= $this->getFieldList('t');
465 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
466 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
467 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
468 } else {
469 $sql .= ' WHERE 1 = 1';
470 }
471
472 // Manage filter
473 $errormessage = '';
474 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
475 if ($errormessage) {
476 $this->errors[] = $errormessage;
477 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
478 return -1;
479 }
480
481 if (!empty($sortfield)) {
482 $sql .= $this->db->order($sortfield, $sortorder);
483 }
484 if (!empty($limit)) {
485 $sql .= ' '.$this->db->plimit($limit, $offset);
486 }
487
488 $resql = $this->db->query($sql);
489 if ($resql) {
490 $num = $this->db->num_rows($resql);
491 $i = 0;
492 while ($i < ($limit ? min($limit, $num) : $num)) {
493 $obj = $this->db->fetch_object($resql);
494
495 $record = new self($this->db);
496 $record->setVarsFromFetchObj($obj);
497
498 $records[$record->id] = $record;
499
500 $i++;
501 }
502 $this->db->free($resql);
503
504 return $records;
505 } else {
506 $this->errors[] = 'Error '.$this->db->lasterror();
507 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
508
509 return -1;
510 }
511 }
512
520 public function update(User $user, $notrigger = 0)
521 {
522 return $this->updateCommon($user, $notrigger);
523 }
524
532 public function delete(User $user, $notrigger = 0)
533 {
534 return $this->deleteCommon($user, $notrigger);
535 }
536
545 public function deleteLine(User $user, $idline, $notrigger = 0)
546 {
547 if ($this->status < 0) {
548 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
549 return -2;
550 }
551
552 return $this->deleteLineCommon($user, $idline, $notrigger);
553 }
554
555
563 public function validate($user, $notrigger = 0)
564 {
565 global $conf;
566
567 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
568
569 $error = 0;
570
571 // Protection
572 if ($this->status == self::STATUS_VALIDATED) {
573 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
574 return 0;
575 }
576
577 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->write))
578 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->skill_advance->validate))))
579 {
580 $this->error='NotEnoughPermissions';
581 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
582 return -1;
583 }*/
584
585 $now = dol_now();
586
587 $this->db->begin();
588
589 // Define new ref
590 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
591 $num = $this->getNextNumRef();
592 } else {
593 $num = (string) $this->ref;
594 }
595 $this->newref = $num;
596
597 if (!empty($num)) {
598 // Validate
599 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
600 $sql .= " SET ref = '".$this->db->escape($num)."',";
601 $sql .= " status = ".self::STATUS_VALIDATED;
602 if (!empty($this->fields['date_validation'])) {
603 $sql .= ", date_validation = '".$this->db->idate($now)."'";
604 }
605 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
606 $sql .= ", fk_user_valid = ".((int) $user->id);
607 }
608 $sql .= " WHERE rowid = ".((int) $this->id);
609
610 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
611 $resql = $this->db->query($sql);
612 if (!$resql) {
613 dol_print_error($this->db);
614 $this->error = $this->db->lasterror();
615 $error++;
616 }
617
618 if (!$error && !$notrigger) {
619 // Call trigger
620 $result = $this->call_trigger('HRM_SKILL_VALIDATE', $user);
621 if ($result < 0) {
622 $error++;
623 }
624 // End call triggers
625 }
626 }
627
628 if (!$error) {
629 $this->oldref = $this->ref;
630
631 // Rename directory if dir was a temporary ref
632 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
633 // Now we rename also files into index
634 $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)."'";
635 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
636 $resql = $this->db->query($sql);
637 if (!$resql) {
638 $error++;
639 $this->error = $this->db->lasterror();
640 }
641 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skill/".$this->db->escape($this->newref)."'";
642 $sql .= " WHERE filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
643 $resql = $this->db->query($sql);
644 if (!$resql) {
645 $error++;
646 $this->error = $this->db->lasterror();
647 }
648
649 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
650 $oldref = dol_sanitizeFileName($this->ref);
651 $newref = dol_sanitizeFileName($num);
652 $dirsource = $conf->hrm->dir_output.'/skill/'.$oldref;
653 $dirdest = $conf->hrm->dir_output.'/skill/'.$newref;
654 if (!$error && file_exists($dirsource)) {
655 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
656
657 if (@rename($dirsource, $dirdest)) {
658 dol_syslog("Rename ok");
659 // Rename docs starting with $oldref with $newref
660 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skill/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
661 foreach ($listoffiles as $fileentry) {
662 $dirsource = $fileentry['name'];
663 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
664 $dirsource = $fileentry['path'].'/'.$dirsource;
665 $dirdest = $fileentry['path'].'/'.$dirdest;
666 @rename($dirsource, $dirdest);
667 }
668 }
669 }
670 }
671 }
672
673 // Set new ref and current status
674 if (!$error) {
675 $this->ref = $num;
676 $this->status = self::STATUS_VALIDATED;
677 }
678
679 if (!$error) {
680 $this->db->commit();
681 return 1;
682 } else {
683 $this->db->rollback();
684 return -1;
685 }
686 }
687
688
696 public function setDraft($user, $notrigger = 0)
697 {
698 // Protection
699 if ($this->status <= self::STATUS_DRAFT) {
700 return 0;
701 }
702
703 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
704 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
705 {
706 $this->error='Permission denied';
707 return -1;
708 }*/
709
710 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILL_UNVALIDATE');
711 }
712
720 public function cancel($user, $notrigger = 0)
721 {
722 // Protection
723 if ($this->status != self::STATUS_VALIDATED) {
724 return 0;
725 }
726
727 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
728 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
729 {
730 $this->error='Permission denied';
731 return -1;
732 }*/
733
734 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILL_CANCEL');
735 }
736
744 public function reopen($user, $notrigger = 0)
745 {
746 // Protection
747 if ($this->status != self::STATUS_CANCELED) {
748 return 0;
749 }
750
751 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
752 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
753 {
754 $this->error='Permission denied';
755 return -1;
756 }*/
757
758 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILL_REOPEN');
759 }
760
781 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
782 {
783 global $conf, $langs, $hookmanager;
784
785 if (!empty($conf->dol_no_mouse_hover)) {
786 $notooltip = 1; // Force disable tooltips
787 }
788
789 $result = '';
790
791 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skill").'</u>';
792 if (isset($this->status)) {
793 $label .= ' '.$this->getLibStatut(5);
794 }
795 $label .= '<br>';
796 $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
797 $label .= '<br><b>'.$langs->trans('Description').':</b> '.dol_htmlentitiesbr(dolGetFirstLineOfText($this->description, 10), 1);
798
799 $url = dol_buildpath('/hrm/skill_card.php', 1).'?id='.$this->id;
800
801 if ($option != 'nolink') {
802 // Add param to save lastsearch_values or not
803 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
804 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
805 $add_save_lastsearch_values = 1;
806 }
807 if ($add_save_lastsearch_values) {
808 $url .= '&save_lastsearch_values=1';
809 }
810 }
811
812 $linkclose = '';
813 if (empty($notooltip)) {
814 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
815 $label = $langs->trans("ShowSkill");
816 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
817 }
818 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
819 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
820 } else {
821 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
822 }
823
824 if ($option == 'nolink') {
825 $linkstart = '<span';
826 } else {
827 $linkstart = '<a href="'.$url.'"';
828 }
829 $linkstart .= $linkclose.'>';
830 if ($option == 'nolink') {
831 $linkend = '</span>';
832 } else {
833 $linkend = '</a>';
834 }
835
836 $result .= $linkstart;
837
838 if (empty($this->showphoto_on_popup)) {
839 if ($withpicto) {
840 $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);
841 }
842 } else {
843 if ($withpicto) {
844 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
845
846 list($class, $module) = explode('@', $this->picto);
847 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
848 $filearray = dol_dir_list($upload_dir, "files");
849 $filename = $filearray[0]['name'];
850 if (!empty($filename)) {
851 $pospoint = strpos($filearray[0]['name'], '.');
852
853 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.dol_substr($filename, 0, $pospoint).'_mini'.dol_substr($filename, $pospoint);
854 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
855 $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>';
856 } else {
857 $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>';
858 }
859
860 $result .= '</div>';
861 } else {
862 $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);
863 }
864 }
865 }
866
867 if ($withpicto != 2) {
868 $result .= $this->label;
869 }
870
871 $result .= $linkend;
872 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
873
874 global $action, $hookmanager;
875 $hookmanager->initHooks(array('skilldao'));
876 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
877 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
878 if ($reshook > 0) {
879 $result = $hookmanager->resPrint;
880 } else {
881 $result .= $hookmanager->resPrint;
882 }
883
884 return $result;
885 }
886
893 public function getLibStatut($mode = 0)
894 {
895 return $this->LibStatut($this->status, $mode);
896 }
897
898 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
906 public function LibStatut($status, $mode = 0)
907 {
908 // phpcs:enable
909 if (empty($status)) {
910 $status = 0;
911 }
912
913 return '';
914 /*
915 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
916 global $langs;
917 //$langs->load("hrm");
918 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
919 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
920 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
921 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
922 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
923 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
924 }
925
926 $statusType = 'status'.$status;
927 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
928 if ($status == self::STATUS_CANCELED) {
929 $statusType = 'status6';
930 }
931
932 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
933 */
934 }
935
942 public function info($id)
943 {
944 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
945 $sql .= ' fk_user_creat, fk_user_modif';
946 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
947 $sql .= ' WHERE t.rowid = '.((int) $id);
948 $result = $this->db->query($sql);
949 if ($result) {
950 if ($this->db->num_rows($result)) {
951 $obj = $this->db->fetch_object($result);
952
953 $this->id = $obj->rowid;
954
955 $this->user_creation_id = $obj->fk_user_creat;
956 $this->user_modification_id = $obj->fk_user_modif;
957 $this->date_creation = $this->db->jdate($obj->datec);
958 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
959 }
960
961 $this->db->free($result);
962 } else {
963 dol_print_error($this->db);
964 }
965 }
966
973 public function initAsSpecimen()
974 {
975 // Set here init that are not commonf fields
976 // $this->property1 = ...
977 // $this->property2 = ...
978
979 return $this->initAsSpecimenCommon();
980 }
981
987 public function getLinesArray()
988 {
989 $this->lines = array();
990
991 $objectline = new Skilldet($this->db);
992 $result = $objectline->fetchAll('ASC', 'rankorder', 0, 0, '(fk_skill:=:'.((int) $this->id).')');
993
994 if (is_numeric($result)) {
995 $this->setErrorsFromObject($objectline);
996 return $result;
997 } else {
998 $this->lines = $result;
999 return $this->lines;
1000 }
1001 }
1002
1008 public function getNextNumRef()
1009 {
1010 global $langs, $conf;
1011 $langs->load("hrm");
1012
1013 if (!getDolGlobalString('hrm_SKILL_ADDON')) {
1014 $conf->global->hrm_SKILL_ADDON = 'mod_skill_standard';
1015 }
1016
1017 if (getDolGlobalString('hrm_SKILL_ADDON')) {
1018 $mybool = false;
1019
1020 $file = getDolGlobalString('hrm_SKILL_ADDON') . ".php";
1021 $classname = getDolGlobalString('hrm_SKILL_ADDON');
1022
1023 // Include file with class
1024 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1025 foreach ($dirmodels as $reldir) {
1026 $dir = dol_buildpath($reldir."core/modules/hrm/");
1027
1028 // Load file with numbering class (if found)
1029 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1030 }
1031
1032 if (!$mybool) {
1033 dol_print_error(null, "Failed to include file ".$file);
1034 return '';
1035 }
1036
1037 if (class_exists($classname)) {
1038 $obj = new $classname();
1039 '@phan-var-force ModeleNumRefEvaluation $obj';
1040 $numref = $obj->getNextValue($this);
1041
1042 if ($numref != '' && $numref != '-1') {
1043 return $numref;
1044 } else {
1045 $this->error = $obj->error;
1046 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1047 return "";
1048 }
1049 } else {
1050 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1051 return "";
1052 }
1053 } else {
1054 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1055 return "";
1056 }
1057 }
1058
1070 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1071 {
1072 global $conf, $langs;
1073
1074 $result = 0;
1075 $includedocgeneration = 0;
1076
1077 $langs->load("hrm");
1078
1079 if (!dol_strlen($modele)) {
1080 $modele = 'standard_skill';
1081
1082 if (!empty($this->model_pdf)) {
1083 $modele = $this->model_pdf;
1084 } elseif (getDolGlobalString('SKILL_ADDON_PDF')) {
1085 $modele = getDolGlobalString('SKILL_ADDON_PDF');
1086 }
1087 }
1088
1089 $modelpath = "core/modules/hrm/doc/";
1090
1091 if ($includedocgeneration && !empty($modele)) {
1092 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1093 }
1094
1095 return $result;
1096 }
1097
1102 public static function typeCodeToLabel($code)
1103 {
1104 global $langs;
1105 $result = '';
1106 switch ($code) {
1107 case 0: $result = $langs->trans("TypeKnowHow");
1108 break; // "Know-how"
1109 case 1: $result = $langs->trans("TypeHowToBe");
1110 break; // "Soft skills"
1111 case 9: $result = $langs->trans("TypeKnowledge");
1112 break; // "Knowledge"
1113 }
1114 return $result;
1115 }
1116
1124 public function getKanbanView($option = '', $arraydata = null)
1125 {
1126 global $selected, $langs;
1127
1128 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1129
1130 $return = '<div class="box-flex-item box-flex-grow-zero">';
1131 $return .= '<div class="info-box info-box-sm">';
1132 $return .= '<span class="info-box-icon bg-infobox-action">';
1133 $return .= img_picto('', $this->picto);
1134 $return .= '</span>';
1135 $return .= '<div class="info-box-content">';
1136 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1137 if ($selected >= 0) {
1138 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1139 }
1140 if (property_exists($this, 'skill_type')) {
1141 $return .= '<br><span class="opacitymedium">'.$langs->trans("Type").'</span>';
1142 $return .= ' : <span class="info-box-label ">'.$this->fields['skill_type']['arrayofkeyval'][$this->skill_type].'</span>';
1143 }
1144 if (property_exists($this, 'description')) {
1145 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Description").'</span> : ';
1146 $return .= '<br><span class="info-box-label ">'.(strlen($this->description) > 30 ? dol_substr($this->description, 0, 25).'...' : $this->description).'</span>';
1147 }
1148 $return .= '</div>';
1149 $return .= '</div>';
1150 $return .= '</div>';
1151 return $return;
1152 }
1153}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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:169
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:66
dol_now($mode='gmt')
Return date for now.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
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_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.