dolibarr 21.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 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 );
115 public $rowid;
116 public $label;
117 public $description;
118 public $fk_user_creat;
119 public $fk_user_modif;
120 public $required_level;
121 public $date_validite;
122 public $temps_theorique;
123 public $skill_type;
124 // END MODULEBUILDER PROPERTIES
125
126
127 // If this object has a subtable with lines
128
129 // /**
130 // * @var string Name of subtable line
131 // */
132 // public $table_element_line = 'hrm_skillline';
133
137 public $fk_element = 'fk_skill';
138
139 // /**
140 // * @var string Name of subtable class that manage subtable lines
141 // */
142 // public $class_element_line = 'Skillline';
143
147 protected $childtables = array(
148 'hrm_skillrank' => ['name' => 'SkillRank'],
149 'hrm_evaluationdet' => ['name' => 'EvaluationDet'],
150 );
151
157 protected $childtablesoncascade = array('hrm_skilldet');
158
159 // /**
160 // * @var SkillLine[] Array of subtable lines
161 // */
162 // public $lines = array();
163
164
165
171 public function __construct(DoliDB $db)
172 {
173 global $conf, $langs;
174
175 $this->db = $db;
176
177 $this->ismultientitymanaged = 0;
178 $this->isextrafieldmanaged = 1;
179
180 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
181 $this->fields['rowid']['visible'] = 0;
182 }
183 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
184 $this->fields['entity']['enabled'] = 0;
185 }
186
187 // Example to show how to set values of fields definition dynamically
188 /*if ($user->rights->hrm->skill->read) {
189 $this->fields['myfield']['visible'] = 1;
190 $this->fields['myfield']['noteditable'] = 0;
191 }*/
192
193 // Unset fields that are disabled
194 foreach ($this->fields as $key => $val) {
195 if (isset($val['enabled']) && empty($val['enabled'])) {
196 unset($this->fields[$key]);
197 }
198 }
199
200 // Translate some data of arrayofkeyval
201 if (is_object($langs)) {
202 foreach ($this->fields as $key => $val) {
203 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
204 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
205 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
206 }
207 }
208 }
209 }
210 }
211
219 public function create(User $user, $notrigger = 0)
220 {
221 global $langs,$conf;
222
223 $resultcreate = $this->createCommon($user, $notrigger);
224
225
226 if ($resultcreate > 0) {
227 // skillDet create
228 $this->createSkills();
229 }
230
231 return $resultcreate;
232 }
233
240 public function createSkills($i = 1)
241 {
242 global $conf, $user, $langs;
243
244 $MaxNumberSkill = getDolGlobalInt('HRM_MAXRANK', self::DEFAULT_MAX_RANK_PER_SKILL);
245 $defaultSkillDesc = getDolGlobalString('HRM_DEFAULT_SKILL_DESCRIPTION', $langs->trans("NoDescription"));
246
247 $error = 0;
248
249 require_once __DIR__ . '/skilldet.class.php';
250
251 $this->db->begin();
252
253 // Create level of skills
254 while ($i <= $MaxNumberSkill) {
255 $skilldet = new Skilldet($this->db);
256 $skilldet->description = $defaultSkillDesc . " " . $i;
257 $skilldet->rankorder = $i;
258 $skilldet->fk_skill = $this->id;
259
260 $result = $skilldet->create($user);
261 if ($result <= 0) {
262 $error++;
263 }
264 $i++;
265 }
266
267 if (!$error) {
268 $this->db->commit();
269
270 setEventMessage($langs->trans('SkillCreated', $i));
271 return 1;
272 } else {
273 $this->db->rollback();
274 return -1;
275 }
276 }
277
285 public function createFromClone(User $user, $fromid)
286 {
287 global $langs, $extrafields;
288 $error = 0;
289
290 dol_syslog(__METHOD__, LOG_DEBUG);
291
292 $object = new self($this->db);
293
294 $this->db->begin();
295
296 // Load source object
297 $result = $object->fetchCommon($fromid);
298 if ($result > 0 && !empty($object->table_element_line)) {
299 $object->fetchLines();
300 }
301
302 // get lines so they will be clone
303 //foreach($this->lines as $line)
304 // $line->fetch_optionals();
305
306 // Reset some properties
307 unset($object->id);
308 unset($object->fk_user_creat);
309 unset($object->import_key);
310
311 // Clear fields
312 if (property_exists($object, 'ref')) {
313 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
314 }
315 if (property_exists($object, 'label')) {
316 // @phan-suppress-next-line PhanTypeInvalidDimOffset
317 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
318 }
319 if (property_exists($object, 'status')) {
320 $object->status = self::STATUS_DRAFT;
321 }
322 if (property_exists($object, 'date_creation')) {
323 $object->date_creation = dol_now();
324 }
325 if (property_exists($object, 'date_modification')) {
326 $object->date_modification = null;
327 }
328 // ...
329 // Clear extrafields that are unique
330 if (is_array($object->array_options) && count($object->array_options) > 0) {
331 $extrafields->fetch_name_optionals_label($this->table_element);
332 foreach ($object->array_options as $key => $option) {
333 $shortkey = preg_replace('/options_/', '', $key);
334 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
335 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
336 unset($object->array_options[$key]);
337 }
338 }
339 }
340
341 // Create clone
342 $object->context['createfromclone'] = 'createfromclone';
343 $result = $object->createCommon($user);
344 if ($result < 0) {
345 $error++;
347 }
348
349 if (!$error) {
350 // copy internal contacts
351 if ($this->copy_linked_contact($object, 'internal') < 0) {
352 $error++;
353 }
354 }
355
356 if (!$error) {
357 // copy external contacts if same company
358 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
359 if ($this->copy_linked_contact($object, 'external') < 0) {
360 $error++;
361 }
362 }
363 }
364
365 unset($object->context['createfromclone']);
366
367 // End
368 if (!$error) {
369 $this->db->commit();
370 return $object;
371 } else {
372 $this->db->rollback();
373 return -1;
374 }
375 }
376
384 public function fetch($id, $ref = null)
385 {
386 $result = $this->fetchCommon($id, $ref);
387 if ($result > 0 && !empty($this->table_element_line)) {
388 $this->fetchLines();
389 }
390 return $result;
391 }
392
398 public function fetchLines()
399 {
400 $this->lines = array();
401 require_once __DIR__ . '/skilldet.class.php';
402 $skilldet = new Skilldet($this->db);
403 $this->lines = $skilldet->fetchAll('ASC', '', 0, 0, '(fk_skill:=:'.$this->id.')');
404
405 if (is_array($this->lines)) {
406 return (count($this->lines) > 0) ? $this->lines : array();
407 } elseif ($this->lines < 0) {
408 $this->setErrorsFromObject($skilldet);
409 return $this->lines;
410 }
411 return [];
412 }
413
414
427 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
428 {
429 dol_syslog(__METHOD__, LOG_DEBUG);
430
431 $records = array();
432
433 $sql = 'SELECT ';
434 $sql .= $this->getFieldList('t');
435 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
436 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
437 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
438 } else {
439 $sql .= ' WHERE 1 = 1';
440 }
441
442 // Manage filter
443 $errormessage = '';
444 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
445 if ($errormessage) {
446 $this->errors[] = $errormessage;
447 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
448 return -1;
449 }
450
451 if (!empty($sortfield)) {
452 $sql .= $this->db->order($sortfield, $sortorder);
453 }
454 if (!empty($limit)) {
455 $sql .= ' '.$this->db->plimit($limit, $offset);
456 }
457
458 $resql = $this->db->query($sql);
459 if ($resql) {
460 $num = $this->db->num_rows($resql);
461 $i = 0;
462 while ($i < ($limit ? min($limit, $num) : $num)) {
463 $obj = $this->db->fetch_object($resql);
464
465 $record = new self($this->db);
466 $record->setVarsFromFetchObj($obj);
467
468 $records[$record->id] = $record;
469
470 $i++;
471 }
472 $this->db->free($resql);
473
474 return $records;
475 } else {
476 $this->errors[] = 'Error '.$this->db->lasterror();
477 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
478
479 return -1;
480 }
481 }
482
490 public function update(User $user, $notrigger = 0)
491 {
492 return $this->updateCommon($user, $notrigger);
493 }
494
502 public function delete(User $user, $notrigger = 0)
503 {
504 return $this->deleteCommon($user, $notrigger);
505 }
506
515 public function deleteLine(User $user, $idline, $notrigger = 0)
516 {
517 if ($this->status < 0) {
518 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
519 return -2;
520 }
521
522 return $this->deleteLineCommon($user, $idline, $notrigger);
523 }
524
525
533 public function validate($user, $notrigger = 0)
534 {
535 global $conf;
536
537 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
538
539 $error = 0;
540
541 // Protection
542 if ($this->status == self::STATUS_VALIDATED) {
543 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
544 return 0;
545 }
546
547 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->write))
548 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->skill_advance->validate))))
549 {
550 $this->error='NotEnoughPermissions';
551 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
552 return -1;
553 }*/
554
555 $now = dol_now();
556
557 $this->db->begin();
558
559 // Define new ref
560 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
561 $num = $this->getNextNumRef();
562 } else {
563 $num = $this->ref;
564 }
565 $this->newref = $num;
566
567 if (!empty($num)) {
568 // Validate
569 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
570 $sql .= " SET ref = '".$this->db->escape($num)."',";
571 $sql .= " status = ".self::STATUS_VALIDATED;
572 if (!empty($this->fields['date_validation'])) {
573 $sql .= ", date_validation = '".$this->db->idate($now)."'";
574 }
575 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
576 $sql .= ", fk_user_valid = ".((int) $user->id);
577 }
578 $sql .= " WHERE rowid = ".((int) $this->id);
579
580 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
581 $resql = $this->db->query($sql);
582 if (!$resql) {
583 dol_print_error($this->db);
584 $this->error = $this->db->lasterror();
585 $error++;
586 }
587
588 if (!$error && !$notrigger) {
589 // Call trigger
590 $result = $this->call_trigger('HRM_SKILL_VALIDATE', $user);
591 if ($result < 0) {
592 $error++;
593 }
594 // End call triggers
595 }
596 }
597
598 if (!$error) {
599 $this->oldref = $this->ref;
600
601 // Rename directory if dir was a temporary ref
602 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
603 // Now we rename also files into index
604 $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)."'";
605 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
606 $resql = $this->db->query($sql);
607 if (!$resql) {
608 $error++;
609 $this->error = $this->db->lasterror();
610 }
611 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skill/".$this->db->escape($this->newref)."'";
612 $sql .= " WHERE filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
613 $resql = $this->db->query($sql);
614 if (!$resql) {
615 $error++;
616 $this->error = $this->db->lasterror();
617 }
618
619 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
620 $oldref = dol_sanitizeFileName($this->ref);
621 $newref = dol_sanitizeFileName($num);
622 $dirsource = $conf->hrm->dir_output.'/skill/'.$oldref;
623 $dirdest = $conf->hrm->dir_output.'/skill/'.$newref;
624 if (!$error && file_exists($dirsource)) {
625 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
626
627 if (@rename($dirsource, $dirdest)) {
628 dol_syslog("Rename ok");
629 // Rename docs starting with $oldref with $newref
630 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skill/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
631 foreach ($listoffiles as $fileentry) {
632 $dirsource = $fileentry['name'];
633 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
634 $dirsource = $fileentry['path'].'/'.$dirsource;
635 $dirdest = $fileentry['path'].'/'.$dirdest;
636 @rename($dirsource, $dirdest);
637 }
638 }
639 }
640 }
641 }
642
643 // Set new ref and current status
644 if (!$error) {
645 $this->ref = $num;
646 $this->status = self::STATUS_VALIDATED;
647 }
648
649 if (!$error) {
650 $this->db->commit();
651 return 1;
652 } else {
653 $this->db->rollback();
654 return -1;
655 }
656 }
657
658
666 public function setDraft($user, $notrigger = 0)
667 {
668 // Protection
669 if ($this->status <= self::STATUS_DRAFT) {
670 return 0;
671 }
672
673 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
674 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
675 {
676 $this->error='Permission denied';
677 return -1;
678 }*/
679
680 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILL_UNVALIDATE');
681 }
682
690 public function cancel($user, $notrigger = 0)
691 {
692 // Protection
693 if ($this->status != self::STATUS_VALIDATED) {
694 return 0;
695 }
696
697 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
698 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
699 {
700 $this->error='Permission denied';
701 return -1;
702 }*/
703
704 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILL_CANCEL');
705 }
706
714 public function reopen($user, $notrigger = 0)
715 {
716 // Protection
717 if ($this->status != self::STATUS_CANCELED) {
718 return 0;
719 }
720
721 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
722 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
723 {
724 $this->error='Permission denied';
725 return -1;
726 }*/
727
728 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILL_REOPEN');
729 }
730
751 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
752 {
753 global $conf, $langs, $hookmanager;
754
755 if (!empty($conf->dol_no_mouse_hover)) {
756 $notooltip = 1; // Force disable tooltips
757 }
758
759 $result = '';
760
761 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skill").'</u>';
762 if (isset($this->status)) {
763 $label .= ' '.$this->getLibStatut(5);
764 }
765 $label .= '<br>';
766 $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
767 $label .= '<br><b>'.$langs->trans('Description').':</b> '.dol_htmlentitiesbr(dolGetFirstLineOfText($this->description, 10), 1);
768
769 $url = dol_buildpath('/hrm/skill_card.php', 1).'?id='.$this->id;
770
771 if ($option != 'nolink') {
772 // Add param to save lastsearch_values or not
773 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
774 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
775 $add_save_lastsearch_values = 1;
776 }
777 if ($add_save_lastsearch_values) {
778 $url .= '&save_lastsearch_values=1';
779 }
780 }
781
782 $linkclose = '';
783 if (empty($notooltip)) {
784 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
785 $label = $langs->trans("ShowSkill");
786 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
787 }
788 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
789 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
790 } else {
791 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
792 }
793
794 if ($option == 'nolink') {
795 $linkstart = '<span';
796 } else {
797 $linkstart = '<a href="'.$url.'"';
798 }
799 $linkstart .= $linkclose.'>';
800 if ($option == 'nolink') {
801 $linkend = '</span>';
802 } else {
803 $linkend = '</a>';
804 }
805
806 $result .= $linkstart;
807
808 if (empty($this->showphoto_on_popup)) {
809 if ($withpicto) {
810 $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);
811 }
812 } else {
813 if ($withpicto) {
814 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
815
816 list($class, $module) = explode('@', $this->picto);
817 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
818 $filearray = dol_dir_list($upload_dir, "files");
819 $filename = $filearray[0]['name'];
820 if (!empty($filename)) {
821 $pospoint = strpos($filearray[0]['name'], '.');
822
823 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
824 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
825 $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>';
826 } else {
827 $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>';
828 }
829
830 $result .= '</div>';
831 } else {
832 $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);
833 }
834 }
835 }
836
837 if ($withpicto != 2) {
838 $result .= $this->label;
839 }
840
841 $result .= $linkend;
842 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
843
844 global $action, $hookmanager;
845 $hookmanager->initHooks(array('skilldao'));
846 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
847 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
848 if ($reshook > 0) {
849 $result = $hookmanager->resPrint;
850 } else {
851 $result .= $hookmanager->resPrint;
852 }
853
854 return $result;
855 }
856
863 public function getLibStatut($mode = 0)
864 {
865 return $this->LibStatut($this->status, $mode);
866 }
867
868 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
876 public function LibStatut($status, $mode = 0)
877 {
878 if (empty($status)) {
879 $status = 0;
880 }
881
882 // phpcs:enable
883 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
884 global $langs;
885 //$langs->load("hrm");
886 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
887 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
888 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
889 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
890 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
891 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
892 }
893
894 $statusType = 'status'.$status;
895 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
896 if ($status == self::STATUS_CANCELED) {
897 $statusType = 'status6';
898 }
899
900 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
901 }
902
909 public function info($id)
910 {
911 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
912 $sql .= ' fk_user_creat, fk_user_modif';
913 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
914 $sql .= ' WHERE t.rowid = '.((int) $id);
915 $result = $this->db->query($sql);
916 if ($result) {
917 if ($this->db->num_rows($result)) {
918 $obj = $this->db->fetch_object($result);
919
920 $this->id = $obj->rowid;
921
922 $this->user_creation_id = $obj->fk_user_creat;
923 $this->user_modification_id = $obj->fk_user_modif;
924 $this->date_creation = $this->db->jdate($obj->datec);
925 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
926 }
927
928 $this->db->free($result);
929 } else {
930 dol_print_error($this->db);
931 }
932 }
933
940 public function initAsSpecimen()
941 {
942 // Set here init that are not commonf fields
943 // $this->property1 = ...
944 // $this->property2 = ...
945
946 return $this->initAsSpecimenCommon();
947 }
948
954 public function getLinesArray()
955 {
956 $this->lines = array();
957
958 $objectline = new Skilldet($this->db);
959 $result = $objectline->fetchAll('ASC', 'rankorder', 0, 0, '(fk_skill:=:'.((int) $this->id).')');
960
961 if (is_numeric($result)) {
962 $this->setErrorsFromObject($objectline);
963 return $result;
964 } else {
965 $this->lines = $result;
966 return $this->lines;
967 }
968 }
969
975 public function getNextNumRef()
976 {
977 global $langs, $conf;
978 $langs->load("hrm");
979
980 if (!getDolGlobalString('hrm_SKILL_ADDON')) {
981 $conf->global->hrm_SKILL_ADDON = 'mod_skill_standard';
982 }
983
984 if (getDolGlobalString('hrm_SKILL_ADDON')) {
985 $mybool = false;
986
987 $file = getDolGlobalString('hrm_SKILL_ADDON') . ".php";
988 $classname = getDolGlobalString('hrm_SKILL_ADDON');
989
990 // Include file with class
991 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
992 foreach ($dirmodels as $reldir) {
993 $dir = dol_buildpath($reldir."core/modules/hrm/");
994
995 // Load file with numbering class (if found)
996 $mybool = ((bool) @include_once $dir.$file) || $mybool;
997 }
998
999 if (!$mybool) {
1000 dol_print_error(null, "Failed to include file ".$file);
1001 return '';
1002 }
1003
1004 if (class_exists($classname)) {
1005 $obj = new $classname();
1006 $numref = $obj->getNextValue($this);
1007
1008 if ($numref != '' && $numref != '-1') {
1009 return $numref;
1010 } else {
1011 $this->error = $obj->error;
1012 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1013 return "";
1014 }
1015 } else {
1016 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1017 return "";
1018 }
1019 } else {
1020 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1021 return "";
1022 }
1023 }
1024
1036 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1037 {
1038 global $conf, $langs;
1039
1040 $result = 0;
1041 $includedocgeneration = 0;
1042
1043 $langs->load("hrm");
1044
1045 if (!dol_strlen($modele)) {
1046 $modele = 'standard_skill';
1047
1048 if (!empty($this->model_pdf)) {
1049 $modele = $this->model_pdf;
1050 } elseif (getDolGlobalString('SKILL_ADDON_PDF')) {
1051 $modele = getDolGlobalString('SKILL_ADDON_PDF');
1052 }
1053 }
1054
1055 $modelpath = "core/modules/hrm/doc/";
1056
1057 if ($includedocgeneration && !empty($modele)) {
1058 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1059 }
1060
1061 return $result;
1062 }
1063
1068 public static function typeCodeToLabel($code)
1069 {
1070 global $langs;
1071 $result = '';
1072 switch ($code) {
1073 case 0: $result = $langs->trans("TypeKnowHow");
1074 break; //"Savoir Faire"
1075 case 1: $result = $langs->trans("TypeHowToBe");
1076 break; // "Savoir être"
1077 case 9: $result = $langs->trans("TypeKnowledge");
1078 break; //"Savoir"
1079 }
1080 return $result;
1081 }
1082
1090 public function getKanbanView($option = '', $arraydata = null)
1091 {
1092 global $selected, $langs;
1093
1094 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1095
1096 $return = '<div class="box-flex-item box-flex-grow-zero">';
1097 $return .= '<div class="info-box info-box-sm">';
1098 $return .= '<span class="info-box-icon bg-infobox-action">';
1099 $return .= img_picto('', $this->picto);
1100 $return .= '</span>';
1101 $return .= '<div class="info-box-content">';
1102 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1103 if ($selected >= 0) {
1104 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1105 }
1106 if (property_exists($this, 'skill_type')) {
1107 $return .= '<br><span class="opacitymedium">'.$langs->trans("Type").'</span>';
1108 $return .= ' : <span class="info-box-label ">'.$this->fields['skill_type']['arrayofkeyval'][$this->skill_type].'</span>';
1109 }
1110 if (property_exists($this, 'description')) {
1111 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Description").'</span> : ';
1112 $return .= '<br><span class="info-box-label ">'.(strlen($this->description) > 30 ? dol_substr($this->description, 0, 25).'...' : $this->description).'</span>';
1113 }
1114 $return .= '</div>';
1115 $return .= '</div>';
1116 $return .= '</div>';
1117 return $return;
1118 }
1119}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:640
$object ref
Definition info.php:79
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 $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.
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.