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 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
317 }
318 if (property_exists($object, 'status')) {
319 $object->status = self::STATUS_DRAFT;
320 }
321 if (property_exists($object, 'date_creation')) {
322 $object->date_creation = dol_now();
323 }
324 if (property_exists($object, 'date_modification')) {
325 $object->date_modification = null;
326 }
327 // ...
328 // Clear extrafields that are unique
329 if (is_array($object->array_options) && count($object->array_options) > 0) {
330 $extrafields->fetch_name_optionals_label($this->table_element);
331 foreach ($object->array_options as $key => $option) {
332 $shortkey = preg_replace('/options_/', '', $key);
333 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
334 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
335 unset($object->array_options[$key]);
336 }
337 }
338 }
339
340 // Create clone
341 $object->context['createfromclone'] = 'createfromclone';
342 $result = $object->createCommon($user);
343 if ($result < 0) {
344 $error++;
346 }
347
348 if (!$error) {
349 // copy internal contacts
350 if ($this->copy_linked_contact($object, 'internal') < 0) {
351 $error++;
352 }
353 }
354
355 if (!$error) {
356 // copy external contacts if same company
357 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
358 if ($this->copy_linked_contact($object, 'external') < 0) {
359 $error++;
360 }
361 }
362 }
363
364 unset($object->context['createfromclone']);
365
366 // End
367 if (!$error) {
368 $this->db->commit();
369 return $object;
370 } else {
371 $this->db->rollback();
372 return -1;
373 }
374 }
375
383 public function fetch($id, $ref = null)
384 {
385 $result = $this->fetchCommon($id, $ref);
386 if ($result > 0 && !empty($this->table_element_line)) {
387 $this->fetchLines();
388 }
389 return $result;
390 }
391
397 public function fetchLines()
398 {
399 $this->lines = array();
400 require_once __DIR__ . '/skilldet.class.php';
401 $skilldet = new Skilldet($this->db);
402 $this->lines = $skilldet->fetchAll('ASC', '', 0, 0, '(fk_skill:=:'.$this->id.')');
403
404 if (is_array($this->lines)) {
405 return (count($this->lines) > 0) ? $this->lines : array();
406 } elseif ($this->lines < 0) {
407 $this->setErrorsFromObject($skilldet);
408 return $this->lines;
409 }
410 return [];
411 }
412
413
426 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
427 {
428 dol_syslog(__METHOD__, LOG_DEBUG);
429
430 $records = array();
431
432 $sql = 'SELECT ';
433 $sql .= $this->getFieldList('t');
434 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
435 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
436 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
437 } else {
438 $sql .= ' WHERE 1 = 1';
439 }
440
441 // Manage filter
442 $errormessage = '';
443 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
444 if ($errormessage) {
445 $this->errors[] = $errormessage;
446 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
447 return -1;
448 }
449
450 if (!empty($sortfield)) {
451 $sql .= $this->db->order($sortfield, $sortorder);
452 }
453 if (!empty($limit)) {
454 $sql .= ' '.$this->db->plimit($limit, $offset);
455 }
456
457 $resql = $this->db->query($sql);
458 if ($resql) {
459 $num = $this->db->num_rows($resql);
460 $i = 0;
461 while ($i < ($limit ? min($limit, $num) : $num)) {
462 $obj = $this->db->fetch_object($resql);
463
464 $record = new self($this->db);
465 $record->setVarsFromFetchObj($obj);
466
467 $records[$record->id] = $record;
468
469 $i++;
470 }
471 $this->db->free($resql);
472
473 return $records;
474 } else {
475 $this->errors[] = 'Error '.$this->db->lasterror();
476 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
477
478 return -1;
479 }
480 }
481
489 public function update(User $user, $notrigger = 0)
490 {
491 return $this->updateCommon($user, $notrigger);
492 }
493
501 public function delete(User $user, $notrigger = 0)
502 {
503 return $this->deleteCommon($user, $notrigger);
504 }
505
514 public function deleteLine(User $user, $idline, $notrigger = 0)
515 {
516 if ($this->status < 0) {
517 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
518 return -2;
519 }
520
521 return $this->deleteLineCommon($user, $idline, $notrigger);
522 }
523
524
532 public function validate($user, $notrigger = 0)
533 {
534 global $conf;
535
536 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
537
538 $error = 0;
539
540 // Protection
541 if ($this->status == self::STATUS_VALIDATED) {
542 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
543 return 0;
544 }
545
546 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->write))
547 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skill->skill_advance->validate))))
548 {
549 $this->error='NotEnoughPermissions';
550 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
551 return -1;
552 }*/
553
554 $now = dol_now();
555
556 $this->db->begin();
557
558 // Define new ref
559 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
560 $num = $this->getNextNumRef();
561 } else {
562 $num = $this->ref;
563 }
564 $this->newref = $num;
565
566 if (!empty($num)) {
567 // Validate
568 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
569 $sql .= " SET ref = '".$this->db->escape($num)."',";
570 $sql .= " status = ".self::STATUS_VALIDATED;
571 if (!empty($this->fields['date_validation'])) {
572 $sql .= ", date_validation = '".$this->db->idate($now)."'";
573 }
574 if (!empty($this->fields['fk_user_valid'])) {
575 $sql .= ", fk_user_valid = ".((int) $user->id);
576 }
577 $sql .= " WHERE rowid = ".((int) $this->id);
578
579 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
580 $resql = $this->db->query($sql);
581 if (!$resql) {
582 dol_print_error($this->db);
583 $this->error = $this->db->lasterror();
584 $error++;
585 }
586
587 if (!$error && !$notrigger) {
588 // Call trigger
589 $result = $this->call_trigger('HRM_SKILL_VALIDATE', $user);
590 if ($result < 0) {
591 $error++;
592 }
593 // End call triggers
594 }
595 }
596
597 if (!$error) {
598 $this->oldref = $this->ref;
599
600 // Rename directory if dir was a temporary ref
601 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
602 // Now we rename also files into index
603 $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)."'";
604 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
605 $resql = $this->db->query($sql);
606 if (!$resql) {
607 $error++;
608 $this->error = $this->db->lasterror();
609 }
610 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skill/".$this->db->escape($this->newref)."'";
611 $sql .= " WHERE filepath = 'skill/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
612 $resql = $this->db->query($sql);
613 if (!$resql) {
614 $error++;
615 $this->error = $this->db->lasterror();
616 }
617
618 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
619 $oldref = dol_sanitizeFileName($this->ref);
620 $newref = dol_sanitizeFileName($num);
621 $dirsource = $conf->hrm->dir_output.'/skill/'.$oldref;
622 $dirdest = $conf->hrm->dir_output.'/skill/'.$newref;
623 if (!$error && file_exists($dirsource)) {
624 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
625
626 if (@rename($dirsource, $dirdest)) {
627 dol_syslog("Rename ok");
628 // Rename docs starting with $oldref with $newref
629 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skill/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
630 foreach ($listoffiles as $fileentry) {
631 $dirsource = $fileentry['name'];
632 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
633 $dirsource = $fileentry['path'].'/'.$dirsource;
634 $dirdest = $fileentry['path'].'/'.$dirdest;
635 @rename($dirsource, $dirdest);
636 }
637 }
638 }
639 }
640 }
641
642 // Set new ref and current status
643 if (!$error) {
644 $this->ref = $num;
645 $this->status = self::STATUS_VALIDATED;
646 }
647
648 if (!$error) {
649 $this->db->commit();
650 return 1;
651 } else {
652 $this->db->rollback();
653 return -1;
654 }
655 }
656
657
665 public function setDraft($user, $notrigger = 0)
666 {
667 // Protection
668 if ($this->status <= self::STATUS_DRAFT) {
669 return 0;
670 }
671
672 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
673 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
674 {
675 $this->error='Permission denied';
676 return -1;
677 }*/
678
679 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILL_UNVALIDATE');
680 }
681
689 public function cancel($user, $notrigger = 0)
690 {
691 // Protection
692 if ($this->status != self::STATUS_VALIDATED) {
693 return 0;
694 }
695
696 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
697 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
698 {
699 $this->error='Permission denied';
700 return -1;
701 }*/
702
703 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILL_CANCEL');
704 }
705
713 public function reopen($user, $notrigger = 0)
714 {
715 // Protection
716 if ($this->status != self::STATUS_CANCELED) {
717 return 0;
718 }
719
720 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
721 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
722 {
723 $this->error='Permission denied';
724 return -1;
725 }*/
726
727 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILL_REOPEN');
728 }
729
750 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
751 {
752 global $conf, $langs, $hookmanager;
753
754 if (!empty($conf->dol_no_mouse_hover)) {
755 $notooltip = 1; // Force disable tooltips
756 }
757
758 $result = '';
759
760 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skill").'</u>';
761 if (isset($this->status)) {
762 $label .= ' '.$this->getLibStatut(5);
763 }
764 $label .= '<br>';
765 $label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
766 $label .= '<br><b>'.$langs->trans('Description').':</b> '.dol_htmlentitiesbr(dolGetFirstLineOfText($this->description, 10), 1);
767
768 $url = dol_buildpath('/hrm/skill_card.php', 1).'?id='.$this->id;
769
770 if ($option != 'nolink') {
771 // Add param to save lastsearch_values or not
772 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
773 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
774 $add_save_lastsearch_values = 1;
775 }
776 if ($add_save_lastsearch_values) {
777 $url .= '&save_lastsearch_values=1';
778 }
779 }
780
781 $linkclose = '';
782 if (empty($notooltip)) {
783 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
784 $label = $langs->trans("ShowSkill");
785 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
786 }
787 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
788 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
789 } else {
790 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
791 }
792
793 if ($option == 'nolink') {
794 $linkstart = '<span';
795 } else {
796 $linkstart = '<a href="'.$url.'"';
797 }
798 $linkstart .= $linkclose.'>';
799 if ($option == 'nolink') {
800 $linkend = '</span>';
801 } else {
802 $linkend = '</a>';
803 }
804
805 $result .= $linkstart;
806
807 if (empty($this->showphoto_on_popup)) {
808 if ($withpicto) {
809 $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);
810 }
811 } else {
812 if ($withpicto) {
813 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
814
815 list($class, $module) = explode('@', $this->picto);
816 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
817 $filearray = dol_dir_list($upload_dir, "files");
818 $filename = $filearray[0]['name'];
819 if (!empty($filename)) {
820 $pospoint = strpos($filearray[0]['name'], '.');
821
822 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
823 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
824 $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>';
825 } else {
826 $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>';
827 }
828
829 $result .= '</div>';
830 } else {
831 $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);
832 }
833 }
834 }
835
836 if ($withpicto != 2) {
837 $result .= $this->label;
838 }
839
840 $result .= $linkend;
841 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
842
843 global $action, $hookmanager;
844 $hookmanager->initHooks(array('skilldao'));
845 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
846 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
847 if ($reshook > 0) {
848 $result = $hookmanager->resPrint;
849 } else {
850 $result .= $hookmanager->resPrint;
851 }
852
853 return $result;
854 }
855
862 public function getLibStatut($mode = 0)
863 {
864 return $this->LibStatut($this->status, $mode);
865 }
866
867 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
875 public function LibStatut($status, $mode = 0)
876 {
877 if (empty($status)) {
878 $status = 0;
879 }
880
881 // phpcs:enable
882 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
883 global $langs;
884 //$langs->load("hrm");
885 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
886 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
887 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
888 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
889 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
890 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
891 }
892
893 $statusType = 'status'.$status;
894 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
895 if ($status == self::STATUS_CANCELED) {
896 $statusType = 'status6';
897 }
898
899 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
900 }
901
908 public function info($id)
909 {
910 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
911 $sql .= ' fk_user_creat, fk_user_modif';
912 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
913 $sql .= ' WHERE t.rowid = '.((int) $id);
914 $result = $this->db->query($sql);
915 if ($result) {
916 if ($this->db->num_rows($result)) {
917 $obj = $this->db->fetch_object($result);
918
919 $this->id = $obj->rowid;
920
921 $this->user_creation_id = $obj->fk_user_creat;
922 $this->user_modification_id = $obj->fk_user_modif;
923 $this->date_creation = $this->db->jdate($obj->datec);
924 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
925 }
926
927 $this->db->free($result);
928 } else {
929 dol_print_error($this->db);
930 }
931 }
932
939 public function initAsSpecimen()
940 {
941 // Set here init that are not commonf fields
942 // $this->property1 = ...
943 // $this->property2 = ...
944
945 return $this->initAsSpecimenCommon();
946 }
947
953 public function getLinesArray()
954 {
955 $this->lines = array();
956
957 $objectline = new Skilldet($this->db);
958 $result = $objectline->fetchAll('ASC', 'rankorder', 0, 0, '(fk_skill:=:'.((int) $this->id).')');
959
960 if (is_numeric($result)) {
961 $this->setErrorsFromObject($objectline);
962 return $result;
963 } else {
964 $this->lines = $result;
965 return $this->lines;
966 }
967 }
968
974 public function getNextNumRef()
975 {
976 global $langs, $conf;
977 $langs->load("hrm");
978
979 if (!getDolGlobalString('hrm_SKILL_ADDON')) {
980 $conf->global->hrm_SKILL_ADDON = 'mod_skill_standard';
981 }
982
983 if (getDolGlobalString('hrm_SKILL_ADDON')) {
984 $mybool = false;
985
986 $file = getDolGlobalString('hrm_SKILL_ADDON') . ".php";
987 $classname = getDolGlobalString('hrm_SKILL_ADDON');
988
989 // Include file with class
990 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
991 foreach ($dirmodels as $reldir) {
992 $dir = dol_buildpath($reldir."core/modules/hrm/");
993
994 // Load file with numbering class (if found)
995 $mybool = ((bool) @include_once $dir.$file) || $mybool;
996 }
997
998 if ($mybool === false) {
999 dol_print_error(null, "Failed to include file ".$file);
1000 return '';
1001 }
1002
1003 if (class_exists($classname)) {
1004 $obj = new $classname();
1005 $numref = $obj->getNextValue($this);
1006
1007 if ($numref != '' && $numref != '-1') {
1008 return $numref;
1009 } else {
1010 $this->error = $obj->error;
1011 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1012 return "";
1013 }
1014 } else {
1015 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1016 return "";
1017 }
1018 } else {
1019 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1020 return "";
1021 }
1022 }
1023
1035 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1036 {
1037 global $conf, $langs;
1038
1039 $result = 0;
1040 $includedocgeneration = 0;
1041
1042 $langs->load("hrm");
1043
1044 if (!dol_strlen($modele)) {
1045 $modele = 'standard_skill';
1046
1047 if (!empty($this->model_pdf)) {
1048 $modele = $this->model_pdf;
1049 } elseif (getDolGlobalString('SKILL_ADDON_PDF')) {
1050 $modele = getDolGlobalString('SKILL_ADDON_PDF');
1051 }
1052 }
1053
1054 $modelpath = "core/modules/hrm/doc/";
1055
1056 if ($includedocgeneration && !empty($modele)) {
1057 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1058 }
1059
1060 return $result;
1061 }
1062
1067 public static function typeCodeToLabel($code)
1068 {
1069 global $langs;
1070 $result = '';
1071 switch ($code) {
1072 case 0: $result = $langs->trans("TypeKnowHow");
1073 break; //"Savoir Faire"
1074 case 1: $result = $langs->trans("TypeHowToBe");
1075 break; // "Savoir être"
1076 case 9: $result = $langs->trans("TypeKnowledge");
1077 break; //"Savoir"
1078 }
1079 return $result;
1080 }
1081
1089 public function getKanbanView($option = '', $arraydata = null)
1090 {
1091 global $selected, $langs;
1092
1093 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1094
1095 $return = '<div class="box-flex-item box-flex-grow-zero">';
1096 $return .= '<div class="info-box info-box-sm">';
1097 $return .= '<span class="info-box-icon bg-infobox-action">';
1098 $return .= img_picto('', $this->picto);
1099 $return .= '</span>';
1100 $return .= '<div class="info-box-content">';
1101 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1102 if ($selected >= 0) {
1103 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1104 }
1105 if (property_exists($this, 'skill_type')) {
1106 $return .= '<br><span class="opacitymedium">'.$langs->trans("Type").'</span>';
1107 $return .= ' : <span class="info-box-label ">'.$this->fields['skill_type']['arrayofkeyval'][$this->skill_type].'</span>';
1108 }
1109 if (property_exists($this, 'description')) {
1110 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Description").'</span> : ';
1111 $return .= '<br><span class="info-box-label ">'.(strlen($this->description) > 30 ? dol_substr($this->description, 0, 25).'...' : $this->description).'</span>';
1112 }
1113 $return .= '</div>';
1114 $return .= '</div>';
1115 $return .= '</div>';
1116 return $return;
1117 }
1118}
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:626
$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 clicable 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)
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.