dolibarr 21.0.0-beta
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 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
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 $conf, $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 global $langs,$conf;
249
250 $resultcreate = $this->createCommon($user, $notrigger);
251
252
253 if ($resultcreate > 0) {
254 // skillDet create
255 $this->createSkills();
256 }
257
258 return $resultcreate;
259 }
260
267 public function createSkills($i = 1)
268 {
269 global $conf, $user, $langs;
270
271 $MaxNumberSkill = getDolGlobalInt('HRM_MAXRANK', self::DEFAULT_MAX_RANK_PER_SKILL);
272 $defaultSkillDesc = getDolGlobalString('HRM_DEFAULT_SKILL_DESCRIPTION', $langs->trans("NoDescription"));
273
274 $error = 0;
275
276 require_once __DIR__ . '/skilldet.class.php';
277
278 $this->db->begin();
279
280 // Create level 0 of skills
281 $skilldet = new Skilldet($this->db);
282 $skilldet->description = $langs->trans('SkillNotRequired');
283 $skilldet->rankorder = 0;
284 $skilldet->fk_skill = $this->id;
285
286 $result = $skilldet->create($user);
287 if ($result <= 0) {
288 $error++;
289 }
290
291 // Create level of skills
292 while ($i <= $MaxNumberSkill) {
293 $skilldet = new Skilldet($this->db);
294 $skilldet->description = $defaultSkillDesc . " " . $i;
295 $skilldet->rankorder = $i;
296 $skilldet->fk_skill = $this->id;
297
298 $result = $skilldet->create($user);
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->import_key);
348
349 // Clear fields
350 if (property_exists($object, 'ref')) {
351 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
352 }
353 if (property_exists($object, 'label')) {
354 // @phan-suppress-next-line PhanTypeInvalidDimOffset
355 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
356 }
357 if (property_exists($object, 'status')) {
358 $object->status = self::STATUS_DRAFT;
359 }
360 if (property_exists($object, 'date_creation')) {
361 $object->date_creation = dol_now();
362 }
363 if (property_exists($object, 'date_modification')) {
364 $object->date_modification = null;
365 }
366 // ...
367 // Clear extrafields that are unique
368 if (is_array($object->array_options) && count($object->array_options) > 0) {
369 $extrafields->fetch_name_optionals_label($this->table_element);
370 foreach ($object->array_options as $key => $option) {
371 $shortkey = preg_replace('/options_/', '', $key);
372 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
373 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
374 unset($object->array_options[$key]);
375 }
376 }
377 }
378
379 // Create clone
380 $object->context['createfromclone'] = 'createfromclone';
381 $result = $object->createCommon($user);
382 if ($result < 0) {
383 $error++;
385 }
386
387 if (!$error) {
388 // copy internal contacts
389 if ($this->copy_linked_contact($object, 'internal') < 0) {
390 $error++;
391 }
392 }
393
394 if (!$error) {
395 // copy external contacts if same company
396 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
397 if ($this->copy_linked_contact($object, 'external') < 0) {
398 $error++;
399 }
400 }
401 }
402
403 unset($object->context['createfromclone']);
404
405 // End
406 if (!$error) {
407 $this->db->commit();
408 return $object;
409 } else {
410 $this->db->rollback();
411 return -1;
412 }
413 }
414
422 public function fetch($id, $ref = null)
423 {
424 $result = $this->fetchCommon($id, $ref);
425 if ($result > 0 && !empty($this->table_element_line)) {
426 $this->fetchLines();
427 }
428 return $result;
429 }
430
436 public function fetchLines()
437 {
438 $this->lines = array();
439 require_once __DIR__ . '/skilldet.class.php';
440 $skilldet = new Skilldet($this->db);
441 $this->lines = $skilldet->fetchAll('ASC', '', 0, 0, '(fk_skill:=:'.$this->id.')');
442
443 if (is_array($this->lines)) {
444 return (count($this->lines) > 0) ? $this->lines : array();
445 } elseif ($this->lines < 0) {
446 $this->setErrorsFromObject($skilldet);
447 return $this->lines;
448 }
449 return [];
450 }
451
452
465 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
466 {
467 dol_syslog(__METHOD__, LOG_DEBUG);
468
469 $records = array();
470
471 $sql = 'SELECT ';
472 $sql .= $this->getFieldList('t');
473 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
474 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
475 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
476 } else {
477 $sql .= ' WHERE 1 = 1';
478 }
479
480 // Manage filter
481 $errormessage = '';
482 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
483 if ($errormessage) {
484 $this->errors[] = $errormessage;
485 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
486 return -1;
487 }
488
489 if (!empty($sortfield)) {
490 $sql .= $this->db->order($sortfield, $sortorder);
491 }
492 if (!empty($limit)) {
493 $sql .= ' '.$this->db->plimit($limit, $offset);
494 }
495
496 $resql = $this->db->query($sql);
497 if ($resql) {
498 $num = $this->db->num_rows($resql);
499 $i = 0;
500 while ($i < ($limit ? min($limit, $num) : $num)) {
501 $obj = $this->db->fetch_object($resql);
502
503 $record = new self($this->db);
504 $record->setVarsFromFetchObj($obj);
505
506 $records[$record->id] = $record;
507
508 $i++;
509 }
510 $this->db->free($resql);
511
512 return $records;
513 } else {
514 $this->errors[] = 'Error '.$this->db->lasterror();
515 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
516
517 return -1;
518 }
519 }
520
528 public function update(User $user, $notrigger = 0)
529 {
530 return $this->updateCommon($user, $notrigger);
531 }
532
540 public function delete(User $user, $notrigger = 0)
541 {
542 return $this->deleteCommon($user, $notrigger);
543 }
544
553 public function deleteLine(User $user, $idline, $notrigger = 0)
554 {
555 if ($this->status < 0) {
556 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
557 return -2;
558 }
559
560 return $this->deleteLineCommon($user, $idline, $notrigger);
561 }
562
563
571 public function validate($user, $notrigger = 0)
572 {
573 global $conf;
574
575 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
576
577 $error = 0;
578
579 // Protection
580 if ($this->status == self::STATUS_VALIDATED) {
581 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
582 return 0;
583 }
584
585 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->write))
586 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->skill_advance->validate))))
587 {
588 $this->error='NotEnoughPermissions';
589 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
590 return -1;
591 }*/
592
593 $now = dol_now();
594
595 $this->db->begin();
596
597 // Define new ref
598 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
599 $num = $this->getNextNumRef();
600 } else {
601 $num = $this->ref;
602 }
603 $this->newref = $num;
604
605 if (!empty($num)) {
606 // Validate
607 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
608 $sql .= " SET ref = '".$this->db->escape($num)."',";
609 $sql .= " status = ".self::STATUS_VALIDATED;
610 if (!empty($this->fields['date_validation'])) {
611 $sql .= ", date_validation = '".$this->db->idate($now)."'";
612 }
613 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
614 $sql .= ", fk_user_valid = ".((int) $user->id);
615 }
616 $sql .= " WHERE rowid = ".((int) $this->id);
617
618 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
619 $resql = $this->db->query($sql);
620 if (!$resql) {
621 dol_print_error($this->db);
622 $this->error = $this->db->lasterror();
623 $error++;
624 }
625
626 if (!$error && !$notrigger) {
627 // Call trigger
628 $result = $this->call_trigger('HRM_SKILL_VALIDATE', $user);
629 if ($result < 0) {
630 $error++;
631 }
632 // End call triggers
633 }
634 }
635
636 if (!$error) {
637 $this->oldref = $this->ref;
638
639 // Rename directory if dir was a temporary ref
640 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
641 // Now we rename also files into index
642 $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)."'";
643 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
644 $resql = $this->db->query($sql);
645 if (!$resql) {
646 $error++;
647 $this->error = $this->db->lasterror();
648 }
649 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skill/".$this->db->escape($this->newref)."'";
650 $sql .= " WHERE filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
651 $resql = $this->db->query($sql);
652 if (!$resql) {
653 $error++;
654 $this->error = $this->db->lasterror();
655 }
656
657 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
658 $oldref = dol_sanitizeFileName($this->ref);
659 $newref = dol_sanitizeFileName($num);
660 $dirsource = $conf->hrm->dir_output.'/skill/'.$oldref;
661 $dirdest = $conf->hrm->dir_output.'/skill/'.$newref;
662 if (!$error && file_exists($dirsource)) {
663 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
664
665 if (@rename($dirsource, $dirdest)) {
666 dol_syslog("Rename ok");
667 // Rename docs starting with $oldref with $newref
668 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skill/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
669 foreach ($listoffiles as $fileentry) {
670 $dirsource = $fileentry['name'];
671 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
672 $dirsource = $fileentry['path'].'/'.$dirsource;
673 $dirdest = $fileentry['path'].'/'.$dirdest;
674 @rename($dirsource, $dirdest);
675 }
676 }
677 }
678 }
679 }
680
681 // Set new ref and current status
682 if (!$error) {
683 $this->ref = $num;
684 $this->status = self::STATUS_VALIDATED;
685 }
686
687 if (!$error) {
688 $this->db->commit();
689 return 1;
690 } else {
691 $this->db->rollback();
692 return -1;
693 }
694 }
695
696
704 public function setDraft($user, $notrigger = 0)
705 {
706 // Protection
707 if ($this->status <= self::STATUS_DRAFT) {
708 return 0;
709 }
710
711 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
712 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
713 {
714 $this->error='Permission denied';
715 return -1;
716 }*/
717
718 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILL_UNVALIDATE');
719 }
720
728 public function cancel($user, $notrigger = 0)
729 {
730 // Protection
731 if ($this->status != self::STATUS_VALIDATED) {
732 return 0;
733 }
734
735 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
736 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
737 {
738 $this->error='Permission denied';
739 return -1;
740 }*/
741
742 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILL_CANCEL');
743 }
744
752 public function reopen($user, $notrigger = 0)
753 {
754 // Protection
755 if ($this->status != self::STATUS_CANCELED) {
756 return 0;
757 }
758
759 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
760 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
761 {
762 $this->error='Permission denied';
763 return -1;
764 }*/
765
766 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILL_REOPEN');
767 }
768
789 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
790 {
791 global $conf, $langs, $hookmanager;
792
793 if (!empty($conf->dol_no_mouse_hover)) {
794 $notooltip = 1; // Force disable tooltips
795 }
796
797 $result = '';
798
799 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skill").'</u>';
800 if (isset($this->status)) {
801 $label .= ' '.$this->getLibStatut(5);
802 }
803 $label .= '<br>';
804 $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
805 $label .= '<br><b>'.$langs->trans('Description').':</b> '.dol_htmlentitiesbr(dolGetFirstLineOfText($this->description, 10), 1);
806
807 $url = dol_buildpath('/hrm/skill_card.php', 1).'?id='.$this->id;
808
809 if ($option != 'nolink') {
810 // Add param to save lastsearch_values or not
811 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
812 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
813 $add_save_lastsearch_values = 1;
814 }
815 if ($add_save_lastsearch_values) {
816 $url .= '&save_lastsearch_values=1';
817 }
818 }
819
820 $linkclose = '';
821 if (empty($notooltip)) {
822 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
823 $label = $langs->trans("ShowSkill");
824 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
825 }
826 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
827 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
828 } else {
829 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
830 }
831
832 if ($option == 'nolink') {
833 $linkstart = '<span';
834 } else {
835 $linkstart = '<a href="'.$url.'"';
836 }
837 $linkstart .= $linkclose.'>';
838 if ($option == 'nolink') {
839 $linkend = '</span>';
840 } else {
841 $linkend = '</a>';
842 }
843
844 $result .= $linkstart;
845
846 if (empty($this->showphoto_on_popup)) {
847 if ($withpicto) {
848 $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);
849 }
850 } else {
851 if ($withpicto) {
852 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
853
854 list($class, $module) = explode('@', $this->picto);
855 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
856 $filearray = dol_dir_list($upload_dir, "files");
857 $filename = $filearray[0]['name'];
858 if (!empty($filename)) {
859 $pospoint = strpos($filearray[0]['name'], '.');
860
861 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
862 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
863 $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>';
864 } else {
865 $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>';
866 }
867
868 $result .= '</div>';
869 } else {
870 $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);
871 }
872 }
873 }
874
875 if ($withpicto != 2) {
876 $result .= $this->label;
877 }
878
879 $result .= $linkend;
880 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
881
882 global $action, $hookmanager;
883 $hookmanager->initHooks(array('skilldao'));
884 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
885 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
886 if ($reshook > 0) {
887 $result = $hookmanager->resPrint;
888 } else {
889 $result .= $hookmanager->resPrint;
890 }
891
892 return $result;
893 }
894
901 public function getLibStatut($mode = 0)
902 {
903 return $this->LibStatut($this->status, $mode);
904 }
905
906 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
914 public function LibStatut($status, $mode = 0)
915 {
916 if (empty($status)) {
917 $status = 0;
918 }
919
920 // phpcs:enable
921 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
922 global $langs;
923 //$langs->load("hrm");
924 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
925 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
926 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
927 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
928 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
929 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
930 }
931
932 $statusType = 'status'.$status;
933 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
934 if ($status == self::STATUS_CANCELED) {
935 $statusType = 'status6';
936 }
937
938 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
939 }
940
947 public function info($id)
948 {
949 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
950 $sql .= ' fk_user_creat, fk_user_modif';
951 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
952 $sql .= ' WHERE t.rowid = '.((int) $id);
953 $result = $this->db->query($sql);
954 if ($result) {
955 if ($this->db->num_rows($result)) {
956 $obj = $this->db->fetch_object($result);
957
958 $this->id = $obj->rowid;
959
960 $this->user_creation_id = $obj->fk_user_creat;
961 $this->user_modification_id = $obj->fk_user_modif;
962 $this->date_creation = $this->db->jdate($obj->datec);
963 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
964 }
965
966 $this->db->free($result);
967 } else {
968 dol_print_error($this->db);
969 }
970 }
971
978 public function initAsSpecimen()
979 {
980 // Set here init that are not commonf fields
981 // $this->property1 = ...
982 // $this->property2 = ...
983
984 return $this->initAsSpecimenCommon();
985 }
986
992 public function getLinesArray()
993 {
994 $this->lines = array();
995
996 $objectline = new Skilldet($this->db);
997 $result = $objectline->fetchAll('ASC', 'rankorder', 0, 0, '(fk_skill:=:'.((int) $this->id).')');
998
999 if (is_numeric($result)) {
1000 $this->setErrorsFromObject($objectline);
1001 return $result;
1002 } else {
1003 $this->lines = $result;
1004 return $this->lines;
1005 }
1006 }
1007
1013 public function getNextNumRef()
1014 {
1015 global $langs, $conf;
1016 $langs->load("hrm");
1017
1018 if (!getDolGlobalString('hrm_SKILL_ADDON')) {
1019 $conf->global->hrm_SKILL_ADDON = 'mod_skill_standard';
1020 }
1021
1022 if (getDolGlobalString('hrm_SKILL_ADDON')) {
1023 $mybool = false;
1024
1025 $file = getDolGlobalString('hrm_SKILL_ADDON') . ".php";
1026 $classname = getDolGlobalString('hrm_SKILL_ADDON');
1027
1028 // Include file with class
1029 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1030 foreach ($dirmodels as $reldir) {
1031 $dir = dol_buildpath($reldir."core/modules/hrm/");
1032
1033 // Load file with numbering class (if found)
1034 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1035 }
1036
1037 if (!$mybool) {
1038 dol_print_error(null, "Failed to include file ".$file);
1039 return '';
1040 }
1041
1042 if (class_exists($classname)) {
1043 $obj = new $classname();
1044 '@phan-var-force ModeleNumRefEvaluation $obj';
1045 $numref = $obj->getNextValue($this);
1046
1047 if ($numref != '' && $numref != '-1') {
1048 return $numref;
1049 } else {
1050 $this->error = $obj->error;
1051 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1052 return "";
1053 }
1054 } else {
1055 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1056 return "";
1057 }
1058 } else {
1059 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1060 return "";
1061 }
1062 }
1063
1075 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1076 {
1077 global $conf, $langs;
1078
1079 $result = 0;
1080 $includedocgeneration = 0;
1081
1082 $langs->load("hrm");
1083
1084 if (!dol_strlen($modele)) {
1085 $modele = 'standard_skill';
1086
1087 if (!empty($this->model_pdf)) {
1088 $modele = $this->model_pdf;
1089 } elseif (getDolGlobalString('SKILL_ADDON_PDF')) {
1090 $modele = getDolGlobalString('SKILL_ADDON_PDF');
1091 }
1092 }
1093
1094 $modelpath = "core/modules/hrm/doc/";
1095
1096 if ($includedocgeneration && !empty($modele)) {
1097 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1098 }
1099
1100 return $result;
1101 }
1102
1107 public static function typeCodeToLabel($code)
1108 {
1109 global $langs;
1110 $result = '';
1111 switch ($code) {
1112 case 0: $result = $langs->trans("TypeKnowHow");
1113 break; //"Savoir Faire"
1114 case 1: $result = $langs->trans("TypeHowToBe");
1115 break; // "Savoir être"
1116 case 9: $result = $langs->trans("TypeKnowledge");
1117 break; //"Savoir"
1118 }
1119 return $result;
1120 }
1121
1129 public function getKanbanView($option = '', $arraydata = null)
1130 {
1131 global $selected, $langs;
1132
1133 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1134
1135 $return = '<div class="box-flex-item box-flex-grow-zero">';
1136 $return .= '<div class="info-box info-box-sm">';
1137 $return .= '<span class="info-box-icon bg-infobox-action">';
1138 $return .= img_picto('', $this->picto);
1139 $return .= '</span>';
1140 $return .= '<div class="info-box-content">';
1141 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1142 if ($selected >= 0) {
1143 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1144 }
1145 if (property_exists($this, 'skill_type')) {
1146 $return .= '<br><span class="opacitymedium">'.$langs->trans("Type").'</span>';
1147 $return .= ' : <span class="info-box-label ">'.$this->fields['skill_type']['arrayofkeyval'][$this->skill_type].'</span>';
1148 }
1149 if (property_exists($this, 'description')) {
1150 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Description").'</span> : ';
1151 $return .= '<br><span class="info-box-label ">'.(strlen($this->description) > 30 ? dol_substr($this->description, 0, 25).'...' : $this->description).'</span>';
1152 }
1153 $return .= '</div>';
1154 $return .= '</div>';
1155 $return .= '</div>';
1156 return $return;
1157 }
1158}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
$object ref
Definition info.php:89
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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: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)
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79